Skip to content

dq.to_qutip

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

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

Parameters

  • x (array_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 large Hilbert space of the composite system, defaults to None (a single system with the same dimension as x).

Returns

QuTiP quantum object or list of QuTiP quantum objects.

Examples

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

For a batched array:

>>> rhos = jnp.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 not inferred automatically, it must be specified with the dims argument:

>>> I = dq.eye(3, 2)
>>> dq.to_qutip(I)
Quantum object: dims=[[6], [6]], 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.]]
>>> dq.to_qutip(I, (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.]]