-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathq-cam30r.py
78 lines (57 loc) · 2 KB
/
q-cam30r.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# q-cam rule30 by Gigagulin 15th Aug 2020
from blueqat import Circuit
import numpy as np
import qcam
# -------- Setting ------------------------------------------------------------------
N=8 # number of cells
R=3 # number of registers
initial_a=np.array([0,0,0,0,0.85,0,0,0],dtype='float') # initial probability distribution
max_step=200 # maximum steps
stepdist_a=np.array([[0]*N]*max_step,dtype='float') # [step-number,cell-number]
probability_a=np.array([0]*N,dtype='float')
stepdist_a[0,0:N]=initial_a[0:N]
stdev_a=np.array([0]*max_step,dtype='float')
Reg0sb=0 # start qubit number of Reg0
Reg1sb=N # start qubit number of Reg1
Reg2sb=N*2 # start qubit number of Reg2
Reg3sb=N*3 # start qubit number of Reg3
Reg0lb=N-1 # last qubit number of Reg0
Reg1lb=N*2-1 # last qubit number of Reg1
Reg2lb=N*3-1 # last qubit number of Reg2
Reg3lb=N*4-1 # last qubit number of Reg3
# -------- Q-Process -----------------------------------------------------------------------
def qproc():
for i in range(N-1):
c.ccx[i, 1+i, Reg1sb+i]
c.ccx[Reg0lb,Reg0sb,Reg1lb]
for i in range(N):
c.cx[i, Reg2sb+i]
for i in range(N-1):
c.cx[Reg2sb+i,i+1]
c.cx[Reg2lb,Reg0sb]
for i in range(N-1):
c.cx[Reg2sb+i+1, i]
c.cx[Reg2sb,Reg0lb]
for i in range(N):
c.cx[Reg1sb+i,i] # error correction
return
# -------- Main Body --------------------------------------------------------------
pstep=0
ret='y'
while ret=='y':
pstep+=1
c=Circuit(N*R)
pinitial_a=probability_a
if pstep==1:
pinitial_a=initial_a
qcam.propinit(N,c,pinitial_a)
qproc()
master_a=np.array(c.run())
num,vector_a,prob_a=qcam.qvextract(N,R,1,master_a)
stdev,probability_a=qcam.qcalcd(N, num,vector_a,prob_a)
qcam.qcresultout(N, pstep, num,pinitial_a,vector_a,prob_a,stdev,probability_a)
stepdist_a[pstep,0:N]=probability_a[0:N]
stdev_a[pstep]=stdev
ret=input(' NEXT(Y/N)?')
qcam.qcfinal(N, pstep, initial_a ,stepdist_a, stdev_a )
qcam.qcamplot(N, pstep, stepdist_a)