Generate the state $\frac{-|0\rangle + |1\rangle}{\sqrt{2}}$ with qiskit: problem with Pauli-Z behavior

3

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?

Daniel Müssig

Posted 2020-02-11T10:12:09.320

Reputation: 187

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. – met927 – 2020-02-11T10:23:05.710

Answers

4

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.

Gadi A

Posted 2020-02-11T10:12:09.320

Reputation: 263

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? – Daniel Müssig – 2020-02-11T14:47:54.453

2What 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. – Gadi A – 2020-02-11T20:57:26.863

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. – Gadi A – 2020-02-11T20:58:48.420