The Controlled RY Gate
Learn how we can implement the controlled RY gate.
We'll cover the following...
A controlled ‐gate
Let’s look at the code.
# Specify the marginal probabilitiesevent_a = 0.4event_b = 0.8qc = QuantumCircuit(4)# Set qubit to priorqc.ry(prob_to_angle(event_a), 0)# Apply half of the modifierqc.ry(prob_to_angle(event_b)/2, 1)# entangle qubits 0 and 1qc.cx(0,1)# Apply the other half of the modifierqc.ry(-prob_to_angle(event_b)/2, 1)# unentganle qubits 0 and 1qc.cx(0,1)run_circuit(qc)
The result shows a probability of 0.32 for measuring qubit 1 as 1
. We only have to measure a single qubit to get the joint probability that we’re looking for.
But how does it work?
Like before, we apply the marginal probability of event in line 8. Next, we apply half of the marginal probability of event . The following figure shows the state that the system would have if we stopped here.
The resulting probabilities are quite a mess. But what we can see is that we split the states where qubit 0 is 0 into two parts: the states 0000 and 0010. We did the same for the states where qubit 0 is 1. Next, in line 14, we apply the CNOT-gate. Let’s see what it does.
The CNOT-gate does not change the probability values, but it switches the states that have these probabilities.
The states and keep their probabilities because the CNOT-gate does not do anything if the control qubit (here, the control qubit is qubit 0) is 0
. By contrast, the states and ...