Skip to content

Python API

The Dynamiqs Python API features two main types of functions: solvers of differential equations describing quantum systems, and various utility functions to ease the creation and manipulation of quantum states and operators.

Quantum solvers

sesolve

Solve the Schrödinger equation.

mesolve

Solve the Lindblad master equation.

smesolve

Solve the diffusive stochastic master equation (SME).

sepropagator

Compute the propagator of the Schrödinger equation.

mepropagator

Compute the propagator of the Lindblad master equation.

Core

Time-dependent arrays

TimeArray

Base class for time-dependent arrays.

constant

Instantiate a constant time-array.

pwc

Instantiate a piecewise constant (PWC) time-array.

modulated

Instantiate a modulated time-array.

timecallable

Instantiate a callable time-array.

Solvers (dq.solver)

Tsit5

Tsitouras method of order 5 (adaptive step size ODE solver).

Dopri5

Dormand-Prince method of order 5 (adaptive step size ODE solver).

Dopri8

Dormand-Prince method of order 8 (adaptive step size ODE solver).

Kvaerno3

Kvaerno's method of order 3 (adaptive step size and implicit ODE solver).

Kvaerno5

Kvaerno's method of order 5 (adaptive step size and implicit ODE solver).

Euler

Euler method (fixed step size ODE solver).

Rouchon1

First-order Rouchon method (fixed step size ODE solver).

Rouchon2

Second-order Rouchon method (fixed step size ODE solver).

Expm

Explicit matrix exponentiation to compute propagators.

Gradients (dq.gradient)

Autograd

Standard automatic differentiation of JAX.

CheckpointAutograd

Checkpointed automatic differentiation.

Options

Options

Generic options for the quantum solvers.

Results

SESolveResult

Result of the Schrödinger equation integration.

MESolveResult

Result of the Lindblad master equation integration.

SEPropagatorResult

Result of the Schrödinger equation integration to obtain the propagator.

MEPropagatorResult

Result of the Lindblad master equation integration to obtain the propagator.

Utilities

Operators

eye

Returns the identity operator.

zero

Returns the null operator.

destroy

Returns a bosonic annihilation operator, or a tuple of annihilation operators for a multi-mode system.

create

Returns a bosonic creation operator, or a tuple of creation operators for a multi-mode system.

number

Returns the number operator of a bosonic mode, or a tuple of number operators for a multi-mode system.

parity

Returns the parity operator of a bosonic mode.

displace

Returns the displacement operator of complex amplitude \(\alpha\).

squeeze

Returns the squeezing operator of complex squeezing amplitude \(z\).

quadrature

Returns the quadrature operator of phase angle \(\phi\).

position

Returns the position operator \(x = (a^\dag + a) / 2\).

momentum

Returns the momentum operator \(p = i (a^\dag - a) / 2\).

sigmax

Returns the Pauli \(\sigma_x\) operator.

sigmay

Returns the Pauli \(\sigma_y\) operator.

sigmaz

Returns the Pauli \(\sigma_z\) operator.

sigmap

Returns the Pauli raising operator \(\sigma_+\).

sigmam

Returns the Pauli lowering operator \(\sigma_-\).

hadamard

Returns the Hadamard transform on \(n\) qubits.

rx

Returns the \(R_x(\theta)\) rotation gate.

ry

Returns the \(R_y(\theta)\) rotation gate.

rz

Returns the \(R_z(\theta)\) rotation gate.

sgate

Returns the \(\text{S}\) gate.

tgate

Returns the \(\text{T}\) gate.

cnot

Returns the \(\text{CNOT}\) gate.

toffoli

Returns the \(\text{Toffoli}\) gate.

States

fock

Returns the ket of a Fock state or a tensor product of Fock states.

fock_dm

Returns the density matrix of a Fock state or a tensor product of Fock states.

basis

Alias of dq.fock().

basis_dm

Alias of dq.fock_dm().

coherent

Returns the ket of a coherent state or a tensor product of coherent states.

coherent_dm

