seQuencing logo

Functions

Parameters

StringParameter

sequencing.parameters.StringParameter(default, **kwargs)[source]

Adds a string parameter.

Parameters

default (str) – Default value.

BoolParameter

sequencing.parameters.BoolParameter(default, **kwargs)[source]

Adds a boolean parameter.

Parameters

default (bool) – Default value.

IntParameter

sequencing.parameters.IntParameter(default, unit=None, **kwargs)[source]

Adds an integer parameter.

Parameters
  • default (int) – Default value.

  • unit (optional, str) – Unit to record in metadata. Default: None.

FloatParameter

sequencing.parameters.FloatParameter(default, unit=None, **kwargs)[source]

Adds a float parameter.

Parameters
  • default (float) – Default value.

  • unit (optional, str) – Unit to record in metadata. Default: None.

NanosecondParameter

sequencing.parameters.NanosecondParameter(default, base=<function IntParameter>, **kwargs)[source]

Adds a nanosecond parameter.

Parameters
  • default (int or float) – Default value.

  • base (optional, type) – IntParameter or FloatParameter. Default: IntParameter

GigahertzParameter

sequencing.parameters.GigahertzParameter(default, base=<function FloatParameter>, **kwargs)[source]

Adds a GHz parameter.

Parameters
  • default (int or float) – Default value.

  • base (optional, type) – IntParameter or FloatParameter. Default: FloatParameter

RadianParameter

sequencing.parameters.RadianParameter(default, base=<function FloatParameter>, **kwargs)[source]

Add a radian parameter.

Parameters
  • default (int or float) – Default value.

  • base (optional, type) – IntParameter or FloatParameter. Default: FloatParameter

DictParameter

sequencing.parameters.DictParameter(default=None, factory=<class 'dict'>, **kwargs)[source]

Adds a dict parameter:

Parameters
  • default (optional, dict) – Default value. Default: None.

  • base (optional, callabe) – Factory function, e.g. dict or collections.OrderedDict. Default: dict.

ListParameter

sequencing.parameters.ListParameter(default=None, factory=<class 'list'>, **kwargs)[source]

Adds a list parameter.

Parameters
  • default (optional, list) – Default value. Default: None.

  • base (optional, callabe) – Factory function, e.g. list or tuple. Default: list.


Modes

sort_modes

sequencing.modes.sort_modes(modes)[source]

Sorts a list of Modes based on the logic described below.

Mode ordering is decided primarily by mode Hilbert space size: modes with more levels go on the right.

Among modes with the same number of levels, the ordering is decided alphanumerically from right to left.

For example, assuming all cavities have the same number of levels and all qubits have the same, smaller, number of levels: [qubit1, qubit0, cavity2, cavity1, cavity0]

Parameters

modes (list[Mode]) – List of modes to sort.

Returns

Sorted list of Modes.

Return type

list[Mode]


Pulses

array_pulse

sequencing.pulses.array_pulse(i_wave, q_wave=None, amp=1, phase=0, detune=0, dt=1.0, noise_sigma=0, noise_alpha=0, scale_noise=False)[source]

Takes a real or complex waveform and applies an amplitude scaling, phase offset, time-dependent phase, and additive Gaussian noise.

Parameters
  • i_wave (array-like) – Real part of the waveform.

  • q_wave (optional, array-like) – Imaginary part of the waveform. If None, the imaginary part is set to 0. Default: None.

  • amp (float) – Factor by which to scale the waveform amplitude. Default: 1.

  • phase (optional, float) – Phase offset in radians. Default: 0.

  • detune (optional, float) – Software detuning/time-dependent phase to apply to the waveform, in GHz. Default: 0.

  • dt (optional, float) – Sample time in nanoseconds.

  • noise_sigma (optional, float) – Standard deviation of additive Gaussian noise applied to the pulse (see scale_noise). Default: 0.

  • noise_alpha (optional, float) – Exponent for the noise PSD S(f). S(f) is proportional to (1/f)**noise_alpha. noise_alpha = 0 for white noise, noise_alpha = 1 for 1/f noise, etc. Default: 0 (white noise).

  • scale_noise (optional, bool) – Whether to scale the noise by amp before adding it to the signal. If False, then noise_sigma has units of GHz. Default: False.

Returns

Complex waveform.

Return type

np.ndarray

pulse_factory

