0
$\begingroup$

I tried to test the Bitflip code using Qiskit. So, see my code below, build the circuit and initialised the first qubit in the state $\biggl[ \frac{1}{\sqrt{3}}, \sqrt{\frac{2}{3}} \biggr]$.

import matplotlib.pyplot as plt
import math  
from qiskit import *
 
 
circuit = QuantumCircuit(3)
 
initial_state = [1/math.sqrt(3), math.sqrt(2/3)]
circuit.initialize(initial_state, 0)
 
circuit.cnot(0, 1) circuit.cnot(0, 2)
 
circuit.barrier() 
circuit.x(0)
circuit.id(1)
circuit.id(2)
circuit.barrier()
 
circuit.cnot(0, 1) circuit.cnot(0, 2)
 
circuit.toffoli(2, 1, 0)
 
 
circuit.draw(output='mpl')
plt.show()
     
backend = Aer.get_backend('statevector_simulator')
job = execute(circuit, backend)
result = job.result()
output_state = result.get_statevector(circuit, decimals=3)
print(output_state.data)

However, when I run this code I get the following:

        [0.   +0.j 0.   +0.j 0.   +0.j 0.   +0.j 0.   +0.j 0.   +0.j 0.577+0.j
 0.816+0.j]

I do not understand why "0.577+0.j 0.816+0.j" is not at the start of this vector. Could you please explain this to me?

$\endgroup$

1 Answer 1

2
$\begingroup$

If your circuit contains the first operation only:

circuit.initialize(initial_state, 0)

then the output state would be $$0.577∣000⟩+0.816∣001⟩$$ and you will get 0.577 and 0.816 as the first two components in the vector.

However, the remaining operations in the circuit change the state of second and third qubits to be $|11\rangle$. That is, the output state is

$$0.577∣110⟩+0.816∣111⟩$$ which makes 0.577 and 0.816 the 7th and 8th components in the vector.

$\endgroup$

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.