seQuencing logo

Classes

Parameters

Parameterized

class sequencing.parameters.Parameterized(name: str, cls: str = '')[source]

A serializable object with parameters.

Parameterized objects must have a name and can have any number of parameters, which can be created using the functions defined in sequencing.parameters, or by using attrs directly via attr.ib().

Parameterized offers the following convenient features:

  • Recursive get() and set() methods for getting and setting attributes of nested Parameterized objects.

  • Methods for converting a Parameterized object into a Python dict, and creating a new Parameterized object from a dict.

  • Methods for serializing a Parameterized object to json and creating a new Parameterized object from json.

Supported parameter types include:

  • StringParameter

  • BoolParameter

  • IntParameter

  • FloatParameter

  • NanosecondParameter

  • GigahertzParameter

  • RadianParameter

  • DictParameter

  • ListParameter

Notes:

  • Subclasses of Parameterized must be decorated with @attr.s

  • Subclasses of Parameterized can define an initialize() method, which takes no arguments. It will be called on instantiation after the attrs-generated __init__ method (see __attrs_post_init__ for more details). If defined, the subclass’ initialize() method should always call super().initialize() to ensure that the superclass is correctly initialized.

initialize()[source]

Called after the attrs-generated __init__ method.

Can be specialized to set private attributes or perform other setup tasks.

get_param(address, *args, delimiter='.')[source]

Recursively “get” a single attribute of nested Parameterized objects.

Parameters
  • address (str) – delimiter-delimited string specifying the attribute to fetch, e.g. instance.param.sub_param.

  • delimiter (optional, str) – String used to split address. Default: '.'.

Returns

Attribute specified by address.

Return type

object

set_param(address, value, delimiter='.')[source]

Recursively “set” a single attribute of nested Parameterized objects.

Parameters
  • address (str) – delimiter-delimited string specifying the attribute to fetch, e.g. instance.param.sub_param.

  • value (object) – Value to assign to the attribute specified by address.

  • delimiter (optional, str) – String used to split address. Default: “.”.

set(**kwargs)[source]

Recursively “set” attributes of nested Parameterized objects.

Attributes must be specified as keyword arguments: attr_address=value, where attr_address is a delimiter-delimited string specifying the attribute to fetch, e.g. instance__param__sub_param=value. The default delimiter is "__", i.e. two underscores. This can be overridden by passing in delimiter as a keyword argument.

get(*addresses, delimiter='.')[source]

Recursively “get” attributes of nested Parameterized objects.

Parameters
  • *names (tuple[str]) – Names of the attributes whose values should be returned.

  • delimiter (optional, str) – Delimiter for the attribute addresses. Default: “.”

Returns

A dictionary of (attr_address, attr_value).

Return type

dict[str, object]

temporarily_set(**kwargs)[source]

A context mangaer that temporarily sets parameter values, then reverts them to the old values.

Delimiter for get() and set() can be chosen using keyword argument delimiter="{whatever}". The default is two underscores, __.

as_dict(json_friendly=True)[source]

Returns a dictionary representation of the object and all of its parameters.

Parameters

json_friendly (optional, bool) – Whether to return a JSON-friendly dictionary. Default:True.

Returns

Dictionary representation of the Parameterized object.

Return type

dict

to_json(dumps=False, json_path=None)[source]

Serialize object to json.

Parameters
  • dumps (optional, bool) – If True, returns the json string instead of writing to file. Default: False.

  • json_path (optional, str) – Path to write json file to. Default: {self.name}.json.

Returns

json string if dumps is True, else writes json to file and returns None.

Return type

str or None

classmethod from_dict(d)[source]

Creates a new instance from a dict like that returned by self.as_dict().

Parameters

d (dict) – Dict from which to create the Parameterized object.

Returns

Instance of Parameterized whose parameters have been populated from d.

Return type

Parameterized

classmethod from_json(json_path=None, json_str=None)[source]

Creates a new instance from a JSON file or string like that returned by self.to_json().

Parameters
  • json_path (optional, str) – Path to JSON file from which to load parameters. Required if json_str is None. Default: None.

  • json_str (optional, str) – JSON string like that returned by self.to_json(dumps=True). Required if json_path is None Default: None.

Returns

Instance of Parameterized whose parameters have been populated from the JSON data.

Return type

Parameterized


Pulses

Pulse

class sequencing.pulses.Pulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False)[source]

Bases: Parameterized

Generates a parameterized complex pulse waveform using callable pulse_func.

Parameters
  • amp (float) – Maximum amplitude of the pulse. Default: 1.

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

  • phase (float) – Phase offset to apply to the waveform, in radians. Default: 0.

  • noise_sigma (float) – Standard deviation of additive Gaussian noise applied to the pulse (in the same units as amp). Default: 0.

  • noise_alpha (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: True.

plot(ax=None, grid=True, legend=True, **kwargs)[source]

Plots the waveform and returns the Axes.

Keyword arguments are passed to __call__().

ConstantPulse

class sequencing.pulses.ConstantPulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False)[source]

Bases: Pulse

A constant (rectangular) pulse.

Parameters
  • amp (float) – Maximum amplitude of the pulse. Default: 1.

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

  • phase (float) – Phase offset to apply to the waveform, in radians. Default: 0.

SmoothedConstantPulse

class sequencing.pulses.SmoothedConstantPulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False, length=100, sigma=0, shape='tanh')[source]

Bases: Pulse

A constant pulse with smoothed ring-up and ring-down.

Parameters
  • amp (float) – Maximum amplitude of the pulse. Default: 1.

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

  • phase (float) – Phase offset to apply to the waveform, in radians. Default: 0.

  • length (int) – Total length of the pulse in ns. Default: 100.

  • sigma (int) – Ring-up and ring-down time in ns. If sigma == 0, then this is equivalent to ControlPulse. The length of the constant portion of the pulse is length - 2 * sigma. Default: 0.

  • shape (str) – String specifying the type of ring-up and ring-down. Valid options are ‘tanh’, ‘cos’, and ‘gaussian’ (see ringup_wave). Default: ‘tanh’.

GaussianPulse

class sequencing.pulses.GaussianPulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False, sigma=10, chop=4, drag=0)[source]

Bases: Pulse

A Gaussian that is “chopped” at +/- (chop / 2) * sigma. The full pulse length is therefore sigma * chop.

Parameters
  • amp (float) – Maximum amplitude of the pulse. Default: 1.

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

  • phase (float) – Phase offset to apply to the waveform, in radians. Default: 0.

  • sigma (float) – Gaussian sigma in ns. Default: 10.

  • chop (int) – The Gaussian is truncated at +/- chop/2 * sigma. Default: 4.

  • drag (float) – DRAG coefficient. Default: 0.

SechPulse

class sequencing.pulses.SechPulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False, sigma=10, chop=4, drag=0)[source]

Bases: Pulse

Hyperbolic secant pulse that is “chopped” at +/- (chop / 2) * sigma.

\[\begin{split}A(t) &= \text{sech}(\rho t)\\ \rho &= \pi / (2\sigma)\end{split}\]

See: https://doi.org/10.1103/PhysRevA.96.042339

Parameters
  • sigma (int) – Pulse “sigma” in ns (see equation above). Default: 10.

  • chop (int) – The waveform is truncated at +/- chop/2 * sigma. Default: 4.

  • drag (float) – DRAG coefficient: imag(wave) = drag * d/dt real(wave). Default: 0.

SlepianPulse

class sequencing.pulses.SlepianPulse(name: str, cls: str = '', amp=1, detune=0, phase=0, dt=1, noise_sigma=0, noise_alpha=0, scale_noise=False, tau=40, width=10, drag=0)[source]

Bases: Pulse

A Slepian Pulse.

See scipy.signal.windows.slepian.

