symmray.spin_local_operators ============================ .. py:module:: symmray.spin_local_operators .. autoapi-nested-parse:: Helper functions for building local spin-1/2 operators from a symbolic description, without any external dependencies. Unlike the fermionic case there are no 'internal' signs to compute, so each named operator is simply given its 2x2 matrix representation and terms are combined via tensor (Kronecker) products. Functions --------- .. autoapisummary:: symmray.spin_local_operators._spin_matrices symmray.spin_local_operators.get_spin_operator symmray.spin_local_operators.get_spinhalf_charge_indexmap symmray.spin_local_operators._spinhalf_index_maps symmray.spin_local_operators.build_local_spin_dense symmray.spin_local_operators.build_local_spin_array symmray.spin_local_operators.tfim_local_array symmray.spin_local_operators.heisenberg_local_array symmray.spin_local_operators.spin_operator_local_array Module Contents --------------- .. py:function:: _spin_matrices() The 2x2 matrix representations of the supported single-site spin-1/2 operators, as a dict of numpy arrays. Cached so they are built only once. .. py:function:: get_spin_operator(label, like='numpy') Get the 2x2 matrix representation of a single-site spin-1/2 operator. :param label: The operator to get, one of "I", "x", "y", "z", "sx", "sy", "sz", "+" or "-". :type label: str :param like: The backend to use, by default "numpy". :type like: str, optional :returns: The 2x2 matrix representation. :rtype: array .. py:function:: get_spinhalf_charge_indexmap(symmetry) Get a mapping of linear index to charge sector for a spin-1/2 site. :param symmetry: The symmetry of the model. Either "Z2", a "ZN" group, or "U1". :type symmetry: str :rtype: list[hashable] .. py:function:: _spinhalf_index_maps(symmetry, nsites) Per-site spin-1/2 index maps, or None when ``symmetry`` is None. .. py:function:: build_local_spin_dense(terms, like='numpy') Compute the dense matrix of a local spin-1/2 operator from a symbolic description. :param terms: The terms in the operator, each a tuple of a coefficient and a tuple of single-site operator labels (see `get_spin_operator`), one per site. All terms should act on the same number of sites. :type terms: Sequence[tuple[float, tuple[str, ...]]] :param like: The backend to use, by default "numpy". :type like: str, optional :returns: The dense operator, of shape ``(2,) * (2 * nsites)`` with axes ordered as ``(ket_0, ..., ket_{n-1}, bra_0, ..., bra_{n-1})``. :rtype: array .. rubric:: Examples The transverse field Ising local term:: build_local_spin_dense( [(-1.0, ("x", "x")), (-3.0, ("z", "I")), (-3.0, ("I", "z"))] ) .. py:function:: build_local_spin_array(terms, symmetry, index_maps=None, charge=None, like='numpy', flat=False) Compute a local spin-1/2 operator as an `AbelianArray`. :param terms: The terms in the operator, each a tuple of a coefficient and a tuple of single-site operator labels (see `get_spin_operator`), one per site. :type terms: Sequence[tuple[float, tuple[str, ...]]] :param symmetry: The symmetry of the operator. Either "Z2", a "ZN" group, or "U1". If None, the raw dense array is returned instead of a symmetric array. :type symmetry: str or None :param index_maps: For each site, the sequence mapping linear index to charge sector. Required unless ``symmetry`` is None. :type index_maps: Sequence[Sequence[hashable]], optional :param charge: The total charge of the array. If not given it is taken as the identity / zero element, suitable for charge-conserving operators. :type charge: hashable, 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, as a dense array if ``symmetry`` is None. :rtype: AbelianArray or AbelianArrayFlat or array .. py:function:: tfim_local_array(symmetry, jx=-1.0, hz=-3.0, coordinations=(1, 1), like='numpy', flat=False) Build an abelian symmetric local operator for the transverse field Ising model:: 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", or None to return the raw dense array. :type symmetry: str or None :param jx: The coupling strength for the X-X interactions, by default -1.0. :type jx: float :param hz: The coupling strength for the Z interactions, by default -3.0. If a tuple is given it should contain the fields for the two sites. :type hz: float or tuple[float, float] :param coordinations: The coordinations of the two sites, by default (1, 1). The fields are divided by these values to account for double counting. :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 Hamiltonian term, dense if ``symmetry`` is None. :rtype: Z2Array or Z2ArrayFlat or array .. py:function:: heisenberg_local_array(symmetry, j=1.0, b=0.0, coordinations=(1, 1), like='numpy', flat=False) Build an abelian symmetric local operator for the Heisenberg model:: H = sum_ij (jx Sx_i Sx_j + jy Sy_i Sy_j + jz Sz_i Sz_j) - sum_i bz Sz_i where the spin operators are the spin-1/2 operators (eigenvalues +/- 1/2). :param symmetry: The symmetry of the model. Either "Z2" or "U1", or None to return the raw dense array. Note "U1" requires the XY couplings to be equal (``jx == jy``), so that total magnetization is conserved. :type symmetry: str or None :param j: The coupling strength, by default 1.0. If a tuple is given it should contain the ``(jx, jy, jz)`` couplings. :type j: float or tuple[float, float, float], optional :param b: The magnetic field along the z-axis, by default 0.0. A scalar is applied uniformly to both sites, while a pair ``(ba, bb)`` sets the two sites' fields independently. Only z-fields are supported as transverse fields would not conserve the symmetry. :type b: float or tuple[float, float], optional :param coordinations: The coordinations of the two sites, by default (1, 1). The fields are divided by these values to account for double counting. :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 Hamiltonian term, dense if ``symmetry`` is None. :rtype: AbelianArray or AbelianArrayFlat or array .. py:function:: spin_operator_local_array(symmetry, op='z', like='numpy', flat=False) Build a single-site abelian symmetric spin-1/2 operator. :param symmetry: The symmetry of the model. Either "Z2", a "ZN" group, or "U1", or None to return the raw dense array. :type symmetry: str or None :param op: The operator to build, by default "z". One of "I", "x", "y", "z", "sx", "sy", "sz", "+" or "-". Note charge-changing operators ("+", "-", and for "U1" also "x", "y") yield an array with non-identity total charge. :type op: str, 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 single-site operator, dense if ``symmetry`` is None. :rtype: AbelianArray or AbelianArrayFlat or array