qick.qick_asm

The higher-level driver for the QICK library. Contains an tProc assembly language wrapper class and auxiliary functions.

Functions

adcfreq(f)

Takes a frequency and casts it to an (even) valid ADC DDS frequency.

cycles2us(cycles)

Converts tProc clock cycles to microseconds.

deg2reg(deg)

Converts degrees into phase register values; numbers greater than 360 will effectively be wrapped.

freq2reg(f)

Converts frequency in MHz to tProc DAC register value.

freq2reg_adc(f)

Converts frequency in MHz to tProc ADC register value.

reg2deg(reg)

Converts phase register values into degrees.

reg2freq(r)

Converts frequency from format readable by tProc DAC to MHz.

reg2freq_adc(r)

Converts frequency from format readable by tProc ADC to MHz.

us2cycles(us)

Converts microseconds to integer number of tProc clock cycles.

Classes

QickProgram([cfg])

QickProgram is a Python representation of the QickSoc processor assembly program.

qick.qick_asm.freq2reg(f)[source]

Converts frequency in MHz to tProc DAC register value.

Parameters

f (float) – frequency (MHz)

Returns

Re-formatted frequency

Return type

int

qick.qick_asm.freq2reg_adc(f)[source]

Converts frequency in MHz to tProc ADC register value.

Parameters

f (float) – frequency (MHz)

Returns

Re-formatted frequency

Return type

int

qick.qick_asm.reg2freq(r)[source]

Converts frequency from format readable by tProc DAC to MHz.

Parameters

r (float) – frequency in tProc DAC format

Returns

Re-formatted frequency in MHz

Return type

float

qick.qick_asm.reg2freq_adc(r)[source]

Converts frequency from format readable by tProc ADC to MHz.

Parameters

r (float) – frequency in tProc ADC format

Returns

Re-formatted frequency in MHz

Return type

float

qick.qick_asm.adcfreq(f)[source]

Takes a frequency and casts it to an (even) valid ADC DDS frequency.

Parameters

f (float) – frequency (MHz)

Returns

Re-formatted frequency

Return type

int

qick.qick_asm.cycles2us(cycles)[source]

Converts tProc clock cycles to microseconds.

Parameters

cycles (int) – Number of tProc clock cycles

Returns

Number of microseconds

Return type

float

qick.qick_asm.us2cycles(us)[source]

Converts microseconds to integer number of tProc clock cycles.

Parameters

cycles (float) – Number of microseconds

Returns

Number of tProc clock cycles

Return type

int

qick.qick_asm.deg2reg(deg)[source]

Converts degrees into phase register values; numbers greater than 360 will effectively be wrapped.

Parameters

deg (float) – Number of degrees

Returns

Re-formatted number of degrees

Return type

int

qick.qick_asm.reg2deg(reg)[source]

Converts phase register values into degrees.

Parameters

cycles (int) – Re-formatted number of degrees

Returns

Number of degrees

Return type

float

class qick.qick_asm.QickProgram(cfg=None)[source]

Bases: object

QickProgram is a Python representation of the QickSoc processor assembly program. It can be used to compile simple assembly programs and also contains macros to help make it easy to configure and schedule pulses.

add_pulse(ch, name, style, idata=None, qdata=None, length=None)[source]

Adds a pulse to the pulse library within the program.

Parameters
  • ch (int) – DAC channel

  • name (str) – Name of the pulse

  • style (str) – Pulse style (“const”, “arb”, “flat_top”, “poly”)

  • idata (array) – I data Numpy array

  • qdata (array) – Q data Numpy array

  • length (int) – Length of pulse in FPGA clock ticks

load_pulses(soc)[source]

Loads pulses that were added using add_pulse into the SoC’s signal generator memories.

Parameters

soc (Qick object) – Qick object

ch_page(ch)[source]

Gets tProc register page associated with channel.

Parameters

ch (int) – DAC channel

Returns

tProc page number

Return type

int

sreg(ch, name)[source]

Gets tProc special register number associated with a channel and register name.

Parameters
  • ch (int) – DAC channel

  • name (str) – Name of special register (“gain”, “freq”)

Returns

tProc special register number

Return type

int

