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 the relevant Sequencer) 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
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
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).
!qblox-pnp list
[2]:
cluster_ip = "10.10.200.42"
cluster_name = "cluster0"
Connect to Cluster#
We now make a connection with the Cluster.
[3]:
cluster: 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,
10: ClusterType.CLUSTER_QTM,
12: ClusterType.CLUSTER_QRC,
}
if cluster_ip is None
else None
),
)
cluster.reset()
print(cluster.get_system_status())
Status: OKAY, Flags: NONE, Slot flags: NONE
Get connected modules#
[4]:
# QCM-RF modules
modules = cluster.get_connected_modules(lambda mod: mod.is_qcm_type and mod.is_rf_type)
# This uses the module of the correct type with the lowest slot index
module = list(modules.values())[0]
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 Waveform Playback for details on how waveform dictionary is structured.
[5]:
# 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. It is important to note that the waveform samples are provided in unitless values ranging from -1 to 1.These map to the full output range of the specific module. For QCM modules this ±2.5 V and ±0.5 V for QRM modules; for RF modules and the QRC this depends on the NCO frequency, LO frequency and mixer calibration parameters and typically hits a minimum value of 5dBm.
[6]:
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 Q1ASM User Guide for a break down of available instructions in the Q1ASM language.
[7]:
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 all marker outputs to high. For RF-modules, this also enables the output switches.
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.
[8]:
# 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.
[9]:
# 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.
[10]:
module.disconnect_outputs()
# Enable marker switches to toggle the RF switch before output port
module.sequencer0.marker_ovr_en(True)
module.sequencer0.marker_ovr_value(3)
module.sequencer0.connect_sequencer("out0")
module.sequencer0.mod_en_awg(True)
module.out0_lo_freq(3e9)
module.sequencer0.nco_freq(10e6)
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.
[11]:
# 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.
[12]:
# Stop all sequencers.
module.stop_sequencer()
# Print status of sequencers 0 and 1 (should now say it is stopped).
print(module.get_sequencer_status(0))
print(module.get_sequencer_status(1))
print()
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: []