6

I'm working through the Qiskit textbook right now, and wanted to complete part 1 of exercise 3.4, which asks me to use qiskit to produce the Bell state:

$$\frac{|01\rangle + |10\rangle}{\sqrt{2}}$$

which is equivalent to

$$\begin{bmatrix} 0 \\ \frac{1}{\sqrt2} \\ \frac{1}{\sqrt2}\\ 0 \end{bmatrix}. $$

When you apply a CNOT to this, we get:

$$\begin{bmatrix} 0 \\ 0 \\ \frac{1}{\sqrt2}\\ \frac{1}{\sqrt2} \end{bmatrix}$$

Which is just $|1\rangle\otimes |+\rangle$. However, I can't figure out how to set my qubits up in the right way.

Any tips on how to use qiskit to get that last matrix?

glS
  • 24,708
  • 5
  • 34
  • 108
aikky
  • 169
  • 4

2 Answers2

5

The circuit to prepare the state $|\psi \rangle = \dfrac{|01\rangle + |10\rangle}{\sqrt{2}} $ is as follows:

     ┌───┐          
q_0: ┤ H ├──■───────
     └───┘┌─┴─┐┌───┐
q_1: ─────┤ X ├┤ X ├
          └───┘└───┘

This can be written in matrix notation as:

\begin{align} U &= (I \otimes X)\cdot CNOT \cdot (H\otimes I) \\ &= \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \otimes \begin{pmatrix} 0 & 1 \\ 1 & 0 \end{pmatrix} \cdot \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\end{pmatrix} \cdot \dfrac{1}{\sqrt{2}}\begin{pmatrix} 1 & 1 \\ 1 & -1 \end{pmatrix} \otimes \begin{pmatrix} 1 & 0 \\ 0 & 1 \end{pmatrix} \\ &= \begin{pmatrix} 0 & 1 & 0 & 0 \\ 1 & 0 & 0 & 0 \\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\end{pmatrix} \cdot \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & 0 & 1\\ 0 & 0 & 1 & 0\end{pmatrix} \cdot \dfrac{1}{\sqrt{2}} \begin{pmatrix} 1 & 0 & 1 & 0 \\ 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0\\ 0 & 1 & 0 & 1\end{pmatrix} \\ &= \dfrac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 1 & 0 & -1 & 0\\ 0 & 1 & 0 & -1 \end{pmatrix} \end{align}

And $$ U |00\rangle =\dfrac{1}{\sqrt{2}}\begin{pmatrix} 0 & 1 & 0 & 1 \\ 1 & 0 & 1 & 0 \\ 1 & 0 & -1 & 0\\ 0 & 1 & 0 & -1 \end{pmatrix} \begin{pmatrix} 1 \\ 0 \\ 0 \\ 0 \end{pmatrix} = \dfrac{1}{\sqrt{2}} \begin{pmatrix} 0 \\ 1 \\ 1 \\ 0 \end{pmatrix} = \dfrac{|01\rangle + |10\rangle}{\sqrt{2}} $$

If you want to generate this circuit with qiskit you can do it as follows:

from qiskit import QuantumRegister, ClassicalRegister, QuantumCircuit

qreg_q = QuantumRegister(2, 'q') creg_c = ClassicalRegister(2, 'c') circuit = QuantumCircuit(qreg_q, creg_c)

circuit.h(qreg_q[0]) circuit.cx(qreg_q[0], qreg_q[1]) circuit.x(qreg_q[1])

luciano
  • 5,763
  • 1
  • 12
  • 34
KAJ226
  • 13,822
  • 2
  • 10
  • 30
  • Cheers for that @KAJ226! I wanted to clear something up about the convention that qiskit uses. Do operations translate from right to left, top to bottom? For example, you placed $⊗$ first, which is the rightmost set of qubit values. Additionally, you wrote the identity matrix first, which is $q_1$'s value. Is that the right way of thinking about this? I've been going from the left to the right. – aikky Feb 04 '21 at 03:10
  • It also looks like the convention is inconsistent with qiskit. – aikky Feb 04 '21 at 03:22
  • The reason it is in the order $(I \otimes X)\cdot CNOT \cdot (H\otimes I)$ is because you multiply this to the state $|\psi \rangle = |00\rangle$ from the left. That is: $U |\psi \rangle = (I \otimes X)\cdot CNOT \cdot (H\otimes I) |00 \rangle $ and hence the operation $ (H\otimes I) |00 \rangle $ get done first. Follow by $CNOT$ then follow by $ (I \otimes X)$. Now, it is good to note that qiskit uses little-endian for both classical bit ordering and qubit ordering. So the state $|0001\rangle$ would be $|1000\rangle$ in qiskit. – KAJ226 Feb 04 '21 at 04:06
  • That almost answers everything. The last thing I'm confused about is the order that tensor product takes. In this case, qiskit would say ($q_0 ⊗ q_1$), right? – aikky Feb 04 '21 at 04:11
  • it reads backward. – KAJ226 Feb 04 '21 at 06:14
  • How did you convert from circuit to matrix representation ? Is there a certain method to do so ? – BrockenDuck Feb 04 '21 at 08:33
2

To provide general answer, Bell states are prepared with circuit described by matrix $CNOT(H \otimes I)$. Which Bell state is returned depends on input to the circuit:

  • input $|00\rangle$ returns $\frac{1}{\sqrt{2}}(|00\rangle + |11\rangle)$
  • input $|01\rangle$ returns $\frac{1}{\sqrt{2}}(|01\rangle + |10\rangle)$
  • input $|10\rangle$ returns $\frac{1}{\sqrt{2}}(|00\rangle - |11\rangle)$
  • input $|11\rangle$ returns $\frac{1}{\sqrt{2}}(|01\rangle - |10\rangle)$

Clearly, value of the second input qubit specifies whether both output qubits will be same (the second input qubit is $|0\rangle$) or opposite (the second input qubit is $|1\rangle$). The first qubit specifies a phase - when the qubit is $|0\rangle$, the phase is 0, when it is $|1\rangle$, the phase is $\pi$ ($\mathrm{e^{i\pi}}=-1$).

Concerning the input, to obtain for example $|01\rangle$, put $X$ gate on second qubit and then apply the circuit for Bell state. Similarly for other inputs.

Martin Vesely
  • 13,891
  • 4
  • 28
  • 65