Measurement simulation
A way to simulate data from measurements of a specific quantum state.
Start with standard imports:
import matplotlib.pyplot as plt
from numpy import sqrt,pi,cos,sin,arange,random,real,imag
from qutip import *
%matplotlib inlineDefine several standard states, these are photon polarization states:
H = Qobj([[1],[0]])
V = Qobj([[0],[1]])
P45 = Qobj([[1/sqrt(2)],[1/sqrt(2)]])
M45 = Qobj([[1/sqrt(2)],[-1/sqrt(2)]])
R = Qobj([[1/sqrt(2)],[-1j/sqrt(2)]])
L = Qobj([[1/sqrt(2)],[1j/sqrt(2)]])# Define the Phv measurement operator:
Phv = H*H.dag() - V*V.dag()
PhvLoading...
Define a quantum state:
psi = 1/sqrt(5)*H + 2/sqrt(5)*V
psiLoading...
# The function to generate a mock data set:
def simulateData(state,oper,size=10000):
"""Generate a simulated data set given a state and measurement operator.
state -> the prepared state
oper -> the measurement operator
Example:
H = Qobj([[1],[0]])
V = Qobj([[0],[1]])
psi = 1/sqrt(5)*H + 2/sqrt(5)*V
Phv = H*H.dag() - V*V.dag()
data = simulateData(psi,Phv)
will generate 10000 values in the data array that obey the probability defined in the state.
"""
A = basis(2,0)
B = basis(2,1)
allowed_results = [A.dag()*oper*A, B.dag()*oper*B]
probability_amps = [A.dag()*state, B.dag()*state]
pvals = [abs(pa.conjugate()*pa) for pa in probability_amps]
data = random.choice(allowed_results,size=size,p=pvals)
return datadata = simulateData(psi,Phv)print("Variance: ",data.var())
print("Mean: ",data.mean())Variance: 0.6523718399999999
Mean: (-0.5896+0j)
plt.hist(real(data))(array([7948., 0., 0., 0., 0., 0., 0., 0., 0.,
2052.]),
array([-1. , -0.8, -0.6, -0.4, -0.2, 0. , 0.2, 0.4, 0.6, 0.8, 1. ]),
<BarContainer object of 10 artists>)