Skip to content

Commit 354ef45

Browse files
author
v_anyuhe
committed
rabi
1 parent a57c36f commit 354ef45

File tree

1 file changed

+65
-21
lines changed

1 file changed

+65
-21
lines changed

experiments/rabi.py

Lines changed: 65 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
import os
3+
import matplotlib.pyplot as plt
34

45
# Add the directory containing your module to Python's search path
56
module_path = ".."
@@ -15,34 +16,19 @@
1516
ds = list_devices()
1617
print(ds)
1718

18-
def test_parametric_waveform():
19+
def test_parametric_waveform(t):
1920
qc = Circuit(2)
2021

2122
param0 = Param("a")
2223
param1 = Param("b")
2324

2425
builder = qc.calibrate("my_gate", [param0, param1])
2526
builder.new_frame("f0", param0)
26-
builder.play("f0", waveforms.CosineDrag(10, 0.2, "0.5*PI", 0.01))
27-
builder.new_frame("f1", param1)
28-
builder.play("f1", waveforms.CosineDrag(20, 0.01, "0", 0))
27+
builder.play("f0", waveforms.CosineDrag(t, 0.2, 0.0, 0.01))
28+
builder.new_frame("f1", param0)
29+
builder.play("f1", waveforms.CosineDrag(t, 0.2, 0.0, 0.01))
2930
builder.build()
3031

31-
tqasm_code = qc.to_tqasm()
32-
tqasm_code = tqasm_code + '\nmygate q[0], q[1]'
33-
print(tqasm_code)
34-
35-
assert "TQASM 0.2;" in tqasm_code
36-
assert "defcal my_gate a, b" in tqasm_code
37-
assert "frame f0 = newframe(a);" in tqasm_code
38-
assert "play(f0, cosine_drag(10, 0.2, 0.5*PI, 0.01));" in tqasm_code
39-
assert "frame f1 = newframe(b);" in tqasm_code
40-
assert "play(f1, cosine_drag(20, 0.01, 0, 0));" in tqasm_code
41-
assert re.search(r"defcal my_gate [^\)]* \s*\{", tqasm_code)
42-
43-
44-
#tc.cloud.apis.set_token("xu1LTrkf0nP6sI8oh.bDPdk35RlOQZYy9hQPU6jK2J4d5AdINAOszCNPxTNGZ3-opBPhWcLcruYuSrvX8is1D9tKgw-O4Zg.Qf7fLp83AtSPP19jD6Na4piICkygomdfyxIjzhO6Zu-s5hgBu2709ZW=")
45-
#tc.cloud.apis.set_provider("tencent")
4632
device_name = "tianji_m2"
4733
d = get_device(device_name)
4834
t = submit_task(
@@ -53,7 +39,65 @@ def test_parametric_waveform():
5339
enable_qos_qubit_mapping=False,
5440
)
5541
rf = t.results()
56-
print(rf)
42+
return rf
43+
44+
data = {
45+
'00': [],
46+
'01': [],
47+
'10': [],
48+
'11': []
49+
}
50+
for i in range(1,5):
51+
result = test_parametric_waveform(i)
52+
print(i, result['00'], result['01'], result['10'], result['11'])
53+
54+
for key in data:
55+
data[key].append(result[key])
56+
57+
58+
plt.figure(figsize=(10, 6))
59+
60+
colors = ['blue', 'green', 'red', 'purple']
61+
marker_size = 4
62+
63+
# for idx, (state, values) in enumerate(data.items()):
64+
# plt.plot(
65+
# range(1, 5),
66+
# values,
67+
# marker='o',
68+
# markersize=marker_size,
69+
# linestyle='-',
70+
# linewidth=1.2,
71+
# color=colors[idx],
72+
# label=state
73+
# )
74+
75+
# plt.xlabel('Parameter i')
76+
# plt.ylabel('Counts')
77+
# plt.title('State Distribution by Parameter')
78+
# plt.legend()
79+
# plt.grid(True, alpha=0.3)
80+
81+
82+
# 子图
83+
for idx, (state, values) in enumerate(data.items()):
84+
plt.subplot(2, 2, idx+1)
85+
86+
plt.plot(
87+
range(1, 5),
88+
values,
89+
marker='o',
90+
markersize=4,
91+
linestyle='-',
92+
linewidth=1.2,
93+
color=colors[idx]
94+
)
95+
96+
plt.xlabel('Parameter i')
97+
plt.ylabel('Counts')
98+
plt.title(f'State {state}')
99+
plt.grid(True, alpha=0.3)
57100

58101

59-
test_parametric_waveform()
102+
plt.tight_layout()
103+
plt.show()

0 commit comments

Comments
 (0)