# I want to initialize any 3 qubit state in Qiskit

The state of interest is (1/sqrt(2))|000> + (1/sqrt(2))|111>. How do I initialize this state in Qiskit ? I know if I plot a histogram it will have 50% probability for |000> and 50% probability for |111>. I have no idea how to evolve it with gates yet, but I will be content with simply initializing it for now. Thank you. Will be happy if I also get bonus code for statevector_simulator, unitary_simulator, counts and plot_histogram

1. Initialize 3 qubits in 0 state: 000

2. Apply Hadamard (H) to the first one: 000 -> 000+100

3. Apply CNOT between first and second: 000+100 -> 000+110

4. Apply CNOT between first (or second) and third: 000+110 -> 000+111

The circuit you are trying to create is something like this:

You can do this in Qiskit as follow:

from qiskit import QuantumCircuit
GHZ_qc = QuantumCircuit(3)
GHZ_qc.h(0)
[GHZ_qc.cx(i,i+1) for i in range(2)]
GHZ_qc.draw()

Out[1]:
┌───┐
q_0: ┤ H ├──■───────
└───┘┌─┴─┐
q_1: ─────┤ X ├──■──
└───┘┌─┴─┐
q_2: ──────────┤ X ├
└───┘


Here's the direct way.

Make a size 8 vector (because it's 2^3qubits) filled with the corresponding amplitudes, going from |000>, |001> .. |110>, |111>. Since in ghz case only |000> and |111> share the total amplitude, fill only those.

ghz = [1/sqrt(2), 0, 0, 0, 0, 0, 0, 1/sqrt(2)]

qc = QuantumCircuit(3)

qc.initialize(ghz)

You can also initialize a subset of qubits by adding a (list of) qubit(s) parameter. Of course, the supplied vector size will have to match.

Enjoy :)