Parameters
  • tau (int) – Pulse length in ns. Default: 40.

  • width (int) – Pulse width in ns (similar to a Gaussian sigma). Default: 10.

  • drag (float) – DRAG coefficient: imag(wave) = drag * d/dt real(wave). Default: 0.


Modes

Mode

class sequencing.modes.Mode(name: str, cls: str = '', levels=2, t1=inf, t2=inf, thermal_population=0, df=0, kerr=0)[source]

Bases: Parameterized

An oscillator that can be embedded in a larger Hilbert space.

Modes have a logical_zero state and logical_one state, based on which Pauli operators and rotations are defined.

Parameters
  • name (str) – Name of the mode for which to construct operators.

  • levels (optional, int) – Number of levels in the mode subspace. Default: 2.

  • t1 (optional, float) – Mode T1 time in nanoseconds. Default: inf.

  • t2 (optional, float) – Mode T2 time in nanoseconds. Default: inf.

  • thermal_population (optional, float) – Mode excited state population (in [0..1]). Default: 0.

  • df (optional, float) – Mode detuning in GHz. Default: 0.

  • kerr (optional, float) – Mode self-Kerr in GHz. Default: 0.

initialize()[source]

Called after the attrs-generated __init__ method.

Can be specialized to set private attributes or perform other setup tasks.

property space

A list of Modes.

This is the Hilbert space in which the mode exists.

property index

The index of the Mode in its Hilbert space.

property I

Identity operator.

property a

Annihilation operator.

property ad

Creation operator.

property n

Number operator.

property x

Position operator.

property y

Momentum (quadrature) operator.

property detuning

Operator representation of a detuning on this mode.

property self_kerr

Operator representation of the mode’s self-Kerr.

property tphi

Pure dephasing time, calculated from t1 and t2.

property Gamma_up

Excitation rate, calulcated from t1 and thermal_population.

property Gamma_down

Decay rate, calculated from t1 and Gamma_up.

property decay

Collapse operator for energy decay.

property excitation

Collapse operator for excitation.

property dephasing

Collapse operator for pure dephasing.

no_loss()[source]

A context manager that temporarily sets a Mode’s coherence parameters to the ideal values: T1 = inf, T2 = inf, thermal population = 0.

use_space(modes)[source]

A context manager that temporarily sets self.modes to modes, then reverts it to the previous value.

Parameters

modes (list[Mode]) – List of Modes specifying the temporary Hilbert space to use.

fock(n=0, full_space=True)[source]

Returns the Fock state |n>, optionally embedded in the full Hilbert space.

Parameters
  • n (optional, int) – Integer corresponding to desired Fock state. Default: 0

  • full_space (optional, bool) – Whether to return the basis state embedded in the full space. Default: True.

Returns

Ket representing the Fock state.

Return type

qutip.Qobj

basis(n=0, full_space=True)

Returns the Fock state |n>, optionally embedded in the full Hilbert space.

Parameters
  • n (optional, int) – Integer corresponding to desired Fock state. Default: 0

  • full_space (optional, bool) – Whether to return the basis state embedded in the full space. Default: True.

Returns

Ket representing the Fock state.

Return type

qutip.Qobj

fock_dm(n=0, full_space=True)[source]

Returns the basis state |n>, optionally embedded in the full Hilbert space, as a density matrix.

Parameters
  • n (optional, int) – Integer corresponding to desired Fock state. Default: 0

  • full_space (optional, bool) – Whether to return the basis state embedded in the full space. Default: True.

Returns

Density matrix representing the Fock product state.

Return type

qutip.Qobj

static tensor(*args)[source]

Calculates the tensor product of input operators.

tensor_with_zero(state)[source]

Returns state on self, tensored with ket(0) on all other modes in self.space.

Parameters

state (qutip.Qobj) – State of the mode.

Returns

state on the mode, tensored with ket(0) on all other modes in self.space.

Return type

qutip.Qobj

tensor_with_I(operator)[source]

Returns operator for self, tensored with I for all other modes in self.space.

Parameters

state (qutip.Qobj) – State of the mode.

Returns

operator for the mode, tensored with I on all other modes in self.space.

Return type

qutip.Qobj

set_logical_states(logical_zero=None, logical_one=None)[source]

Sets the mode’s logical zero and logical one states.

Parameters
  • logical_zero (optional, qutip.Qobj) – Ket representing the mode’s logical zero state. If None, the Fock state ket(0) is used as logical zero. logical_zero must have the same dimensions as the mode itself. Default: None.

  • logical_one (optional, qutip.Qobj) – Ket representing the mode’s logical one state. If None, the Fock state ket(1) is used as logical one. logical_one must ahve the same dimensions as the mode itself. Default: None.

logical_zero(full_space=True)[source]

Returns the mode’s logical zero state, optionally embedded in the full Hilbert space defined by self.space.

Parameters

full_space (optional, bool) – Whether to embed logical_zero in the full Hilbert space. Default: True.

Returns

Ket representing the mode’s logical zero state.

Return type

qutip.Qobj

logical_one(full_space=True)[source]

Returns the mode’s logical one state, optionally embedded in the full Hilbert space defined by self.space.

Parameters

full_space (optional, bool) – Whether to embed logical_one in the full Hilbert space. Default: True.

Returns

Ket representing the mode’s logical one state.

Return type

qutip.Qobj

logical_states(full_space=True)[source]

Returns the mode’s logical zero and logical one states, optionally embedded in the full Hilbert space defined by self.space.

Parameters

full_space (optional, bool) – Whether to embed logical states in the full Hilbert space. Default: True.

Returns

Kets representing the mode’s logical zero and logical ones states.

Return type

tuple[qutip.Qobj, qutip.Qobj]

sigmax(full_space=True)[source]

Pauli X operator

\[X = \left|0_L\rangle\langle1_L\right| + \left|1_L\rangle\langle0_L\right|\]
Parameters

full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Pauli X operator.

Return type

qutip.Qobj

sigmay(full_space=True)[source]

Pauli Y operator

\[Y = -i\left(\left|0_L\rangle\langle1_L\right| - \left|1_L\rangle\langle0_L\right|\right)\]
Parameters

full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Pauli Y operator.

Return type

qutip.Qobj

sigmaz(full_space=True)[source]

Pauli Z operator.

\[Z = \left|0_L\rangle\langle0_L\right| - \left|1_L\rangle\langle1_L\right|\]
Parameters

full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Pauli Z operator.

Return type

qutip.Qobj

Raxis(theta, phi, full_space=True)[source]

Operator for a rotation of angle theta about an axis specified 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.

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Raxis operator.

Return type

qutip.Qobj

Rx(theta, full_space=True)[source]

Operator for a rotation of angle theta about the x axis.

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

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Rx operator.

Return type

qutip.Qobj

Ry(theta, full_space=True)[source]

Operator for a rotation of angle theta about the y axis.

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

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Ry operator.

Return type

qutip.Qobj

Rz(theta, full_space=True)[source]

Operator for a rotation of angle theta about the z axis.

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

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Rz operator.

Return type

qutip.Qobj

hadamard(full_space=True)[source]

Hadamard operator.

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

full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Hadamard operator.

Return type

qutip.Qobj

Rphi(phi, full_space=True)[source]

Phase shift operator.

\[R_\phi = \exp(i\phi a^\dagger a)\]
Parameters
  • phi (float) – Number state-dependent phase shift to apply to the mode.

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Phase shift operator.

Return type

qutip.Qobj

operator_expr(expr)[source]

Evaluate an expression composed of single-mode operators.

See Mode.OPERATORS for the full list of supported operators.

Parameters

expr (str) – String representation of the operator expression to evaluate.

Returns

Evaluated operator expression.

Return type

qutip.Qobj

PulseMode

class sequencing.modes.PulseMode(name: str, cls: str = '', levels=2, t1=inf, t2=inf, thermal_population=0, df=0, kerr=0, pulses=NOTHING, default_pulse='gaussian_pulse')[source]

