Skip to content

dq.asqarray

asqarray(
    x: QArrayLike,
    dims: tuple[int, ...] | None = None,
    layout: Layout | None = None,
    *,
    offsets: tuple[int, ...] | None = None
) -> QArray

Converts a qarray-like into a qarray.

Parameters:

  • x –

    Object to convert.

  • dims (tuple of ints or None) –

    Hilbert space dimension of each subsystem. Defaults to None (x.dims if available, individual system dims=(n,) otherwise).

  • layout –

    Matrix layout. If None, the default layout is dq.dense, except for qarrays that are directly returned, and for sequences of dq.dia qarrays with identical dims and shape, which are stacked in dq.dia if offsets is None.

  • offsets –

    Offsets of the stored diagonals if layout==dq.dia. If None, offsets are determined automatically from the matrix structure. This argument can also be explicitly specified to ensure compatibility with JAX transformations, which require static offset values.

Returns:

  • Qarray representation of the input.

See also

Examples:

>>> dq.asqarray([[1, 0], [0, -1]])
QArray: shape=(2, 2), dims=(2,), dtype=int32, layout=dense
[[ 1  0]
 [ 0 -1]]
>>> dq.asqarray([[1, 0], [0, -1]], layout=dq.dia)
QArray: shape=(2, 2), dims=(2,), dtype=int32, layout=dia, ndiags=1
[[ 1  â‹…]
 [ â‹… -1]]
>>> dq.asqarray([qt.sigmax(), qt.sigmay(), qt.sigmaz()])
QArray: shape=(3, 2, 2), dims=(2,), dtype=complex64, layout=dense
[[[ 0.+0.j  1.+0.j]
  [ 1.+0.j  0.+0.j]]

 [[ 0.+0.j  0.-1.j]
  [ 0.+1.j  0.+0.j]]

 [[ 1.+0.j  0.+0.j]
  [ 0.+0.j -1.+0.j]]]
>>> dq.asqarray([dq.sigmax(), dq.sigmaz()])
QArray: shape=(2, 2, 2), dims=(2,), dtype=complex64, layout=dia, ndiags=3
[[[   â‹…     1.+0.j]
  [ 1.+0.j    â‹…   ]]

 [[ 1.+0.j    â‹…   ]
  [   â‹…    -1.+0.j]]]