3
$\begingroup$

I'm using qiskit with the online IBM Quantum Lab and when I run the following code

from qiskit import QuantumCircuit, Aer, execute
from qiskit.visualization import plot_bloch_multivector

qc = QuantumCircuit(1) 

qc.h(0)
qc.h(0)
qc.h(0)

out = execute(qc,Aer.get_backend('statevector_simulator')).result().get_statevector()
print(out)
plot_bloch_multivector(out)

... it results in the following state vector for the qubit:

[0.70710678+0.00000000e+00j 0.70710678+1.57009246e-16j]

As you can see there's a very small imaginary component in the |1> amplitude.

These imaginary values pop up often with qiskit, such as:

qc.x(0)
qc.h(0)
--> [ 0.70710678+0.00000000e+00j -0.70710678+8.65956056e-17j]

or even very small non-imaginary numbers, such as:

qc.x(0)
qc.h(0)
qc.h(0)
--> [6.123234e-17+0.00000000e+00j 1.000000e+00-2.22044605e-16j]

Is this something unique to quantum mechanics/computing that actually has practical consequences when doing computation, or perhaps simply a quirk of Python's scientific notation implementation.

$\endgroup$
1
  • 5
    $\begingroup$ These are just precision errors. The calculations are using doubles, and $\frac{1}{\sqrt{2}}$ has no exact representation as a double. $\endgroup$ – Jonathan Trousdale Apr 29 at 17:33
3
$\begingroup$

This is just a quirk of how complex numbers are implemented in Python/Numpy, etc. At the end of the day, these are represented as floating-point numbers within the target simulator. These are then transformed via various mathematical operations to implement the simulation and this eventually leads to an accumulation of round off error. For all intents and purposes, e-16 is zero, but a computer doesn't know that.

$\endgroup$
1
  • 1
    $\begingroup$ That's why the real parts are imprecise, but how are nonzero imaginary parts creeping in? The initial state vector and the gates are purely real, and the sum and product of complex numbers with exactly-zero imaginary parts have exactly zero imaginary part, even by IEEE rules. $\endgroup$ – benrg Apr 29 at 20:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.