# Normalization of the quantum state in Cirq

My understanding, for instance from this youtube video, is the following:
Assuming a state $$\psi = \alpha |0\rangle + \beta |1\rangle$$, where $$\alpha$$ and $$\beta$$ can be complex. I believe any state is always normalized, so that $$|\alpha|^2 + |\beta|^2 = 1$$. The probabilities can be calculated as follows: $$P_0 = |\alpha|^2$$ and $$P_1 = |\beta|^2$$.

I am currently switching from Qiskit to Cirq. In Cirq, I simulate a simple 3-qubit circuit (see code below). I get the following state:

[0.34538722-0.7061969j  0.29214734-0.14894447j 0.29214737-0.14894448j
0.13474798+0.02354215j 0.29214734-0.14894444j 0.13474798+0.02354215j
0.134748  +0.02354216j 0.03903516+0.04161799j]


When adding all the squares of the real components, I end up with 0.4313373551216718. This is confusing me, as this appears to be non-normalized.

My question: Why does this not add up to 1?

Minimal example:

import cirq
import sympy
import numpy as np
import math

# qubits
q = cirq.GridQubit.rect(1, 3)
q_pi = np.pi/4 # quarter_py

# Create a circuit on these qubits using the parameters you created above.
circuit = cirq.Circuit(
cirq.rx(0.1).on(q), cirq.rx(0.1).on(q), cirq.rx(0.1).on(q),
cirq.ry(q_pi).on(q), cirq.ry(q_pi).on(q), cirq.ry(q_pi).on(q),
cirq.rz(q_pi).on(q), cirq.rz(q_pi).on(q), cirq.rz(q_pi).on(q))

simulator = cirq.Simulator()
results = simulator.simulate(program=circuit, param_resolver=resolver, qubit_order=q).final_state
print(results)

print(np.sum([math.pow(x.real,2) for x in results]))


You say "I believe any state is always normalized, so that $$|\alpha|^2 + |\beta|^2 = 1$$", but you don't apply this to your calculation. The summation of squares of the absolute values is what gets the appropriate answer. For a single qubit system, $$|\psi\rangle = \alpha|0\rangle + \beta|1\rangle$$ and $$|\alpha|^2 + |\beta|^2 = 1$$. For a multiqubit system (3 in your case), $$|\psi\rangle = \alpha_{000}|000\rangle + \alpha_{001}|001\rangle ... + \alpha_{111}|111\rangle$$ and $$|\alpha_{000}|^2 + |\alpha_{001}|^2 + ... + |\alpha_{111}|^2 = 1$$. The following will give you what you want.

import cirq
import sympy
import numpy as np
import math

# qubits
q = cirq.GridQubit.rect(1, 3)
q_pi = np.pi/4 # quarter_py
# Create a circuit on these qubits using the parameters you created above.
circuit = cirq.Circuit(
cirq.rx(0.1).on(q), cirq.rx(0.1).on(q), cirq.rx(0.1).on(q),
cirq.ry(q_pi).on(q), cirq.ry(q_pi).on(q), cirq.ry(q_pi).on(q),
cirq.rz(q_pi).on(q), cirq.rz(q_pi).on(q), cirq.rz(q_pi).on(q))

simulator = cirq.Simulator()
results = simulator.simulate(program=circuit, qubit_order=q).final_state
results_abs = map(abs, results)
print(np.sum([math.pow(x,2) for x in results_abs])) # prints 0.9999995465139359 which is ~=1


The answer from Victory Omole is correct. Some additional background on my mistake: I did not take the square of the absolute value of the complex numbers, but I took the square of the real component of the complex numbers. My error is explained well here. The real component of a complex number $$a + bi$$ is $$a$$. The absolute value of a complex number $$a + bi$$ is $$\sqrt(a^2 + b^2)$$. As pointed out, this is the difference between x.real and abs(x) in python.