Bases: Mode

A Mode that has Pulses.

Parameters
  • name (str) – Name of the mode for which to construct operators.

  • levels (optional, int) – Number of levels in the mode subspace. Default: 2.

  • t1 (optional, float) – Mode T1 time in nanoseconds. Default: inf.

  • t2 (optional, float) – Mode T2 time in nanoseconds. Default: inf.

  • thermal_population (optional, float) – Mode excited state population (in [0..1]). Default: 0.

  • df (optional, float) – Mode detuning in GHz. Default: 0.

  • kerr (optional, float) – Mode self-Kerr in GHz. Default: 0.

  • pulses (optional, dict[str, Pulse]) – Dict of pulses defined for this Mode. Default: empty dict {}.

  • default_pulse (optional, str) – Name of the default Pulse for this Mode. Default: “gaussian_pulse”.

initialize()[source]

Called after the attrs-generated __init__ method.

Can be specialized to set private attributes or perform other setup tasks.

add_pulse(cls=<class 'sequencing.pulses.GaussianPulse'>, name=None, error_if_exists=False, **kwargs)[source]

Creates a new pulse of type cls and adds it to self.pulses.

Keyword arguments are passed to cls.__init__().

Parameters
  • cls (optional, type) – Pulse class to instantiate. Default: GaussianPulse.

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

  • error_if_exists (optional, bool) – Whether to raise an exception if a pulse with the same name already exists. Default: False.

amplitude(amp, pulse_name=None)[source]

A context manager that temporarily sets the amplitude of a given pulse to amp, then reverts it to its previous value.

Parameters
  • amp (float) – Amplitude to temporarilty set.

  • pulse_name (optional, str) – Name of the pulse whose amplitude you would like to set. If None, uses self.default_pulse. Default: None.

pulse_scale(scale, pulse_name=None)[source]

A context manager that temporarily scales the amplitude of a given pulse by scale, then reverts it to its previous value (i.e. scale = 1).

Parameters
  • scale (float) – Factor by which to temporarilty scale the pulse amplitude.

  • pulse_name (optional, str) – Name of the pulse whose amplitude you would like to scale. If None, uses self.default_pulse. Default: None.

Qubit

class sequencing.modes.Qubit(name: str, cls: str = '', levels=2, t1=inf, t2=inf, thermal_population=0, df=0, kerr=0, pulses=NOTHING, default_pulse='gaussian_pulse')[source]

Bases: PulseMode

Fixed-frequency qubit.

A PulseMode whose primary operations are rotations on the Bloch Sphere.

Parameters
  • name (str) – Name of the mode for which to construct operators.

  • levels (optional, int) – Number of levels in the mode subspace. Default: 2.

  • t1 (optional, float) – Mode T1 time in nanoseconds. Default: inf.

  • t2 (optional, float) – Mode T2 time in nanoseconds. Default: inf.

  • thermal_population (optional, float) – Mode excited state population (in [0..1]). Default: 0.

  • df (optional, float) – Mode detuning in GHz. Default: 0.

  • kerr (optional, float) – Mode self-Kerr in GHz. Default: 0.

  • pulses (optional, dict[str, Pulse]) – Dict of pulses defined for this Mode. Default: empty dict {}.

  • default_pulse (optional, str) – Name of the default Pulse for this Mode. Default: “gaussian_pulse”.

property anharmonicity

Alias for Qubit.kerr

rotate(angle, phase, pulse_name=None, unitary=False, **kwargs)[source]

Generate a pulse to rotate the qubit by a given angle about a given axis.

Keyword arguments are passed to the Pulse object.

Parameters
  • angle (float) – Rotation angle in radians.

  • phase (float) – Rotation axis relative to the x axis.

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

  • unitary (optional, bool) – Whether to return the corresponding unitary operator instead of executing the pulse. Default: False.

Returns

If unitary is True, returns the unitary operator Rx(angle), otherwise returns the resulting Operation object.

Return type

qutip.Qobj or Operation

rotate_x(angle, unitary=False, **kwargs)[source]

Generate a rotation about the x axis.

Keyword arguments are passed to Qubit.rotate() if unitary is False.

Parameters
  • angle (float) – Rotation angle in radians.

  • unitary (optional, bool) – Whether to return the corresponding unitary operator instead of executing the pulse. Default: False.

Returns

If unitary is True, returns the unitary operator Rx(angle), otherwise returns the resulting Operation object.

Return type

qutip.Qobj or Operation

rotate_y(angle, unitary=False, **kwargs)[source]

Generate a rotation about the y axis.

Keyword arguments are passed to Qubit.rotate() if unitary is False.

Parameters
  • angle (float) – Rotation angle in radians.

  • unitary (optional, bool) – Whether to return the corresponding unitary operator instead of executing the pulse. Default: False.

Returns

If unitary is True, returns the unitary operator Ry(angle), otherwise returns the resulting Operation object.

Return type

qutip.Qobj or Operation

Transmon

class sequencing.modes.Transmon(name: str, cls: str = '', levels=2, t1=inf, t2=inf, thermal_population=0, df=0, kerr=0, pulses=NOTHING, default_pulse='gaussian_pulse')[source]

Bases: Qubit

Fixed-frequency transmon qubit.

A PulseMode whose primary operations are rotations on the Bloch Sphere.

Parameters
  • name (str) – Name of the mode for which to construct operators.

  • levels (optional, int) – Number of levels in the mode subspace. Default: 2.

  • t1 (optional, float) – Mode T1 time in nanoseconds. Default: inf.

  • t2 (optional, float) – Mode T2 time in nanoseconds. Default: inf.

  • thermal_population (optional, float) – Mode excited state population (in [0..1]). Default: 0.

  • df (optional, float) – Mode detuning in GHz. Default: 0.

  • kerr (optional, float) – Mode self-Kerr in GHz. Default: 0.

  • pulses (optional, dict[str, Pulse]) – Dict of pulses defined for this Mode. Default: empty dict {}.

  • default_pulse (optional, str) – Name of the default Pulse for this Mode. Default: “gaussian_pulse”.

Cavity

class sequencing.modes.Cavity(name: str, cls: str = '', levels=2, t1=inf, t2=inf, thermal_population=0, df=0, kerr=0, pulses=NOTHING, default_pulse='gaussian_pulse')[source]

Bases: PulseMode

Weakly non-linear cavity.

A PulseMode whose primary operation is displacements.

Parameters
  • name (str) – Name of the mode for which to construct operators.

  • levels (optional, int) – Number of levels in the mode subspace. Default: 2.

  • t1 (optional, float) – Mode T1 time in nanoseconds. Default: inf.

  • t2 (optional, float) – Mode T2 time in nanoseconds. Default: inf.

  • thermal_population (optional, float) – Mode excited state population (in [0..1]). Default: 0.

  • df (optional, float) – Mode detuning in GHz. Default: 0.

  • kerr (optional, float) – Mode self-Kerr in GHz. Default: 0.

  • pulses (optional, dict[str, Pulse]) – Dict of pulses defined for this Mode. Default: empty dict {}.

  • default_pulse (optional, str) – Name of the default Pulse for this Mode. Default: “gaussian_pulse”.

D(alpha, full_space=True)[source]

Returns the displacement operator.

Parameters
  • alpha (complex) – Displacement amplitude.

  • full_space (optional, bool) – Whether to embed the operator in the full Hilbert space. Default: True.

Returns

Displacement operator.

Return type

qutip.Qobj

displace(alpha, unitary=False, pulse_name=None, **kwargs)[source]

Generate a displacement of amplitude alpha.

Keyword arguments are passed to the Pulse object if unitary is False.

Parameters
  • alpha (complex) – Displacement amplitude.

  • unitary (optional, bool) – Whether to return the unitary operator instead of generating a pulse. Default: False.

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

