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

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)
circuit.z(q)
circuit.h(q)
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)
circuit.z(q)
# 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?

• 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. Feb 11, 2020 at 10:23

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.
• 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. Feb 11, 2020 at 20:57