13
13
import tensorcircuit as tc
14
14
15
15
16
- def exp_fit (x , y ):
17
- def fit_function (x_values , y_values , function , init_params ):
18
- fitparams , _ = curve_fit (function , x_values , y_values , init_params )
19
- return fitparams
16
+ def fit_function (x_values , y_values , function , init_params ):
17
+ fitparams , _ = curve_fit (function , x_values , y_values , init_params )
18
+ return fitparams
20
19
21
- fit_params = fit_function (
22
- x , y , lambda x , A , C , T : (A * np .exp (- x / T ) + C ), [- 3 , 0 , 100 ]
23
- )
24
-
25
- _ , _ , T = fit_params
26
20
27
- return T
28
-
29
-
30
- @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
31
- def test_calib_t1 (backend ):
32
-
33
- t1 = 300
34
- t2 = 100
35
- time = 100
36
- nstep = int (4 * t1 / time )
21
+ def T1_cali (t1 , t2 , time , method , excitedstatepopulation ):
37
22
38
23
# calibrating experiments
24
+ nstep = int (4 * t1 / time )
39
25
pex = []
40
26
for i in range (nstep ):
41
27
@@ -44,38 +30,42 @@ def test_calib_t1(backend):
44
30
for _ in range (i ):
45
31
dmc .i (0 )
46
32
dmc .thermalrelaxation (
47
- 0 , t1 = t1 , t2 = t2 , time = time , method = "AUTO" , excitedstatepopulation = 0
33
+ 0 ,
34
+ t1 = t1 ,
35
+ t2 = t2 ,
36
+ time = time ,
37
+ method = method ,
38
+ excitedstatepopulation = excitedstatepopulation ,
48
39
)
49
40
50
41
val = dmc .expectation_ps (z = [0 ])
51
42
p = (1 - val ) / 2.0
52
43
pex .append (p )
53
44
54
- # data fitting
55
- x1 = np .array ([i * time for i in range (nstep )])
56
- y1 = np .array (np .real (pex ))
45
+ timelist = np .array ([i * time for i in range (nstep )])
46
+ measurement = np .array (np .real (pex ))
57
47
58
- T1 = exp_fit (x1 , y1 )
59
- np .testing .assert_allclose (t1 , T1 , atol = 1e-1 )
48
+ return measurement , timelist
60
49
61
50
62
- @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
63
- def test_calib_t2 (backend ):
51
+ def T2_cali (t1 , t2 , time , method , excitedstatepopulation ):
64
52
65
- pex = []
66
- t1 = 300
67
- t2 = 280
68
- time = 50
53
+ # calibrating experiments
69
54
nstep = int (4 * t2 / time )
70
-
55
+ pex = []
71
56
for i in range (nstep ):
72
57
73
58
dmc = tc .DMCircuit (1 )
74
59
dmc .h (0 )
75
60
for _ in range (0 , i ):
76
61
dmc .i (0 )
77
62
dmc .thermalrelaxation (
78
- 0 , t1 = t1 , t2 = t2 , time = time , method = "AUTO" , excitedstatepopulation = 0
63
+ 0 ,
64
+ t1 = t1 ,
65
+ t2 = t2 ,
66
+ time = time ,
67
+ method = method ,
68
+ excitedstatepopulation = excitedstatepopulation ,
79
69
)
80
70
# dmc.rz(0,theta = i*np.pi/1.5)
81
71
dmc .h (0 )
@@ -84,44 +74,81 @@ def test_calib_t2(backend):
84
74
p = (1 - val ) / 2.0
85
75
pex .append (p )
86
76
87
- # data fitting
88
- x1 = np .array ([i * time for i in range (nstep )])
89
- y1 = np .array (np .real (pex ))
90
-
91
- T2 = exp_fit (x1 , y1 )
92
- np .testing .assert_allclose (t2 , T2 , atol = 1e-1 )
77
+ timelist = np .array ([i * time for i in range (nstep )])
78
+ measurement = np .array (np .real (pex ))
93
79
80
+ return measurement , timelist
94
81
95
- @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
96
- def test_calib_dep (backend ):
97
82
83
+ def dep_cali (dep , nqubit ):
98
84
pex = []
99
- pz = 0.02
100
85
nstep = 40
101
86
for i in range (nstep ):
102
87
103
88
dmc = tc .DMCircuit (1 )
104
89
dmc .x (0 )
105
90
for _ in range (i ):
106
91
dmc .s (0 )
107
- dmc .generaldepolarizing (0 , p = pz , num_qubits = 1 )
92
+ dmc .generaldepolarizing (0 , p = dep , num_qubits = nqubit )
108
93
109
94
val = dmc .expectation_ps (z = [0 ])
110
95
p = (1 - val ) / 2.0
111
96
if i % 2 == 0 :
112
97
pex .append (p )
113
98
114
- # data fitting
115
- x1 = np .array ([i for i in range (0 , nstep , 2 )])
116
- y1 = np .array (np .real (pex ))
99
+ timelist = np .array ([i for i in range (0 , nstep , 2 )])
100
+ measurement = np .array (np .real (pex ))
101
+
102
+ return measurement , timelist
103
+
104
+
105
+ @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
106
+ def test_cali_t1 (backend ):
107
+ t1 = 300
108
+ t2 = 100
109
+ time = 100
110
+ method = "AUTO"
111
+ excitedstatepopulation = 0
112
+ measurement , timelist = T1_cali (t1 , t2 , time , method , excitedstatepopulation )
113
+
114
+ fit_params = fit_function (
115
+ timelist , measurement , lambda x , A , C , T : (A * np .exp (- x / T ) + C ), [- 3 , 0 , 100 ]
116
+ )
117
+
118
+ _ , _ , T = fit_params
119
+
120
+ np .testing .assert_allclose (t1 , T , atol = 1e-1 )
121
+
122
+
123
+ @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
124
+ def test_cali_t2 (backend ):
125
+ t1 = 300
126
+ t2 = 280
127
+ time = 50
128
+ method = "AUTO"
129
+ excitedstatepopulation = 0
130
+ measurement , timelist = T2_cali (t1 , t2 , time , method , excitedstatepopulation )
117
131
118
- def fit_function (x_values , y_values , function , init_params ):
119
- fitparams , _ = curve_fit (function , x_values , y_values , init_params )
120
- return fitparams
132
+ fit_params = fit_function (
133
+ timelist , measurement , lambda x , A , C , T : (A * np .exp (- x / T ) + C ), [- 3 , 0 , 100 ]
134
+ )
135
+
136
+ _ , _ , T = fit_params
121
137
122
- fit_params = fit_function (x1 , y1 , lambda x , A , B , C : (A * B ** x + C ), [- 0 , 0 , 0 ])
138
+ np .testing .assert_allclose (t2 , T , atol = 1e-1 )
139
+
140
+
141
+ @pytest .mark .parametrize ("backend" , [lf ("npb" ), lf ("tfb" ), lf ("jaxb" )])
142
+ def test_cali_dep (backend ):
143
+ dep = 0.02
144
+ nqubit = 1
145
+ measurement , timelist = dep_cali (dep , nqubit )
146
+
147
+ fit_params = fit_function (
148
+ timelist , measurement , lambda x , A , B , C : (A * B ** x + C ), [- 0 , 0 , 0 ]
149
+ )
123
150
124
151
_ , B , _ = fit_params
125
- pz1 = (1 - B ) / 4.0
152
+ dep1 = (1 - B ) / 4.0 ** nqubit
126
153
127
- np .testing .assert_allclose (pz , pz1 , atol = 1e-1 )
154
+ np .testing .assert_allclose (dep , dep1 , atol = 1e-1 )
0 commit comments