sequencing.pulses.pulse_factory(cls, name=None, **kwargs)[source]

Returns a function that creates an instance if the given pulse class.

Keyword arguments are passed to cls.__init__().

Parameters
  • cls (type) – Subclass of Pulse of which to create an instance.

  • name (optional, str) – Name of the resulting pulse. If None, will use a snake-case version of the class name, e.g. ‘GaussianPulse’ -> ‘gaussian_pulse’. Default: None.

Returns

A function that takes no arguments and returns an instance of cls.

Return type

callable


Sequencing

ket2dm

sequencing.sequencing.ket2dm(obj)[source]

Converts a qutip.Qobj from a ket to a density matrix.

ops2dms

sequencing.sequencing.ops2dms(ops)[source]

Converts a qutip.Qobj or sequence of qutip.Qobj from kets to density matrices.

get_sequence

sequencing.sequencing.get_sequence(system=None)[source]

Returns the global PulseSequence.

Parameters

system (optional, System) – If system is not None, the global PulseSequence is reset. Default: None.

Returns

The global PulseSequence.

Return type

PulseSequence

sync

sequencing.sequencing.sync(seq=None)[source]

Ensure that the Hamiltonian channels all align up to this point.

This means that all operations which follow the sync will be executed after all those before the sync. Sequences are constructed in terms of blocks of operations separated by sync()s. Within a block, channels are made to have equal duration by padding shorter channels to the maximum channel length.

Parameters

seq (optional, CompiledPulseSequence) – CompiledPulseSequence on which to apply the sync. If None, a SyncOperation is appended to the global PulseSequence. Default: None.

delay

sequencing.sequencing.delay(length, sync_before=True, sync_after=True, seq=None)[source]

Adds a global delay to the sequence, delaying all channels by the same amount.

Parameters
  • length (int) – Length of the delay.

  • sync_before (optional, bool) – Whether to insert a sync() before the delay. Default: True.

  • sync_after (optional, bool) – Whether to insert a sync() after the delay. Default: True.

  • seq (optional, CompiledPulseSequence) – CompiledPulseSequence on which to apply the delay. If None, a DelayOperation is appended to the global CompiledPulseSequence. Default: None.

delay_channels

sequencing.sequencing.delay_channels(channels, length, seq=None)[source]

Adds a delay of duration length to only the channels specified in channels.

Parameters
  • channels (str | list | dict) – Either the name of a single channel, a list of channel names, or a dict of the form {channel_name: H_op}, or a dict of the form {channel_name: (H_op, C_op)}. One of the latter two is required if the channels are not yet defined in seq.channels (i.e. if no previous Operations have involved these channels).

  • length (int) – Duration of the delay.

  • seq (optional, CompiledPulseSequence) – CompiledPulseSequence on which to delay channels. If None, a DelayChannelsOperation is appended to the global CompiledPulseSequence. Default: None.

@capture_operation

@sequencing.sequencing.capture_operation[source]

A decorator used to wrap functions that return an Operation, which captures the Operation and adds it to the global PulseSequence.

If a function that is decorated with @capture_operation is called with the keyword argument capture=False, the Operation returned by the wrapped function will not be captured and added to the global PulseSequence, but rather returned as normal.


Gates

@sequencing.gates.single_qubit_gate[source]

A decorator used to specify that the decorated function is a single-qubit gate acting on one or more Modes.

@sequencing.gates.pulsed_gate_exists[source]

A decorator used to specify types of Modes for which a pulse-based version of the gate exists.

If the first argument is None, then the gate is required to be unitary-only for all types of Modes.

Single-qubit gates

sequencing.gates.rx(theta, *qubits, **kwargs)[source]

Rotates each mode about its x axis by a given angle.

\[R_x(\theta) = \exp(-i\theta/2 \cdot X)\]
Parameters
  • theta (float) – Rotation angle in radians.

  • *qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.ry(theta, *qubits, **kwargs)[source]

Rotates each mode about its y axis by a given angle.

\[R_y(\theta) = \exp(-i\theta/2 \cdot Y)\]
Parameters
  • theta (float) – Rotation angle in radians.

  • *qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.rz(phi, *qubits, **kwargs)[source]

Rotates each mode about its z axis by a given angle.

\[R_z(\phi) = \exp(-i\phi/2 \cdot Z)\]
Parameters
  • phi (float) – Rotation angle in radians.

  • *qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.x(*qubits, **kwargs)[source]

