Skip to content

dq.QArray

Dynamiqs custom array to represent quantum objects.

A qarray is a wrapper around the data structure representing a quantum object (a ket, a density matrix, an operator, a superoperator, etc.) that offers convenience methods.

There are two types of qarrays:

  • DenseQArray: wrapper around JAX arrays, dense representation of the array.
  • SparseDIAQArray: Dynamiqs sparse diagonal format, storing only the non-zero diagonals.
Constructing a new qarray from an other array type

Use the function dq.asqarray() to create a qarray from a qarray-like. Objects that can be converted to a QArray are of type dq.QArrayLike. This includes all numeric types (bool, int, float, complex), a NumPy or JAX array, a Dynamiqs qarray, a QuTiP qobj, or any nested sequence of these types. See also dq.isqarraylike().

Attributes

  • dtype (numpy dtype) –

    Data type.

  • shape (tuple of ints) –

    Shape.

  • ndim (int) –

    Number of dimensions in the shape.

  • layout (Layout) –

    Data layout, either dq.dense or dq.dia.

  • dims (tuple of ints) –

    Hilbert space dimension of each subsystem.

  • mT (qarray) –

    Returns the qarray transposed over its last two dimensions.

  • vectorized (bool) –

    Whether the underlying object is non-vectorized (ket, bra or operator) or vectorized (operator in vector form or superoperator in matrix form).

Arithmetic operation support

Qarrays support basic arithmetic operations -, +, *, /, @ with other qarray-likes.

Shortcuts methods to use quantum utilities

Many functions of the library can be called directly on a qarray rather than through the functional API. For example, you can use x.dag() instead of dq.dag(x).

Here is the list of qarray methods:

Method Description
x.conj() Returns the element-wise complex conjugate of the qarray.
x.dag() Alias of dq.dag(x).
x.powm() Alias of dq.powm(x).
x.expm() Alias of dq.expm(x).
x.cosm() Alias of dq.cosm(x).
x.sinm() Alias of dq.sinm(x).
x.trace() Alias of dq.trace(x).
x.ptrace(keep) Alias of dq.ptrace(x, keep, dims=x.dims).
x.norm() Alias of dq.norm(x).
x.unit() Alias of dq.unit(x).
x.isket() Alias of dq.isket(x).
x.isbra() Alias of dq.isbra(x).
x.isdm() Alias of dq.isdm(x).
x.isop() Alias of dq.isop(x).
x.isherm() Alias of dq.isherm(x).
x.toket() Alias of dq.toket(x).
x.tobra() Alias of dq.tobra(x).
x.todm() Alias of dq.todm(x).
x.proj() Alias of dq.proj(x).
x.reshape(*shape) Returns a reshaped copy of a qarray.
x.broadcast_to(*shape) Broadcasts a qarray to a new shape.
x.addscalar(y) Adds a scalar.
x.elmul(y) Computes the element-wise multiplication.
x.elpow(power) Computes the element-wise power.

There are also several conversion methods available:

Method Description
x.to_qutip() Alias of dq.to_qutip(x, dims=x.dims).
x.to_jax() Alias of dq.to_jax(x).
x.to_numpy() Alias of dq.to_numpy(x).
x.asdense() Converts to a dense layout.
x.assparsedia() Converts to a sparse diagonal layout.

QArray.conj

conj() -> QArray

Returns the element-wise complex conjugate of the qarray.

Returns

New qarray with element-wise complex conjuguated values.

QArray.reshape

reshape(*shape: int) -> QArray

Returns a reshaped copy of a qarray.

Parameters

  • *shape –

    New shape, which must match the original size.

Returns

New qarray with the given shape.

QArray.broadcast_to

broadcast_to(*shape: int) -> QArray

Broadcasts a qarray to a new shape.

Parameters

  • *shape –

    New shape, which must be compatible with the original shape.

Returns

New qarray with the given shape.

QArray.asdense

asdense() -> DenseQArray

Converts to a dense layout.

Returns

A DenseQArray.

QArray.assparsedia

assparsedia() -> SparseDIAQArray

Converts to a sparse diagonal layout.

Returns

A SparseDIAQArray.

QArray.addscalar

addscalar(y: ArrayLike) -> QArray

Adds a scalar.

Parameters

  • y –

    Scalar to add, whose shape should be broadcastable with the qarray.

Returns

New qarray resulting from the addition with the scalar.

QArray.elmul

elmul(y: QArrayLike) -> QArray

Computes the element-wise multiplication.

Parameters

  • y –

    Qarray-like to multiply with element-wise.

Returns

New qarray resulting from the element-wise multiplication.

QArray.elpow

elpow(power: int) -> QArray

Computes the element-wise power.

Parameters

  • power –

    Power to raise to.

Returns

New qarray with elements raised to the specified power.