qick.helpers

Support functions.

Functions

DRAG(mu, si, length, maxv, delta, alpha)

Create I and Q arrays for a DRAG pulse.

ch2list(ch)

convert a channel number or a list of ch numbers to list of integers

check_bytes(val, length)

Test if a signed int will fit in the specified number of bytes.

check_keys(keys, required, optional)

Check whether the keys defined for a pulse are supported and sufficient for this generator and pulse type.

cosine([length, maxv])

Create a numpy array containing a cosine shaped envelope function

decode_array(json_array)

Convert a base64-encoded array back into numpy.

gauss([mu, si, length, maxv])

Create a numpy array containing a Gaussian function

json2progs(s)

Read QICK programs from JSON.

progs2json(proglist)

Dump QICK programs to a JSON string.

to_int(val, scale[, quantize, parname, trunc])

Convert a parameter value from user units to ASM units.

triang([length, maxv])

Create a numpy array containing a triangle function

Classes

NpEncoder(*[, skipkeys, ensure_ascii, ...])

JSON encoder with support for numpy objects and custom classes with to_dict methods.

qick.helpers.to_int(val, scale, quantize=1, parname=None, trunc=False)[source]

Convert a parameter value from user units to ASM units. Normally this means converting from float to int. For the v2 tProcessor this can also convert QickSweep to QickSweepRaw. To avoid overflow, values are rounded towards zero using np.trunc().

Parameters:
  • val (float or QickSweep) – parameter value or sweep range

  • scale (float) – conversion factor

  • quantize (int) – rounding step for ASM value

  • parname (str) – parameter type - only for sweeps

  • trunc (bool) – round towards zero using np.trunc(), instead of to closest integer using np.round()

Returns:

ASM value

Return type:

int or QickSweepRaw

qick.helpers.check_bytes(val, length)[source]

Test if a signed int will fit in the specified number of bytes.

Parameters:
  • val (int) – value to test

  • length (int) – number of bytes

Returns:

True if value will fit, False otherwise

Return type:

bool

qick.helpers.cosine(length=100, maxv=30000)[source]

Create a numpy array containing a cosine shaped envelope function

Parameters:
  • length (int) – Length of array

  • maxv (float) – Maximum amplitude of cosine flattop function

Returns:

Numpy array containing a cosine flattop function

Return type:

array

qick.helpers.gauss(mu=0, si=25, length=100, maxv=30000)[source]

Create a numpy array containing a Gaussian function

Parameters:
  • mu (float) – Mu (peak offset) of Gaussian

  • sigma (float) – Sigma (standard deviation) of Gaussian

  • length (int) – Length of array

  • maxv (float) – Maximum amplitude of Gaussian

Returns:

Numpy array containing a Gaussian function

Return type:

array

qick.helpers.DRAG(mu, si, length, maxv, delta, alpha)[source]

Create I and Q arrays for a DRAG pulse. Based on QubiC and Qiskit-Pulse implementations.

Parameters:
  • mu (float) – Mu (peak offset) of Gaussian

  • si (float) – Sigma (standard deviation) of Gaussian

  • length (int) – Length of array

  • maxv (float) – Maximum amplitude of Gaussian

  • delta (float) – anharmonicity of the qubit (units of 1/sample time)

  • alpha (float) – alpha parameter of DRAG (order-1 scale factor)

Returns:

Numpy array with I and Q components of the DRAG pulse

Return type:

array, array

qick.helpers.triang(length=100, maxv=30000)[source]

Create a numpy array containing a triangle function

Parameters:
  • length (int) – Length of array

  • maxv (float) – Maximum amplitude of triangle function

Returns:

Numpy array containing a triangle function

Return type:

array

class qick.helpers.NpEncoder(*, skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, default=None)[source]

Bases: JSONEncoder

JSON encoder with support for numpy objects and custom classes with to_dict methods. Taken from https://stackoverflow.com/questions/50916422/python-typeerror-object-of-type-int64-is-not-json-serializable

default(obj)[source]

Implement this method in a subclass such that it returns a serializable object for o, or calls the base implementation (to raise a TypeError).

For example, to support arbitrary iterators, you could implement default like this:

def default(self, o):
    try:
        iterable = iter(o)
    except TypeError:
        pass
    else:
        return list(iterable)
    # Let the base class default method raise the TypeError
    return JSONEncoder.default(self, o)
qick.helpers.decode_array(json_array)[source]

Convert a base64-encoded array back into numpy.

qick.helpers.progs2json(proglist)[source]

Dump QICK programs to a JSON string.

Parameters:

proglist (list of dict) – A list of program dictionaries to dump.

Returns:

A JSON string.

Return type:

str

qick.helpers.json2progs(s)[source]

Read QICK programs from JSON.

Parameters:

s (file-like object or string) – A JSON file or JSON string.

Returns:

A list of program dictionaries.

Return type:

list of dict

qick.helpers.ch2list(ch: Union[List[int], int]) List[int][source]

convert a channel number or a list of ch numbers to list of integers

Parameters:

ch – channel number or list of channel numbers

Returns:

list of channel number(s)

qick.helpers.check_keys(keys, required, optional)[source]

Check whether the keys defined for a pulse are supported and sufficient for this generator and pulse type. Raise an exception if there is a problem.

Parameters:
  • params (set-like) – Parameter keys defined for this pulse

  • required (list) – Required keys (these must be present)

  • optional (list) – Optional keys (these are not required, but may be present)