Returns

If unitary is True, returns the unitary operator Ry(angle), otherwise returns the resulting Operation object.

Return type

qutip.Qobj or Operation


System

CouplingTerm

class sequencing.system.CouplingTerm(*terms, strength=1, add_hc=False)[source]

An object representing a coupling between multiple Modes, given by a Hamiltonian term of the form strength * product(operators). If the keyword argument add_hc is provided and is True, then the Hamiltonian term takes the form strength * (product(operators) + product(operators).dag()).

Parameters
  • terms (list[tuple[Mode, str]]) – List of tuples of (mode, expr), which defines the coupling. Each expr is a string containing an algebraic expression involving the Mode’s operators. See Mode.operator_expr() for more details. The resulting operators are given by mode.operator_expr(expr).

  • strength (optional, float) – Coefficient parameterizing the strength of the coupling. Strength should be given in units of 2 * pi * GHz. Default: 1.

  • add_hc (optional, bool) – Whether to add the Hermitian conjugate of the product of the operators. Default: False.

H(strength=None, add_hc=None)[source]

Returns the operator representing the coupling term.

Parameters
  • strength (optional, float) – Coefficient parameterizing the strength of the coupling. Strength should be given in units of 2 * pi * GHz. Defaults to self.strength.

  • add_hc (optional, bool) – Whether to add the Hermitian conjugate of product of self.operators. Defaults to self.add_hc.

Returns

Operator representing the coupling term.

Return type

qutip.Qobj

System

class sequencing.system.System(name: str, cls: str = '', modes=NOTHING, cross_kerrs=NOTHING)[source]

Bases: Parameterized

A collection of Modes that can be coupled together.

modes

List of all Modes in the system.

Type

list[Mode]

coupling_terms

A dictionary of CouplingTerm objects specifying all interactions in the system.

Type

dict[frozenset[str], list[CouplingTerm]]

cross_kerrs

A dictionary of cross-Kerr values in units of GHz.

Type

dict[frozenset[str], float]

initialize()[source]

Called after the attrs-generated __init__ method.

Can be specialized to set private attributes or perform other setup tasks.

get_mode(mode)[source]

Fetch a mode by name.

Parameters

mode (str or Mode) – Name of Mode to fetch, or the Mode itself.

Returns

The requested Mode.

Return type

Mode

property levels

Dictionary of (mode_name, number_of_levels)

property active_modes

List of the modes currently being used.

use_modes(modes)[source]

A context manager that temporarily sets self.active_modes to modes, then reverts self.active_modes to its previous value.

Parameters

modes (list[Mode]) – List of Modes to temporarily assign to self.active_modes.

static tensor(*args)[source]

Calculates the tensor product of input operators.

I(modes=None)[source]

Identity operator.

Parameters

modes (optional, list[Mode]) – List of Modes to use in constructing H0. If None, will use self.active_modes. Default: None.

Returns

Identity operator on the Hilbert space defined by modes.

Return type

qutip.Qobj

eye(modes=None)

Identity operator.

Parameters

modes (optional, list[Mode]) – List of Modes to use in constructing H0. If None, will use self.active_modes. Default: None.

Returns

Identity operator on the Hilbert space defined by modes.

Return type

qutip.Qobj

fock(*args, **kwargs)[source]

Returns a product state in the Fock basis. States can be specified either positionally or as keyword arguments.

Parameters
  • *args (tuple) – Fock states of Modes in the order of self.modes.

  • **kwargs (dict) – Fock states of Modes specified as keyword arguments, mode_name=n.

Returns

The requested product state.

Return type

qutip.Qobj

fock_dm(*args, **kwargs)[source]

Returns a product state in the Fock basis, as a density matrix.

States can be specified either positionally or as keyword arguments.

Parameters
  • *args (tuple) – Fock states of Modes in the order of self.modes.

  • **kwargs (dict) – Fock states of Modes specified as keyword arguments, mode_name=n.

Returns

The requested product state, as a density matrix.

Return type

qutip.Qobj

basis(*args, **kwargs)

Returns a product state in the Fock basis. States can be specified either positionally or as keyword arguments.

Parameters
  • *args (tuple) – Fock states of Modes in the order of self.modes.

  • **kwargs (dict) – Fock states of Modes specified as keyword arguments, mode_name=n.

Returns

The requested product state.

Return type

qutip.Qobj

ground_state()[source]

Returns the ground state of the system.

Returns

The system’s ground state.

Return type

qutip.Qobj

logical_basis(*args, **kwargs)[source]

Returns a product state in the basis spanned by the logical states of all modes. Logical states can be specified either positionally or as keyword arguments.

Parameters
  • *args (tuple) – Logical states of Modes in the order of self.modes.

  • **kwargs (dict) – Logical states of Modes specified as keyword arguments, mode_name=n.

Returns

The requested product state.

Return type

qutip.Qobj

set_cross_kerr(mode1, mode2, chi=0)[source]

Set the cross-Kerr (in GHz) between two modes. Note that the order of mode1 and mode2 doesn’t matter.

Parameters
  • mode1 (Mode or str) – Instance of Mode or the name of a member of self.modes.

  • mode2 (Mode or str) – Instance of Mode or the name of a member of self.modes.

  • chi (optional, float) – Cross-Kerr between mode0 and mode1 in GHz. Default: 0.

couplings(modes=None, clean=True)[source]

Returns all of the static coupling terms in the Hamiltonian.

Parameters
  • modes (optional, list[Mode]) – List of Modes to use in constructing H0. If None, will use self.active_modes. Default: None.

  • clean (optional, bool) – Only keep operators with nonzero elements. Default: True.

Returns

List of static coupling terms.

Return type

list[qutip.Qobj]

H0(modes=None, clean=True)[source]

Returns the static Hamiltonian consisting of all self-Kerrs and inter-mode couplings.

Parameters
  • modes (optional, list[Mode]) – List of Modes to use in constructing H0. If None, will use self.active_modes. Default: None.

  • clean (optional, bool) – Only keep operators with nonzero elements. Default: True.

Returns

Static Hamiltonian in list form.

Return type

list[qutip.Qobj]

c_ops(modes=None, clean=True)[source]

Returns a list of collapse operators corresponding to loss (decay/excitation) and dephasing of all modes.

Parameters
  • modes (optional, list[Mode]) – List of Modes to use in constructing H0. If None, will use self.active_modes. Default: None.

  • clean (optional, bool) – Only keep operators with nonzero elements. Default: True.

Returns

List of all collapse operators.

Return type

list[qutip.Qobj]

as_dict(json_friendly=False)[source]

Overrides Parameterized.as_dict() in order to deal with cross_kerrs.

Parameters

json_friendly (optional, bool) – Whether to return a JSON-friendly dictionary. Default:True.

Returns

Dictionary representation of the System object.

Return type

dict

classmethod from_json(json_path=None, json_str=None)[source]

Overrides Parameterized.from_json() in order to deal with cross_kerrs.

Parameters
  • json_path (optional, str) – Path to JSON file from which to load parameters. Required if json_str is None. Default: None.

  • json_str (optional, str) – JSON string like that returned by self.to_json(dumps=True). Required if json_path is None Default: None.

Returns

Instance of System whose parameters have been populated from the JSON data.

Return type

System


Sequencing

HamiltonianChannels

class sequencing.sequencing.HamiltonianChannels(channels=None, collapse_channels=None, t0=0, dt=1)[source]

Object prepresenting a set of Hamiltonian ‘channels’ with time-dependent coefficients.

Parameters
  • channels (optional, dict) – Dict of {channel_name: {‘H’: hamiltonian_term, ‘time_dependent’: td_bool}}, where hamiltonian_term is a qutip.Qobj and td_bool is a boolean flag indicating whether this Hamiltonian will be given time-dependence (defaults to False). Default: None.

  • collapse_channels (optional, dict) – Similar to channels, but for collapse operators instead of Hamiltonian terms. Default: None.

