Applying the Prior
Learn how we can apply the prior.
The overlap when applying the prior twice
# Specify the prior probability and the modifierprior = 0.4modifier = 1.2qc = QuantumCircuit(4)# Apply prior to qubit 0qc.ry(prob_to_angle(prior), 0)# Apply prior to qubit 1qc.ry(prob_to_angle(prior), 1)run_circuit(qc)
This problem originated when we applied the prior probability for the second time. We aimed at two states, each representing the prior. When we look at the result, we can see that, in fact, the probability of measuring qubit 0 as 1
is 0.4
(the prior), and the probability of measuring qubit 1 as 1
is 0.4
, too. also, see that these probabilities are not independent of each other, but they overlap in the state .
When applying the prior to qubit 1, we need to leave the states where qubit 0 is 1
untouched.
Let’s take a look.
Applying the prior to qubit 1 from the remainder
# Specify the prior probability and the modifierprior = 0.4modifier = 1.2qc = QuantumCircuit(4)# Apply prior to qubit 0qc.ry(prob_to_angle(prior), 0)# Apply prior to qubit 1qc.x(0)qc.cry(prob_to_angle(prior/(1-prior)), 0, 1)qc.x(0)run_circuit(qc)
Three lines do the trick:
qc.x(0)qc.cry(prob_to_angle(prior/(1-prior)), 0, 1)qc.x(0)
Let’s go through these lines step by step. In the first step, we apply the NOT-gate to qubit 0. It switches the probabilities of the states where qubit 0 is 0
with those where qubit 0 is 1
.
We set the prior (0.4
) as the probability of measuring qubit 0 as 1
. The NOT-gate reverses this. Now, we have the probability of 0.4
of measuring qubit 0 as 0
.
This also means we measure the remainder (0.6
) when qubit 0 is 1
. Simply put, the NOT-gate is our way of saying: “Let’s proceed to work with the remainder, not the prior.”
This is the preparation for our next step. The controlled -gate.
qc.cry(prob_to_angle(prior/(1-prior)), 0, 1)
We only apply a rotation of qubit 1 when qubit 0 is 1
. This is the case only for ...