See also

An IPython notebook version of this tutorial can be downloaded here:

binned_acquisition.ipynb

Binned acquisition

In this tutorial we will demonstrate the sequencer based acquisition binning procedure. The binning process is applied on the input path after real-time demodulation, (weighed) integration, IQ rotation and discretization. It allows storing both the integration and discretization results on the fly without intervention of the host PC in up to 131072 bins. It also allows averaging those bins on the fly as well (see section Acquisition). We will show this by using a Pulsar QRM and directly connecting outputs \(\text{O}^{[1-2]}\) to inputs \(\text{I}^{[1-2]}\) respectively. We will then use the Pulsar QRM’s sequencers to sequence waveforms on the outputs and simultaneously acquire the resulting waveforms on the inputs.

Setup

First, we are going to import the required packages and connect to the instrument.

[1]:
#Set up the environment.
import pprint
import os
import scipy.signal
import math
import json
import matplotlib.pyplot
import numpy

from pulsar_qrm.pulsar_qrm import pulsar_qrm

#Connect to the Pulsar QRM at default IP address.
pulsar = pulsar_qrm("qrm", "192.168.0.2")

#Reset the instrument for good measure.
pulsar.reset()
print("Status:")
print(pulsar.get_system_status())
Status:
{'status': 'OKAY', 'flags': []}

Generate waveforms and weights

Next, we need to create the waveforms used by the sequence for playback on the outputs as well as weights used by the sequence for weighed integrations.

[2]:
#Waveform and weight parameters
waveform_weight_length = 600 #nanoseconds

#Waveform dictionary (data will hold the samples and index will be used to select the waveforms in the instrument).
waveforms_weights = {
                "gaussian": {"data": [], "index": 0},
                "sine":     {"data": [], "index": 1},
                "block":    {"data": [], "index": 2}
            }

#Create gaussian waveform/weight
if "gaussian" in waveforms_weights:
    waveforms_weights["gaussian"]["data"] = scipy.signal.gaussian(waveform_weight_length, std=0.12 * waveform_weight_length)

#Create sine waveform/weight
if "sine" in waveforms_weights:
    waveforms_weights["sine"]["data"] = [math.sin((2*math.pi/waveform_weight_length)*i) for i in range(0, waveform_weight_length)]

#Create block waveform/weight
if "block" in waveforms_weights:
    waveforms_weights["block"]["data"] = [1.0 for _ in range(0, waveform_weight_length)]

Specify acquisitions

We also need to specify the acquisitions so that the instrument can allocate the required memory for it’s acquisition list. In this case we will create 4 acquisition specifications that each create multiple bins.

[3]:
#Acquisitions
acquisitions = {"non_weighed":  {"num_bins": 10,
                                 "index":    0},
                "weighed":      {"num_bins": 10,
                                 "index":    1},
                "large":        {"num_bins": 131072,
                                 "index":    2},
                "avg":          {"num_bins": 10,
                                 "index":    3}}

Create Q1ASM program

Now that we have the waveform and acquisition specifications for the sequence, we need a simple Q1ASM program that sequences the waveforms and triggers the acquisitions. In this case we will simply trigger 10 non-weighed acquisitions and store each acquisition in a separate bin.

[4]:
#Sequence program.
seq_prog = """
      move    0,R0        #Loop iterator.
      nop

loop: acquire 0,R0,1000   #Acquire bins and store them in "non_weighed" acquisition.
      add     R0,1,R0     #Increment iterator
      nop                 #Wait a cycle for R0 to be available.
      jlt     R0,10,@loop #Run until number of iterations is done.

      stop                #Stop.
"""

Upload sequence

Now that we have the waveform, weights and acquisition specifications and Q1ASM program, we can combine them in a sequence stored in a JSON file.

[5]:
#Reformat waveforms/weights to lists if necessary.
for name in waveforms_weights:
    if str(type(waveforms_weights[name]["data"]).__name__) == "ndarray":
        waveforms_weights[name]["data"] = waveforms_weights[name]["data"].tolist()  # JSON only supports lists

#Add sequence program and waveforms to single dictionary and write to JSON file.
wave_and_prog_dict = {"waveforms": waveforms_weights, "weights": waveforms_weights, "acquisitions": acquisitions, "program": seq_prog}
with open("sequence.json", 'w', encoding='utf-8') as file:
    json.dump(wave_and_prog_dict, file, indent=4)
    file.close()

