Skip to content

dq.sparsedia_from_dict

sparsedia_from_dict(
    offsets_diags: dict[int, ArrayLike],
    dims: tuple[int, ...] | None = None,
    dtype: DTypeLike | None = None,
) -> SparseDIAQArray

Initialize a SparseDIAQArray from a dictionary of offsets and diagonals.

Parameters

  • offsets_diags –

    Dictionary where keys are offsets and values are diagonals of shapes (..., n-|offset|) with a common batch shape between all diagonals.

  • dims (tuple of ints or None) –

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

  • dtype –

    Data type of the qarray. If None, the data type is inferred from the diagonals.

Returns

A SparseDIAQArray with non-zero diagonals at the specified offsets.

Examples

>>> dq.sparsedia_from_dict({0: [1, 2, 3], 1: [4, 5], -1: [6, 7]})
QArray: shape=(3, 3), dims=(3,), dtype=int32, layout=dia, ndiags=3
[[1 4 â‹…]
 [6 2 5]
 [â‹… 7 3]]
>>> dq.sparsedia_from_dict({0: jnp.ones((3, 2))})
QArray: shape=(3, 2, 2), dims=(2,), dtype=float32, layout=dia, ndiags=1
[[[1. â‹… ]
  [ â‹… 1.]]

 [[1. â‹… ]
  [ â‹… 1.]]

 [[1. â‹… ]
  [ â‹… 1.]]]