property times

Array of times.

add_channel(name, H=None, C_op=None, time_dependent=False, error_if_exists=True)[source]

Add a channel with specified Hamiltonian term H or collapse operator C_op.

Parameters
  • name (str) – Name of the Hamiltonian channel.

  • H (optional, qutip.Qobj) – Hamiltonian term for this channel.

  • C_op (optional, qutip.Qobj) – Collapse operator for this channel.

  • time_dependent (optional, bool) – Whether this channel has time-dependent Hamiltonian coefficients. Default: False.

  • error_if_exists (optional, bool) – Whether to raise an exception if a channel with the same name already exists. Default: True.

add_operation(channel_name, t0=None, duration=None, times=None, H=None, C_op=None, coeffs=1, coeffs_args=None, coeffs_kwargs=None)[source]

Add an operation to a given channel, padding all other channels accordingly.

Parameters
  • channel_name (str) – Name of the Hamiltonian channel this operation acts on.

  • t0 (optional, int) – Starting time of this operation (required along with duration if you do not provide an array of times). Default: None.

  • duration (optional, int) – Length of this operation (required along with t0 if you do not provide an array of times). Default: None.

  • times (optional, sequence[int]) – Sequence of time points. Default: None.

  • H (optional, qutip.Qobj) – Hamiltonian for the given channel (required if this channel is not yet in self.channels). Default: None.

  • C_op (optional, qutip.Qobj) – Collapse operator for the given channel (required if this channel is not yet in self.collapse_channels).

  • coeffs (optional, number | sequence | callable) – Hamiltonian coefficients for the given time points. You can specify single int/float/complex for constant coefficients, or provide a function that takes time as its first argument and returns coefficiencts. Default: None.

  • coeffs_args (optional, sequence) – Positional arguments passed to coeffs if coeffs is callable. Default: None.

  • coeffs_kwargs (optional, dict) – Keyword arguments passed to coeffs if coeffs is a function. Default: None.

Important note: if reset_t0 is in coeffs_kwargs and is True, then the first argument for coeffs will be times-times[0] instead of times. This allows for the user to take care of phase bookkeeping.

delay_channels(channel_names, duration)[source]

Add a delay of length duration to channels specified in the list channel_names.

build_hamiltonian()[source]

Assemble the channels into a list of Hamiltonian terms and collapse operators which can be ingested by qutip.mesolve.

Returns

H, C_ops, times

Return type

tuple[list, list, np.ndarray]

plot_coefficients(subplots=True, plot_imag=False, step=False)[source]

Plot the Hamiltionian coefficients for all channels.

Parameters
  • subplots (optional, bool) – If True, plot each channel on a different axis. Default: True.

  • plot_imag (optional, bool) – If True, plot both real and imag. Default: False.

  • step (optional, bool) – It True, use axis.step() instead of axis.plot(). Default: False.

Returns

(fig, ax): matplotlib Figure and axes.

Return type

tuple

CompiledPulseSequence

class sequencing.sequencing.CompiledPulseSequence(system=None, channels=None, t0=0)[source]

Creates time-dependent Hamiltonian channels from a sequence of Operations.

Parameters
  • system (optional, subsystems.System) – System containing the Modes on which to operate.

  • channels (opional, dict) – Dict of initial channels to pass the HamiltonianChannels. Default: None.

add_channel(name, H=None, C_op=None, time_dependent=False, error_if_exists=True)[source]

Add a channel with specified Hamiltonian term H or collapse operator C_op.

Parameters
  • name (str) – Name of the Hamiltonian channel.

  • H (optional, qutip.Qobj) – Hamiltonian term for this channel.

  • C_op (optional, qutip.Qobj) – Collapse operator for this channel.

  • time_dependent (optional, bool) – Whether this channel has time-dependent Hamiltonian coefficients. Default: False.

  • error_if_exists (optional, bool) – Whether to raise an exception if a channel with the same name already exists. Default: True.

add_operation(operation)[source]

Add an Operation (time dependent Hamiltonian or collapse terms) to the HamiltonianChannels at the current time.

Parameters

operation (Operation) – Operation object to add to the pulse sequence.

delay(length, sync_before=True, sync_after=True)[source]

Add a global delay to the sequence.

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

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

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