X gate.

\[X = R_x(\pi)\]
Parameters

*qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.y(*qubits, **kwargs)[source]

Y gate.

\[Y = R_y(\pi)\]
Parameters

*qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.z(*qubits, **kwargs)[source]

Z gate.

\[Z = R_z(\pi)\]
Parameters

*qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.h(*qubits, **kwargs)[source]

Hadamard gate.

\[H = \frac{1}{\sqrt{2}}\left(X + Z\right)\]
Parameters

*qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

sequencing.gates.r(theta, phi, *qubits, **kwargs)[source]

Rotate each mode by an angle theta about the axis given by phi.

\[R_\text{axis}(\theta,\phi) = \exp\left(-i\theta/2 \cdot (\cos(\phi)X + \sin(\phi)Y)\right)\]
Parameters
  • theta (float) – Rotation angle in radians.

  • phi (float) – Angle between the axis of rotation and the x axis.

  • *qubits (tuple[Mode]) – Modes to which to apply the gate.

Returns

List of length len(qubits), or None if the gates were captured.

Return type

list[Operation or qutip.Qobj] or None

Two-qubit gates

sequencing.gates.cu(control, target, theta, phi, lamda)[source]

Controlled-U gate.

\[\begin{split}CU(\theta,\phi,\lambda) &= |00\rangle\langle00|\\ &+ |01\rangle\langle01|\\ &+ \cos(\theta/2)|10\rangle\langle10|\\ &+ e^{i(\phi + \lambda)}\cos(\theta/2)|11\rangle\langle11|\\ &+ e^{i\phi}\sin(\theta/2)|11\rangle\langle10|\\ &- e^{i\lambda}\sin(\theta/2)|10\rangle\langle11|\\\end{split}\]
Parameters
  • control (Mode) – Mode acting as control qubit.

  • target (Mode) – Mode acting as the target qubit.

  • theta (float) – Euler angles, in radians.

  • phi (float) – Euler angles, in radians.

  • lamda (float) – Euler angles, in radians.

Returns

The CU operator.

Return type

qutip.Qobj

sequencing.gates.cx(control, target)[source]

Controlled-X gate.

\[\begin{split}CX &= |00\rangle\langle00|\\ &+ |01\rangle\langle01|\\ &+ |11\rangle\langle10|\\ &+ |10\rangle\langle11|\\\end{split}\]
Parameters
  • control (Mode) – Mode acting as control qubit.

  • target (Mode) – Mode acting as the target qubit.

Returns

The CX operator.

Return type

qutip.Qobj

sequencing.gates.cy(control, target)[source]

Controlled-Y gate.

\[\begin{split}CY &= |00\rangle\langle00|\\ &+ |01\rangle\langle01|\\ &+ i|11\rangle\langle10|\\ &- i|10\rangle\langle11|\\\end{split}\]
Parameters
  • control (Mode) – Mode acting as control qubit.

  • target (Mode) – Mode acting as the target qubit.

Returns

The CY operator.

Return type

qutip.Qobj

sequencing.gates.cz(control, target)[source]

Controlled-Z gate.

\[\begin{split}CZ &= |00\rangle\langle00|\\ &+ |01\rangle\langle01|\\ &+ |10\rangle\langle10|\\ &- |11\rangle\langle11|\\\end{split}\]
Parameters
  • control (Mode) – Mode acting as control qubit.

  • target (Mode) – Mode acting as the target qubit.

Returns

The CZ operator.

Return type

qutip.Qobj

sequencing.gates.cphase(control, target, phi)[source]

Controlled-phase gate.

\[\begin{split}C_\text{phase} &= |00\rangle\langle00|\\ &+ |01\rangle\langle01|\\ &+ |10\rangle\langle10|\\ &+ e^{i\varphi}|11\rangle\langle11|\\\end{split}\]
Parameters
  • control (Mode) – Mode acting as control qubit.

  • target (Mode) – Mode acting as the target qubit.

  • phi (float) – Phase in radians.

Returns

The Cphase operator.

Return type

qutip.Qobj

sequencing.gates.swap(qubit1, qubit2)[source]

SWAP gate.

