Package: qpysequence
QPySequenceIntroductionQPySequence, which stands forQblox Python Sequence, is a python library developed by Qilimanjaro to create thesequence.jsonfile that is uploaded to a Qblox sequencer.
The sequences that are uploaded to the Qblox instruments is a dictionary of four components:Waveforms: dictionary containing an explicit array representation of the pulses to be played, each identified with an index and a name.Acquisitions: dictionary containing different specifications for the acquisition of data, mainly the number of bins, each identified with an index and a name.Weights: dictionary containing lists of time-dependent acquisition weights, each associated with an index and a name.Program: description of the sequence in the Q1ASM language, represented as a plain text. In the program all waveforms, acquisitions and weights are referenced by their indices.In theQblox docsthere are several examples on how to write a Q1ASM program to perform a certain experiment as well as the necessary waveforms, acquisitions and weights to complete the sequence. This is task usually done by manually writing the waveforms and weights dictionaries with an inline numpy array generating function, the acquisitions are specified also manually, and finally a Q1ASM program is writen as a python formated string, with some variables inside for certain parameters.This procedure is feasible for small examples and certain simple experiments. However, when integrating this into a larger codebase, for example, inside of a general quantum control library, with a complex class structure, holding many instrument drivers and being developed by several colaborators; the maintenance, quality, readability and debugging of the code can become a cumbersome task.While certain parts of this procedure could be modularized with some helper functions, the string nature of the Q1ASM program as well with the remaining parts of the sequence it is connected to, indirectly via integers (the indices) that have to be handled separately, still leaves a lot of room for improvement with the implementation of a higher abstraction layer that would handle the creation of the sequence in an easier and more robust manner.QPySequence is a library that handles all the components of a sequence as python objects, from the sequence itself to each instruction of the program, including new abstractions as blocks and loops to structure the program in a more clear and readable way.StructureThe main classes of QPySequence imitate the structure of thesequence.jsonitself:Waveforms,Acquisitions,WeightsandProgram, as well as the classSequencewhich contains them.
TheProgramclass is the one with higher complexity of the main four, with several internal classes used to structure all the instructions it holds (instances of classes which inherit from the abstractInstructionclass). In contrast, the other three main classes (Acquisitions,WeightsandWaveforms) share a very similar structure, since their structure is that of their dictionary counterpart insequence.json, with the addition of methods that facilitate their construction.
All the classes that are not internal have an implementation of therepr()method, which gives the equivalent string representation of that object that will be actually sent to the sequencer. In this way, when aSequenceobject is completed with all of its components and itsrepr()method is called, it calls therepr()method of its elements, which gets recursively repeated until until reaching the lower layers, obtaining finally the complete string representation of thesequence.jsonfile that can be directly uploaded to a Qblox sequencer.
Therepr()method can be called on any component of QPySequence, which allow to only generate the string representation of a single component, as theProgramfor example, if desired.ExampleThis simple example illustrates how to create a sequence for an averaged readoutimportqpysequenceasqpsimportnumpyasnp# Experiment parametersreadout_duration=1000play_acq_delay=120averaging_repetitions=1024# Create waveformswaveforms=qps.waveforms.Waveforms()readout_pulse=np.array([1.0+0.0jfor_inrange(readout_duration)],dtype=np.complex128)ro_index_i,ro_index_q=waveforms.add_pair_from_complex(readout_pulse)# Create acquisitionsacquisitions=qps.acquisitions.Acquisitions()acq_index=acquisitions.add("averaged")# Create an empty weights objectweights={}# Create the programprogram=qps.program.Program()main_loop=qps.program.Loop("main",averaging_repetitions)play=qps.program.instructions.Play(ro_index_i,ro_index_q,play_acq_delay)acquire=qps.program.instructions.Acquire(acq_index,bin_index=0,wait_time=readout_duration)main_loop.append_components([play,acquire])program.append_block(main_loop)# Create the sequence with all the componentssequence=qps.Sequence(program,waveforms,acquisitions,weights)# The sequence can now be converted to a json string and uploaded to a qblox sequencersequence_json=repr(sequence)Development setupIf you want to participate in the project, set up first your local environment, set up the git hooks and install the library.Read thedevelopmentdocumentation.