Let’s write the JSON file to the instruments. We will use sequencer 0, which will drive outputs \(\text{O}^{[1-2]}\) and acquire on inputs \(\text{I}^{[1-2]}\).

[6]:
#Upload waveforms, weights and programs.
pulsar.sequencer0_waveforms_and_program(os.path.join(os.getcwd(), "sequence.json"))

Play sequence

The sequence has been uploaded to the instrument. Now we need to configure the sequencers. To keep it simple we will set a DC signal on the outputs of the instrument by enabling the sequencer offsets and disabling the modulation. These DC signals will then be acquired through the inputs, so we will also disable the demodulation on the input path. Furthermore, since we are running non-weighed integrations we need to specify the integration length. This integration length will be used for every non-weighed integration moving forward. We will also put the integration result phase rotation to 0 degrees and discretation threshold to 0.

[7]:
#Configure scope mode
pulsar.scope_acq_sequencer_select(0)
pulsar.scope_acq_trigger_mode_path0("sequencer")
pulsar.scope_acq_trigger_mode_path1("sequencer")

#Configure the sequencer
pulsar.sequencer0_offset_awg_path0(0.5)
pulsar.sequencer0_offset_awg_path1(0.5)
pulsar.sequencer0_mod_en_awg(False)
pulsar.sequencer0_demod_en_acq(False)
pulsar.sequencer0_integration_length_acq(1000)
pulsar.sequencer0_phase_rotation_acq(0)
pulsar.sequencer0_discretization_threshold_acq(0)

Now let’s start the sequence.

[8]:
#Arm and start sequencer.
pulsar.arm_sequencer()
pulsar.start_sequencer()

#Print status of sequencer.
print("Status:")
print(pulsar.get_sequencer_state(0, 1))
Status:
{'status': 'STOPPED', 'flags': ['ACQ SCOPE DONE PATH 0', 'ACQ SCOPE DONE PATH 1', 'ACQ BINNING DONE']}

Retrieve acquisition

Next we will have a quick look at the input signal, so that we can compare it to the integration results. Since we are integrating over a DC signal we are expecting the integration results to be roughly equal to the average DC value.

[9]:
#Wait for the sequencer to stop with a timeout period of one minute.
pulsar.get_acquisition_state(0, 1)

#Move acquisition data from temporary memory to acquisition list.
pulsar.store_scope_acquisition(0, "non_weighed")

#Get acquisition list from instrument.
non_weighed_acq = pulsar.get_acquisitions(0)["non_weighed"]

#Plot acquired signal on both inputs.
fig, ax = matplotlib.pyplot.subplots(1, 1, figsize=(15, 15/2/1.61))
ax.plot(non_weighed_acq["acquisition"]["scope"]["path0"]["data"][0:1000])
ax.plot(non_weighed_acq["acquisition"]["scope"]["path1"]["data"][0:1000])
ax.set_xlabel('Time (ns)')
ax.set_ylabel('Relative amplitude')
matplotlib.pyplot.show()
../_images/tutorials_binned_acquisition_18_0.png

To check if the integration results match with what we expect, we need to divide the integration results by the integration length which was set through the corresponding QCoDeS parameter. Note that the ‘valid’ key of the dictionary indicates if the bin was actually set during the sequence.

[10]:
int_len = pulsar.sequencer0_integration_length_acq()
bins = non_weighed_acq["acquisition"]["bins"]
bins["integration"]["path0"] = [(val/int_len) for val in bins["integration"]["path0"]]
bins["integration"]["path1"] = [(val/int_len) for val in bins["integration"]["path1"]]
bins
[10]:
{'integration': {'path0': [0.2617440156326331,
   0.2617664875427455,
   0.2616521739130435,
   0.2617200781631656,
   0.2617606253053249,
   0.2618138739618955,
   0.26161895456766,
   0.26183194919394237,
   0.26166878358573525,
   0.2616653639472399],
  'path1': [0.25907181240840255,
   0.25914704445530046,
   0.25897850512945775,
   0.2589057156814851,
   0.2591377625793845,
   0.25907474352711285,
   0.2590297997068881,
   0.25914460185637517,
   0.2591094284318515,
   0.2590801172447484]},
 'threshold': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
 'avg_cnt': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}

Weighed acquisition