Returns the density matrix of a coherent state or a tensor product of coherent states.

ground

Returns the eigenvector with eigenvalue -1 of the Pauli \(\sigma_z\) operator.

excited

Returns the eigenvector with eigenvalue +1 of the Pauli \(\sigma_z\) operator.

Quantum utilities

dag

Returns the adjoint (complex conjugate transpose) of a matrix.

powm

Returns the \(n\)-th matrix power of an array.

expm

Returns the matrix exponential of an array.

cosm

Returns the cosine of an array.

sinm

Returns the sine of an array.

trace

Returns the trace of an array along its last two dimensions.

tracemm

Return the trace of a matrix multiplication using a fast implementation.

ptrace

Returns the partial trace of a ket, bra or density matrix.

tensor

Returns the tensor product of multiple kets, bras, density matrices or operators.

expect

Returns the expectation value of an operator or list of operators on a ket, bra or density matrix.

norm

Returns the norm of a ket, bra or density matrix.

unit

Normalize a ket, bra or density matrix to unit norm.

dissipator

Applies the Lindblad dissipation superoperator to a density matrix.

lindbladian

Applies the Lindbladian superoperator to a density matrix.

isket

Returns True if the array is in the format of a ket.

isbra

Returns True if the array is in the format of a bra.

isdm

Returns True if the array is in the format of a density matrix.

isop

Returns True if the array is in the format of an operator.

isherm

Returns True if the array is Hermitian.

toket

Returns the ket representation of a pure quantum state.

tobra

Returns the bra representation of a pure quantum state.

todm

Returns the density matrix representation of a quantum state.

proj

Returns the projection operator onto a pure quantum state.

braket

Returns the inner product \(\braket{\psi|\varphi}\) between two kets.

overlap

Returns the overlap between two quantum states.

fidelity

Returns the fidelity of two states, kets or density matrices.

entropy_vn

Returns the Von Neumann entropy of a ket or density matrix.

bloch_coordinates

Returns the spherical coordinates \((r, \theta, \phi)\) of a ket or density matrix on the Bloch sphere.

wigner

Compute the Wigner distribution of a ket or density matrix.

to_qutip

Convert an array-like object into a QuTiP quantum object (or a list of QuTiP quantum objects if it has more than two dimensions).

set_device

Configure the default device.

set_precision

Configure the default floating point precision.

set_matmul_precision

Configure the default precision for matrix multiplications on GPUs and TPUs.

Vectorization

operator_to_vector

Returns the vectorized version of an operator.

vector_to_operator

Returns the operator version of a vectorized operator.

spre

Returns the superoperator formed from pre-multiplication by an operator.

spost

Returns the superoperator formed from post-multiplication by an operator.

sprepost

Returns the superoperator formed from pre- and post-multiplication by operators.

sdissipator

Returns the Lindblad dissipation superoperator (in matrix form).

slindbladian

Returns the Lindbladian superoperator (in matrix form).

Quantum optimal control

snap_gate

Returns a SNAP gate.

cd_gate

Returns a conditional displacement gate.

Random arrays (dq.random)

real

Returns an array of uniformly distributed random real numbers.

complex

Returns an array of uniformly distributed random complex numbers.

herm

Returns a random complex Hermitian matrix.

psd

Returns a random complex positive semi-definite matrix.

dm

Returns a random density matrix (hermitian, positive semi-definite, and unit trace).

ket

Returns a random ket with unit norm.

Plotting (dq.plot)

wigner

Plot the Wigner function of a state.

wigner_mosaic

Plot the Wigner function of multiple states in a mosaic arrangement.

wigner_gif

Plot a GIF of the Wigner function of multiple states.

pwc_pulse

Plot a piecewise constant pulse.

fock

Plot the photon number population of a state.

fock_evolution

Plot the photon number population of state as a function of time.

hinton

Plot a Hinton diagram.

gifit

Transform a plot function into a new function that returns an animated GIF.

grid

Returns a figure and an iterator of subplots organised in a grid.

mplstyle

Set custom Matplotlib style.