set_pulse_registers(ch, freq=None, phase=None, addr=None, gain=None, phrst=None, stdysel=None, mode=None, outsel=None, length=None, t=None)[source]

A macro to set (optionally) the pulse parameters including frequency, phase, address of pulse, gain, stdysel, mode register (compiled from length and other flags), outsel, length, and schedule time.

Parameters
  • ch (int) – DAC channel

  • freq (float) – Frequency (MHz)

  • phase (float) – Phase (degrees)

  • addr (int) – Address

  • gain (float) – Gain (DAC units)

  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

  • t (int) – The number of clock ticks at which point the pulse starts

Returns

  • rp (int) The pulse page

  • r_freq (int) The pulse phase

  • r_phase (int) The pulse phase

  • r_addr (int) The pulse address

  • r_gain (int) The pulse gain

  • r_mode (int) The pulse mode

  • r_t (int) The pulse beginning time

const_pulse(ch, name=None, freq=None, phase=None, gain=None, phrst=None, stdysel=None, mode=None, outsel=None, length=None, t='auto', play=True)[source]

Schedule and (optionally) play a constant pulse, can autoschedule this based on previous pulses.

Parameters
  • ch (int) – DAC channel

  • name (str) – Pulse name

  • freq (float) – Frequency (MHz)

  • phase (float) – Phase (degrees)

  • gain (float) – Gain (DAC units)

  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

  • t (int) – The number of clock ticks at which point the pulse starts

arb_pulse(ch, name=None, freq=None, phase=None, gain=None, phrst=None, stdysel=None, mode=None, outsel=None, length=None, t='auto', play=True)[source]

Schedule and (optionally) play an arbitrary pulse, can autoschedule this based on previous pulses.

Parameters
  • ch (int) – DAC channel

  • name (str) – Pulse name

  • freq (float) – Frequency (MHz)

  • phase (float) – Phase (degrees)

  • gain (float) – Gain (DAC units)

  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

  • t (int) – The number of clock ticks at which point the pulse starts

flat_top_pulse(ch, name=None, freq=None, phase=None, gain=None, phrst=None, stdysel=None, mode=None, outsel=None, length=None, t='auto', play=True)[source]

Schedule and (optionally) play an a flattop pulse with arbitrary ramps, can autoschedule based on previous pulses To use these pulses one should use add_pulse to add the ramp waveform which should go from 0 to maxamp and back down to zero with the up and down having the same length, the first half will be used as the ramp up and the second half will be used as the ramp down.

Parameters
  • ch (int) – DAC channel

  • name (str) – Pulse name

  • freq (float) – Frequency (MHz)

  • phase (float) – Phase (degrees)

  • gain (float) – Gain (DAC units)

  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

  • t (int) – The number of clock ticks at which point the pulse starts

pulse(ch, name=None, freq=None, phase=None, gain=None, phrst=None, stdysel=None, mode=None, outsel=None, length=None, t='auto', play=True)[source]

Overall pulse class which will select the correct function to call based on the ‘style’ parameter of the named pulse.

Parameters
  • ch (int) – DAC channel

  • name (str) – Pulse name

  • freq (float) – Frequency (MHz)

  • phase (float) – Phase (degrees)

  • gain (float) – Gain (DAC units)

  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

  • t (int) – The number of clock ticks at which point the pulse starts

Returns

Dict of pulse styles

Return type

dict

align(chs)[source]

Sets all of the last times for each channel included in chs to the latest time in any of the channels.

safe_regwi(rp, reg, imm, comment=None)[source]

Due to the way the instructions are setup immediate values can only be 30bits before not loading properly. This comes up mostly when trying to regwi values into registers, especially the _frequency_ and _phase_ pulse registers. safe_regwi can be used wherever one might use regwi and will detect if the value is >2**30 and if so will break it into two steps, putting in the first 30 bits shifting it over and then adding the last two.

Parameters
  • rp (int) – Register page

  • reg (int) – Register number

  • imm (int) – Value of the write

  • comment (str) – Comment associated with the write

sync_all(t=0)[source]

Aligns and syncs all channels with additional time t.

Parameters

t (int) – The time offset in clock ticks

