forked from LFL-Lab/Dissipator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sequence.py
438 lines (384 loc) · 20.1 KB
/
sequence.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
# -*- coding: utf-8 -*-
"""
Created on Fri Apr 28 13:00:18 2023
@author: lfl
"""
import numpy as np
from qm import LoopbackInterface, SimulationConfig
from qm.qua import *
from qm.QuantumMachinesManager import QuantumMachinesManager
from qualang_tools.loops import from_array
from helper_functions import declare_streams, declare_vars, res_demod
from Utilities import clk
class sequence():
# def __init__(self, name, n_avg=100, amp_r_scale=1, amp_ffl_scale=1, **kwargs):
def __init__(self,qb,name,**kwargs):
self.name = name
# self.seq_pars = qb.seq_pars
self.qb_pars = qb.pars
self.seq_pars = {}
# self.exp_dict = {'n_avg': n_avg,
# 'amp_r_scale': amp_r_scale,
# 'amp_ffl_scale': amp_ffl_scale}
for key in kwargs.keys():
self.seq_pars[key] = kwargs.get(key)
# def make_sequence(self, qb, tmin = 16, tmax=1e3, dt=8, scrambling_amp=0., ffl_len=2e3, saturation_dur=2e3, with_ffl='True', with_scram='True', detuning=0):
def make_resonator_spec_sequence(self):
n_avg = self.qb_pars['n_avg']
IF_min = self.seq_pars['IF_min']
IF_max = self.seq_pars['IF_max']
df = self.seq_pars['df']
freqs = np.arange(IF_min, IF_max + df/2, df, dtype=int)
res_ringdown_time = self.qb_pars['resettime']['rr']
tof_in_us = self.qb_pars['tof'] * 1e-3
IQ_rotation = self.qb_pars['IQ_rotation']
phase_prefactor = tof_in_us * 0.000064 # 0.000064 = 2^6 * 1e-6, to compensate for right-bitshift by 6 bits
initial_frame_rotation = self.qb_pars['tof'] * IF_min/1e9
### QUA code ###
with program() as prog:
n, I, Q, f = declare_vars([int, fixed, fixed, int])
I_st, Q_st, n_stream = declare_streams(stream_num=3)
phase_shift = declare(fixed)
df = declare(int, value=int(df))
with for_(n, 0, n < n_avg, n + 1):
save(n,n_stream)
reset_frame('rr')
frame_rotation_2pi(IQ_rotation + initial_frame_rotation,'rr')
# with for_each_(f, freqs_list):
with for_(*from_array(f, freqs)):
update_frequency("rr", f,keep_phase=False)
assign(phase_shift, Cast.mul_fixed_by_int(phase_prefactor, (df>>6)))
frame_rotation_2pi(phase_shift,'rr')
wait(res_ringdown_time, "rr")
measure("readout", "rr", None,*res_demod(I, Q,switch_weights=False))
save(I, I_st)
save(Q, Q_st)
with stream_processing():
I_st.buffer(len(freqs)).average().save('I')
Q_st.buffer(len(freqs)).average().save('Q')
n_stream.save('n')
return prog
def make_qubit_spec_sequence(self,):
n_avg = self.qb_pars['n_avg']
IF_min = self.seq_pars['IF_min']
IF_max = self.seq_pars['IF_max']
df = self.seq_pars['df']
qubit_amp = self.seq_pars['amp_q_scaling']
saturation_dur = self.seq_pars['saturation_dur']
on_off = self.seq_pars['on_off']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
freqs = np.arange(IF_min, IF_max + df/2, df, dtype=int)
qubit_reset_time = self.qb_pars['resettime']['qubit']
rr_reset_time = self.qb_pars['resettime']['rr']
with program() as prog:
# update_frequency('rr', self.qb_pars['rr_IF'])
n, I, Q = declare_vars([int, fixed, fixed])
I_stream, Q_stream, n_stream = declare_streams(stream_num=3)
if on_off:
I_b, Q_b, I_tot,Q_tot = declare_vars([fixed,fixed, fixed, fixed])
f = declare(int)
with for_(n, 0, n < n_avg, n + 1):
save(n, n_stream)
with for_(*from_array(f, freqs)):
update_frequency("qubit", f)
# measure background
if on_off:
measure("readout", "rr", None, *res_demod(I_b, Q_b,switch_weights=True))
wait(rr_reset_time, "rr")
align("rr", "qubit") # wait for operations on resonator to finish before playing qubit pulse
play('const'*amp(qubit_amp), "qubit", duration=saturation_dur)
align("qubit", "rr")
measure("readout", "rr", None, *res_demod(I, Q,switch_weights=True))
wait(qubit_reset_time,'qubit')
if on_off:
assign(I_tot, I - I_b)
assign(Q_tot, Q - Q_b)
save(I_tot, I_stream)
save(Q_tot, Q_stream)
else:
save(I, I_stream)
save(Q, Q_stream)
with stream_processing():
I_stream.buffer(len(freqs)).average().save('I')
Q_stream.buffer(len(freqs)).average().save('Q')
n_stream.save('n')
return prog
def make_power_rabi_sequence(self,):
# if self.name == 'ringdown_drive_on':
# tmin = clk(tmin)
# tmax = clk(tmax)
# dt = clk(dt)
# t_arr = np.arange(tmin, tmax + dt/2, dt, dtype = int)
# resettime_clk= clk(qb.pars['rr_resettime'])
# n_avg = self.exp_dict['n_avg']
# amp_r_scale = self.exp_dict['amp_r_scale']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# rr_IF = qb.pars['rr_IF']
# ffl_IF = qb.pars['ffl_IF']
# with program() as prog:
# update_frequency('rr', rr_IF)
# update_frequency('ffl', ffl_IF)
# n, t, I, Q = qb.declare_vars([int, int, fixed, fixed])
# I_stream, Q_stream, n_stream = qb.declare_streams(stream_num=3)
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_stream)
# with for_each_(t, t_arr):
# with if_(t==0):
# play("readout"*amp(amp_r_scale), "rr")
# measure("void", "rr", None,*qb.res_demod(I,Q))
# wait(resettime_clk, "rr")
# save(I, I_stream)
# save(Q, Q_stream)
# with else_():
# play("readout"*amp(amp_r_scale), "rr")
# align("ffl", "rr")
# play('gaussian'*amp(amp_ffl_scale), "ffl", duration=t)
# align("ffl", "rr")
# measure("void", "rr", None,*qb.res_demod(I,Q))
# wait(resettime_clk, "rr")
# save(I, I_stream)
# save(Q, Q_stream)
# with stream_processing():
# I_stream.buffer(len(t_arr)).average().save("I")
# Q_stream.buffer(len(t_arr)).average().save("Q")
# n_stream.save('n')
# elif self.name =='spec_wffl':
# resettime_clk= clk(qb.pars['qubit_resettime'])
# n_avg = self.exp_dict['n_avg']
# IF_min = self.exp_dict['IF_min']
# IF_max = self.exp_dict['IF_max']
# df = self.exp_dict['df']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# freqs = np.arange(IF_min, IF_max + df/2, df, dtype=int)
# rr_pulse_len_in_clk = qb.pars['rr_pulse_len_in_clk']
# with program() as prog:
# update_frequency('rr', qb.pars['rr_IF'])
# update_frequency('qubit', (qb.pars['qubit_freq']-qb.pars['qubit_LO']))
# update_frequency('ffl', (qb.pars['ffl_freq']-qb.pars['ffl_LO']))
# n, I, Q = qb.declare_vars([int, fixed, fixed])
# I_stream, Q_stream, n_stream = qb.declare_streams(stream_num=3)
# f = declare(int)
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_stream)
# with for_(f, IF_min, f < IF_max + df/2, f + df):
# update_frequency("rr", f)
# wait(resettime_clk, "rr")
# #align("qubit","rr")
# #play("pi", "qubit")
# align("ffl", "rr")
# play('const'*amp(amp_ffl_scale), "ffl", duration=9000)
# align("ffl", "rr")
# measure("readout", "rr", None, *qb.res_demod(I, Q))
# save(I, I_stream)
# save(Q, Q_stream)
# with stream_processing():
# I_stream.buffer(len(freqs)).average().save('I')
# Q_stream.buffer(len(freqs)).average().save('Q')
# n_stream.save('n')
# def make_qubit_reset_sequence():
# ##start with a scrambling pulse of length saturation_dur and amplitude scrambling amp on the qubit and then play (or dont play) ffl pulse for length ffl_len and then do rabi.
# resettime_clk= clk(qb.pars['qubit_resettime'])
# n_avg = self.exp_dict['n_avg']
# tmin = clk(tmin)
# tmax = clk(tmax)
# dt = clk(dt)
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# amp_q_scaling=1.
# var_arr = np.arange(tmin, tmax + dt/2, dt, dtype = int)
# with program() as prog:
# # n = declare(int)
# # I=declare(fixed)
# # I_st = declare_stream()
# # Q = declare(fixed)
# # Q_st = declare_stream()
# # n_st=declare_stream()
# n, t, I, Q = qb.declare_vars([int, int, fixed, fixed])
# I_st, Q_st, n_st = qb.declare_streams(stream_num=3)
# update_frequency('qubit', (qb.pars['qubit_freq']-qb.pars['qubit_LO'])) # sets the IF frequency of the qubit
# update_frequency('rr', qb.pars['rr_IF'])
# update_frequency('ffl', qb.pars['ffl_IF'])
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_st)
# with for_each_(t,var_arr):
# play("const" * amp(scrambling_amp), "qubit", duration = clk(saturation_dur)) #play scrambling pulse
# align("qubit", "ffl")
# play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len))
# align("qubit","ffl")
# play("pi" * amp(amp_q_scaling), "qubit", duration=t)
# align()
# measure("readout", "rr", None, *qb.res_demod(I, Q))
# save(I, I_st)
# save(Q, Q_st)
# wait(resettime_clk,"qubit")
# with stream_processing():
# I_st.buffer(len(var_arr)).average().save("I")
# Q_st.buffer(len(var_arr)).average().save("Q")
# n_st.save('n')
# elif self.name == 'cavity-reset':
# tmin = clk(tmin)
# tmax = clk(tmax)
# dt = clk(dt)
# t_arr = np.arange(tmin, tmax + dt/2, dt, dtype = int)
# resettime_clk= clk(qb.pars['qubit_resettime'])
# n_avg = self.exp_dict['n_avg']
# amp_r_scale = self.exp_dict['amp_r_scale']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# rr_IF = qb.pars['rr_IF']
# ffl_IF = qb.pars['ffl_IF']
# qb_IF=qb.pars['qubit_IF']+detuning
# with program() as prog:
# update_frequency('rr', rr_IF)
# update_frequency('ffl', ffl_IF)
# update_frequency('qubit' ,qb_IF)
# n, t, I, Q = qb.declare_vars([int, int, fixed, fixed])
# I_stream, Q_stream, n_stream = qb.declare_streams(stream_num=3)
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_stream)
# with for_each_(t, t_arr):
# play("readout"*amp(amp_r_scale), "rr")
# align('ffl','rr')
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len))
# play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len))
# wait(clk(80))
# align('ffl','qubit')
# play("pi_half", "qubit")
# with if_(t>0):
# # #align("ffl","qubit")
# wait(t)
# # #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=t)
# # #
# # # #wait(t+clk(20))
# play("pi", "qubit")
# with if_(t>0):
# wait(t, "qubit")
# play("pi_half", "qubit")
# align("qubit","rr")
# # play("pi","qubit")
# # align("qubit","rr")
# # with if_(t>0):
# # play('gaussian'*amp(amp_ffl_scale), "ffl", duration=t)
# # align("ffl","rr")
# measure("readout", "rr", None, *qb.res_demod(I, Q))
# save(I, I_stream)
# save(Q, Q_stream)
# wait(resettime_clk, 'rr')
# with stream_processing():
# I_stream.buffer(len(t_arr)).average().save("I")
# Q_stream.buffer(len(t_arr)).average().save("Q")
# n_stream.save('n')
# elif self.name == 'cavity-cooling':
# tmin = clk(tmin)
# tmax = clk(tmax)
# dt = clk(dt)
# t_arr = np.arange(tmin, tmax + dt/2, dt, dtype = int)
# resettime_clk= clk(qb.pars['qubit_resettime'])
# n_avg = self.exp_dict['n_avg']
# amp_r_scale = self.exp_dict['amp_r_scale']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# rr_IF = qb.pars['rr_IF']
# ffl_IF = qb.pars['ffl_IF']
# qb_IF=qb.pars['qubit_IF']+detuning
# with program() as prog:
# update_frequency('rr', rr_IF)
# update_frequency('ffl', ffl_IF)
# update_frequency('qubit' ,qb_IF)
# n, t, I, Q= qb.declare_vars([int, int, fixed, fixed])
# I_stream, Q_stream, n_stream = qb.declare_streams(stream_num=3)
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_stream)
# with for_each_(t, t_arr):
# #play("readout"*amp(amp_r_scale), "rr")
# #align('ffl','rr')
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len))
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len), condition= with_ffl==True)
# #wait(clk(200))
# #align('ffl','qubit')
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=2*t+)
# play('const'*amp(amp_ffl_scale), "ffl", duration=2*t+100)
# wait(40,"qubit")
# play("pi_half", "qubit")
# align('rr','qubit')
# play("readout"*amp(amp_r_scale), "rr", duration=2*t+20)
# with if_(t>0):
# wait(t,"qubit")
# play("pi", "qubit")
# with if_(t>0):
# wait(t,"qubit")
# play("pi_half", "qubit")
# #align("qubit","rr")
# align("ffl","rr")
# measure("readout", "rr", None, *qb.res_demod(I, Q))
# save(I, I_stream)
# save(Q, Q_stream)
# wait(resettime_clk)
# with stream_processing():
# I_stream.buffer(len(t_arr)).average().save("I")
# Q_stream.buffer(len(t_arr)).average().save("Q")
# n_stream.save('n')
# elif self.name == 'cavity-cooling-ramsey':
# tmin = clk(tmin)
# tmax = clk(tmax)
# dt = clk(dt)
# t_arr = np.arange(tmin, tmax + dt/2, dt, dtype = int)
# resettime_clk= clk(qb.pars['qubit_resettime'])
# n_avg = self.exp_dict['n_avg']
# amp_r_scale = self.exp_dict['amp_r_scale']
# amp_ffl_scale = self.exp_dict['amp_ffl_scale']
# rr_IF = qb.pars['rr_IF']
# ffl_IF = qb.pars['ffl_IF']
# qb_IF=qb.pars['qubit_IF']+detuning
# with program() as prog:
# update_frequency('rr', rr_IF)
# update_frequency('ffl', ffl_IF)
# update_frequency('qubit' ,qb_IF+detuning)
# n, t, I, Q= qb.declare_vars([int, int, fixed, fixed])
# I_stream, Q_stream, n_stream = qb.declare_streams(stream_num=3)
# with for_(n, 0, n < n_avg, n + 1):
# save(n, n_stream)
# with for_each_(t, t_arr):
# #play("readout"*amp(amp_r_scale), "rr")
# #align('ffl','rr')
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len))
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=clk(ffl_len), condition= with_ffl==True)
# #wait(clk(200))
# #align('ffl','qubit')
# #play('gaussian'*amp(amp_ffl_scale), "ffl", duration=2*t+)
# play('const'*amp(amp_ffl_scale), "ffl", duration=t+90)
# wait(40,"qubit")
# play("pi_half", "qubit")
# align('rr','qubit')
# play("readout"*amp(amp_r_scale), "rr", duration=t)
# with if_(t>0):
# wait(t,"qubit")
# play("pi_half", "qubit")
# #align("qubit","rr")
# align("ffl","rr")
# measure("readout", "rr", None, *qb.res_demod(I, Q))
# save(I, I_stream)
# save(Q, Q_stream)
# wait(resettime_clk)
# with stream_processing():
# I_stream.buffer(len(t_arr)).average().save("I")
# Q_stream.buffer(len(t_arr)).average().save("Q")
# n_stream.save('n')
# return prog
def simulate_sequence(self,qb, duration):
duration = clk(duration)
qmm = QuantumMachinesManager(host=host, port=port)
prog = self.make_sequence(qb)
job = qmm.simulate(qb.config, prog, SimulationConfig(duration=duration))
samples = job.get_simulated_samples()
samples.con1.plot()
qmm.close_all_quantum_machines()
return samples
# def main():
# qb = dissipator('diss08_11a',device_name='diss08_11a')
# qb.update_value('ffl_freq', 3.07e9)
# qb.update_value('ffl_IF', 350e6)
# qb.update_value('ffl_LO', qb.pars['ffl_freq'] - qb.pars['ffl_IF'])
#qb.update_value('rr_pulse_len_in_clk', 20)
# seq = sequence('qb-reset', IF_min=45e6,IF_max=54e6,df=0.1e6, res_ringdown_time=int(40))
# samples = seq.simulate_sequence(qb, duration=3000)
#qb.update_value('rr_pulse_len_in_clk', 500)
if __name__ == "__main__":
main()