See also
A Jupyter notebook version of this tutorial can be downloaded here
.
Basic sequencing#
In this tutorial we will demonstrate basic sequencer based operations (see Sequencer Operation) for programming a qblox instrument. This includes creating a sequence consisting of waveforms and a simple Q1ASM program, and executing this sequence synchronously on multiple sequencers.
The general process for setting up and executing a program on a Q1 sequencer is as follows:
Connect to instrument
Prepare a sequence (JSON formatted file) which consists of
Waveforms for playback
Weights for weighted integration
Acquisitions for capture
Q1ASM program to be executed by the sequencer
This sequence is then loaded onto a sequencer on the connected instrument using the method
instrument_variable.sequencerX.sequence("SequenceFile.json")
The sequencer is then setup over its API as necessary
Sequencer is then armed and started to commence the experiment
Stop the sequencer and close down all instruments
This tutorial will give a basic introduction on how to work with the waveforms and Q1ASM segments of a sequence.
In the Tutorial the sequence is going to consecutively play two waveforms, a gaussian and block with a duration of 22ns each, with an increasing wait period in between them. We will increase the wait period by 20ns repeated 100 times, after which the sequence is stopped. The sequence will also trigger marker output 1 at every interval, so that the sequence can be easily monitored on an oscilloscope.
Setup#
First, we are going to import the required packages.
[1]:
from __future__ import annotations
import json
from typing import TYPE_CHECKING, Callable
import matplotlib.pyplot as plt
import numpy as np
import scipy.signal
from qcodes.instrument import find_or_create_instrument
from qblox_instruments import Cluster, ClusterType
if TYPE_CHECKING:
from qblox_instruments.qcodes_drivers.module import Module
Scan For Clusters#
We scan for the available devices connected via ethernet using the Plug & Play functionality of the Qblox Instruments package (see Plug & Play for more info).
[2]:
!qblox-pnp list
No devices found
[3]:
cluster_ip = "10.10.200.42"
cluster_name = "cluster0"
Connect to Cluster#
We now make a connection with the Cluster.
[4]:
cluster = find_or_create_instrument(
Cluster,
recreate=True,
name=cluster_name,
identifier=cluster_ip,
dummy_cfg=(
{
2: ClusterType.CLUSTER_QCM,
4: ClusterType.CLUSTER_QRM,
6: ClusterType.CLUSTER_QCM_RF,
8: ClusterType.CLUSTER_QRM_RF,
}
if cluster_ip is None
else None
),
)
Get connected modules#
[5]:
def get_connected_modules(cluster: Cluster, filter_fn: Callable | None = None) -> dict[int, Module]:
def checked_filter_fn(mod: ClusterType) -> bool:
if filter_fn is not None:
return filter_fn(mod)
return True
return {
mod.slot_idx: mod for mod in cluster.modules if mod.present() and checked_filter_fn(mod)
}
[6]:
# QCM-RF modules
modules = get_connected_modules(cluster, lambda mod: not mod.is_qrm_type and mod.is_rf_type)
modules
[6]:
{6: <Module: cluster0_module6 of Cluster: cluster0>,
10: <Module: cluster0_module10 of Cluster: cluster0>}
[7]:
# This uses the module of the correct type with the lowest slot index
module = list(modules.values())[0]
Reset the Cluster#
We reset the Cluster to enter a well-defined state. Note that resetting will clear all stored parameters, so resetting between experiments is usually not desirable.
[8]:
cluster.reset()
print(cluster.get_system_status())
Status: OKAY, Flags: NONE, Slot flags: NONE
Generate waveforms#
Next, we need to create the gaussian and block waveforms for the sequence. The waveforms constructed here will be referenced by the Q1ASM program for playback. See section Sequencer for details on how waveform dictionary is structured.
[9]:
# Waveform parameters
waveform_length = 22 # nanoseconds
# Waveform dictionary (data will hold the samples and index will be used to select the waveforms in the instrument).
waveforms = {
"gaussian": {
"data": scipy.signal.windows.gaussian(waveform_length, std=0.12 * waveform_length).tolist(),
"index": 0,
},
"block": {"data": [1.0 for i in range(0, waveform_length)], "index": 1},
}
Let’s plot the waveforms to see what we have created.
[10]:
time = np.arange(0, max(len(d["data"]) for d in waveforms.values()), 1)
fig, ax = plt.subplots(1, 1)
for wf, d in waveforms.items():
ax.plot(time[: len(d["data"])], d["data"], label=wf)
ax.legend()
ax.grid(alpha=1 / 10)
ax.set_ylabel("Waveform primitive amplitude")
ax.set_xlabel("Time (ns)")
plt.draw()
plt.show()
Create Q1ASM program#
Now that we have the waveforms for the sequence, we need a Q1ASM program that sequences the waveforms as previously described. The Q1ASM program can address the memory in the sequences waveforms and acquisitions to construct a program for playback. View Q1 Programming for a break down of available instructions in the Q1ASM language.
[11]:
# Sequence program.
seq_prog = """
move 100,R0 #Loop iterator.
move 20,R1 #Initial wait period in ns.
wait_sync 4 #Wait for sequencers to synchronize and then wait another 4 ns.
loop: set_mrk 15 #Set marker output and enable output 1 and 2.
play 0,1,4 #Play a gaussian and a block on output path 0 and 1 respectively and wait 4 ns.
set_mrk 3 #Reset marker outputs.
upd_param 18 #Update parameters and wait the remaining 18 ns of the waveforms.
wait R1 #Wait period.
play 1,0,22 #Play a block and a gaussian on output path 0 and 1 respectively and wait 22 ns.
wait 1000 #Wait a 1us in between iterations.
add R1,20,R1 #Increase wait period by 20 ns.
loop R0,@loop #Subtract one from loop iterator.
stop #Stop the sequence after the last iteration.
"""
Prepare and Upload sequence#
Now that we have the waveforms and Q1ASM program, we can combine them in a sequence stored in a JSON file.
[12]:
# Add sequence to single dictionary and write to JSON file.
sequence = {
"waveforms": waveforms,
"weights": {},
"acquisitions": {},
"program": seq_prog,
}
with open("sequence.json", "w", encoding="utf-8") as file:
json.dump(sequence, file, indent=4)
file.close()
Let’s write the JSON file to the instruments. We will use sequencer 0 and 1, which will drive outputs \(\text{O}^{[1-2]}\) and \(\text{O}^{[3-4]}\) respectively.
[13]:
# Upload sequence.
module.sequencer0.sequence("sequence.json")
module.sequencer1.sequence("sequence.json")
Play sequence#
The sequence has been uploaded to the instrument. Now we need to configure the sequencers in the instrument to use the wait_sync
instruction at the start of the Q1ASM program to synchronize.
[14]:
# Configure the sequencers to synchronize.
module.sequencer0.sync_en(True)
module.sequencer1.sync_en(True)
# Map sequencers to specific outputs (but first disable all sequencer connections).
module.disconnect_outputs()
module.sequencer0.connect_sequencer("out0")
module.out0_lo_freq(3e9)
module.sequencer0.nco_freq(50e6)
Now let’s start the sequence. If you want to observe the sequence, this is the time to connect an oscilloscope to marker output 1 and one or more of the four outputs. Configure the oscilloscope to trigger on the marker output 1.
[15]:
# Arm and start both sequencers.
module.arm_sequencer(0)
module.arm_sequencer(1)
module.start_sequencer()
# Print status of both sequencers.
print(module.get_sequencer_status(0))
print(module.get_sequencer_status(1))
Status: OKAY, State: STOPPED, Info Flags: NONE, Warning Flags: NONE, Error Flags: NONE, Log: []
Status: OKAY, State: STOPPED, Info Flags: NONE, Warning Flags: NONE, Error Flags: NONE, Log: []
Stop#
Finally, let’s stop the sequencers if they haven’t already and close the instrument connection. One can also display a detailed snapshot containing the instrument parameters before closing the connection by uncommenting the corresponding lines.
[16]:
# Stop both sequencers.
module.stop_sequencer()
# Print status of both sequencers (should now say it is stopped).
print(module.get_sequencer_status(0))
print(module.get_sequencer_status(1))
print()
# Print an overview of the instrument parameters.
print("Snapshot:")
module.print_readable_snapshot(update=True)
# Reset the cluster
cluster.reset()
print(cluster.get_system_status())
Status: OKAY, State: STOPPED, Info Flags: FORCED_STOP, Warning Flags: NONE, Error Flags: NONE, Log: []
Status: OKAY, State: STOPPED, Info Flags: FORCED_STOP, Warning Flags: NONE, Error Flags: NONE, Log: []
Snapshot:
cluster0_module6:
parameter value
--------------------------------------------------------------------------------
marker0_exp0_config : bypassed
marker0_exp1_config : bypassed
marker0_exp2_config : bypassed
marker0_exp3_config : bypassed
marker0_fir_config : bypassed
marker0_inv_en : False
marker1_exp0_config : bypassed
marker1_exp1_config : bypassed
marker1_exp2_config : bypassed
marker1_exp3_config : bypassed
marker1_fir_config : bypassed
marker1_inv_en : False
marker2_exp0_config : bypassed
marker2_exp1_config : bypassed
marker2_exp2_config : bypassed
marker2_exp3_config : bypassed
marker2_fir_config : bypassed
marker3_exp0_config : bypassed
marker3_exp1_config : bypassed
marker3_exp2_config : bypassed
marker3_exp3_config : bypassed
marker3_fir_config : bypassed
out0_att : 0 (dB)
out0_exp0_config : bypassed
out0_exp1_config : bypassed
out0_exp2_config : bypassed
out0_exp3_config : bypassed
out0_fir_config : bypassed
out0_latency : 0 (s)
out0_lo_en : True
out0_lo_freq : 3000000000 (Hz)
out0_lo_freq_cal_type_default : off (Hz)
out0_offset_path0 : 7.625 (mV)
out0_offset_path1 : 7.625 (mV)
out1_att : 0 (dB)
out1_exp0_config : bypassed
out1_exp1_config : bypassed
out1_exp2_config : bypassed
out1_exp3_config : bypassed
out1_fir_config : bypassed
out1_latency : 0 (s)
out1_lo_en : True
out1_lo_freq : 6000000000 (Hz)
out1_lo_freq_cal_type_default : off (Hz)
out1_offset_path0 : 7.625 (mV)
out1_offset_path1 : 7.625 (mV)
present : True
cluster0_module6_sequencer0:
parameter value
--------------------------------------------------------------------------------
connect_out0 : IQ
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 5e+07 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : True
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
cluster0_module6_sequencer1:
parameter value
--------------------------------------------------------------------------------
connect_out0 : off
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 0 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : True
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
cluster0_module6_sequencer2:
parameter value
--------------------------------------------------------------------------------
connect_out0 : off
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 0 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : False
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
cluster0_module6_sequencer3:
parameter value
--------------------------------------------------------------------------------
connect_out0 : off
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 0 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : False
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
cluster0_module6_sequencer4:
parameter value
--------------------------------------------------------------------------------
connect_out0 : off
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 0 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : False
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
cluster0_module6_sequencer5:
parameter value
--------------------------------------------------------------------------------
connect_out0 : off
connect_out1 : off
cont_mode_en_awg_path0 : False
cont_mode_en_awg_path1 : False
cont_mode_waveform_idx_awg_path0 : 0
cont_mode_waveform_idx_awg_path1 : 0
gain_awg_path0 : 1
gain_awg_path1 : 1
marker_ovr_en : False
marker_ovr_value : 0
mixer_corr_gain_ratio : 1
mixer_corr_phase_offset_degree : -0
mod_en_awg : False
nco_freq : 0 (Hz)
nco_freq_cal_type_default : off (Hz)
nco_phase_offs : 0 (Degrees)
nco_prop_delay_comp : 0 (ns)
nco_prop_delay_comp_en : False (ns)
offset_awg_path0 : 0
offset_awg_path1 : 0
sync_en : False
trigger10_count_threshold : 1
trigger10_threshold_invert : False
trigger11_count_threshold : 1
trigger11_threshold_invert : False
trigger12_count_threshold : 1
trigger12_threshold_invert : False
trigger13_count_threshold : 1
trigger13_threshold_invert : False
trigger14_count_threshold : 1
trigger14_threshold_invert : False
trigger15_count_threshold : 1
trigger15_threshold_invert : False
trigger1_count_threshold : 1
trigger1_threshold_invert : False
trigger2_count_threshold : 1
trigger2_threshold_invert : False
trigger3_count_threshold : 1
trigger3_threshold_invert : False
trigger4_count_threshold : 1
trigger4_threshold_invert : False
trigger5_count_threshold : 1
trigger5_threshold_invert : False
trigger6_count_threshold : 1
trigger6_threshold_invert : False
trigger7_count_threshold : 1
trigger7_threshold_invert : False
trigger8_count_threshold : 1
trigger8_threshold_invert : False
trigger9_count_threshold : 1
trigger9_threshold_invert : False
upsample_rate_awg_path0 : 0
upsample_rate_awg_path1 : 0
Status: OKAY, Flags: NONE, Slot flags: NONE