Next we will show weighed integrations. To do this, we will need to modify the sequence program slightly and reupload the program. We will be using a the gaussian weight to integrate over input path 0 and the sine weight to integrate over input path 1. The integration length of a weighed integration is determined by the weight length.

[11]:
#Sequence program.
seq_prog = """
      move            0,R0            #Loop iterator.
      move            0,R1            #Weight for path 0.
      move            1,R2            #Weight for path 1.
      nop

loop: acquire_weighed 1,R0,R1,R2,1000 #Acquire bins and store them in "weighed" acquisition.
      add             R0,1,R0         #Increment iterator
      nop                             #Wait a cycle for R0 to be available.
      jlt             R0,10,@loop     #Run until number of iterations is done.

      stop                            #Stop.
"""
[12]:
#Reformat waveforms/weights to lists if necessary.
for name in waveforms_weights:
    if str(type(waveforms_weights[name]["data"]).__name__) == "ndarray":
        waveforms_weights[name]["data"] = waveforms_weights[name]["data"].tolist()  # JSON only supports lists

#Add sequence program and waveforms to single dictionary and write to JSON file.
wave_and_prog_dict = {"waveforms": waveforms_weights, "weights": waveforms_weights, "acquisitions": acquisitions, "program": seq_prog}
with open("sequence.json", 'w', encoding='utf-8') as file:
    json.dump(wave_and_prog_dict, file, indent=4)
    file.close()
[13]:
#Upload waveforms weights and programs.
pulsar.sequencer0_waveforms_and_program(os.path.join(os.getcwd(), "sequence.json"))

Let’s start the sequence and retrieve the results.

[14]:
#Arm and start sequencer.
pulsar.arm_sequencer()
pulsar.start_sequencer()

#Print status of sequencer.
print("Status:")
print(pulsar.get_sequencer_state(0, 1))
Status:
{'status': 'STOPPED', 'flags': ['ACQ SCOPE DONE PATH 0', 'ACQ SCOPE DONE PATH 1', 'ACQ BINNING DONE']}
[15]:
#Wait for the sequencer to stop with a timeout period of one minute.
pulsar.get_acquisition_state(0, 1)

#Get acquisition list from instrument.
weighed_acq = pulsar.get_acquisitions(0)["weighed"]

To check if the integration results match with what we expect, we need to divide the integration results by the integration length again. In this case the integration length is determined by the length of the weights.

[16]:
int_len = waveform_weight_length
bins = weighed_acq["acquisition"]["bins"]
bins["integration"]["path0"] = [(val/int_len) for val in bins["integration"]["path0"]]
bins["integration"]["path1"] = [(val/int_len) for val in bins["integration"]["path1"]]
bins
[16]:
{'integration': {'path0': [0.0786350597309108,
   0.07865644927655557,
   0.07864557790156369,
   0.07859572119990514,
   0.07866723235046272,
   0.07862791251383085,
   0.07861894438519257,
   0.07856020507171202,
   0.0786306275733104,
   0.07863066018902637],
  'path1': [-0.00010140782953785837,
   -1.9978717052061127e-05,
   2.7874504589150565e-06,
   -3.3927106420387784e-05,
   8.420821013939877e-06,
   -8.682542247097141e-05,
   -6.557111272174412e-05,
   -0.00012384823764160688,
   -4.9532931014499116e-05,
   -0.00010997462576846804]},
 'threshold': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
 'avg_cnt': [1, 1, 1, 1, 1, 1, 1, 1, 1, 1]}

Large number of bins

The Pulsar QRM supports up to 131072 bins. To show that, we need to change the program slightly again. We will use the non-weighed acquisition program, but now we will loop over the maximum number of acquisitions while storing each result in a separate bin.

[17]:
#Sequence program.
seq_prog = """
      move    0,R0            #Loop iterator.
      nop

loop: acquire 2,R0,1000       #Acquire bins and store them in "large" acquisition.
      add     R0,1,R0         #Increment iterator
      nop                     #Wait a cycle for R0 to be available.
      jlt     R0,131072,@loop #Run until number of iterations is done.

      stop                    #Stop.
"""
[18]:
#Reformat waveforms/weights to lists if necessary.
for name in waveforms_weights:
    if str(type(waveforms_weights[name]["data"]).__name__) == "ndarray":
        waveforms_weights[name]["data"] = waveforms_weights[name]["data"].tolist()  # JSON only supports lists