marker(t, t1=0, t2=0, t3=0, t4=0, adc1=0, adc2=0, rp=0, r_out=31, short=True)[source]

Sets the value of the marker bits at time t. This triggers the ADC(s) at a specified time t and also sends trigger values to 4 PMOD pins for syncing a scope trigger. Channel 0 of the tProc is connected to triggers/PMODs. E.g. if t3=1 PMOD0_2 goes high.

Parameters
  • t (int) – The number of clock ticks at which point the pulse starts

  • t1 (int) – t1 - value of an external pin connected to the PMOD (PMOD0_0)

  • t2 (int) – t2 - value of an external pin connected to the PMOD (PMOD0_1)

  • t3 (int) – t3 - value of an external pin connected to the PMOD (PMOD0_2)

  • t4 (int) – t4 - value of an external pin connected to the PMOD (PMOD0_3)

  • adc1 (bool) – 1 if ADC channel 0 is triggered; 0 otherwise.

  • adc2 (bool) – 1 if ADC channel 1 is triggered; 0 otherwise.

  • rp (int) – Register page

  • r_out (int) – Register number

  • short (bool) – If 1, plays a short marker pulse that is 5 clock ticks long

trigger_adc(adc1=0, adc2=0, adc_trig_offset=270, t=0)[source]

Triggers the ADC(s) at a specified time t+adc_trig_offset.

Parameters
  • adc1 (bool) – 1 if ADC channel 0 is triggered; 0 otherwise.

  • adc2 (bool) – 1 if ADC channel 1 is triggered; 0 otherwise.

  • adc_trig_offset (int) – Offset time at which the ADC is triggered (in clock ticks)

  • t (int) – The number of clock ticks at which point the ADC trigger starts

convert_immediate(val)[source]

Convert the register value to ensure that it is positive and not too large. Throws an error if you ever try to use a value greater than 2**31 as an immediate value.

Parameters

val (int) – Original register value

Returns

Converted register value

Return type

int

compile_instruction(inst, debug=False)[source]

Converts an assembly instruction into a machine bytecode.

Parameters
  • inst (dict) – Assembly instruction

  • debug (bool) – If True, debug mode is on

Returns

Compiled instruction in binary

Return type

int

compile(debug=False)[source]

Compiles program to machine code.

Parameters

debug (bool) – If True, debug mode is on

Returns

List of binary instructions

Return type

list

get_mode_code(phrst, stdysel, mode, outsel, length)[source]

Creates mode code for the mode register in the set command, by setting flags and adding the pulse length.

Parameters
  • phrst (bool) – If 1, it resets the phase coherent accumulator

  • stdysel (bool) – Selects what value is output continuously by the signal generator after the generation of a pulse. If 0, it is the last calculated sample of the pulse. If 1, it is a zero value.

  • mode (bool) – Selects whether the output is periodic or one-shot. If 0, it is one-shot. If 1, it is periodic.

  • outsel (int) – Selects the output source. The output is complex. Tables define envelopes for I and Q. If 0, the output is the product of table and DDS. If 1, the output is the DDS only. If 2, the output is from the table for the real part, and zeros for the imaginary part. If 3, the output is always zero.

  • length (int) – The number of samples in the pulse

Returns

Compiled mode code in binary

Return type

int

append_instruction(name, *args)[source]

Append instruction to the program list

Parameters
  • name (str) – Instruction name

  • *args

    Instruction arguments

label(name)[source]

Add line number label to the labels dictionary. This labels the instruction by its position in the program list. The loopz and condj commands use this label information.

Parameters

name (str) – Instruction name

comment(comment)[source]

Dummy function used for comments.

Parameters

comment (str) – Comment

hex()[source]

Returns hex representation of program as string.

Returns

Compiled program in hex format

Return type

str

bin()[source]

Returns binary representation of program as string.

Returns

Compiled program in binary format

Return type

str

asm()[source]

Returns assembly representation of program as string, should be compatible with the parse_prog from the parser module.

Returns

asm file

Return type

str

compare_program(fname)[source]

For debugging purposes to compare binary compilation of parse_prog with the compile.

Parameters

fname (str) – File the comparison program is stored in

Returns

True if programs are identical; False otherwise

Return type

bool