\[\begin{split}\text{SWAP} &= |00\rangle\langle00|\\ &+ |01\rangle\langle10|\\ &+ |10\rangle\langle01|\\ &+ |11\rangle\langle11|\\\end{split}\]
Parameters
  • qubit1 (Mode) – Mode acting as the first qubit.

  • qubit2 (Mode) – Mode acting as the second qubit.

Returns

The SWAP operator.

Return type

qutip.Qobj

sequencing.gates.swapphi(control, target, phi)[source]

SWAPphi gate.

\[\begin{split}\text{SWAP}_\varphi &= |00\rangle\langle00|\\ &+ ie^{-i\varphi}|01\rangle\langle10|\\ &- ie^{i\varphi}|10\rangle\langle01|\\ &+ |11\rangle\langle11|\\\end{split}\]

Note

SWAPphi is only a “controlled” gate for certain values of \(\varphi\). For \(\varphi = n\pi + \frac{\pi}{2}\) the gate is symmetric with respect to qubit ordering.

Parameters
  • control (Mode) – Mode acting as the control qubit.

  • target (Mode) – Mode acting as the target qubit.

  • phi (float) – Phase in radians.

Returns

The SWAPphi operator.

Return type

qutip.Qobj

sequencing.gates.iswap(qubit1, qubit2)[source]

iSWAP gate.

\[\begin{split}i\text{SWAP} &= |00\rangle\langle00|\\ &+ i|01\rangle\langle10|\\ &+ i|10\rangle\langle01|\\ &+ |11\rangle\langle11|\\\end{split}\]
Parameters
  • qubit1 (Mode) – Mode acting as the first qubit.

  • qubit2 (Mode) – Mode acting as the second qubit.

Returns

The iSWAP operator.

Return type

qutip.Qobj

sequencing.gates.eswap(control, target, theta_c, phi=1.5707963267948966)[source]

eSWAP gate.

\[\begin{split}e\text{SWAP}_\varphi(\theta_c) &= \exp(-i\theta_c/2\cdot\text{SWAP}\varphi)\\ &= \cos(\theta_c/2) I - i\sin(\theta_c/2)\text{SWAP}_\varphi\end{split}\]

Note

eSWAP is only a “controlled” gate for certain values of \(\varphi\). For \(\varphi = n\pi + \frac{\pi}{2}\) the gate is symmetric with respect to qubit ordering.

Parameters
  • control (Mode) – Mode acting as the control qubit.

  • target (Mode) – Mode acting as the target qubit.

  • theta_c (float) – Control angle in radians.

  • phi (optional, float) – Phase in radians. Default: pi/2.

Returns

The eSWAP operator.

Return type

qutip.Qobj

sequencing.gates.sqrtswap(qubit1, qubit2)[source]

SqrtSWAP gate.

\[\sqrt{\text{SWAP}}\]
Parameters
  • qubit1 (Mode) – Mode acting as the first qubit.

  • qubit2 (Mode) – Mode acting as the second qubit.

Returns

The SqrtSWAP operator.

Return type

qutip.Qobj

sequencing.gates.sqrtiswap(qubit1, qubit2)[source]

SqrtiSWAP gate.

\[\sqrt{i\text{SWAP}}\]
Parameters
  • qubit1 (Mode) – Mode acting as the first qubit.

  • qubit2 (Mode) – Mode acting as the second qubit.

Returns

The SqrtiSWAP operator.

Return type

qutip.Qobj


QASM

parse_qasm_gate

sequencing.qasm.parse_qasm_gate(qasm_str)[source]

Parses a QASM string like 'u3(pi/2,0,pi)' into the gate name 'u3' and a tuple of float arguments (np.pi/2, 0, np.pi/2).

Parameters

qasm_str (str) – String like ‘u3(pi/2,0,pi)’

Returns

(gate name, gate args)

Return type

tuple[str, tuple[float]]


Calibration

tune_rabi

sequencing.calibration.tune_rabi(system, init_state, e_ops=None, mode_name='qubit', pulse_name=None, amp_range=(-2, 2, 51), progbar=True, plot=True, ax=None, ylabel=None, update=True, verify=True)[source]

Tune the amplitude of a Transmon pulse using an amplitude-Rabi experiment.

