Quantum A Or B?
Probabilistic Programming on a quantum computer in practice
Do you want to get started with Quantum Machine Learning? Have a look at Hands-On Quantum Machine Learning With Python.
Quantum computing is a tool for statistical modeling. As such, working with probabilistic variables is your daily business.
Yet, it has its specific way of working that is sometimes hard to get used to. Therefore, today, I’d like to present a small exercise. Suppose you have two random events, A and B. A occurs with a probability of 40%, and B with a probability of 60%. So, we can say p(A) = 40% and p(B) = 60%. Moreover, both events co-occur with a probability of 20%. Thus p(A AND B) = 20%. As a result, the probability of either event must be 80% (p(A OR B) = 80%).
But how do we model this in a quantum circuit in Qiskit — IBM’s quantum development kit?
So, let’s start with modeling the two marginal probabilities.
from qiskit import QuantumCircuit, Aer, execute
from qiskit import ClassicalRegister, QuantumRegister
from qiskit.visualization import plot_histogram
from math import asin, sqrt
def prob_to_angle(prob):
# Converts a given P(psi) value into an equivalent theta value.
return 2*asin(sqrt(prob))
# The marginal probability of A
p_a = 0.4
# the marginal…