symmray.bosonic_common

Common methods for any ‘bosonic’ (non-fermionic) arrays.

Classes

BosonicCommon

Mixin for bosonic (non-fermionic) arrays.

Module Contents

class symmray.bosonic_common.BosonicCommon[source]

Mixin for bosonic (non-fermionic) arrays.

to_pytree()[source]

Convert this abelian array to a pytree purely of non-symmray containers and objects.

_binary_blockwise_op(other, fn, missing=None, inplace=False)[source]
_split(*args, **kwargs)[source]
transpose(axes=None, inplace=False) BosonicCommon[source]

Transpose this abelian array.

Parameters:
  • axes (tuple[int, ...] | None, optional) – A permutation of the axes to transpose the array by. If None, the axes will be reversed.

  • inplace (bool, optional) – Whether to perform the operation inplace or return a new array.

Return type:

BosonicCommon

conj(inplace=False) BosonicCommon[source]

Return the complex conjugate of this abelian array, including the indices and any subindex fusing information.

Parameters:

inplace (bool, optional) – Whether to perform the operation inplace or return a new array.

Return type:

BosonicCommon

dagger(inplace=False) BosonicCommon[source]

Return the adjoint of this abelian array, including the indices and any subindex fusing information.

Parameters:

inplace (bool, optional) – Whether to perform the operation inplace or return a new array.

Return type:

AbelianArray

dagger_project_left[source]
dagger_project_right[source]
dagger_compose_left[source]
dagger_compose_right[source]
_fuse_core(*axes_groups, mode='auto', inplace=False) BosonicCommon[source]

The core implementation of the fuse operation, which fuses multiple axes into a single group, and returns a new array with the new sectors and blocks. The new axes are inserted at the minimum axis of any of the groups.

unfuse(axis, inplace=False) BosonicCommon[source]

Unfuse the axis index, which must carry subindex information, likely generated automatically from a fusing operation.

Parameters:
  • axis (int) – The axis to unfuse. It must have subindex information (.indices[axis].subinfo), typically from a previous fusing operation.

  • inplace (bool, optional) – Whether to perform the operation inplace or return a new array.

Return type:

BosonicCommon

squeeze(axis=None, inplace=False) BosonicCommon[source]

Squeeze the abelian array, removing axes of size 1.

Parameters:
  • axis (int or sequence of int, optional) – The axis or axes to squeeze. If None, all axes of size 1 will be removed.

  • inplace (bool, optional) – Whether to perform the operation inplace or return a new array.

Return type:

BosonicCommon

einsum(eq, preserve_array=False)[source]

Einsum for abelian arrays, currently only single term.

Parameters:
  • eq (str) – The einsum equation, e.g. “abcb->ca”. The output indices must be specified and only trace and permutations are allowed.

  • preserve_array (bool, optional) – If tracing to a scalar, whether to return an abelian array object with no indices, or simply the scalar itself (the default).

Return type:

BosonicCommon or scalar

tensordot(other, axes=2, mode='auto', preserve_array=False)[source]

Tensordot between two abelian symmetric arrays.

Parameters:
  • other (BosonicCommon) – The other array to contract with.

  • axes (int or tuple[int]) – The axes to contract. If an integer, the last axes axes of self will be contracted with the first axes axes of other. If a tuple, the axes to contract in self and other respectively.

  • mode ({"auto", "fused", "blockwise"}) – The mode to use for the contraction. If “auto”, it will choose between “fused” and “blockwise” based on the number of axes to contract.

  • preserve_array (bool, optional) – Whether to return a scalar if the result is a scalar.

__matmul__(other, preserve_array=False)[source]
trace()[source]

Compute the trace of the abelian array, assuming it is a square matrix.

to_dense()[source]

Convert this abelian array to a dense array, by combining all the blocks into a single large array, filling in zeros where necessary.

Returns:

A dense array with the same shape as this abelian array.

Return type:

array_like

allclose(other, **allclose_opts)[source]

Test whether this abelian array is close to another, that is, has all the same sectors, and the corresponding arrays are close.

Parameters:
  • other (BosonicCommon) – The other array to compare to.

  • allclose_opts – Keyword arguments to pass to allclose.

Return type:

bool

test_allclose(other, **allclose_opts)[source]

Assert that this abelian array is close to another, that is, has all the same sectors, and the corresponding arrays are close. Unlike allclose, this raises an AssertionError with details if not.

Parameters:
  • other (BosonicCommon) – The other array to compare to.

  • allclose_opts – Keyword arguments to pass to allclose.

Raises:

AssertionError – If the arrays are not close.

eigh(**kwargs)[source]

Eigenvalue decomposition of this assumed Hermitian abelian array.

Returns:

  • w (vector) – The eigenvalues as a vector.

  • u (BosonicCommon) – The array of eigenvectors.

cholesky(*, upper=False) BosonicCommon[source]

Cholesky decomposition of this assumed positive-definite array.

Parameters:

upper (bool, optional) – Whether to return the upper triangular Cholesky factor. Default is False, returning the lower triangular factor.

Returns:

l_or_r – The Cholesky factor. Lower triangular if upper=False, upper triangular if upper=True.

Return type:

BosonicCommon

cholesky_regularized(absorb=0, shift=True)[source]

Cholesky decomposition with optional diagonal regularization, returning results in an SVD-like (left, None, right) format for compatibility with tensor network split drivers.

Parameters:
  • absorb ({-12, 0, 12}, optional) –

    How to return the factors:

    • 0 ('both'): return (L, None, L^H).

    • -12 ('lsqrt'): return (L, None, None).

    • 12 ('rsqrt'): return (None, None, L^H).

  • shift (float, optional) – Diagonal regularization shift. If True or negative, auto-compute from dtype machine epsilon. The shift is always applied as a relative shift scaled by the trace of each block. Default is True.

Returns:

  • left (BosonicCommon or None) – The lower Cholesky factor, or None.

  • s (None) – Always None (no singular values).

  • right (BosonicCommon or None) – The conjugate transpose of the Cholesky factor, or None.