Parameters
  • system (System) – System containing the Transmon whose pulse you want to tune.

  • init_state (qutip.Qobj) – Initial state of the system.

  • e_ops (optional, list[qutip.Qobj]) – List of expectation operators. If none, defaults to init_state. Default: None.

  • mode_name (optional, str) – Name of the Transmon mode. Default: ‘qubit’.

  • pulse_name (optional, str) – Name of the pulse to tune. If None, will use transmon.default_pulse. Default: None.

  • amp_range (optional, tuple[float, float, int]) – Range over which to sweep the pulse amplitude, specified by (start, stop, num_steps). The units are such that, if the pulse is tuned up, amplitude of 1 generates a rotation by pi. Default: (-2, 2, 51).

  • progbar (optional, bool) – Whether to display a tqdm progress bar. Default: True.

  • plot (optional, bool) – Whether to plot the results: Default: True.

  • ax (optional, matplotlib axis) – Axis on which to plot results. If None, one is automatically created. Default: None.

  • ylabel (optional, str) – ylabel for the plot. Default: None.

  • update (optional, bool) – Whether to update the pulse amplitude based on the fit result. Default: True.

  • verify (optional, bool) – Whether to re-run the Rabi sequence with the newly-determined amplitude to verify correctness. Default: True.

Returns

(fig, ax), old_amp, new_amp

Return type

tuple[tuple, float, float]

tune_drag

sequencing.calibration.tune_drag(system, init_state, e_ops=None, mode_name='qubit', pulse_name=None, drag_range=(-5, 5, 21), progbar=True, plot=True, ax=None, ylabel=None, update=True)[source]

Tune the DRAG coefficient for a Transmon pulse by executing Rx(pi) - Ry(pi/2) and Ry(pi) - Rx(pi/2) using different DRAG values.

Parameters
  • system (System) – System containing the Transmon whose pulse you want to tune.

  • init_state (qutip.Qobj) – Initial state of the system.

  • e_ops (optional, list[qutip.Qobj]) – List of expectation operators. If None, defaults to init_state. Default: None.

  • mode_name (optional, str) – Name of the Cavity mode. Default: ‘qubit’.

  • pulse_name (optional, str) – Name of the pulse to tune. If None, will use qubit.default_pulse. Default: None.

  • drag_range (optional, tuple[float, float, int]) – Range over which to sweep the DRAG value, specified by (start, stop, num_steps). Default: (-5, 5, 21)

  • progbar (optional, bool) – Whether to display a tqdm progress bar. Default: True.

  • plot (optional, bool) – Whether to plot the results: Default: True.

  • ax (optional, matplotlib axis) – Axis on which to plot results. If None, one is automatically created. Default: None.

  • ylabel (optional, str) – ylabel for the plot. Default: None.

  • update (optional, bool) – Whether to update the DRAG value based on the fit result. Default: True.

Returns

(fig, ax), old_drag, new_drag

Return type

tuple[tuple, float, float]

tune_displacement

sequencing.calibration.tune_displacement(system, init_state, e_ops=None, mode_name='cavity', pulse_name=None, amp_range=(0.1, 3, 51), progbar=True, plot=True, ax=None, ylabel=None, update=True, verify=True)[source]

Tune the amplitude of a Cavity pulse using a displacement experiment.

Parameters
  • system (System) – System containing the Cavity whose pulse you want to tune.

  • init_state (qutip.Qobj) – Initial state of the system.

  • e_ops (optional, list[qutip.Qobj]) – List of expectation operators. If None, defaults to init_state. Default: None.

  • mode_name (optional, str) – Name of the Cavity mode. Default: ‘cavity’.

  • pulse_name (optional, str) – Name of the pulse to tune. If None, will use cavity.default_pulse. Default: None.

  • amp_range (optional, tuple[float, float, int]) – Range over which to sweep the pulse amplitude, specified by (start, stop, num_steps). The units are such that, if the pulse is tuned up, amplitude of 1 generates a displacement of alpha = 1. Default: (0.1, 3, 51).

  • progbar (optional, bool) – Whether to display a tqdm progress bar. Default: True.

  • plot (optional, bool) – Whether to plot the results: Default: True.

  • ax (optional, matplotlib axis) – Axis on which to plot results. If None, one is automatically created. Default: None.

  • ylabel (optional, str) – ylabel for the plot. Default: None.

  • update (optional, bool) – Whether to update the pulse amplitude based on the fit result. Default: True.

  • verify (optional, bool) – Whether to re-run the sequence with the newly-determined amplitude to verify correctness. Default: True.

Returns

(fig, ax), old_amp, new_amp

Return type

tuple[tuple, float, float]