symmray ======= .. py:module:: symmray Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/symmray/_version/index /autoapi/symmray/array_common/index /autoapi/symmray/bosonic_common/index /autoapi/symmray/common/index /autoapi/symmray/fermionic_common/index /autoapi/symmray/fermionic_local_operators/index /autoapi/symmray/flat/index /autoapi/symmray/hamiltonians/index /autoapi/symmray/index_common/index /autoapi/symmray/interface/index /autoapi/symmray/linalg/index /autoapi/symmray/linalg_common/index /autoapi/symmray/networks/index /autoapi/symmray/scipy/index /autoapi/symmray/sparse/index /autoapi/symmray/symmetries/index /autoapi/symmray/utils/index /autoapi/symmray/utils_test/index /autoapi/symmray/vector_common/index Classes ------- .. autoapisummary:: symmray.FermionicOperator symmray.AbelianArrayFlat symmray.Z2ArrayFlat symmray.FermionicArrayFlat symmray.Z2FermionicArrayFlat symmray.FlatVector symmray.AbelianArray symmray.U1Array symmray.U1U1Array symmray.Z2Array symmray.Z2Z2Array symmray.BlockIndex symmray.FermionicArray symmray.U1FermionicArray symmray.U1U1FermionicArray symmray.Z2FermionicArray symmray.Z2Z2FermionicArray symmray.BlockVector symmray.U1 symmray.U1U1 symmray.Z2 symmray.Z2Z2 symmray.ZN symmray.Symmetry Functions --------- .. autoapisummary:: symmray.build_local_fermionic_array symmray.build_local_fermionic_elements symmray.fermi_hubbard_local_array symmray.fermi_hubbard_spinless_local_array symmray.fermi_number_down_local_array symmray.fermi_number_operator_spinful_local_array symmray.fermi_number_operator_spinless_local_array symmray.fermi_number_up_local_array symmray.fermi_spin_operator_local_array symmray.ham_fermi_hubbard_from_edges symmray.ham_fermi_hubbard_spinless_from_edges symmray.ham_heisenberg_from_edges symmray.ham_tfim_from_edges symmray.abs symmray.align_axes symmray.all symmray.any symmray.clip symmray.conj symmray.einsum symmray.expand_dims symmray.fuse symmray.imag symmray.isfinite symmray.lddiv symmray.ldmul symmray.log symmray.log2 symmray.log10 symmray.max symmray.min symmray.multiply_diagonal symmray.rddiv symmray.rdmul symmray.real symmray.reshape symmray.sqrt symmray.squeeze symmray.sum symmray.take symmray.tensordot symmray.trace symmray.transpose symmray.MPS_abelian_rand symmray.MPS_fermionic_rand symmray.PEPS3D_abelian_rand symmray.PEPS3D_fermionic_rand symmray.PEPS_abelian_rand symmray.PEPS_fermionic_rand symmray.TN_abelian_from_edges_rand symmray.TN_fermionic_from_edges_rand symmray.parse_edges_to_site_info symmray.default_tensordot_mode symmray.get_default_tensordot_mode symmray.set_default_tensordot_mode symmray.get_symmetry symmray.get_zn_symmetry_cls Package Contents ---------------- .. py:class:: FermionicOperator(label, dual=False, parity=1) Simple class to represent a fermionic operator with a label, a dual flag, and a parity 'switch' indicating whether the fermion is present. .. py:attribute:: __slots__ :value: ('_label', '_dual', '_parity') .. py:attribute:: _label .. py:attribute:: _dual :value: False .. py:attribute:: _parity :value: 1 .. py:method:: to_pytree() Convert this fermionic operator to a pytree purely of non-symmray containers and objects. .. py:method:: from_pytree(data) :classmethod: Create a fermionic operator from a pytree purely of non-symmray containers and objects. .. py:property:: label .. py:property:: dual .. py:property:: parity .. py:property:: dag .. py:method:: __eq__(other) .. py:method:: __lt__(other) .. py:method:: __repr__() .. py:function:: build_local_fermionic_array(terms, bases, symmetry, index_maps, like='numpy', flat=False) Compute a local fermionic operator as a `FermionicArray`. :param terms: The terms in the operator, each a tuple of a coefficient and a tuple of FermionicOperator instances. :type terms: tuple[tuple[float, tuple[FermionicOperator, ...]]] :param bases: The tensor bases to compute the operator elements in. Each basis is a sequence of multiple FermionicOperator instances acting on the vacuum. :type bases: tuple[tuple[tuple[FermionicOperator]]] :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2" or "U1U1". :type symmetry: str :param index_maps: For each basis, the sequence mapping linear index to charge sector. :type index_maps: Sequence[Sequence[hashable]] :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: build_local_fermionic_elements(terms, bases) Compute the elements of a local fermionic operator in a given tensor basis, including 'internal' signs. :param terms: The terms in the operator, each a tuple of a coefficient and a tuple of FermionicOperator or tuple[label, op] instances. :type terms: tuple[tuple[float, tuple[FermionicOperator, ...]]] :param bases: The tensor bases to compute the operator elements in. Each basis is a sequence of multiple FermionicOperator instancess acting on the vacuum. :type bases: tuple[tuple[tuple[FermionicOperator]]] :returns: A list of tuples of tensor indices and the corresponding tensor element, including phases. :rtype: list[tuple[tuple[int], float]] .. rubric:: Examples Compute the elements of a local fermionic operator in a tensor basis:: a, b = map(FermionicOperator, "ab") basis_a = [(), (a.dag,)] basis_b = [(), (b.dag,)] bases = (basis_a, basis_b) t = 1.0 U = 8.0 terms = ( (-t, (a.dag, b)), (-t, (b.dag, a)), (U, (a.dag, a, b.dag, b)), ) build_local_fermionic_elements(terms, bases) # {(0, 1, 1, 0): -1.0, (1, 0, 0, 1): -1.0, (1, 1, 1, 1): -8.0} .. py:function:: fermi_hubbard_local_array(symmetry, t=1.0, U=8.0, mu=0.0, coordinations=(1, 1), like='numpy', flat=False) Construct the fermionic local tensor for the Fermi-Hubbard model. The indices are ordered as (a, b, a', b'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively and similar for site b. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param t: The hopping parameter, by default 1.0. :type t: float, optional :param U: The interaction parameter, by default 8.0. If a tuple, then the interaction parameter is different for each site. :type U: float or (float, float), optional :param mu: The chemical potential, by default 0.0. If a tuple, then the chemical potential is different for each site. :type mu: float or (float, float), optional :param coordinations: The coordinations of the sites, by default (1, 1). If applying this local operator to every edge in a graph, then the single site contributions can be properly accounted for if the coordinations are provided. :type coordinations: tuple[int, int], optional :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: fermi_hubbard_spinless_local_array(symmetry, t=1.0, V=8.0, mu=0.0, delta=0.0, coordinations=(1, 1), like='numpy', flat=False) Construct the fermionic local tensor for the spinless Fermi-Hubbard model. The indices are ordered as (a, b, a', b'). :param symmetry: The symmetry of the model. Either "Z2" or "U1". :type symmetry: str :param t: The hopping parameter, by default 1.0. :type t: float, optional :param V: The nearest-neighbor interaction parameter, by default 8.0. :type V: float, optional :param mu: The chemical potential, by default 0.0. If a tuple, then the chemical potential is different for each site. :type mu: float or (float, float), optional :param delta: The nearest neighbor superconducting pairing parameter, by default 0.0. :type delta: float, optional :param coordinations: The coordinations of the sites, by default (1, 1). If applying this local operator to every edge in a graph, then the single site contributions can be properly accounted for if the coordinations are provided. :type coordinations: tuple[int, int], optional :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: fermi_number_down_local_array(symmetry, like='numpy', flat=False) Construct the 'down' fermionic number operator for the Fermi-Hubbard model. The indices are ordered as (a, a'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively for single site `a`. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: fermi_number_operator_spinful_local_array(symmetry, like='numpy', flat=False) Construct the fermionic number operator for the Fermi-Hubbard model. The indices are ordered as (a, a'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively for single site `a`. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: **array** -- The local operator in fermionic array form. :rtype: FermionicArray .. py:function:: fermi_number_operator_spinless_local_array(symmetry, like='numpy', flat=False) Construct the fermionic number operator for the spinless Fermi-Hubbard model. The indices are ordered as (a, a'). The local basis is like (|0>, a+|0>) for single site a. :param symmetry: The symmetry of the model. Either "Z2" or "U1". :type symmetry: str :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: fermi_number_up_local_array(symmetry, like='numpy', flat=False) Construct the 'up' fermionic number operator for the Fermi-Hubbard model. The indices are ordered as (a, a'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively for single site `a`. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:function:: fermi_spin_operator_local_array(symmetry, like='numpy', flat=False) Construct the fermionic spin operator for the Fermi-Hubbard model. The indices are ordered as (a, a'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively for single site `a`. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return a flat array, by default False. :type flat: bool, optional :returns: The local operator in fermionic array form. :rtype: FermionicArray or FermionicArrayFlat .. py:class:: AbelianArrayFlat(sectors, blocks, indices, symmetry=None, label=None) Bases: :py:obj:`symmray.flat.flat_array_common.FlatArrayCommon`, :py:obj:`symmray.flat.flat_data_common.FlatCommon`, :py:obj:`symmray.bosonic_common.BosonicCommon`, :py:obj:`symmray.array_common.ArrayCommon`, :py:obj:`symmray.common.SymmrayCommon` Base class for abelian arrays with flat storage and cyclic symmetry. :param sectors: The stack of sector keys, with shape (num_blocks, ndim). Each row represents a sector of a corresponding block, and each column represents a charge in a given axis. :type sectors: array_like :param blocks: The stack of array blocks, with shape (num_blocks, *shape_block), i.e. `ndim + 1` dimensions, where the first dimension is the block index, which should match the first dimension of `sectors`, and the rest are the dimensions of individual blocks. :type blocks: array_like :param indices: Indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: __slots__ :value: ('_blocks', '_indices', '_label', '_sectors', '_symmetry', 'backend') .. py:attribute:: fermionic :value: False .. py:attribute:: static_symmetry :value: None .. py:method:: check() Check the internal consistency of the array. .. py:method:: new_with(sectors, blocks, indices, label=None) -> AbelianArrayFlat Create a new flat abelian array of the same class as this one. Unlike `copy`, this does not copy over any existing data and drops for example `label`. .. py:method:: copy(deep=False) -> AbelianArrayFlat Create a copy of the array. .. py:method:: copy_with(sectors=None, blocks=None, indices=None) -> AbelianArrayFlat A copy of this block array with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: modify(sectors=None, blocks=None, indices=None) -> AbelianArrayFlat Modify this flat array in place with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: set_params(params) Set the underlying array blocks. .. py:method:: from_pytree(pytree) -> AbelianArrayFlat :classmethod: Create a flat abelian array from a pytree purely of non-symmray containers and objects. .. py:method:: from_blocks(blocks, indices, symmetry=None, label=None) -> AbelianArrayFlat :classmethod: Create a flat array from an explicit dictionary of blocks, and sequence of indices or duals. :param blocks: A dictionary mapping sector keys (tuples of charges) to blocks (arrays). :type blocks: dict[tuple[int, ...], array_like] :param indices: A sequence of indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] | sequence[bool] :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional :param label: An optional label for the array, potentially needed for ordering dummy odd fermionic modes. :type label: hashable, optional :rtype: AbelianArrayFlat .. py:method:: from_blocksparse(x: symmray.sparse.sparse_abelian_array.AbelianArray, symmetry=None) -> AbelianArrayFlat :classmethod: Create a flat abelian array from a blocksparse abelian array. :param x: The blocksparse abelian array to convert. :type x: AbelianArray :param symmetry: The symmetry to use. If not supplied, the symmetry of `x` is used. :type symmetry: str or Symmetry, optional .. py:method:: to_blocksparse() -> symmray.sparse.sparse_abelian_array.AbelianArray Create a blocksparse abelian array from this flat abelian array. .. py:method:: _map_blocks(fn_sector=None, fn_block=None) .. py:method:: sort_stack(axes=None, all_axes=None, inplace=False) -> AbelianArrayFlat Lexicgraphic sort the stack of sectors and blocks according to the values of charges in the specified axes, optionally filling in the rest of the axes with the remaining axes in the order they appear. :param axes: The axes to sort by. If a single integer is given, it will be interpreted as the axis to sort by. If a tuple of integers is given, it will be interpreted as the axes to sort by in order. Default is None, if all_axes is also None or True, this will sort all axes in their current order. :type axes: int | tuple[int, ...], optional :param all_axes: Whether to include all non-specified axes as tie-breakers, after the specified axes. If ``None``, the default, this will be True if `axes` is not supplied explicitly, and False otherwise. :type all_axes: bool, optional :param inplace: Whether to perform the operation inplace or return a new array. Default is False, which returns a new array. :type inplace: bool, optional .. py:class:: Z2ArrayFlat(sectors, blocks, indices, symmetry=None, label=None) Bases: :py:obj:`AbelianArrayFlat` Base class for abelian arrays with flat storage and cyclic symmetry. :param sectors: The stack of sector keys, with shape (num_blocks, ndim). Each row represents a sector of a corresponding block, and each column represents a charge in a given axis. :type sectors: array_like :param blocks: The stack of array blocks, with shape (num_blocks, *shape_block), i.e. `ndim + 1` dimensions, where the first dimension is the block index, which should match the first dimension of `sectors`, and the rest are the dimensions of individual blocks. :type blocks: array_like :param indices: Indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: static_symmetry .. py:class:: FermionicArrayFlat(sectors, blocks, indices, phases=None, label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`symmray.fermionic_common.FermionicCommon`, :py:obj:`symmray.flat.flat_array_common.FlatArrayCommon`, :py:obj:`symmray.flat.flat_data_common.FlatCommon`, :py:obj:`symmray.array_common.ArrayCommon`, :py:obj:`symmray.common.SymmrayCommon` Fermionic abelian symmetric array with flat backend. :param sectors: The stack of sector keys, with shape (num_blocks, ndim). Each row represents a sector of a corresponding block, and each column represents a charge in a given axis. :type sectors: array_like :param blocks: The stack of array blocks, with shape (num_blocks, *shape_block), i.e. `ndim + 1` dimensions, where the first dimension is the block index, which should match the first dimension of `sectors`, and the rest are the dimensions of individual blocks. :type blocks: array_like :param indices: Indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] :param phases: An array of +/- 1 phases, with shape (num_blocks,), giving the phase of each block. If not supplied, all phases are assumed to be +1. :type phases: array_like, optional :param label: An optional label for the array, potentially needed for ordering dummy odd fermionic modes. :type label: hashable, optional :param dummy_modes: A sequence of dummy fermionic modes representing to effectively prepend to the array. :type dummy_modes: sequence[FermionicOperator], optional :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: __slots__ :value: ('_blocks', '_dummy_modes', '_indices', '_phases', '_sectors', '_symmetry', 'backend') .. py:attribute:: fermionic :value: True .. py:attribute:: static_symmetry :value: None .. py:attribute:: _dummy_modes :value: () .. py:property:: phases The phases for each block. .. py:property:: parity The total parity of the array, 0 for even, 1 for odd. .. py:method:: check() Check the internal consistency of the array. .. py:method:: new_with(sectors, blocks, indices, label=None) -> FermionicArrayFlat Create a new flat fermionic array of the same class as this one. Unlike `copy`, this does not copy over any existing data and drops by default `label`, `phases`, and `dummy_modes`. .. py:method:: copy(deep=False) -> FermionicArrayFlat Create a copy of the array. .. py:method:: copy_with(sectors=None, blocks=None, indices=None, phases=None) -> FermionicArrayFlat A copy of this fermionic flat array with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: modify(sectors=None, blocks=None, indices=None, phases=None, dummy_modes=None) -> FermionicArrayFlat Modify this fermionic flat array in place with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: set_params(params) Set the underlying array blocks. .. py:method:: to_pytree() Convert this flat fermionic array to a pytree purely of non-symmray containers and objects. .. py:method:: from_pytree(data) :classmethod: Create a flat fermionic array from a pytree purely of non-symmray containers and objects. .. py:method:: _map_blocks(fn_sector=None, fn_block=None) .. py:method:: from_blocks(blocks, indices, phases=None, label=None, dummy_modes=None, symmetry=None) -> FermionicArrayFlat :classmethod: Create a fermionic flat array from an explicit dictionary of blocks, and sequence of indices or duals. :param blocks: A dictionary mapping sector keys (tuples of charges) to blocks (arrays). :type blocks: dict[tuple[int, ...], array_like] :param indices: A sequence of indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] | sequence[bool] :param phases: A dictionary mapping sector keys to +/- 1 phases. If not supplied, all phases are assumed to be +1. :type phases: dict[tuple[int, ...], int], optional :param label: An optional label for the array, potentially needed for ordering dummy odd fermionic modes. :type label: hashable, optional :param dummy_modes: A sequence of dummy fermionic modes representing to effectively prepend to the array. :type dummy_modes: sequence[FermionicOperator], optional :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:method:: from_blocksparse(x: symmray.sparse.sparse_fermionic_array.FermionicArray, symmetry=None) :classmethod: Create a fermionic flat array from a fermionic blocksparse array. :param x: The fermionic blocksparse array to convert. :type x: FermionicArray :param symmetry: The symmetry to use. If not supplied, the symmetry of `x` is used. :type symmetry: str or Symmetry, optional .. py:method:: to_blocksparse() -> symmray.sparse.sparse_fermionic_array.FermionicArray Convert this fermionic flat array to a fermionic blocksparse array. :returns: The equivalent fermionic blocksparse array. :rtype: FermionicArray .. py:method:: sort_stack(axes=None, all_axes=None, inplace=False) -> FermionicArrayFlat Lexicgraphic sort the stack of sectors and blocks according to the values of charges in the specified axes, optionally filling in the rest of the axes with the remaining axes in the order they appear. :param axes: The axes to sort by. If a single integer is given, it will be interpreted as the axis to sort by. If a tuple of integers is given, it will be interpreted as the axes to sort by in order. Default is None, if all_axes is also None or True, this will sort all axes in their current order. :type axes: int | tuple[int, ...], optional :param all_axes: Whether to include all non-specified axes as tie-breakers, after the specified axes. If ``None``, the default, this will be True if `axes` is not supplied explicitly, and False otherwise. :type all_axes: bool, optional :param inplace: Whether to perform the operation inplace or return a new array. Default is False, which returns a new array. :type inplace: bool, optional .. py:method:: phase_sync(inplace=False) -> FermionicArrayFlat Multiply all lazy phases into the block arrays. :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The resolved array, which now has all trivial (+1) phases. :rtype: FermionicArrayFlat .. py:method:: phase_flip(*axs, inplace=False) -> FermionicArrayFlat Flip the phase of all sectors with odd parity at the given axis. :param ax: The axis along which to flip the phase. :type ax: int :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The phase-flipped array. :rtype: FermionicArrayFlat .. py:method:: phase_transpose(axes=None, inplace=False) -> FermionicArrayFlat Phase this fermionic array as if it were transposed virtually, i.e. the actual arrays are not transposed. Useful when one wants the actual data layout to differ from the required fermionic mode layout. :param axes: The permutation of axes, by default None. :type axes: tuple of int, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :rtype: FermionicArrayFlat .. py:method:: phase_sector(sector, inplace=False) :abstractmethod: .. py:method:: phase_global(inplace=False) Flip the global phase of the array. :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :rtype: FermionicArray .. py:method:: _resolve_dummy_modes_conj(phase_permutation=True) Assuming we have effectively taken the conjugate of a fermionic array with dummy modes, get their new order and compute any phase changes coming from moving back to the beginning of the index order. .. py:method:: _resolve_dummy_modes_combine(a, b) Calculate the new combined dummy modes and any associated global phases combing from contracting two fermionic arrays `a` and `b`. This modifies this array in place. .. py:method:: _resolve_dummy_modes_squeeze(axes_squeeze) Assuming we are about to squeeze away `axes_squeeze`, compute the phases associated with moving them to the beginning of the array, and then turn them into dummy modes. .. py:method:: transpose(axes=None, phase=True, inplace=False) -> FermionicArrayFlat Transpose this flat fermionic array, by default accounting for the phases accumulated from swapping odd charges. :param axes: The permutation of axes, by default None. :type axes: tuple of int, optional :param phase: Whether to flip the phase of sectors whose odd charges undergo a odd permutation. By default True. :type phase: bool, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The transposed array. :rtype: FermionicArrayFlat .. py:method:: conj(phase_permutation=True, phase_dual=False, inplace=False) Conjugate this flat fermionic array. By default this include phases from both the virtual flipping of all axes, but *not* the conjugation of dual indices, such that:: ( tensordot_fermionic(x.conj(), x, ndim) == tensordot_fermionic(x, x.conj(), ndim) ) If all indices have matching dualness (i.e. all bra or all ket), *or* you set `phase_dual=True` then the above contractions will also be equal to ``x.norm() ** 2``. :param phase_permutation: Whether to flip the phase of sectors whose odd charges undergo a odd permutation due to *virtually* flipping the order of axes, by default True. :type phase_permutation: bool, optional :param phase_dual: Whether to flip the phase of dual indices, by default False. If a FermionicArrayFlat has a mix of dual and non-dual indices, and you are explicitly forming the norm, you may want to set this to True. But if it is part of a large tensor network you only need to flip the phase of true 'outer' dual indices. :type phase_dual: bool, optional :rtype: FermionicArrayFlat .. py:method:: dagger(phase_dual=False, inplace=False) Fermionic conjugate transpose. .. py:method:: eigh(phase_eigenvalues=True) -> tuple[symmray.flat.flat_vector.FlatVector, FermionicArrayFlat] Hermitian eigen-decomposition of this flat fermionic array. :param phase_eigenvalues: If True, any local phase will be absorbed into the eigenvalues, such that `U @ diag(w) @ U.H == a` always holds. By default True. If `False` then one of `U` or `U.H` should be phased individually to account for local phasesin the above expression. :type phase_eigenvalues: bool, optional :returns: * **eigenvalues** (*FlatVector*) -- The eigenvalues. * **eigenvectors** (*FermionicArrayFlat*) -- The abelian array of right eigenvectors. .. py:class:: Z2FermionicArrayFlat(sectors, blocks, indices, phases=None, label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`FermionicArrayFlat` Fermionic abelian symmetric array with flat backend. :param sectors: The stack of sector keys, with shape (num_blocks, ndim). Each row represents a sector of a corresponding block, and each column represents a charge in a given axis. :type sectors: array_like :param blocks: The stack of array blocks, with shape (num_blocks, *shape_block), i.e. `ndim + 1` dimensions, where the first dimension is the block index, which should match the first dimension of `sectors`, and the rest are the dimensions of individual blocks. :type blocks: array_like :param indices: Indices describing the dualness and any subindex information for each dimension of the array. If bools are supplied, they will be converted to a FlatIndex with the corresponding dualness, and no subindex information. :type indices: sequence[FlatIndex] :param phases: An array of +/- 1 phases, with shape (num_blocks,), giving the phase of each block. If not supplied, all phases are assumed to be +1. :type phases: array_like, optional :param label: An optional label for the array, potentially needed for ordering dummy odd fermionic modes. :type label: hashable, optional :param dummy_modes: A sequence of dummy fermionic modes representing to effectively prepend to the array. :type dummy_modes: sequence[FermionicOperator], optional :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: static_symmetry .. py:class:: FlatVector(sectors, blocks) Bases: :py:obj:`symmray.flat.flat_data_common.FlatCommon`, :py:obj:`symmray.vector_common.VectorCommon`, :py:obj:`symmray.common.SymmrayCommon` Class for storing block vectors with flat storage, e.g. for the singular- or eigen- values of a matrix. This is equivalent to the diagonal of a zero charge abelian matrix. :param sectors: The vector of charges, with shape (num_blocks,). :type sectors: array_like :param blocks: The stack of vectors, with shape (num_blocks, charge_subsize). :type blocks: array_like .. py:attribute:: __slots__ :value: ('_blocks', '_sectors', 'backend') .. py:method:: from_blocks(blocks) :classmethod: Create a flat vector from a dictionary of blocks. :param blocks: Dictionary mapping sector (charge) to block (array). :type blocks: dict .. py:method:: from_blockvector(blockvector) :classmethod: Create a flat backend vector from a sparse backend BlockVector. :param blockvector: The BlockVector to convert. :type blockvector: BlockVector .. py:method:: to_blockvector() Convert to a sparse backend BlockVector. .. py:method:: from_fill_fn(fill_fn, sectors, charge_size) :classmethod: Create a flat vector by filling blocks using a function that takes a shape and returns an array. :param fill_fn: Function that takes a shape tuple and returns an array of that shape. :type fill_fn: callable :param sectors: The vector of charges, with shape (num_blocks,). If an integer is given, it is assumed to be Z{N} symmetry and the sectors are set to range(N). If a string is given, it is assumed to be of the form "ZN" for some integer N. :type sectors: array_like or int or str :param charge_size: The size of each charge block. :type charge_size: int :param like: :type like: str or array_like, optional .. py:method:: rand(sectors, charge_size, dist='normal', seed=None, like='numpy') :classmethod: .. py:property:: size The total size of all elements in the vector. .. py:property:: shape :type: tuple[int, Ellipsis] Get the effective shape of the vector. .. py:method:: copy(deep=False) -> FlatVector .. py:method:: copy_with(sectors=None, blocks=None) -> FlatVector Create a copy of the vector with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: modify(sectors=None, blocks=None) Modify the vector in place with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: check() .. py:method:: sort_stack(inplace=False) Sort the sectors and associated blocks in ascending order of charge. .. py:method:: _binary_blockwise_op(other, fn, missing=None, inplace=False) .. py:method:: to_dense() .. py:method:: __repr__() .. py:function:: ham_fermi_hubbard_from_edges(symmetry, edges, t=1.0, U=8.0, mu=0.0, like='numpy', flat=False) Return a dict of local 2-body Hamiltonian terms for the Fermi-Hubbard model on the given lattice defined by `edges`. The indices are ordered as (a, b, a', b'), with the local basis like (|00>, ad+|00>, au+|00>, au+ad+|00>) for site a with up (au) and down (ad) spin respectively and similar for site b. :param symmetry: The symmetry of the model. Either "Z2", "U1", "Z2Z2", or "U1U1". :type symmetry: str :param edges: A list of edges representing the lattice, each edge is a tuple of two nodes, each node is some hashable label. :type edges: Sequence[tuple[Hashable, Hashable]] :param t: The hopping parameter, by default 1.0. If a dict is given it should map edges to values, if a callable it should take the two sites as input. :type t: float, dict or callable, optional :param U: The interaction parameter, by default 8.0. If a dict is given it should map sites to values, if a callable it should take the site as input. :type U: float dict or callable, optional :param mu: The chemical potential, by default 0.0. :type mu: float, optional :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return flat arrays, by default False. :type flat: bool, optional :returns: A dictionary mapping edges to local Hamiltonian terms. :rtype: dict[tuple[Hashable, Hashable], FermionicArray | FermionicArrayFlat] .. py:function:: ham_fermi_hubbard_spinless_from_edges(symmetry, edges, t=1.0, V=0.0, mu=0.0, delta=0.0, like='numpy', flat=False) Return a dict of local 2-body Hamiltonian terms for the 'spinless Fermi-Hubbard' or ('t-V') model on the given lattice defined by `edges`. model on the given lattice defined by `edges`. :param symmetry: The symmetry of the model. Either "Z2" or "U1". :type symmetry: str :param edges: A list of edges representing the lattice, each edge is a tuple of two nodes, each node is some hashable label. :type edges: Sequence[tuple[Hashable, Hashable]] :param t: The hopping parameter, by default 1.0. :type t: float, optional :param V: The nearest neighbor interaction parameter, by default 0.0. :type V: float, optional :param mu: The chemical potential, by default 0.0. :type mu: float, optional :param delta: The nearest neighbor superconducting pairing parameter, by default 0.0. :type delta: float, optional :param like: The backend to use, by default "numpy". :type like: str, optional :param flat: Whether to return flat arrays, by default False. :type flat: bool, optional :returns: A dictionary mapping edges to local Hamiltonian terms. :rtype: dict[tuple[Hashable, Hashable], FermionicArray | FermionicArrayFlat] .. py:function:: ham_heisenberg_from_edges(symmetry, edges, flat=False, **kwargs) Return a dict of local 2-body Hamiltonian abelian symmetric terms for the Heisenberg model on the given lattice defined by `edges`. :param symmetry: The symmetry of the model. Either "Z2" or "U1". :type symmetry: str :param edges: A list of edges representing the lattice, each edge is a tuple of two nodes, each node is some hashable label. :type edges: Sequence[tuple[Hashable, Hashable]] :param flat: Whether to return flat arrays, by default False. :type flat: bool, optional :returns: A dictionary mapping edges to local Hamiltonian terms. :rtype: dict[tuple[Hashable, Hashable], AbelianArray | AbelianArrayFlat] .. py:function:: ham_tfim_from_edges(symmetry, edges, jx=-1.0, hz=-3.0, flat=False) Return a dict of local 2-body Hamiltonian abelian symmetric terms for the transverse field Ising model on the given lattice defined by `edges`:: H = jx * sum_ij X_i X_j + hz * sum_i Z_i Note that its rotated into the x-basis so that the Z2 symmetry is manifest. :param symmetry: The symmetry of the model. Should be "Z2". :type symmetry: str :param edges: A list of edges representing the lattice, each edge is a tuple of two nodes, each node is some hashable label. :type edges: Sequence[tuple[Hashable, Hashable]] :param jx: The coupling strength for the X-X interactions, by default -1.0. If a dict is given it should map edges to values, if a callable it should take the two sites as input. :type jx: float, dict, or callable, optional :param hz: The coupling strength for the Z interactions, by default -3.0. If a dict is given it should map sites to values, if a callable it should take the site as input. :type hz: float, dict or callable, optional :param flat: Whether to return flat arrays, by default False. :type flat: bool, optional :returns: A dictionary mapping edges to local Hamiltonian terms. :rtype: dict[tuple[Hashable, Hashable], AbelianArray | AbelianArrayFlat] .. py:function:: abs(x) Return the absolute value of a `symmray` array. .. py:function:: align_axes(x, y, axes) .. py:function:: all(x) Check if all elements of a `symmray` array are true. .. py:function:: any(x) Check if any elements of a `symmray` array are true. .. py:function:: clip(x, a_min, a_max) Clip the values of a `symmray` array. .. py:function:: conj(x, **kwargs) Conjugate a `symmray` array. .. py:function:: einsum(*args, **kwargs) Perform an Einstein summation on a `symmray` array, this simply uses `cotengra` to dispatch the full expression into pairwise tensordot (or einsum if necessary) calls. .. py:function:: expand_dims(x, axis) Expand the shape of a `symmray` array. .. py:function:: fuse(x, *axes_groups) Fuse multiple axes of a `symmray` array. .. py:function:: imag(x) Return the imaginary part of a `symmray` array. .. py:function:: isfinite(x) Check if a `symmray` array contains only finite values. .. py:function:: lddiv(v, x) Left divide a `symmray` matrix `x` by a vector `v`. .. py:function:: ldmul(v, x) Left multiply a `symmray` matrix `x` by a vector `v`. .. py:function:: log(x) Return the natural logarithm of a `symmray` array. .. py:function:: log2(x) Return the base-2 logarithm of a `symmray` array. .. py:function:: log10(x) Return the base-10 logarithm of a `symmray` array. .. py:function:: max(x) Return the maximum value of a `symmray` array. .. py:function:: min(x) Return the minimum value of a `symmray` array. .. py:function:: multiply_diagonal(x, v, axis) Multiply a `symmray` array by a vector as if contracting a diagonal matrix into one axis. .. py:function:: rddiv(x, v) Right divide a `symmray` matrix `x` by a vector `v`. .. py:function:: rdmul(x, v) Right multiply a `symmray` matrix `x` by a vector `v`. .. py:function:: real(x) Return the real part of a `symmray` array. .. py:function:: reshape(a, newshape, **kwargs) Reshape a `symmray` array, via fusing or unfusing. .. py:function:: sqrt(x) Return the square root of a `symmray` array. .. py:function:: squeeze(x, axis=None) Remove single-dimensional entries from shape of a `symmray` array. .. py:function:: sum(x) Return the sum of a `symmray` array. .. py:function:: take(a, indices, axis, **kwargs) Take elements from a `symmray` array along an axis. .. py:function:: tensordot(a, b, axes=2, **kwargs) Contract two `symmray` arrays along the specified axes. :param a: First array to contract. :type a: AbelianArray or FermionicArray :param b: Second array to contract, with same type as `a`. :type b: AbelianArray or FermionicArray :param axes: If an integer, the number of axes to contract. If a tuple, the axes to contract. Default is 2. :type axes: int or tuple of int, optional .. py:function:: trace(a) Return the trace of a `symmray` array. .. py:function:: transpose(a, axes=None, **kwargs) Transpose a `symmray` array. .. py:function:: MPS_abelian_rand(symmetry, L, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', fermionic=False, flat=False, site_charge=None, subsizes='maximal', **kwargs) Create a random MPS with abelian symmetry. :param symmetry: The symmetry of the MPS. :type symmetry: str or Symmetry :param L: The number of sites. :type L: int :param bond_dim: The total (sum of charge sizes) bond dimension of the MPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the MPS is cyclic. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param fermionic: Whether to generate fermionic tensors. :type fermionic: bool, optional :param flat: Whether to generate 'flat' backend arrays (True) or the default block-sparse backend arrays (False). :type flat: bool, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.MatrixProductState .. py:function:: MPS_fermionic_rand(symmetry, L, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', site_charge=None, subsizes='maximal', **kwargs) Create a random fermionic MPS. This is a wrapper around :func:`MPS_abelian_rand` with `fermionic=True`. :param symmetry: The symmetry of the MPS. :type symmetry: str or Symmetry :param L: The number of sites. :type L: int :param bond_dim: The total (sum of charge sizes) bond dimension of the MPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the MPS is cyclic. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.MatrixProductState .. py:function:: PEPS3D_abelian_rand(symmetry, Lx, Ly, Lz, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{},{},{}', site_ind_id='k{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', fermionic=False, site_charge=None, subsizes='maximal', **kwargs) Create a random 3D PEPS with abelian symmetry. :param symmetry: The symmetry of the PEPS. :type symmetry: str or Symmetry :param Lx: Length of the PEPS in the x-direction. :type Lx: int :param Ly: Length of the PEPS in the y-direction. :type Ly: int :param Lz: Length of the PEPS in the z-direction. :type Lz: int :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the PEPS is cyclic in the x-direction. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param fermionic: Whether to generate fermionic tensors. :type fermionic: bool, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.PEPS3D .. py:function:: PEPS3D_fermionic_rand(symmetry, Lx, Ly, Lz, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{},{},{}', site_ind_id='k{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', site_charge=None, subsizes='maximal', **kwargs) Create a random 3D fermionic PEPS. This is a wrapper around :func:`PEPS3D_abelian_rand` with `fermionic=True`. :param symmetry: The symmetry of the PEPS. :type symmetry: str or Symmetry :param Lx: Length of the PEPS in the x-direction. :type Lx: int :param Ly: Length of the PEPS in the y-direction. :type Ly: int :param Lz: Length of the PEPS in the z-direction. :type Lz: int :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the PEPS is cyclic in the x-direction. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.PEPS3D .. py:function:: PEPS_abelian_rand(symmetry, Lx, Ly, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{},{}', site_ind_id='k{},{}', x_tag_id='X{}', y_tag_id='Y{}', fermionic=False, flat=False, site_charge=None, subsizes='maximal', **kwargs) Create a random 2D PEPS with abelian symmetry. :param symmetry: The symmetry of the PEPS. :type symmetry: str or Symmetry :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the PEPS is cyclic in the x-direction. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param fermionic: Whether to generate fermionic tensors. :type fermionic: bool, optional :param flat: Whether to generate 'flat' backend arrays (True) or the default block-sparse backend arrays (False). :type flat: bool, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.PEPS .. py:function:: PEPS_fermionic_rand(symmetry, Lx, Ly, bond_dim, phys_dim=2, cyclic=False, seed=None, dtype='float64', site_tag_id='I{},{}', site_ind_id='k{},{}', x_tag_id='X{}', y_tag_id='Y{}', site_charge=None, subsizes='maximal', **kwargs) Create a random 2D fermionic PEPS. This is a wrapper around :func:`PEPS_abelian_rand` with `fermionic=True`. :param symmetry: The symmetry of the PEPS. :type symmetry: str or Symmetry :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, a default charge distribution is chosen. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: int or dict, optional :param cyclic: Whether the PEPS is cyclic in the x-direction. :type cyclic: bool, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.PEPS .. py:function:: TN_abelian_from_edges_rand(symmetry, edges, bond_dim, phys_dim=None, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', fermionic=False, flat=False, site_charge=None, subsizes='maximal', **kwargs) Build a random abelian symmetric `quimb.tensor` amplitude or PEPS from edges. :param symmetry: The symmetry of the PEPS. Currently only "Z2" and "U1" are supported. :type symmetry: {"Z2", "U1", "Z2Z2", "U1U1", ZN} :param edges: The edges of the PEPS. Each edge is a tuple of the form `(cooa, coob)` where cooa and coob are hashable labels of the two sites. :type edges: list of tuples :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, all sites have the same dimension. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: None, int or dict, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param fermionic: Whether to generate fermionic tensors. :type fermionic: bool, optional :param flat: Whether to generate 'flat' backend arrays (True) or the default block-sparse backend arrays (False). :type flat: bool, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alternate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.TensorNetworkGen or quimb.tensor.TensorNetworkGenVector .. py:function:: TN_fermionic_from_edges_rand(symmetry, edges, bond_dim, phys_dim=None, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', site_charge=None, subsizes='maximal', **kwargs) Create a random fermionic tensor network from edges. This is a wrapper around :func:`TN_abelian_from_edges_rand` with `fermionic=True`. :param symmetry: The symmetry of the PEPS. Currently only "Z2" and "U1" are supported. :type symmetry: {"Z2", "U1", "Z2Z2", "U1U1", ZN} :param edges: The edges of the PEPS. Each edge is a tuple of the form `(cooa, coob)` where cooa and coob are hashable labels of the two sites. :type edges: list of tuples :param bond_dim: The total (sum of charge sizes) bond dimension of the PEPS. You can also provide an explicit map of bond charges to sizes. :type bond_dim: int or dict :param phys_dim: The physical dimension of each site. If None, no physical sites are included. If an integer, all sites have the same dimension. If a dictionary, a custom map of physical charges to sizes. :type phys_dim: None, int or dict, optional :param seed: The random seed or generator to use. :type seed: None, int or np.random.Generator, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: The tag format for each site tensor. :type site_tag_id: str, optional :param site_ind_id: The index format for each site tensor, if physical sites are included. :type site_ind_id: str, optional :param site_charge: A function that takes a site index and returns the charge of that site. By default it will create all even parity tensors if Z2=0 or it will alernate between 0 and 1 for U1. :type site_charge: callable, optional :param subsizes: The sizes of the charge sectors. If None, the sizes are randomly determined. If "equal", the sizes are equal (up to remainders). If "maximal", as many charges as possible will be chosen. :type subsizes: {"maximal", "equal"}, optional :param kwargs: Additional arguments to pass to :func:`symmray.utils.get_rand`. :rtype: quimb.tensor.TensorNetworkGen or quimb.tensor.TensorNetworkGenVector .. py:function:: parse_edges_to_site_info(edges, bond_dim, phys_dim=2, site_ind_id='k{}', bond_ind_id='b{}-{}', site_tag_id='I{}') Given a list of edges, return a dictionary of site information, each specifying the local shape, index identifiers, index dualnesses, and tags. The dualnesses of the bonds are set in a canonical order corresponding to sorting all the sites and the edges. :param edges: The edges of the graph. :type edges: Sequence[Tuple[hashable, hashable]] :param bond_dim: The internal bond dimension. :type bond_dim: int :param phys_dim: The physical dimension of the sites. :type phys_dim: int, optional :param site_ind_id: The identifier for the site indices. :type site_ind_id: str, optional :param bond_ind_id: The identifier for the bond indices. :type bond_ind_id: str, optional :param site_tag_id: The identifier for the site tags. :type site_tag_id: str, optional :rtype: Dict[hashable, Dict[str, Any]] .. py:class:: AbelianArray(indices, charge=None, blocks=(), symmetry=None, label=None) Bases: :py:obj:`symmray.sparse.sparse_array_common.SparseArrayCommon`, :py:obj:`symmray.sparse.sparse_data_common.BlockCommon`, :py:obj:`symmray.bosonic_common.BosonicCommon`, :py:obj:`symmray.array_common.ArrayCommon`, :py:obj:`symmray.common.SymmrayCommon` A block sparse array with symmetry constraints. :param indices: The indices of the array. :type indices: tuple[BlockIndex] :param charge: The total charge of the array, if not given it will be inferred from either the first sector or set to the identity charge, if no sectors are given. :type charge: hashable, optionals :param blocks: A mapping of each 'sector' (tuple of charges) to the data array. :type blocks: dict[tuple[hashable], array_like] :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: __slots__ :value: ('_blocks', '_charge', '_indices', '_label', '_symmetry') .. py:attribute:: fermionic :value: False .. py:attribute:: static_symmetry :value: None .. py:method:: new_with(indices, charge, blocks, label=None) -> AbelianArray Create a new block sparse abelian array of the same class as this one. Unlike `copy`, this does not copy over any existing data and drops for example `label`. .. py:method:: copy() Copy this abelian block sparse array. .. py:method:: copy_with(indices=None, charge=None, blocks=None) A copy of this block array with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: modify(indices=None, charge=None, blocks=None) Modify this block array in place with some attributes replaced. Note that checks are not performed on the new properties, this is intended for internal use. .. py:method:: from_pytree(pytree) :classmethod: Create a sparse abelian array from a pytree purely of non-symmray containers and objects. .. py:method:: _map_blocks(fn_block=None, fn_sector=None, fn_filter=None) Map the blocks and their keys (sectors) of the array inplace. .. py:method:: solve(b: AbelianArray, **kwargs) -> AbelianArray Solve the linear system `A @ x == b` for x, where A is this array. :param b: The right-hand side array. :type b: AbelianArray :returns: **x** -- The solution array. :rtype: AbelianArray .. py:class:: U1Array(indices, charge=None, blocks=(), symmetry=None, label=None) Bases: :py:obj:`AbelianArray` A block array with U1 symmetry. .. py:attribute:: static_symmetry .. py:method:: to_pyblock3(flat=False) .. py:method:: to_yastn(**config_opts) .. py:class:: U1U1Array(indices, charge=None, blocks=(), symmetry=None, label=None) Bases: :py:obj:`AbelianArray` A block array with U1 x U1 symmetry. .. py:attribute:: static_symmetry .. py:class:: Z2Array(indices, charge=None, blocks=(), symmetry=None, label=None) Bases: :py:obj:`AbelianArray` A block array with Z2 symmetry. .. py:attribute:: static_symmetry .. py:method:: to_pyblock3(flat=False) .. py:class:: Z2Z2Array(indices, charge=None, blocks=(), symmetry=None, label=None) Bases: :py:obj:`AbelianArray` A block array with Z2 x Z2 symmetry. .. py:attribute:: static_symmetry .. py:class:: BlockIndex(chargemap=None, dual=False, subinfo=None, linearmap=None) Bases: :py:obj:`symmray.index_common.Index` An index of a block sparse, abelian symmetric tensor. This is intended to be used immutably. :param chargemap: A mapping from charge to size. :type chargemap: dict[int, int] :param dual: Whether the index is 'dual' or not, i.e. whether the flow is 'outwards' / (+ve) / ket-like = ``False`` or 'inwards' / (-ve) / bra-like = ``True``. The sign of charge contributions is then ``(-1) ** dual``. :type dual: bool, optional :param subinfo: Information about the subindices of this index and their extents if this index was formed from fusing. :type subinfo: SubIndexInfo, optional :param linearmap: If provided, a sequence of (charge, offset) pairs for a linear ordering of this index. This can be supplied instead of ``chargemap``, in which case the ``chargemap`` is built from this. If not provided, it is built on demand from ``chargemap``, assuming blocks of sorted charges. :type linearmap: Sequence[tuple[hashable, int], ...], optional .. py:attribute:: __slots__ :value: ('_chargemap', '_dual', '_subinfo', '_hashkey', '_linearmap') .. py:attribute:: _dual :value: False .. py:attribute:: _subinfo :value: None .. py:attribute:: _hashkey :value: None .. py:attribute:: _linearmap :value: None .. py:method:: to_pytree() Convert this sparse index to a pytree purely of non-symmray containers and objects. .. py:method:: from_pytree(pytree) :classmethod: Create a sparse index from a pytree purely of non-symmray containers and objects. .. py:method:: copy_with(**kwargs) A copy of this index with some attributes replaced. Note that checks are not performed on the new propoerties, this is intended for internal use. .. py:method:: to_flat() Convert this index to a flat index. .. py:property:: chargemap A mapping from charge to size. .. py:property:: linearmap A sequence of (charge, offset) pairs for each element of this index, in linear order. This is built on demand if not provided at creation. .. py:property:: subshape .. py:property:: charges The charges of this index. .. py:property:: sizes The sizes of the blocks of this index. .. py:property:: size_total The total size of this index, i.e. the sum of the sizes of all blocks. .. py:property:: num_charges The number of charges. .. py:method:: conj() A copy of this index with the dualness reversed. .. py:method:: drop_charges(charges) Return a new index with all charges in ``charges`` removed. :param charges: The charges to remove. :type charges: Sequence[hashable] :returns: A new index with the charges removed. :rtype: BlockIndex .. py:method:: select_charge(charge, subselect=None) -> BlockIndex Drop all but the specified charge from this index. :param charge: The charge to keep. :type charge: hashable :param subselect: If provided, a range of indices within the selected charge block to keep. If not provided, the entire block is kept. :type subselect: slice or array_like, optional :rtype: BlockIndex .. py:method:: size_of(c) The size of the block with charge ``c``. .. py:method:: linear_to_charge_and_offset(i) Given a linear index ``i`` into this index (as if it were a dense array), return the corresponding charge and offset within that charge block. :param i: The linear index into this index. :type i: int :returns: * **charge** (*hashable*) -- The charge corresponding to the linear index. * **offset** (*int*) -- The offset within the charge block corresponding to the linear index. .. py:method:: check() Check that the index is well-formed, i.e. all sizes are positive. .. py:method:: matches(other) Whether this index matches ``other`` index, namely, whether the ``chargemap`` of each matches, their dualnesses are opposite, and also whether their subindices match, if they have any. For debugging. :param other: The other index to compare to. :type other: BlockIndex .. py:method:: hashkey() Get a hash key for this index. .. py:method:: __hash__() :abstractmethod: .. py:method:: __str__() .. py:method:: __repr__() .. py:function:: default_tensordot_mode(mode) Context manager to temporarily change the default tensordot mode. :param mode: The mode to use for the contraction. :type mode: {"auto", "fused", "blockwise"} .. py:function:: get_default_tensordot_mode() Get the current default tensordot mode. .. py:function:: set_default_tensordot_mode(mode) Set the default tensordot mode. :param mode: The mode to use for the contraction. None is no-op. :type mode: {"auto", "fused", "blockwise", None} .. py:class:: FermionicArray(indices, charge=None, blocks=(), phases=(), label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`symmray.fermionic_common.FermionicCommon`, :py:obj:`symmray.sparse.sparse_array_common.SparseArrayCommon`, :py:obj:`symmray.sparse.sparse_data_common.BlockCommon`, :py:obj:`symmray.array_common.ArrayCommon`, :py:obj:`symmray.common.SymmrayCommon` A fermionic block symmetry array. :param indices: The indices of the array. :type indices: tuple of Index :param charge: The total charge of the array, if not given it will be inferred from either the first sector or set to the identity charge, if no sectors are given. :type charge: hashable, optionals :param blocks: The blocks of the array, by default empty. :type blocks: dict, optional :param phases: The lazy phases of each block, by default empty. :type phases: dict, optional :param label: An optional label for the array, potentially needed for ordering dummy odd fermionic modes. :type label: hashable, optional :param symmetry: The symmetry of the array, if not using a specific symmetry class. :type symmetry: str or Symmetry, optional .. py:attribute:: __slots__ :value: ('_blocks', '_charge', '_dummy_modes', '_indices', '_label', '_phases', '_symmetry') .. py:attribute:: fermionic :value: True .. py:attribute:: static_symmetry :value: None .. py:attribute:: _phases .. py:attribute:: _dummy_modes :value: () .. py:method:: to_pytree() Convert this sparse fermionic array to a pytree purely of non-symmray containers and objects. .. py:method:: from_pytree(data) :classmethod: Create a sparse fermionic array from a pytree purely of non-symmray containers and objects. .. py:property:: parity The parity of the total charge. .. py:property:: phases The lazy phases of each sector. Trivial phases are not necessarily stored. .. py:method:: copy() Create a copy of this fermionic array. :returns: The copied array. :rtype: FermionicArray .. py:method:: new_with(indices, charge, blocks, label=None) Create a new block sparse fermionic array of the same class as this one. Unlike `copy`, this does not copy over any existing data and drops by default `label`, `phases`, and `dummy_modes`. .. py:method:: copy_with(indices=None, blocks=None, charge=None, phases=None) Create a copy of this fermionic array with some attributes replaced. :param indices: The new indices, if None, the original indices are used. :type indices: tuple of Index, optional :param blocks: The new blocks, if None, the original blocks are used. :type blocks: dict, optional :param charge: The new total charge, if None, the original charge is used. :type charge: int, optional :param phases: The new phases, if None, the original phases are used. :type phases: dict, optional .. py:method:: modify(indices=None, blocks=None, charge=None, phases=None, dummy_modes=None) Modify this fermionic array inplace. This is for internal use, and does not perform any checks on the updated attributes. :param indices: The new indices, if None, the original indices are used. :type indices: tuple of Index, optional :param blocks: The new blocks, if None, the original blocks are used. :type blocks: dict, optional :param charge: The new total charge, if None, the original charge is used. :type charge: int, optional :param phases: The new phases, if None, the original phases are used. :type phases: dict, optional :param dummy_modes: The new dummy_modes, if None, the original dummy_modes are used. :type dummy_modes: object or FermionicOperator, optional .. py:method:: randomize_phases(seed=None, inplace=False) -> FermionicArray Randomize the phases of each sector to either +1 or -1. This is useful for testing. :param seed: The random seed or generator, by default None. :type seed: int or numpy.random.Generator, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The phase randomized array. :rtype: FermionicArray .. py:method:: phase_sync(inplace=False) -> FermionicArray Multiply all lazy phases into the block arrays. :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The resolved array, which now has no lazy phases. :rtype: FermionicArray .. py:method:: phase_flip(*axs, inplace=False) -> FermionicArray Flip the phase of all sectors with odd parity at the given axis. :param ax: The axis along which to flip the phase. :type ax: int :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The phase-flipped array. :rtype: FermionicArray .. py:method:: phase_transpose(axes=None, inplace=False) Phase this fermionic array as if it were transposed virtually, i.e. the actual arrays are not transposed. Useful when one wants the actual data layout to differ from the required fermionic mode layout. :param axes: The permutation of axes, by default None. :type axes: tuple of int, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :rtype: FermionicArray .. py:method:: phase_sector(sector, inplace=False) Flip the phase of a specific sector. :param sector: The sector to flip the phase of. :type sector: tuple of hashable :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :rtype: FermionicArray .. py:method:: phase_global(inplace=False) Flip the global phase of the array. :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :rtype: FermionicArray .. py:method:: _map_blocks(fn_block=None, fn_sector=None, fn_filter=None) Map the blocks and their keys (sectors) of the array inplace. .. py:method:: _resolve_dummy_modes_conj(phase_permutation=True) Assuming we have effectively taken the conjugate of a fermionic array with dummy modes, get their new order and compute any phase changes coming from moving back to the beginning of the index order. .. py:method:: _resolve_dummy_modes_combine(left, right) Calculate the new combined dummy odd modes and any associated global phases combing from contracting two fermionic arrays `a` and `b`. This modifies this array in place. .. py:method:: _resolve_dummy_modes_squeeze(axes_squeeze) Assuming we are about to squeeze away `axes_squeeze`, compute the phases associated with moving them to the beginning of the array, and then turn them into dummy modes. .. py:method:: transpose(axes=None, phase=True, inplace=False) Transpose the fermionic array, by default accounting for the phases accumulated from swapping odd charges. :param axes: The permutation of axes, by default None. :type axes: tuple of int, optional :param phase: Whether to flip the phase of sectors whose odd charges undergo a odd permutation. By default True. :type phase: bool, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The transposed array. :rtype: FermionicArray .. py:method:: conj(phase_permutation=True, phase_dual=False, inplace=False) Conjugate this fermionic array. By default this include phases from both the virtual flipping of all axes, but *not* the conjugation of dual indices, such that:: ( tensordot_fermionic(x.conj(), x, ndim) == tensordot_fermionic(x, x.conj(), ndim) ) If all indices have matching dualness (i.e. all bra or all ket), *or* you set `phase_dual=True` then the above contractions will also be equal to ``x.norm() ** 2``. :param phase_permutation: Whether to flip the phase of sectors whose odd charges undergo a odd permutation due to *virtually* flipping the order of axes, by default True. :type phase_permutation: bool, optional :param phase_dual: Whether to flip the phase of dual indices, by default False. If a FermionicArray has a mix of dual and non-dual indices, and you are explicitly forming the norm, you may want to set this to True. But if it is part of a large tensor network you only need to flip the phase of true 'outer' dual indices. :type phase_dual: bool, optional :rtype: FermionicArray .. py:method:: dagger(phase_dual=False, inplace=False) Fermionic adjoint, implements `.H` attribute. :param phase_dual: Whether to flip the phase of dual indices, by default False. If a FermionicArray has a mix of dual and non-dual indices, and you are explicitly forming the norm, you may want to set this to True. But if it is part of a large tensor network you only need to flip the phase of 'outer' dual indices. :type phase_dual: bool, optional :param inplace: Whether to perform the operation in place. :type inplace: bool, optional :returns: The conjugate transposed array. :rtype: FermionicArray .. py:method:: eigh(phase_eigenvalues=True, **kwargs) -> tuple[symmray.sparse.sparse_vector.BlockVector, FermionicArray] Eigenvalue decomposition of this assumed Hermitian block sparse fermionic array. :param phase_eigenvalues: If True, any local phase will be absorbed into the eigenvalues, such that `U @ diag(w) @ U.H == a` always holds. By default True. If `False` then one of `U` or `U.H` should be phased individually to account for local phasesin the above expression. :type phase_eigenvalues: bool, optional :returns: * **w** (*BlockVector*) -- The eigenvalues as a vector. If `phase_eigenvalues` is True, then eigenvalues corresponding to odd parity sectors will be negated depending of the inner index dualness. * **U** (*FermionicArray*) -- The array of eigenvectors. .. py:class:: U1FermionicArray(indices, charge=None, blocks=(), phases=(), label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`FermionicArray` A fermionic block array with U1 symmetry. .. py:attribute:: static_symmetry .. py:method:: to_pyblock3(flat=False) .. py:class:: U1U1FermionicArray(indices, charge=None, blocks=(), phases=(), label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`FermionicArray` A fermionic block array with U1 x U1 symmetry. .. py:attribute:: static_symmetry .. py:class:: Z2FermionicArray(indices, charge=None, blocks=(), phases=(), label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`FermionicArray` A fermionic block array with Z2 symmetry. .. py:attribute:: static_symmetry .. py:method:: to_pyblock3(flat=False) .. py:class:: Z2Z2FermionicArray(indices, charge=None, blocks=(), phases=(), label=None, dummy_modes=None, symmetry=None) Bases: :py:obj:`FermionicArray` A fermionic block array with Z2 x Z2 symmetry. .. py:attribute:: static_symmetry .. py:class:: BlockVector(blocks) Bases: :py:obj:`symmray.sparse.sparse_data_common.BlockCommon`, :py:obj:`symmray.vector_common.VectorCommon`, :py:obj:`symmray.common.SymmrayCommon` Class for storing block vectors with sparse storage, e.g. for the singular- or eigen- values of a matrix. This is equivalent to the diagonal of a zero charge abelian matrix. :param blocks: A dictionary mapping sector keys to array blocks. :type blocks: dict .. py:attribute:: __slots__ :value: ('_blocks',) .. py:attribute:: ndim :value: 1 .. py:method:: copy() .. py:property:: size The total size of all elements in the vector. .. py:property:: shape Get the effective shape of the vector. .. py:method:: _binary_blockwise_op(other, fn, missing=None, inplace=False) .. py:method:: check() Check that the block vector is well formed. .. py:method:: to_flat() Convert the block sparse vector to a flat vector. .. py:method:: to_dense() Convert the block vector to a dense array. .. py:method:: allclose(other, **allclose_opts) .. py:method:: test_allclose(other, **allclose_opts) Like `allclose` but raises an AssertionError with details if not close. .. py:method:: __repr__() .. py:class:: U1 Bases: :py:obj:`Symmetry` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: __slots__ :value: () .. py:method:: valid(*charges: int) -> bool Check if all charges are valid for the symmetry. .. py:method:: combine(*charges: int) -> int Combine / add charges according to the symmetry. .. py:method:: sign(charge: int, dual=True) -> int Negate a charge according to the symmetry and flag ``dual``. .. py:method:: parity(charge: int) -> int Return the parity, 0 or 1, of a charge according to the symmetry. .. py:method:: random_charge(seed=None) -> int Return a random valid charge, for testing purposes. .. py:class:: U1U1 Bases: :py:obj:`Symmetry` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: __slots__ :value: () .. py:method:: valid(*charges: tuple[int, int]) -> bool Check if all charges are valid for the symmetry. .. py:method:: combine(*charges: tuple[int, int]) -> tuple[int, int] Combine / add charges according to the symmetry. .. py:method:: sign(charge: tuple[int, int], dual=True) -> tuple[int, int] Negate a charge according to the symmetry and flag ``dual``. .. py:method:: parity(charge: tuple[int, int]) -> int Return the parity, 0 or 1, of a charge according to the symmetry. .. py:method:: random_charge(seed=None) -> tuple[int, int] Return a random valid charge, for testing purposes. .. py:class:: Z2 Bases: :py:obj:`ZN` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: N :value: 2 .. py:method:: sign(charge: int, dual=True) -> int Negate a charge according to the symmetry and flag ``dual``. .. py:class:: Z2Z2 Bases: :py:obj:`Symmetry` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: __slots__ :value: () .. py:method:: valid(*charges: tuple[int, int]) -> bool Check if all charges are valid for the symmetry. .. py:method:: combine(*charges: tuple[int, int]) -> tuple[int, int] Combine / add charges according to the symmetry. .. py:method:: sign(charge: tuple[int, int], dual=True) -> tuple[int, int] Negate a charge according to the symmetry and flag ``dual``. .. py:method:: parity(charge: tuple[int, int]) -> int Return the parity, 0 or 1, of a charge according to the symmetry. .. py:method:: random_charge(seed=None) -> tuple[int, int] Return a random valid charge, for testing purposes. .. py:class:: ZN Bases: :py:obj:`Symmetry` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: __slots__ :value: ('N',) .. py:method:: valid(*charges: int) -> bool Check if all charges are valid for the symmetry. .. py:method:: combine(*charges: int) -> int Combine / add charges according to the symmetry. .. py:method:: sign(charge: int, dual=True) -> int Negate a charge according to the symmetry and flag ``dual``. .. py:method:: parity(charge: int) -> int Return the parity, 0 or 1, of a charge according to the symmetry. .. py:method:: random_charge(seed=None) -> int Return a random valid charge, for testing purposes. .. py:method:: __reduce__() .. py:class:: Symmetry Bases: :py:obj:`abc.ABC` Helper class that provides a standard way to create an ABC using inheritance. .. py:attribute:: __slots__ :value: () .. py:method:: valid(*charges) :abstractmethod: Check if all charges are valid for the symmetry. .. py:method:: combine(*charges) :abstractmethod: Combine / add charges according to the symmetry. .. py:method:: sign(charge, dual=True) :abstractmethod: Negate a charge according to the symmetry and flag ``dual``. .. py:method:: parity(charge) :abstractmethod: Return the parity, 0 or 1, of a charge according to the symmetry. .. py:method:: random_charge(seed=None) :abstractmethod: Return a random valid charge, for testing purposes. .. py:method:: __str__() .. py:method:: __eq__(other) .. py:method:: __hash__() .. py:method:: __repr__() .. py:function:: get_symmetry(symmetry: str | Symmetry) -> Symmetry Get a symmetry instance by name. :param symmetry: The symmetry to get. :type symmetry: str or Symmetry :returns: The symmetry instance. :rtype: Symmetry .. py:function:: get_zn_symmetry_cls(N: int) -> type Get a ZN symmetry class.