3
$\begingroup$

I want to construct the following state of a qubit using a quantum circuit: $\frac{-|0\rangle + |1\rangle}{\sqrt{2}}$

When I use the following qiskit code in Python:

q = QuantumRegister(1)
c = ClassicalRegister(1)
circuit = QuantumCircuit(q, c)
circuit.x(q[0])
circuit.z(q[0])
circuit.h(q[0])
backend = BasicAer.get_backend('statevector_simulator')
job = execute(circuit, backend)
amplitudes = job.result().get_statevector(circuit)
print(amplitudes)

I get [ 0.70710678+0.00000000e+00j -0.70710678+8.65956056e-17j]. When I remove the Pauli-Z gate I get: [ 0.70710678+0.00000000e+00j -0.70710678+8.65956056e-17j], i.e. the same result.

However, using Quirk I get the expected output. With the IBM Quantum Experience, I'm not sure. I get [ -0.707+0j, 0.707+0j ] and it says 'The qubit 0 is the one that is furthest to the right on the state.' So I guess it's also not the correct result.

I am using qiskit==0.15.0 and qiskit-aqua==0.6.4, which I updated after having this problem in an older version, too.

I also tested the following circuit:

# setup the circuit as before
circuit.x(q[0])
circuit.z(q[0])
# get and print amplitudes

Which results in [ 0.+0.0000000e+00j -1.+1.2246468e-16j], as I had expected.

Thus I am guessing, that I miss something. Can anyone explain this behavior?

$\endgroup$
1
  • $\begingroup$ Qubit 0 does not mean the one in the |0> state, it means the 1st qubit (we count them from 0) so the result [-0.7, 0.7] is the same as the state you described. The order the coefficient are in is simply numerical order, so the 1st number is the 1st coefficient, 2nd is the 2nd and so on if you have more qubits. $\endgroup$
    – met927
    Commented Feb 11, 2020 at 10:23

1 Answer 1

4
$\begingroup$

Generally, quantum states are determined up to a phase - i.e. up to multiplication by scalar. So $\frac{\left|0\right\rangle -\left|1\right\rangle }{\sqrt{2}},\frac{-\left|0\right\rangle +\left|1\right\rangle }{\sqrt{2}}$ are essentially the same state.

It is a good question how the statevector simulator chooses to normalize its statevector representation.

$\endgroup$
3
  • $\begingroup$ Ok, I can understand this. But I also would like to know, how it works internally and what the purpose of this simulator is. I expected the exact amplitudes. Can someone point us maybe to further resources/documentation? $\endgroup$ Commented Feb 11, 2020 at 14:47
  • 2
    $\begingroup$ What happens in practice is that the qiskit transpiler identifies a circuit optimization and changes the circuit accordingly, since the result is correct. But you can disable all optimizations with the relevant parameter: job = execute(circuit, backend, optimization_level=0). This will result in the amplitudes you're interested in. $\endgroup$
    – Gadi A
    Commented Feb 11, 2020 at 20:57
  • $\begingroup$ Also, as far as I could understand from the Aer and BasicAer code, the statevector simulator uses no normalizations; so the behavior here is a result of the transpiler optimizations alone. $\endgroup$
    – Gadi A
    Commented Feb 11, 2020 at 20:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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