Skip to content
Permalink
master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
#Quantum Simulator
#We want to generate two files:
#Alice
# Alice intensity choice, Alice Basis Choice, Alice Element Choice
# Bob
# Bob Basis Choice, Bob Measurement Result
# Where Alice's choices are random, and Bob's Measurement Result is as follows, based on alice's choice:
# With Pr(Vacuum)
# vacum hjjhbbbbbbbbbbbbbbbbbbbn
# With Pr(1-EQ(11 paper he sent me)*(1/2*Pr(Double) + 1-(pr(double))*Overall Gain) (eq10)
#check to see that we get ~150 clicks from vacuums, 10^5 clicks from decoy and 10^6 clicks from signal ,m
import numpy as np
import math
from config import *
VAC = 3
DUB = 2
def Alice_Choices(int_pdf, basis_pdf):
intensity = np.random.choice(int_pdf[0],1, p=int_pdf[1])[0]
basis = np.random.choice(basis_pdf[0],1, p=basis_pdf[1])[0]
element = np.random.choice([0,1],1, [.5,.5])[0]
return [intensity, basis, element]
def Bob_Results(alice_choices, basis_pdf, Bob_params):
alice_int = alice_choices[0]
alice_basis = alice_choices[1]
alice_element = alice_choices[2]
Y0 = Bob_params[0]
Nu = Bob_params[1]
e0 = Bob_params[2]
ed = Bob_params[3]
Double = Bob_params[4]
noise = Bob_params[5]
bob_basis = np.random.choice(basis_pdf[0], 1, p=basis_pdf[1])[0]
gain = Y0+1-math.exp(-1*alice_int*Nu) #prob of a detection = Y0+1 - e^-(nu*mu)
detection = np.random.choice([True, False], 1, p=[gain, 1-gain])[0]
#if it is a detection and there is not a double click, add a noise paramater
if detection:
double_occ = np.random.choice([True, False], 1, p=[Double, 1-Double])[0]
if double_occ:
result = DUB
else:
if bob_basis == alice_basis:
QBER = e0*Y0+ed*(1-math.exp(-1*alice_int*Nu)) if not noise else noise
result = np.random.choice([alice_element, (alice_element + 1)%2], 1,p=[1-QBER, QBER])[0]
else:
result = np.random.choice([alice_element, (alice_element + 1)%2],1, p=[.5, .5])[0]
else:
result = VAC
return [bob_basis, result]
def main_loop():
#Alice Params
# mu1 vacc, mu2 decoy, mu3 signal intensities
# pi is probability of mui being chosen
# pza = .5
# bases = ([0,1], [pza, 1-pza])
#Alice choice
alice_choices = Alice_Choices(intensities, bases)
#Bob Params
# #
# alpha = .15
# length = 1
# tAB = 10 ** -((alpha*length)/10)
# eta_det = .1
# t_bob = .1
# eta_bob = t_bob*eta_det
# noise = .05
# Y0 = 1e-5
# eta = tAB*eta_bob #could precompute nui (and this is eq 5 if we want to further paramaterize)
# e0 = .5
# edetect = 1e-3
# pdouble = 1e-3
# bob_params = [Y0, eta, e0, edetect, pdouble, noise]
# pzb = .5
# bob_bases = [[0,1],[pzb, 1-pzb]]
bob_results = Bob_Results(alice_choices, bob_bases, bob_params)
#print("Alice: " + str(alice_choices))
#print("Bob: " + str([ ' ' ]+bob_results))
return alice_choices, bob_results
# mu1, mu2, mu3 = .0007, .1, .4
# p3 = .6
# p2 = .2
# p1 = 1-p2-p3
# intensities = ([mu1,mu2,mu3], [p1,p2,p3])
# N = int(1e9)
with open("bob_data.csv", "w+") as bob:
with open("alice_data.csv", "w+") as alice:
with open("combined_data.csv", "w+") as comb:
alice.write("B, Y, Mu\n")
bob.write("B, Y\n")
comb.write("Ba, Bb, Ya, Yb, Mu\n")
i = 0
vac = [0,0,0]
error = [0,0,0]
int_count = [0,0,0]
corr = [0,0,0]
dub = [0,0,0]
click = [0,0,0]
while(i<=N):
a,b = main_loop()
alice.write("{}, {}, {}\n".format(a[1], a[2], a[0]))
bob.write("{}, {}\n".format(b[0],b[1]))
comb.write("{}, {}, {}, {}, {}\n".format(a[1], b[0], a[2], b[1], a[0]))
#Stats:
#Vac on each
#Error on each
i+=1
int_count[intensities[0].index(a[0])]+=1
if b[1] == VAC:
vac[intensities[0].index(a[0])]+=1
else:
click[intensities[0].index(a[0])]+=1
if b[1] == DUB:
dub[intensities[0].index(a[0])]+=1
if b[0] == a[1] and b[1]!=VAC and b[1]!=a[2]:
error[intensities[0].index(a[0])]+=1
if b[0] == a[1] and b[1]==a[2]:
corr[intensities[0].index(a[0])]+=1
if i % 5000 == 0:
print("{} rounds completed".format(i))
print("Intensities: " + str(intensities[0]))
print("Int Counts: " + str(int_count))
print("Vac Counts: " + str([float(v) for v in vac]))
print("Click Counts: " + str([float(v) for v in click]))
print("Dubl Counts: " + str([float(d) for d in dub]))
print("Corr Counts: " + str([float(c) for c in corr]))
print("Error Counts: " + str([float(e) for e in error]))
bob.write("\nend\n")
alice.write("\nend\n")
comb.write("\nend\n")
comb.write("\n{} rounds completed".format(i))
comb.write("\nIntensities: " + str(intensities[0]))
comb.write("\nIntensity p's: " + str(intensities[1]))
comb.write("\nInt Counts: " + str(int_count))
comb.write("\nVac Counts: " + str([float(v) for v in vac]))
comb.write("\nClick Counts: " + str([float(v) for v in click]))
comb.write("\nDub Counts: " + str([float(d) for d in dub]))
comb.write("\nCorr Counts: " + str([float(c) for c in corr]))
comb.write("\nError Counts: " + str([float(e) for e in error]))