cuquantum.densitymat.MultidiagonalOperator

class cuquantum.densitymat.MultidiagonalOperator(data, offsets, callback=None)[source]

Multidiagonal single-mode operator from data buffer, offsets and optional callback.

Parameters
  • data – Data buffer for diagonal elements, of shape (mode_dimension, num_diagonals).

  • offsets – The diagonal offsets of length num_diagonals.

  • callback – A CPU callback function with signature (t, args) -> np.ndarray.

Note

  • The data layout is different from scipy.sparse.dia_matrix and cupyx.scipy.sparse.dia_matrix. In this class, the elements of the offsets[i]-th diagonal corresponds to the i-th column of the input data buffer read from the top of the column.

  • A copy will be created on the data buffer and can be accessed through the data attribute.

  • The returned array needs to be consistent with the provided data buffer in terms of shape and data type. The data buffer will be updated when this instance is involved in a compute method of an Operator or OperatorAction.

Examples

>>> import numpy as np
>>> from cuquantum.densitymat import MultidiagonalOperator

Suppose we want to construct a creation operator on a Hilbert space of dimension 3 as a MultidiagonalOperator. It can be constructed from the data buffer and diagonal offsets as

>>> data = np.array([[1], [np.sqrt(2)], [0]]) # the last element doesn't matter
>>> offsets = [-1]
>>> dia_op = MultidiagonalOperator(data, offsets)

If we already have the elementary operator in scipy.sparse.dia_matrix format, e.g,

>>> dia_matrix = scipy.sparse.dia_matrix(...) # put your data here

We can create a MultidiagonalOperator with the following:

>>> offsets = list(dia_matrix.offsets)
>>> data = np.zeros((dia_matrix.shape[0], len(offsets)), dtype=dia_matrix.dtype)
>>> for i, offset in enumerate(offsets):
>>>    end = None if offset == 0 else -abs(offset)
>>>    data[:end, i] = dia_matrix.diagonal(offset)
>>> dia_op = MultidiagonalOperator(data, offsets)

Methods

__add__(other: Union[DenseOperator, MultidiagonalOperator]) Union[DenseOperator, MultidiagonalOperator][source]

Add an elementary operator to this instance and return a new elementary operator of the same type as other.

__init__(data: Union[numpy.ndarray, cupy.ndarray], offsets: Sequence[int], callback: Optional[Callable[[float, Sequence], numpy.ndarray]] = None) None[source]

Initialize a multidiagonal single-mode operator from data buffer, offsets and optional callback.

__matmul__(other: Union[DenseOperator, MultidiagonalOperator]) Union[DenseOperator, MultidiagonalOperator][source]

Perform matrix multiplication between this instance and another elementary operator and return a new elementary operator of the same type as other.

__mul__(scalar: numbers.Number) MultidiagonalOperator[source]

Multiply this instance with a scalar on the left.

__rmul__(scalar: numbers.Number) MultidiagonalOperator[source]

Multiply this instance with a scalar on the right.

__sub__(other: Union[DenseOperator, MultidiagonalOperator]) Union[DenseOperator, MultidiagonalOperator][source]

Subtract an elementary operator from this instance and return a new elementary operator of the same type as other.

copy() MultidiagonalOperator[source]

Return a copy of the multidiagonal elementary operator.

dag() MultidiagonalOperator[source]

Return the conjugate complex transpose of this instance.

to_array(t: Optional[float] = None, args: Optional[Sequence] = None, device: str = 'cpu') Union[numpy.ndarray, cupy.ndarray][source]

Return the array form of the multidiagonal elementary operator.

Parameters
  • t – Time variable in callback, only required is callback is not None.

  • args – Additional arguments in callback, only required if callback is not None.

  • device – Device on which to return the array. Defaults to "cpu".

Returns

Array form of the multidiagonal elementary operator on the specified device.

Note

This function returns the dense array form of the multidiagonal elementary operator. If the original data buffer containing the diagonal elements is needed, use the data attribute.

to_dense() DenseOperator[source]

Return the DenseOperator form of the multidiagonal elementary operator.

Attributes

data

Data buffer of the elementary operator.