#Add sequence program and waveforms to single dictionary and write to JSON file.
wave_and_prog_dict = {"waveforms": waveforms_weights, "weights": waveforms_weights, "acquisitions": acquisitions, "program": seq_prog}
with open("sequence.json", 'w', encoding='utf-8') as file:
    json.dump(wave_and_prog_dict, file, indent=4)
    file.close()
[19]:
#Upload waveforms weights and programs.
pulsar.sequencer0_waveforms_and_program(os.path.join(os.getcwd(), "sequence.json"))

Let’s start the sequence and retrieve the results.

[20]:
#Arm and start sequencer.
pulsar.arm_sequencer()
pulsar.start_sequencer()

#Print status of sequencer.
print("Status:")
print(pulsar.get_sequencer_state(0, 1))
Status:
{'status': 'STOPPED', 'flags': ['ACQ SCOPE DONE PATH 0', 'ACQ SCOPE DONE PATH 1', 'ACQ BINNING DONE']}
[21]:
#Wait for the sequencer to stop with a timeout period of one minute.
pulsar.get_acquisition_state(0, 1)

#Get acquisition list from instrument.
large_acq = pulsar.get_acquisitions(0)["large"]

Since the number of bins is now to large to simply print, we will check the number of bins and we will check the bins for NaN values which indicate that a bin is not written.

[22]:
int_len = pulsar.sequencer0_integration_length_acq()
bins = large_acq["acquisition"]["bins"]
bins["integration"]["path0"] = [(val/int_len) for val in bins["integration"]["path0"]]
bins["integration"]["path1"] = [(val/int_len) for val in bins["integration"]["path1"]]

print("Number of bins: {}".format(len(bins["avg_cnt"])))
for it, val in enumerate(bins["integration"]["path0"]):
    if math.isnan(val):
        Exception("NaN found at index {}.".format(it))
for it, val in enumerate(bins["integration"]["path0"]):
    if math.isnan(val):
        Exception("NaN found at index {}.".format(it))
for it, val in enumerate(bins["integration"]["path0"]):
    if math.isnan(val):
        Exception("NaN found at index {}.".format(it))
print("All values are valid.")
Number of bins: 131072
All values are valid.

We will also plot the integration results in every bin to visualize the contents.

[23]:
#Plot bins
fig, ax = matplotlib.pyplot.subplots(1, 1, figsize=(15, 15/2/1.61))
ax.plot(bins["integration"]["path0"])
ax.plot(bins["integration"]["path1"])
ax.set_xlabel('Bin index')
ax.set_ylabel('Relative amplitude')
matplotlib.pyplot.show()
../_images/tutorials_binned_acquisition_40_0.png

Averaging

As you might have noticed, the acquisition results also contain an average counter. This average counter reflects the number of times a bin as been averaged during the sequence. Each time a the sequence writes to the same bin the results are automatically accumulated and the average counter is increased. Upon retrieval of the acquisition results, each result is divide by the average counter and therefore automatically averaged. To show this, we will change the sequence one last time. This time we will average 10 bins a 1000 times each.

[24]:
#Sequence program.
seq_prog = """
      move    0,R1         #Average iterator.

avg:  move    0,R0         #Bin iterator.
      nop

loop: acquire 3,R0,1000    #Acquire bins and store them in "avg" acquisition.
      add     R0,1,R0      #Increment bin iterator
      nop                  #Wait a cycle for R0 to be available.
      jlt     R0,10,@loop  #Run until number of avg iterations is done.
      add     R1,1,R1      #Increment avg iterator
      nop                  #Wait a cycle for R1 to be available.
      jlt     R1,1000,@avg #Run until number of average iterations is done.

      stop                 #Stop.
"""
[25]:
#Reformat waveforms/weights to lists if necessary.
for name in waveforms_weights:
    if str(type(waveforms_weights[name]["data"]).__name__) == "ndarray":
        waveforms_weights[name]["data"] = waveforms_weights[name]["data"].tolist()  # JSON only supports lists

#Add sequence program and waveforms to single dictionary and write to JSON file.
wave_and_prog_dict = {"waveforms": waveforms_weights, "weights": waveforms_weights, "acquisitions": acquisitions, "program": seq_prog}
with open("sequence.json", 'w', encoding='utf-8') as file:
    json.dump(wave_and_prog_dict, file, indent=4)
    file.close()
