Skip to content

dq.to_qutip

to_qutip(x: QArrayLike, dims: tuple[int, ...] | None = None) -> Qobj | list[Qobj]

Convert a qarray-like into a QuTiP Qobj or list of Qobjs.

Parameters

  • x (qarray-like of shape (..., n, 1) or (..., 1, n) or (..., n, n)) –

    Ket, bra, density matrix or operator.

  • dims (tuple of ints or None) –

    Dimensions of each subsystem in the composite system Hilbert space tensor product. Defaults to None (x.dims if available, single Hilbert space dims=(n,) otherwise).

Returns

QuTiP Qobj or list of QuTiP Qobj.

Examples

>>> dq.fock(3, 1)
QArray: shape=(3, 1), dims=(3,), dtype=complex64, layout=dense
[[0.+0.j]
 [1.+0.j]
 [0.+0.j]]
>>> dq.to_qutip(dq.fock(3, 1))
Quantum object: dims=[[3], [1]], shape=(3, 1), type='ket', dtype=Dense
Qobj data =
[[0.]
 [1.]
 [0.]]

For a batched qarray:

>>> rhos = dq.stack([dq.coherent_dm(16, i) for i in range(5)])
>>> rhos.shape
(5, 16, 16)
>>> len(dq.to_qutip(rhos))
5

Note that the tensor product structure is inferred automatically for qarrays. It can be specified with the dims argument for other types.

>>> dq.to_qutip(dq.eye(3, 2))
Quantum object: dims=[[3, 2], [3, 2]], shape=(6, 6), type='oper', dtype=Dense, isherm=True
Qobj data =
[[1. 0. 0. 0. 0. 0.]
 [0. 1. 0. 0. 0. 0.]
 [0. 0. 1. 0. 0. 0.]
 [0. 0. 0. 1. 0. 0.]
 [0. 0. 0. 0. 1. 0.]
 [0. 0. 0. 0. 0. 1.]]