# How to design a circuit which produces the state $|\psi\rangle = \frac{1}{2}|{010}\rangle + \frac{\sqrt{3}}{2} |{101}\rangle$?

The quantum state to achieve is: $$|{\psi}\rangle= \frac{1}{2}|{010}\rangle + \frac{\sqrt{3}}{2} |{101}\rangle$$

So far I know how to produce the $$\frac{1}{2}|{010}\rangle$$ state in qiskit as follows:

qr = QuantumRegister(3, name='qreg')
qcirc = QuantumCircuit(qr)

qcirc.h(0)
qcirc.x(1)
qcirc.cx(0, 1)


I am having trouble with producing the combination of both of those states.

You can use the initialize method of a QuantumCircuit in order to create any state you want:

qc = QuantumCircuit(3)
qc.initialize(np.array([0, 0, .5, 0, 0, np.sqrt(3)/2, 0, 0]))
qc.decompose(reps=6).draw("mpl")


which gives:

However, this method does not guarantee that it will give the most optimal way of creating a quantum state. Here, we can use the structure of the Quantum state we wish to create to build an efficient circuit.

Note that if we apply an $$X$$ gate on the state we wish to create, we end up with: $$\frac12|000\rangle+\frac{\sqrt{3}}{2}|111\rangle$$ which closely looks like the well-known GHZ state. So suppose we know how to create the following state: $$\frac12|000\rangle+\frac{\sqrt{3}}{2}|100\rangle$$ We could then apply a cx(0, 1) and a cx(0, 2) to create: $$\frac12|000\rangle+\frac{\sqrt{3}}{2}|111\rangle$$ And finally, we could apply an $$X$$ gate on the second qubit, giving: $$\frac12|010\rangle+\frac{\sqrt{3}}{2}|101\rangle$$ So, it's now only a matter of creating $$\frac12|000\rangle+\frac{\sqrt{3}}{2}|100\rangle$$. Note that in this state the two last qubits are in the $$|0\rangle$$ state, so we just leave them untouched. We thus want to apply a rotation gate on the first qubit. If we write it like this: $$\frac12|0\rangle+\frac{\sqrt{3}}{2}|1\rangle=\cos\left(\frac\pi3\right)|0\rangle+\sin\left(\frac\pi3\right)|1\rangle$$ we can see that we can apply an RYGate with parameter $$\theta=\frac{2\pi}{3}$$ to create the amplitude that we want. All in all, the code would look like this:

qc = QuantumCircuit(3)
qc.ry(2 * np.pi/3, 0)
qc.cx(0, 1)
qc.cx(0, 2)
qc.x(1)
qc.draw("mpl")


which gives:

We can check that this gives us the expected state using the Statevector class:

from qiskit.quantum_info import Statevector
Statevector(qc).draw("latex")


which gives us $$\frac12|010\rangle+\frac{\sqrt{3}}{2}|101\rangle$$ as expected.

Here is one way:

This is a QASM format circuit for doing this:

OPENQASM 2.0;
include "qelib1.inc";

// Qubits: [q(0), q(1), q(2)]
qreg q[3];
creg m0[1];  // Measurement: row=0,col=11
creg m1[1];  // Measurement: row=1,col=12
creg m2[1];  // Measurement: row=2,col=13

ry(pi*-0.1668113496) q[0];
x q[1];
x q[2];
h q[0];
cx q[0],q[1];
cx q[1],q[2];
measure q[0] -> m0[0];
measure q[1] -> m1[0];
measure q[2] -> m2[0];