[26]:
#Upload waveforms weights and programs.
pulsar.sequencer0_waveforms_and_program(os.path.join(os.getcwd(), "sequence.json"))

Let’s start the sequence and retrieve the results.

[27]:
#Arm and start sequencer.
pulsar.arm_sequencer()
pulsar.start_sequencer()

#Print status of sequencer.
print("Status:")
print(pulsar.get_sequencer_state(0, 1))
Status:
{'status': 'STOPPED', 'flags': ['ACQ SCOPE DONE PATH 0', 'ACQ SCOPE DONE PATH 1', 'ACQ BINNING DONE']}

Note that the average count of each bin is now set to a 1000.

[28]:
#Wait for the sequencer to stop with a timeout period of one minute.
pulsar.get_acquisition_state(0, 1)

#Get acquisition list from instrument.
avg_acq = pulsar.get_acquisitions(0)["avg"]
[29]:
int_len = pulsar.sequencer0_integration_length_acq()
bins = avg_acq["acquisition"]["bins"]
bins["integration"]["path0"] = [(val/int_len) for val in bins["integration"]["path0"]]
bins["integration"]["path1"] = [(val/int_len) for val in bins["integration"]["path1"]]
bins
[29]:
{'integration': {'path0': [0.26156631656082074,
   0.261566979482169,
   0.26156731998045923,
   0.26156682804103565,
   0.2615662457254519,
   0.2615670156326331,
   0.261570118221788,
   0.2615649677576942,
   0.26156611919882755,
   0.26156983585735216],
  'path1': [0.25899853102100634,
   0.258998406936981,
   0.2590020117244748,
   0.25900156472887154,
   0.25899741377625796,
   0.25899950464093796,
   0.25900023448949683,
   0.25900074743527113,
   0.25899728431851493,
   0.2589945398143625]},
 'threshold': [1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0],
 'avg_cnt': [1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000]}

Stop

Finally, let’s stop the sequencers if they haven’t already and close the instrument connection.

[30]:
#Stop sequencer.
pulsar.stop_sequencer()

#Print status of sequencer.
print("Status:")
print(pulsar.get_sequencer_state(0))
print()

#Print an overview of the instrument parameters.
print("Snapshot:")
pulsar.print_readable_snapshot(update=True)

#Close the instrument connection.
pulsar.close()
Status:
{'status': 'STOPPED', 'flags': ['FORCED STOP', 'ACQ SCOPE DONE PATH 0', 'ACQ SCOPE DONE PATH 1', 'ACQ BINNING DONE']}

Snapshot:
qrm:
        parameter                                  value
--------------------------------------------------------------------------------
IDN                                         :   {'manufacturer': 'Qblox', 'mode...
in0_amp_gain                                :   4294967290 (dB)
in1_amp_gain                                :   4294967290 (dB)
reference_source                            :   internal
scope_acq_avg_mode_en_path0                 :   False
scope_acq_avg_mode_en_path1                 :   False
scope_acq_sequencer_select                  :   0
scope_acq_trigger_level_path0               :   0
scope_acq_trigger_level_path1               :   0
scope_acq_trigger_mode_path0                :   sequencer
scope_acq_trigger_mode_path1                :   sequencer
sequencer0_cont_mode_en_awg_path0           :   False
sequencer0_cont_mode_en_awg_path1           :   False
sequencer0_cont_mode_waveform_idx_awg_path0 :   0
sequencer0_cont_mode_waveform_idx_awg_path1 :   0
sequencer0_demod_en_acq                     :   False
sequencer0_discretization_threshold_acq     :   0
sequencer0_gain_awg_path0                   :   1
sequencer0_gain_awg_path1                   :   1
sequencer0_integration_length_acq           :   1000
sequencer0_marker_ovr_en                    :   False
sequencer0_marker_ovr_value                 :   0
sequencer0_mod_en_awg                       :   False
sequencer0_nco_freq                         :   0 (Hz)
sequencer0_nco_phase_offs                   :   0 (Degrees)
sequencer0_offset_awg_path0                 :   0.49998
sequencer0_offset_awg_path1                 :   0.49998
sequencer0_phase_rotation_acq               :   0 (Degrees)
sequencer0_sync_en                          :   False
sequencer0_upsample_rate_awg_path0          :   0
sequencer0_upsample_rate_awg_path1          :   0
sequencer0_waveforms_and_program            :   /home/jordy/Projects/pulsar_qrm...