0
$\begingroup$

Currently I'm trying to calculate the circuits I'm building and show that they work as intended. Somehow, my measurments do not, at all, represent my calculated expectancies. This is my circuit in qiskit:

     ┌───────────┐┌──────────┐
q_0: ┤ Ry(alpha) ├┤ Ry(beta) ├
     └───────────┘└────┬─────┘
q_1: ──────────────────■──────

Both qubits start off in the $|0\rangle$ state. So, the first calculation applies only to $q_0$, which looks like this: $$ RY(\theta) = \begin{pmatrix} \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix}\\ $$

$$ q_0 =\ RY(\theta)|0\rangle =\ \begin{pmatrix}\cos\frac{\theta}{2} \\ \sin\frac{\theta}{2}\end{pmatrix}\\ $$

After this, I have to get the tensor product of both qubits, which results in this:

$$ \begin{pmatrix}\cos\frac{\alpha}{2} \\ \sin\frac{\alpha}{2}\end{pmatrix} \otimes \begin{pmatrix}1 \\ 0\end{pmatrix} =\ \begin{pmatrix} \cos\frac{\alpha}{2} \\ 0 \\ \sin\frac{\alpha}{2} \\ 0\end{pmatrix}\\ $$

So far, so good. Now, I take the CRY-Gate and its matrix (as given here), and multiply it:

$$ \begin{pmatrix} 1 & 0 & 0 & 0 \\ 0 & 1 & 0 & 0 \\ 0 & 0 & \cos\frac{\theta}{2} & -\sin\frac{\theta}{2} \\ 0 & 0 & \sin\frac{\theta}{2} & \cos\frac{\theta}{2} \end{pmatrix} \begin{pmatrix} \cos\frac{\alpha}{2} \\ 0 \\ \sin\frac{\alpha}{2} \\ 0\end{pmatrix} =\ \begin{pmatrix} \cos\frac{\alpha}{2} \\ 0 \\ \cos\frac{\beta}{2}\sin\frac{\alpha}{2} \\ \sin\frac{\beta}{2}\sin\frac{\alpha}{2}\end{pmatrix}\\ $$

This shows that in a simulation, I have a given probability of getting either $|00\rangle$, $|10\rangle$ or $|11\rangle$ . Yet, this is what happens:

#prepare circuit
circuit = QuantumCircuit(2)
circuit.ry(Parameter('alpha'),0)
circuit.cry(Parameter('beta'),1,0)

#add parameters and measure
parameterized_circuit = qc.bind_parameters(parameters)
parameterized_circuit.measure_all()

#prepare simulation
simulator = QasmSimulator()
compiled_circuit = transpile(parameterized_circuit, simulator)

#run, get counts and visualize
job = simulator.run(compiled_circuit, shots=10000)
result = job.result()
counts = result.get_counts(parameterized_circuit)
display(plot_histogram(counts))

No matter the parameters used, I never get a single $|11\rangle$ state. For exmaple, using the parameters

[np.pi/2, 3*np.pi/4]

results in the following histogram:

[np.pi/2, 3*np.pi/4]

Somehow I am thinking that my calculations are wrong, but am not sure. Specially considering that I've done the same thing with $CRY(\theta)$ inversed (so, control qubit is $q_0$ and target is $q_1$), and the results are the same.

$\endgroup$
1
  • 2
    $\begingroup$ Maybe you should check again that making q0 the control doesn't work, because your problem is definitely that using q1 as the control means the operations does nothing because q1 is in the 0 state. $\endgroup$ Oct 27 at 21:38
2
$\begingroup$

The probabilities plot you have at the end is correct. You can see this by two ways, intuition or explicit calculation of the circuit.

1. Intuition:

The second qubit, $q_1$ start in the state $|0\rangle$ and it acts as a control. Thus, it will not change, that is, it will remain in the state $|0\rangle$. Which matches what you have in the probabilities plot. The first qubit undergoes some changes because of the $RY$ gate so hence you expect it to be in the superposition of $|0\rangle$ and $|1\rangle$, which also matches with that plot in your question.

2. Explicit Calculation:

The circuit you had in mind:

     ┌───────────┐┌──────────┐
q_0: ┤ Ry(alpha) ├┤ Ry(beta) ├
     └───────────┘└────┬─────┘
q_1: ──────────────────■──────

is actually have the form

$$ CRY_{1,0} \cdot (RY \otimes I)\cdot |00\rangle $$

Here note that

$$CRY_{1,0} = I \otimes |0\rangle\langle0| + RY \otimes |1\rangle \langle 1| = \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \cos \theta/2 & 0 & -\sin\theta/2 \\ 0 & 0 & 1 & 0\\ 0 & \sin \theta/2 & 0 & \cos \theta/2 \end{pmatrix} $$

This is different than what you had. The matrix you had is $CRY_{01}$. The controlled is the first qubit and the target is the secon qubit. Here the control qubit is the second qubit and the target is the first qubit. Now, note that

$$ \begin{pmatrix} 1 & 0 & 0 & 0\\ 0 & \cos \theta/2 & 0 & -\sin\theta/2 \\ 0 & 0 & 1 & 0\\ 0 & \sin \theta/2 & 0 & \cos \theta/2 \end{pmatrix} \begin{pmatrix} \cos\frac{\alpha}{2} \\ 0 \\ \sin\frac{\alpha}{2} \\ 0\end{pmatrix} = \begin{pmatrix} \cos\frac{\theta}{2} \\ 0 \\ \sin\frac{\theta}{2} \\ 0\end{pmatrix} = \cos\frac{\theta}{2}|00\rangle + \sin\frac{\theta}{2}|10\rangle $$

But in Qiskit, it uses little Endian, so you see $|10\rangle$ as $|01\rangle$ instead.


If you want to get the state that you had in mind, perhaps you should switch the control. That is,

     ┌─────────┐         
q_0: ┤ RY(0.5) ├────■────
     └─────────┘┌───┴───┐
q_1: ───────────┤ RY(2) ├
                └───────┘
c: 2/════════════════════
$\endgroup$
1
  • 1
    $\begingroup$ You're right, that was my intuition too. But I thought that maybe some sort of mystery was acting on my qubits :P So basically all I had was the endians mixed up which made me pick the wrong matrix. Oh well, thanks a lot! $\endgroup$
    – Redimo
    Oct 27 at 22:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.