sync()[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.

build_hamiltonian()[source]

Assemble the channels into a list of Hamiltonian terms and collapse operators which can be ingested by qutip.mesolve.

Returns

H, C_ops, times

Return type

tuple[list, list, np.ndarray]

run(init_state, c_ops=None, e_ops=None, options=None, only_final_state=False, progress_bar=None)[source]

Simulate the sequence using qutip.mesolve.

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

  • c_ops (optional, list) – List of additional collapse operators. Default: None.

  • e_ops (optional, list) – List of expectation operators. Default: None.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • only_final_state (optional, bool) – Whether to query the system’s state at only the initial and final times rather than at every time step in the Hamiltonian. Default: False.

  • progress_bar (optional, None) – Whether to use qutip’s progress bar. Default: None (no progress bar).

Returns

qutip.Solver.Result instance.

Return type

qutip.solver.Result

propagator(c_ops=None, options=None, unitary_mode='batch', parallel=False)[source]

Calculate the propagator using qutip.propagator().

Parameters
  • c_ops (list[qutip.Qobj]) – List of collapse operators.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • progress_bar (optional, None) – Whether to use qutip’s progress bar. Default: None (no progress bar).

  • unitary_mode (optional, "batch" or "single") – Solve all basis vectors simulaneously (“batch”) or individually (“single”). Default: “batch”.

  • parallel (optional, bool) – Run the propagator in parallel mode. This will override the unitary_mode settings if set to True. Default: False.

Returns

List of Qobjs representing the propagator U(t).

Return type

list[qutip.Qobj]

plot_coefficients(subplots=True, plot_imag=False, step=False)[source]

Plot the Hamiltionian coefficients for all channels.

Parameters
  • subplots (optional, bool) – If True, plot each channel on a different axis. Default: True.

  • plot_imag (optional, bool) – If True, plot both real and imag. Default: False.

  • step (optional, bool) – It True, use axis.step() instead of axis.plot(). Default: False.

Returns

(fig, ax): matplotlib Figure and axes.

Return type

tuple

PulseSequence

class sequencing.sequencing.PulseSequence(system=None, t0=0, items=None)[source]

Bases: ValidatedList

A list-like container of Operation, SyncOperation, DelayOperation, and DelayChannelOperation objects, which can be compiled into a CompiledPulseSequence at a later time.

Parameters
  • system (optional, System) – The System associated with the PulseSequence. Default: None.

  • t0 (optional, int) – The start time of the PulseSequence. Default: 0.

  • items (optional, iterable) – Iterable containing initial values with which to populate the PulseSequence. Default: None.

set_system(system=None, t0=0)[source]

Sets the System and start time for the PulseSequence.

Parameters
  • system (optional, System) – The System associated with the PulseSequence. Default: None.

  • t0 (optional, int) – The start time of the PulseSequence. Default: 0.

compile()[source]

Compiles the PulseSequence into a CompiledPulseSequence.

Returns

A new CompiledPulseSequence.

Return type

CompiledPulseSequence

property times

Array of times.

property channels

Dict of Hamiltonian channels.

run(init_state, c_ops=None, e_ops=None, options=None, only_final_state=False, progress_bar=None)[source]

Simulate the sequence using qutip.mesolve.

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

  • c_ops (optional, list) – List of additional collapse operators. Default: None.

  • e_ops (optional, list) – List of expectation operators. Default: None.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • only_final_state (optional, bool) – Whether to query the system’s state at only the initial and final times rather than at every time step in the Hamiltonian. Default: False.

  • progress_bar (optional, None) – Whether to use qutip’s progress bar. Default: None (no progress bar).

Returns

qutip.solver.Result instance.

Return type

qutip.solver.Result

propagator(c_ops=None, options=None, unitary_mode='batch', parallel=False, progress_bar=None)[source]

Calculate the propagator using qutip.propagator().

Parameters
  • c_ops (list[qutip.Qobj]) – List of collapse operators.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • progress_bar (optional, None) – Whether to use qutip’s progress bar. Default: None (no progress bar).

  • unitary_mode (optional, "batch" or "single") – Solve all basis vectors simulaneously (“batch”) or individually (“single”). Default: “batch”.

  • parallel (optional, bool) – Run the propagator in parallel mode. This will override the unitary_mode settings if set to True. Default: False.

Returns

List of Qobjs representing the propagator U(t).

Return type

list[qutip.Qobj]

plot_coefficients(subplots=True, plot_imag=False, step=False)[source]

Plot the Hamiltionian coefficients for all channels.

Parameters
  • subplots (optional, bool) – If True, plot each channel on a different axis. Default: True.

  • plot_imag (optional, bool) – If True, plot both real and imag. Default: False.

  • step (optional, bool) – It True, use axis.step() instead of axis.plot(). Default: False.

Returns

(fig, ax): matplotlib Figure and axes.

Return type

tuple

append(item)

Add an item to the end of the ValidatedList.

clear()

Remove all items from the ValidatedList.

extend(iterable)

Extend the ValidatedList by appending all the items from the iterable.

insert(i, item)

Insert an item at a given position in the ValidatedList.

pop(i=-1)

Remove the item at the given position in the ValidatedList, and return it.

Sequence

class sequencing.sequencing.main.Sequence(system, operations=None)[source]

Bases: ValidatedList

A list-like container of PulseSequence, Operation, and unitary objects, which can be used to evolve an initial state.

Parameters
  • system (System) – System upon which the sequence will act.

  • operations (optional, list[qutip.Qobj, PulseSequence, Operation]) – Initial list of Operations or unitaries. Default: None.

reset_pulse_sequence()[source]

Reset the current pulse sequence.

capture()[source]

Appends the current pulse sequence if it is not empty.

run(init_state, e_ops=None, options=None, full_evolution=True, progress_bar=False)[source]

Evolves init_state using each PulseSequence, Operation, or unitary applied in series.

Parameters
  • init_state (qutip.Qobj) – Initial state to evolve.

  • options (optional, qutip.Options) – qutip solver options. Default: None.

  • full_evolution (optional, bool) – Whether to store the states for every time point in the included Sequences. If False, only the final state will be stored. Default: True.

  • progress_bar (optional, bool) – If True, displays a progress bar when iterating through the Sequence. Default:True.

Returns

SequenceResult containing the time evolution of the system.

Return type

SequenceResult

propagator(c_ops=None, options=None, unitary_mode='batch', parallel=False, progress_bar=False)[source]

Calculate the propagator using qutip.propagator().

Parameters
  • c_ops (list[qutip.Qobj]) – List of collapse operators.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • progress_bar (optional, bool) – Whether to use qutip’s progress bar. Default: None (no progress bar).

  • unitary_mode (optional, "batch" or "single") – Solve all basis vectors simulaneously (“batch”) or individually (“single”). Default: “batch”.

  • parallel (optional, bool) – Run the propagator in parallel mode. This will override the unitary_mode settings if set to True. Default: False.

  • progress_bar – If True, displays a progress bar when iterating through the Sequence. Default:True.

Returns

List of Qobjs representing the propagator U(t).

Return type

list[qutip.Qobj]

plot_coefficients(subplots=True, sharex=True, sharey=True)[source]

Plot the Hamiltionian coefficients for all channels. Unitaries are represented by vertical lines.

Parameters
  • subplots (optional, bool) – If True, plot each channel on a different axis. Default: True.

  • sharex (optional, bool) – Share x axes if subplots is True. Default: True.

  • sharey (optional, bool) – Share y axes if subplots is True. Default: True.

Returns

(fig, ax): matplotlib Figure and axes.

Return type

tuple

append(item)

Add an item to the end of the ValidatedList.

clear()

Remove all items from the ValidatedList.

extend(iterable)

Extend the ValidatedList by appending all the items from the iterable.

insert(i, item)

Insert an item at a given position in the ValidatedList.

pop(i=-1)

Remove the item at the given position in the ValidatedList, and return it.

SequenceResult

class sequencing.sequencing.SequenceResult(times=None, states=None, expect=None, num_collapse=0)[source]

An object that mimics qutip.solver.Result for Sequences.

times

Array of times.

Type

np.ndarray

states

List of states.

Type

list[qutip.Qobj]

expect

List of arrays of expectation values.

Type

list[np.ndarray]

num_expect

Number of expectation operators, num_expect == len(expect).

Type

int

num_collapse

Number of collapse operators involved in the Sequence.

Type

int

solver

Name of the ‘solver’ used to generate the SequenceResult. This is always ‘sequencing.Sequence’.

Type

str

HTerm

class sequencing.sequencing.HTerm(H, coeffs, args, kwargs)

A namedtuple specifying a time-depdendent Hamiltonian term.

Parameters
  • H (qutip.Qobj) – The Hamiltonian operator.

  • coeffs (optional, number, array-like, or callable) – Time-dependent coefficients for the given operator. You can specify single int/float/complex for constant coefficients, or provide a function that takes time as its first argument and returns coefficiencts. Default: None.

  • args (optional, iterable) – Positional arguments passed to coeffs if coeffs is callable. Default: None.

  • kwargs (optional, dict) – Keyword arguments passed to coeffs if coeffs is a function. Default: None.

H

Alias for field number 0

args

Alias for field number 2

coeffs

Alias for field number 1

kwargs

Alias for field number 3

CTerm

class sequencing.sequencing.CTerm(op, coeffs, args, kwargs)

A namedtuple specifying a time-depdendent collapse operator.

Parameters
  • op (qutip.Qobj) – The collapse operator.

  • coeffs (optional, number, array-like, or callable) – Time-dependenct oefficients for the given operator. You can specify single int/float/complex for constant coefficients, or provide a function that takes time as its first argument and returns coefficiencts. Default: None.

  • args (optional, iterable) – Positional arguments passed to coeffs if coeffs is callable. Default: None.

  • kwargs (optional, dict) – Keyword arguments passed to coeffs if coeffs is a function. Default: None.

args

Alias for field number 2

coeffs

Alias for field number 1

kwargs

Alias for field number 3

op

Alias for field number 0

Operation

class sequencing.sequencing.Operation(duration, terms)

A namedtuple specifying a set of HTerms that are applied simultaneously.

Parameters
  • duration (int) – The number of time points in each of the terms, i.e. the duration of the operation.

  • terms (dict) – Dict of (hamiltonian_channel_name, HTerm)

duration

Alias for field number 0

terms

Alias for field number 1

SyncOperation

class sequencing.sequencing.SyncOperation[source]

When inserted into a PulseSequence, ensures 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 syncs. Within a block, channels are made to have equal duration by padding shorter channels to the maximum channel length.

DelayOperation

class sequencing.sequencing.DelayOperation(length, sync_before=True, sync_after=True)[source]

When inserted into a PulseSequence, 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.

DelayChannelsOperation

class sequencing.sequencing.DelayChannelsOperation(channels, length)[source]

When inserted into a PulseSequence, 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.

ValidatedList

class sequencing.sequencing.common.ValidatedList(iterable=None)[source]

A list-like container which is enforced to only accept values of the types listed in the class attribute VALID_TYPES.

Parameters

iterable (optional, iterable) – Iterable of initial values with which to populate the list. Default: None.

append(item)[source]

Add an item to the end of the ValidatedList.

extend(iterable)[source]

Extend the ValidatedList by appending all the items from the iterable.

insert(i, item)[source]

Insert an item at a given position in the ValidatedList.

pop(i=-1)[source]

Remove the item at the given position in the ValidatedList, and return it.

clear()[source]

Remove all items from the ValidatedList.


Gates

TwoQubitGate

class sequencing.gates.twoqubit.TwoQubitGate(qubit1, qubit2)[source]

An object representing a 2-qubit gate, which handles validation of the objects on which it acts, as well as the creation logical states for use in constructing the gate.

Parameters
  • qubit1 (Mode) – Mode acting as the first qubit.

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

logical_state(qubit1_state, qubit2_state)[source]

Return the logical state ket(qubit1_state, qubit2_state).

Parameters
  • qubit1_state (0 or 1) – qubit1 state.

  • qubit2_state (0 or 1) – qubit2 state.

Returns

Ket representing the requested logical state.

Return type

qutip.Qobj

ControlledTwoQubitGate

class sequencing.gates.twoqubit.ControlledTwoQubitGate(control=None, target=None)[source]

Bases: TwoQubitGate

An object representing a controlled 2-qubit gate, which handles validation of the objects on which it acts, as well as the creation of logical states for use in constructing the gate.

Control qubit is listed first, target is second.

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

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

CUGate

class sequencing.gates.twoqubit.CUGate(control=None, target=None)[source]

Bases: ControlledTwoQubitGate

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.

__call__(theta, phi, lamda)[source]
Parameters
  • 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

CXGate

class sequencing.gates.CXGate(control=None, target=None)[source]

Bases: CUGate

Controlled-X gate.

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

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

__call__()[source]
Returns

The CX operator.

Return type

qutip.Qobj

CYGate

class sequencing.gates.CYGate(control=None, target=None)[source]

Bases: CUGate

Controlled-Y gate.

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

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

__call__()[source]
Returns

The CY operator.

Return type

qutip.Qobj

CZGate

class sequencing.gates.CZGate(control=None, target=None)[source]

Bases: CUGate

Controlled-Z gate.

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

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

__call__()[source]
Returns

The CZ operator.

Return type

qutip.Qobj

CPhaseGate

class sequencing.gates.CPhaseGate(control=None, target=None)[source]

Bases: ControlledTwoQubitGate

Controlled-phase gate.

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

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

__call__(phi)[source]
Parameters

phi (float) – Phase in radians.

Returns

The Cphase operator.

Return type

qutip.Qobj

SWAPGate

class sequencing.gates.SWAPGate(qubit1, qubit2)[source]

Bases: TwoQubitGate

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.

__call__()[source]
Returns

The SWAP operator.

Return type

qutip.Qobj

SWAPphiGate

class sequencing.gates.SWAPphiGate(control=None, target=None)[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.

__call__(phi)[source]
Parameters

phi (float) – Phase in radians.

Returns

The SWAPphi operator.

Return type

qutip.Qobj

iSWAPGate

class sequencing.gates.iSWAPGate(qubit1, qubit2)[source]

Bases: TwoQubitGate

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.

__call__()[source]
Returns

The iSWAP operator.

Return type

qutip.Qobj

eSWAPGate

class sequencing.gates.eSWAPGate(control=None, target=None)[source]

Bases: ControlledTwoQubitGate

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.

__call__(theta_c, phi=1.5707963267948966)[source]
Parameters
  • theta_c (float) – Control angle in radians.

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

Returns

The eSWAP operator.

Return type

qutip.Qobj

SqrtSWAPGate

class sequencing.gates.SqrtSWAPGate(qubit1, qubit2)[source]

Bases: TwoQubitGate

SqrtSWAP gate.

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

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

__call__()[source]
Returns

The SqrtSWAP operator.

Return type

qutip.Qobj

SqrtiSWAPGate

class sequencing.gates.SqrtiSWAPGate(qubit1, qubit2)[source]

Bases: TwoQubitGate

SqrtiSWAP gate.

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

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

__call__()[source]
Returns

The SqrtiSWAP operator.

Return type

qutip.Qobj


QASM

QasmSequence

class sequencing.qasm.QasmSequence(system, operations=None)[source]

Bases: Sequence

A Sequence with methods implementing the single-qubit gates defined in the OpenQASM specification.

References

  1. https://qiskit.github.io/openqasm/

  2. https://arxiv.org/abs/1707.03429

  3. https://qiskit.org/textbook/ch-states/single-qubit-gates.html

Parameters
  • system (System) – System upon which the sequence will act.

  • operations – (optional, list[CompiledPulseSequence, Operation, Sequence]): Initial list of Operations or unitaries. Default: None.

U(theta, phi, lamda, *qubits, unitary=True, append=True)[source]
\[U(\theta,\phi,\lambda) = u_3(\theta,\phi,\lambda) = R_z(\phi)R_y(\theta)R_z(\lambda)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

u3(theta, phi, lamda, *qubits, unitary=True, append=True)
\[U(\theta,\phi,\lambda) = u_3(\theta,\phi,\lambda) = R_z(\phi)R_y(\theta)R_z(\lambda)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

u2(phi, lamda, *qubits, unitary=True, append=True)[source]
\[u_2(\phi,\lambda) = U(\pi/2,\phi,\lambda)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

u1(lamda, *qubits, append=True)[source]
\[p(\lambda) = u_1(\lambda) = U(0,0,\lambda) = R_z(\lambda)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

p(lamda, *qubits, append=True)
\[p(\lambda) = u_1(\lambda) = U(0,0,\lambda) = R_z(\lambda)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

id(*qubits, unitary=True, append=True)[source]

Identity.

\[I = U(0,0,0)\]
Returns

qutip.Qobj or None

x(*qubits, unitary=True, append=True)[source]
\[x = u_3(\pi,0,\pi)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

y(*qubits, unitary=True, append=True)[source]
\[y = u_3(\pi,\pi/2,\pi/2)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

z(*qubits, append=True)[source]
\[z = u_1(\pi) = R_z(\pi)\]
Returns

qutip.Qobj or None

h(*qubits, unitary=True, append=True)[source]
\[h = i \cdot u_2(0,\pi)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

s(*qubits, append=True)[source]
\[s = \sqrt{z} = u_1(\pi/2) = R_z(\pi/2)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

sdg(*qubits, append=True)[source]
\[s^\dagger = u_1(-\pi/2) = R_z(-\pi/2)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

t(*qubits, append=True)[source]
\[t = u_1(\pi/4) = R_z(\pi/4)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

tdg(*qubits, append=True)[source]
\[t^\dagger = u_1(-\pi/4) = R_z(-\pi/4)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

rx(theta, *qubits, unitary=True, append=True)[source]
\[R_x(\theta) = u_3(\theta,-\pi/2,\pi/2)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

ry(theta, *qubits, unitary=True, append=True)[source]
\[R_y(\theta) = u_3(\theta,0,0)\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

rz(phi, *qubits, append=True)[source]
\[R_z(\phi) = u_1(\phi)\]
Returns

qutip.Qobj or None

sx(*qubits, unitary=True, append=True)[source]
\[\begin{split}\sqrt{X} &= \exp(i\pi/4)R_x(\pi/2)\\ &= \exp(-i\pi/4)R_z(-\pi/2)\cdot H\cdot R_z(-\pi/2)\\ &= \exp(-i\pi/4)s^\dagger\cdot H\cdot s^\dagger\end{split}\]
Returns

qutip.Qobj or list[qutip.Qobj] or None

gphase(gamma, *qubits, append=True)[source]

Adds a global phase to the sequence.

Parameters
  • gamma (float) – Phase angle in radians.

  • *qubits – Sequence of qubits (ignored completely).

  • append (optional, bool) – If True, append the gate to self rather than returning it. Default: True.

Returns

If append is False, returns the gphase unitary, otherwise returns None.

Return type

qutip.Qobj or None

CX(control, target, append=True)[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.

  • append (optional, bool) – If True, append the gate to self rather than returning it. Default: True.

Returns

If append is False, returns the CX unitary, otherwise returns None.

Return type

qutip.Qobj or None

barrier(*args, append=True)[source]

Equivalent to sync().

NOTE: Currently only a “global” barrier/sync is supported.

assemble()[source]

Rearrange the sequence so that blocks of operations not separated by a barrier are executed in parallel.

qasm(qasm_str, unitary=True, append=True)[source]

Executes a gate specified by a single QASM instruction, e.g. ‘rx(pi) q[0];’. The qubit index in the QuantumRegister corresponds to the index in self.system.active_modes.

Parameters
  • qasm_str (str) – String specifying the QASM gate to execute.

  • unitary (optional, bool) – Whether to use the unitary instead of pulse-based version of the gate. This argument is ignored if only the unitary version exists. Default: True.

  • append (optional, bool) – Whether to append the gate to self instead of returning it to the user. This argument is ignored for barrier. Default: True.

Returns

If append is False, returns the result of the gate, which will be either an Operation, a qutip.Qobj, or a list composed of those types. If append is True, returns None.

Return type

list, Operation, qutip.Qobj, or None

qasm_circuit(circuit, unitary=True, append=True)[source]

Executes a full QASM circuit, ignoring reset, measure, and conditional instructions.

Parameters
  • circuit (str or list[str]) – The circuit to execute, either as a list of gates or as a newline-delimited string.

  • unitary (optional, bool) – Whether to use the unitary instead of pulse-based version of the each gate. This argument is ignored if only the unitary version exists. Default: True.

  • append (optional, bool) – Whether to append each gate to self instead of returning it to the user. This argument is ignored for barrier. Default: True.

Returns

If append is False, returns a list of Operation (if unitary is False) and qutip.Qobj. If append is True, returns None.

Return type

list or None

run(init_state, e_ops=None, options=None, full_evolution=True, progress_bar=False)[source]

Evolves init_state using each PulseSequence, Operation, or unitary applied in series.

Parameters
  • init_state (qutip.Qobj) – Initial state to evolve.

  • options (optional, qutip.Options) – qutip solver options. Default: None.

  • full_evolution (optional, bool) – Whether to store the states for every time point in the included Sequences. If False, only the final state will be stored. Default: True.

  • progress_bar (optional, bool) – If True, displays a progress bar when iterating through the Sequence. Default:True.

Returns

SequenceResult containing the time evolution of the system.

Return type

SequenceResult

plot_coefficients(subplots=True, sharex=True, sharey=True)[source]

Plot the Hamiltionian coefficients for all channels. Unitaries are represented by vertical lines.

Parameters
  • subplots (optional, bool) – If True, plot each channel on a different axis. Default: True.

  • sharex (optional, bool) – Share x axes if subplots is True. Default: True.

  • sharey (optional, bool) – Share y axes if subplots is True. Default: True.

Returns

(fig, ax): matplotlib Figure and axes.

Return type

tuple

measure(state, *qubits)[source]

Meausure each qubit in its logical basis by tracing over all other modes and then taking the expectation value of the projector onto logical one acting on the state.

Parameters
  • state (qutip.Qobj) – The state to measure.

  • *qubits – (sequence[Mode]): Tuple of Modes to measure. If qubits is empty, then all Modes in self.system.active_modes are measured.

Returns

List of expectation values.

Return type

list[float]

append(item)

Add an item to the end of the ValidatedList.

capture()

Appends the current pulse sequence if it is not empty.

clear()

Remove all items from the ValidatedList.

extend(iterable)

Extend the ValidatedList by appending all the items from the iterable.

insert(i, item)

Insert an item at a given position in the ValidatedList.

pop(i=-1)

Remove the item at the given position in the ValidatedList, and return it.

propagator(c_ops=None, options=None, unitary_mode='batch', parallel=False, progress_bar=False)

Calculate the propagator using qutip.propagator().

Parameters
  • c_ops (list[qutip.Qobj]) – List of collapse operators.

  • options (optional, qutip.Options) – qutip solver options. Note: defaults to max_step = 1.

  • progress_bar (optional, bool) – Whether to use qutip’s progress bar. Default: None (no progress bar).

  • unitary_mode (optional, "batch" or "single") – Solve all basis vectors simulaneously (“batch”) or individually (“single”). Default: “batch”.

  • parallel (optional, bool) – Run the propagator in parallel mode. This will override the unitary_mode settings if set to True. Default: False.

  • progress_bar – If True, displays a progress bar when iterating through the Sequence. Default:True.

Returns

List of Qobjs representing the propagator U(t).

Return type

list[qutip.Qobj]

reset_pulse_sequence()

Reset the current pulse sequence.


Benchmarking

Benchmark

class sequencing.benchmarking.Benchmark(sequence, init_state, target_unitary, run_sequence=True)[source]

A class for comparing the performance of a given control sequence to a target unitary.

Parameters
  • sequence (PulseSequence, CompiledPulseSequence, or Sequence) – The sequence to benchmark.

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

  • target_unitary (qutip.Qobj) – The unitary to which to compare the sequence.

  • run_sequence (optional, bool) – Whether to run the sequence immediately upon creating the Benchmark. Default: True.

run_sequence(**kwargs)[source]

Simulate the sequence and save the final state.

Keyword arguments are passed to self.seq.run().

fidelity(target_state=None)[source]

Returns the fidelty of the state resulting from the sequence to the target state.

Parameters

target_state (optional, qutip.Qobj) – State to which to compare the final state. Defaults to``target_unitary * init_state``.

Returns

float or None

tracedist(target_state=None, sparse=False, tol=0)[source]

Returns the trace distance from the state resulting from the sequence to the target state.

Parameters
  • target_state (optional, qutip.Qobj) – State to which to compare the final state. Defaults to``target_unitary * init_state``.

  • sparse – See qutip.tracedist.

  • tol – See qutip.tracedist.

Returns

float or None

purity()[source]

Returns the purity of the final state.

Returns

float or None

plot_wigners(target_state=None, actual_state=None, sel=None, cmap='RdBu', disp_range=(-5, 5, 201))[source]

Plots the Wigner function of the final state and the target state.

Parameters
  • target_state (optional, qutip.Qobj) – State to which to compare the final state. Defaults to``target_unitary * init_state``.

  • actual_state (optional, qutip.Qobj) – State to compare the target_state. Defaults to self.mesolve_state.

  • sel (optional, int or list[int]) – Indices of modes to keep when taking the partial trace of the target and actual states. If None, no partial trace is taken. Default: None.

  • cmap (optional, str) – Name of the matplotlib colormap to use. Default: ‘RdBu’

  • disp_range (tuple[float, float, int]) – Range of displacements to use when compouting the Wigner function, specified as (start, stop, num_steps). Default: (-5, 5, 201).

Returns

matplotlib Figure and Axis.

Return type

tuple

plot_fock_distribution(target_state=None, actual_state=None, sel=None, offset=0, ax=None, unit_y_range=True)[source]

Plots the photon number distribution of the target and actual states.

Parameters
  • target_state (optional, qutip.Qobj) – State to which to compare the final state. Defaults to``target_unitary * init_state``.

  • actual_state (optional, qutip.Qobj) – State to compare the target_state. Defaults to self.mesolve_state.

  • sel (optional, int or list[int]) – Indices of modes to keep when taking the partial trace of the target and actual states. If None, no partial trace is taken. Default: None.

  • offset (optional, int) – Minimum photon number to plot. Default: 0.

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

  • unit_y_range (optional, bool) – Whether to force the y axis limits to (0, 1). Default: True.

Returns

matplotlib Figure and Axis.

Return type

tuple