quimb.operator ============== .. py:module:: quimb.operator .. autoapi-nested-parse:: Tools for 'symbolically' and consistently defining operators and hamiltonians, which can then be built out into various matrix or tensor network forms such as sparse matrices and MPOs. Submodules ---------- .. toctree:: :maxdepth: 1 /autoapi/quimb/operator/builder/index /autoapi/quimb/operator/configcore/index /autoapi/quimb/operator/hilbertspace/index /autoapi/quimb/operator/models/index /autoapi/quimb/operator/pepobuilder/index Classes ------- .. autoapisummary:: quimb.operator.SparseOperatorBuilder quimb.operator.HilbertSpace Functions --------- .. autoapisummary:: quimb.operator.get_mat quimb.operator.fermi_hubbard_from_edges quimb.operator.fermi_hubbard_spinless_from_edges quimb.operator.heisenberg_from_edges quimb.operator.rand_operator Package Contents ---------------- .. py:class:: SparseOperatorBuilder(terms=(), hilbert_space: quimb.operator.hilbertspace.HilbertSpace = None, dtype=None, jordan_wigner=False, pauli_decompose=False, atol=1e-12) Object for building operators with sparse structure. Specifically, a sum of terms, where each term is a product of operators, where each of these local operators acts on a single site and has at most one entry per row. :param terms: The terms to initialize the builder with. ``add_term`` is simply called on each of these. :type terms: sequence, optional :param hilbert_space: The Hilbert space to build the operator in. If this is not supplied then a minimal Hilbert space will be constructed from the sites used, when required. The default symmetry and sector to build operators in is inherited from this Hilbert space, but can be overridden. :type hilbert_space: HilbertSpace :param dtype: A default data type for the coefficients of the operator. If not provided, will be automatically determined at building time based on the terms in the operator. If the operator is complex, will be set to ``np.complex128``. If the operator is real, will be set to ``np.float64``. Individual building methods can override this. :type dtype: numpy.dtype or str, optional :param jordan_wigner: Whether to apply the Jordan-Wigner transformation to the terms automatically when processing them. This prepends pauli Z strings to all creation and annihilation operators. :type jordan_wigner: bool, optional :param pauli_decompose: Whether to apply the Pauli decomposition to the terms automatically when processing them. This decomposes all local operators into sums of Pauli operators. If "zx" is supplied, the decomposition is done in terms of the real `ZX = iY` operator instead of `Y`. :type pauli_decompose: bool or "zx", optional :param atol: The absolute tolerance for considering coefficients to be null when simplifying and decomposing terms. :type atol: float, optional .. py:attribute:: _sites_used .. py:attribute:: _hilbert_space :value: None .. py:attribute:: _terms_raw .. py:attribute:: _terms_final :value: None .. py:attribute:: _transform_jordan_wigner :value: False .. py:attribute:: _transform_pauli_decompose :value: False .. py:attribute:: _atol :value: 1e-12 .. py:attribute:: _dtype :value: None .. py:attribute:: _coupling_maps .. py:attribute:: _cache .. py:property:: sites_used A tuple of the sorted coordinates/sites seen so far. .. py:property:: hilbert_space :type: quimb.operator.hilbertspace.HilbertSpace The Hilbert space of the operator. Created from the sites seen so far if not supplied at construction. .. py:property:: nsites The total number of coordinates/sites seen so far. .. py:method:: site_to_reg(site) Get the register / linear index of coordinate ``site``. .. py:method:: reg_to_site(reg) Get the site of register / linear index ``reg``. .. py:property:: terms_raw A tuple of the raw terms seen so far, as a mapping from operator strings to coefficients. .. py:method:: _reset_caches() Reset any cached representations of the operator, used whenever the terms are modified in any way, and thus require reprocessing. .. py:method:: _get_terms_final() Get the processed terms, applying any requested transformations, if not already done. .. py:property:: terms A tuple of the, possibly transformed, terms seen so far. .. py:property:: nterms The total number of terms seen so far. .. py:property:: locality The locality of the operator, the maximum support of any term. .. py:property:: iscomplex Whether the operator has complex terms. .. py:method:: add_term(*coeff_ops) Add a term to the operator. :param coeff: The overall coefficient of the term. :type coeff: float, optional :param ops: The operators of the term, together with the sites they act on. Each term should be a pair of ``(operator, site)``, where ``operator`` can be: - ``'x'``, ``'y'``, ``'z'``: Pauli matrices - ``'sx'``, ``'sy'``, ``'sz'``: spin operators (i.e. scaled Pauli matrices) - ``'+'``, ``'-'``: creation/annihilation operators - ``'n'``, ``'sn'``, or ``'h'``: number, symmetric number (n - 1/2) and hole (1 - n) operators. And ``site`` is a hashable object that represents the site that the operator acts on. If this builder has an associated Hilbert space already, the site must be present in that Hilbert space, else a minimal Hilbert space will be constructed from the sites used, when required. :type ops: sequence of tuple[str, hashable] .. py:method:: __iadd__(term) .. py:method:: __isub__(term) .. py:method:: jordan_wigner_transform(value=None) Toggle transforming the terms in this operator by pre-prending pauli Z strings to all creation and annihilation operators. This is always applied directly as the first processing step to the raw terms, so that the fermionic ordering is respected. Note this doesn't decompose +, - into (X + iY) / 2 and (X - iY) / 2, it just prepends Z strings. Use `pauli_decompose` to get the full decomposition. The placement of the Z strings is defined by the ordering of the hilbert space, by default, the sorted order of the site labels. :param value: Whether to apply the Jordan-Wigner transformation. If `None` (the default) then this method acts as toggle. Whereas supplying `True` or `False` explicitly sets or unsets the transformation. :type value: bool, optional .. py:method:: pauli_decompose(value=None, atol=None, use_zx=False) Transform the terms in this operator by decomposing them into Pauli strings. :param value: Whether to apply the Pauli decomposition. If `None` (the default) then this method acts as toggle. Whereas supplying `True` or `False` explicitly sets or unsets the transformation. :type value: bool, optional .. py:method:: show(filler='.') Print an ascii representation of the terms in this operator. .. py:method:: get_dtype(dtype=None) Calculate the numpy data type of the operator to use. :param dtype: The data type of the coefficients. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype or str, optional :returns: **dtype** -- The data type of the coefficients. :rtype: numpy.dtype .. py:method:: get_coupling_map(dtype=None) Build and cache the coupling map for the specified dtype. :param dtype: The data type of the coefficients. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :returns: **coupling_map** -- The operator defined as tuple of flat arrays. :rtype: tuple[ndarray] .. py:method:: flatconfig_coupling(flatconfig, dtype=None) Get an array of other configurations coupled to the given individual ``flatconfig`` by this operator, and the corresponding coupling coefficients. This is for use with VMC for example. :param flatconfig: The linear array of the configuration to get the coupling for. :type flatconfig: array[np.uint8] :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :returns: * **coupled_flatconfigs** (*ndarray[np.uint8]*) -- Each distinct flatconfig coupled to ``flatconfig``. * **coeffs** (*ndarray[dtype]*) -- The corresponding coupling coefficients. .. py:method:: config_coupling(config, dtype=None) Get a list of other configurations coupled to ``config`` by this operator, and the corresponding coupling coefficients. This is for use with VMC for example. :param config: The configuration to get the coupling for. :type config: dict[site, int] :returns: * **coupled_configs** (*list[dict[site, np.uint8]]*) -- Each distinct configuration coupled to ``config``. * **coeffs** (*list[dtype]*) -- The corresponding coupling coefficients. .. py:method:: evaluate_exact_flatconfigs(fn_amplitude, progbar=False) Calculate the expectation value of this operator with respect to a wavefunction provided as a function with signature:: fn_amplitude(flatconfig: ndarray[np.uint8]) -> z: float | complex .. py:method:: evaluate_exact_configs(fn_amplitude, progbar=False) Calculate the expectation value of this operator with respect to a wavefunction provided as a function with signature:: fn_amplitude(config: dict[site, int]) -> z: float | complex .. py:method:: build_coo_data(sector=None, symmetry=None, dtype=None, parallel=False) Build the raw data for a sparse matrix in COO format, optionally in parallel. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :param parallel: Whether to build the matrix in parallel (multi-threaded). If True, will use number of threads equal to the number of available CPU cores. If False, will use a single thread. If an integer is provided, it will be used as the number of threads to use. :type parallel: bool or int, optional :returns: * **data** (*array*) -- The data entries for the sparse matrix in COO format. * **rows** (*array*) -- The row indices for the sparse matrix in COO format. * **cols** (*array*) -- The column indices for the sparse matrix in COO format. * **d** (*int*) -- The total number of basis states. .. py:method:: build_sparse_matrix(sector=None, symmetry=None, dtype=None, stype='csr', parallel=False) Build a sparse matrix in the given format. Optionally in parallel. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :param stype: The sparse matrix format to use. Can be one of 'coo', 'csr', 'csc', 'bsr', 'lil', 'dok', or 'dia'. Default is 'csr'. :type stype: str, optional :param parallel: Whether to build the matrix in parallel (multi-threaded). :type parallel: bool, optional :rtype: scipy.sparse matrix .. py:method:: build_dense(sector=None, symmetry=None, dtype=None, parallel=False) Get the dense (`numpy.ndarray`) matrix representation of this operator. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :param parallel: Whether to build the matrix in parallel (multi-threaded). If True, will use number of threads equal to the number of available CPU cores. If False, will use a single thread. If an integer is provided, it will be used as the number of threads to use. :type parallel: bool or int, optional :returns: **A** -- The dense matrix representation of this operator. :rtype: numpy.ndarray .. py:method:: matvec(x, out=None, sector=None, symmetry=None, dtype=None, parallel=False) Apply this operator lazily (i.e. without constructing a sparse matrix) to a vector. This uses less memory but is much slower. :param x: The vector to apply the operator to. :type x: array :param out: An array to store the result in. If not provided, a new array will be created. :type out: array, optional :param sector: The sector of the Hilbert space. If None, the default sector is used. The implicit size should match that of `x`. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param dtype: The data type of the matrix. If not provided, will be automatically set as the same as the input vector. :type dtype: numpy.dtype, optional :param parallel: Whether to apply the operator in parallel (multi-threaded). If True, will use number of threads equal to the number of available CPU cores. If False, will use a single thread. If an integer is provided, it will be used as the number of threads to use. Uses `num_threads` more memory but is faster. :type parallel: bool or int, optional :returns: **out** -- The result of applying the operator to the vector. :rtype: array .. py:method:: aslinearoperator(sector=None, symmetry=None, dtype=None, parallel=False) Get a `scipy.sparse.linalg.LinearOperator` for this operator. This is a lazy representation of the operator, which uses `matvec` to apply the operator to a vector. Less memory is required than constructing the full sparse matrix, but it is significantly slower. Note currently the operator is assumed to be hermitian. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :param parallel: Whether to apply the operator in parallel (multi-threaded). If True, will use number of threads equal to the number of available CPU cores. If False, will use a single thread. If an integer is provided, it will be used as the number of threads to use. Uses `num_threads` more memory but is faster. :type parallel: bool or int, optional :returns: **Alo** -- The linear operator representation of this operator. :rtype: scipy.sparse.linalg.LinearOperator .. py:method:: build_local_terms(dtype=None) Get a dictionary of local terms, where each key is a sorted tuple of sites, and each value is the local matrix representation of the operator on those sites. For use with e.g. tensor network algorithms. Note terms acting on the same sites are summed together and the size of each local matrix is exponential in the locality of that term. :returns: **Hk** -- The local terms. :rtype: dict[tuple[hashable], numpy.ndarray] .. py:method:: build_local_ham(dtype=None) Get a `LocalHamGen` object for this operator. :param dtype: The data type of the matrix. If not provided, will be automatically determined based on the terms in the operator. :type dtype: numpy.dtype, optional :returns: **H** -- The local Hamiltonian representation of this operator. :rtype: LocalHamGen .. py:method:: build_state_machine_greedy(atol=1e-12) .. py:method:: draw_state_machine(method='greedy', figsize='auto', G=None) Draw the fintie state machine for this operator, as if buildling the MPO. .. py:method:: build_mpo(method='greedy', dtype=None, **mpo_opts) Build a matrix product operator (MPO) representation of this operator. :param method: The method to use for building the MPO. Currently only "greedy" is supported. :type method: str, optional :param dtype: The data type of the MPO. If not supplied, will be chosen automatically based on the terms in the operator. :type dtype: type, optional :param mpo_opts: Additional options to pass to the MPO constructor. See `MatrixProductOperator` for details. :type mpo_opts: keyword arguments :returns: **mpo** -- The MPO representation of this operator. :rtype: MatrixProductOperator .. py:method:: __repr__() .. py:method:: build_matrix_ikron(**ikron_opts) Build either the dense or sparse matrix of this operator via explicit calls to `ikron`. This is a slower but useful alternative testing method. .. py:function:: get_mat(op, dtype=None) .. py:class:: HilbertSpace(sites, dims=2, order=None, sector=None, symmetry=None) Take a set of 'sites' (any sequence of sortable, hashable objects), and map this into a 'register' or linearly indexed range, optionally using a particular ordering. A symmetry and sector can also be specified, which will change the size of the Hilbert space and how the valid configurations are enumerated. Some nomenclature: - *site*: a hashable label for a site in the Hilbert space. This can be any python object (e.g. tuple[str | int]). - *register*: a linear index for a site in the Hilbert space. This is an integer in the range [0, nsites), and requires an ordering of the sites. - *configuration*: a mapping from sites to their occupation number or spin state. This is a dictionary mapping from site to int. - *flat configuration*: a flat array of the occupation number or spin state of each site in the order given by this Hilbert space (i.e. a mapping of register to int). This is a 1D array of length nsites with dtype np.uint8, for efficient manipulation with numba and numpy. - *rank*: a linear index for a configuration in the Hilbert space, taking into account any symmetries and sectors. This is an integer in the range [0, size), where size is the size of the Hilbert space given the symmetry and sector. :param sites: The sites to map into a linear register. If an integer, simply use ``range(sites)``. If a dict, the keys are the sites and the values are the dimensions, in which case the `dims` argument is ignored. :type sites: int, sequence of hashable objects, or dict :param dims: The local dimensions of each site. If an integer, all sites have the same dimension. If a sequence, it should be the same length as `sites`. You can also provide the dimensions as part of the `sites` argument by passing a dict, in which case this argument is ignored. :type dims: int or sequence of int, optional :param order: How to order the sites. If `None` or `False` (default), the sites are kept in the order supplied. If `True`, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites. :type order: bool, sequence[hashable] or callable, optional :param sector: The sector of the Hilbert space. If None, no sector is assumed. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space if any. If `None` and a `sector` is provided, the symmetry will be inferred from the sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional .. py:attribute:: _size :value: None .. py:attribute:: _sizes :value: None .. py:attribute:: _strides :value: None .. py:attribute:: _pt :value: None .. py:method:: set_ordering(order) Set the ordering of the sites in this Hilbert space. :param order: How to order the sites. If `None` or `False` (default), the sites are kept in the order supplied. If `True`, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites. :type order: bool, sequence[hashable] or callable, optional .. py:method:: from_edges(edges, order=None) :classmethod: Construct a HilbertSpace from a set of edges, which are pairs of sites. :param edges: The edges to parse. :type edges: Iterable[tuple[hashable, hashable]]] :param order: How to order the sites. If `None` or `False` (default), the sites are kept in the order supplied. If `True`, the sites are sorted. If a sequence, it should be a permutation of the sites, and this will be used to order them. If a callable, it should be a sorting key function which will be used to order the sites. :type order: bool, sequence[hashable] or callable, optional .. py:property:: sites The ordered tuple of all sites in the Hilbert space. .. py:property:: sector The sector of the Hilbert space. .. py:method:: get_sector_numba(sector=None, symmetry=None) The sector of the Hilbert space, in 'numba form'. A non-default symmetry and sector can be provided. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :returns: * **sector** (*ndarray[int64]*) -- The sector of the Hilbert space, in 'numba form'. This is a 1D array of length 1, 2 or 4, depending on the symmetry. * **symmetry** (*str*) -- The symmetry of the Hilbert space. This is one of "None", "Z2", "U1", or "U1U1". .. py:property:: symmetry The symmetry of the Hilbert space. .. py:property:: nsites The total number of sites in the Hilbert space. .. py:method:: get_sizes() Get a numpy array of the ordered sizes of each site in the Hilbert space. .. py:property:: sizes Get a numpy array of the ordered sizes of each site in the Hilbert space. .. py:method:: get_strides() Get the strides for each site in the Hilbert space. .. py:property:: strides Get the strides for each site in the Hilbert space. .. py:method:: get_pascal_table() Get a sufficiently large pascal table for this Hilbert space. .. py:method:: get_size(sector=None, symmetry=None) Get the size of the Hilbert space, optionally given a non-default symmetry and sector. :param sector: The sector of the Hilbert space. If None, the default sector is used. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space. If None, the default symmetry is used, or inferred from the supplied sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional .. py:property:: size Get the size of this Hilbert space, taking into account the default symmetry and sector. .. py:method:: site_size(site) Get the local dimension of a given site. .. py:method:: site_to_reg(site) Convert a site to a linear register index. .. py:method:: reg_to_site(reg) Convert a linear register index back to a site. .. py:method:: has_site(site) Check if this HilbertSpace contains a given site. .. py:method:: rank_to_flatconfig(rank) Convert a rank (linear index) into a flat configuration. :param rank: The rank (linear index) to convert. :type rank: int :returns: **flatconfig** -- A flat configuration, with the occupation number or spin state of each site in the order given by this ``HilbertSpace``. :rtype: ndarray[uint8] .. py:method:: flatconfig_to_rank(flatconfig) Convert a flat configuration into a rank (linear index). :param flatconfig: A flat configuration, with the occupation number or spin state of each site in the order given by this ``HilbertSpace``. :type flatconfig: ndarray[uint8] :returns: **rank** -- The rank (linear index) of the flat configuration in the Hilbert space. :rtype: int .. py:method:: config_to_flatconfig(config) Turn a configuration into a flat configuration, assuming the order given by this ``HilbertSpace``. :param config: A dictionary mapping sites to their occupation number / spin. :type config: dict[hashable, int] :returns: **flatconfig** -- A flat configuration, with the occupation number or spin state of each site in the order given by this ``HilbertSpace``. :rtype: ndarray[uint8] .. py:method:: flatconfig_to_config(flatconfig) Turn a flat configuration into a configuration, assuming the order given by this ``HilbertSpace``. :param flatconfig: A flat configuration, with the occupation number or spin state of each site in the order given by this ``HilbertSpace``. :type flatconfig: ndarray[uint8] :returns: **config** -- A dictionary mapping sites to their occupation number / spin state. :rtype: dict[hashable, int] .. py:method:: rank_to_config(rank) Convert a rank (linear index) into a configuration. :param rank: The rank (linear index) to convert. :type rank: int :returns: **config** -- A dictionary mapping sites to their occupation number / spin state. :rtype: dict[hashable, int] .. py:method:: config_to_rank(config) Convert a configuration into a rank (linear index). :param config: A dictionary mapping sites to their occupation number / spin state. :type config: dict[hashable, int] :returns: **rank** -- The rank (linear index) of the configuration in the Hilbert space. :rtype: int .. py:method:: rand_rank(seed=None) Get a random rank (linear index) in the Hilbert space. :param seed: The random seed or generator to use. If None, a new generator will be created with default settings. :type seed: None, int or numpy.random.Generator, optional :returns: **rank** -- A random rank in the Hilbert space. :rtype: int64 .. py:method:: rand_flatconfig(seed=None) Get a random flat configuration. :param seed: The random seed or generator to use. If None, a new generator will be created with default settings. :type seed: None, int or numpy.random.Generator, optional :returns: **flatconfig** -- A flat configuration, with the occupation number or spin state of each site in the order given by this ``HilbertSpace``. :rtype: ndarray[uint8] .. py:method:: rand_config(seed=None) Get a random configuration. :param seed: The random seed or generator to use. If None, a new generator will be created with default settings. :type seed: None, int or numpy.random.Generator, optional :returns: **config** -- A dictionary mapping sites to their occupation number / spin state. :rtype: dict[hashable, np.uint8] .. py:method:: __repr__() .. py:function:: fermi_hubbard_from_edges(edges, t=1.0, U=1.0, mu=0.0, order=None, sector=None, symmetry=None, hilbert_space=None, dtype=None, pauli_decompose=False) Create a Fermi-Hubbard Hamiltonian on the graph defined by ``edges``. The Hamiltonian is given by: .. math:: H = -t \sum_{\{i,j\}}^{|E|} \sum_{\sigma \in \uparrow, \downarrow} \left( c_{\sigma,i}^\dagger c_{\sigma,j} + c_{\sigma,j}^\dagger c_{\sigma,i} \right) + U \sum_{i}^{|V|} n_{\uparrow,i} n_{\downarrow,i} - \mu \sum_{i}^{|V|} \left( n_{\uparrow,i} + n_{\downarrow,i} \right) where :math:`\{i,j\}` are the edges of the graph, and :math:`c_{\sigma,i}` is the fermionic annihilation operator acting on site :math:`i` with spin :math:`\sigma`. The Jordan-Wigner transformation is used to implement fermionic statistics. :param edges: The edges, as pairs of hashable 'sites', that define the graph. Multiple edges are allowed, but will be treated as a single edge. :type edges: Iterable[tuple[hashable, hashable]] :param t: The hopping amplitude. Default is 1.0. If a tuple it specifies the up and down spin hoppings respectively. A dict or callable can be supplied to have edge-dependent hoppings. :type t: float or tuple[float, float] or dict or callable, optional :param U: The on-site interaction strength. Default is 1.0. A dict or callable can be supplied to have site-dependent interactions. :type U: float or dict or callable, optional :param mu: The chemical potential. Default is 0.0. If a tuple it specifies the up and down spin chemical potentials respectively. A dict or callable can be supplied to have site-dependent chemical potentials. :type mu: float or tuple[float, float] or dict or callable, optional :param order: If provided, use this to order the sites. If a callable, it should be a sorting key. If a sequence, it should be a permutation of the sites, and ``key=order.index`` will be used. :type order: callable or sequence of hashable objects, optional :param sector: The sector of the Hilbert space. If None, no sector is assumed. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space if any. If `None` and a `sector` is provided, the symmetry will be inferred from the sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param hilbert_space: The Hilbert space to use. If not given, one will be constructed automatically from the edges. This overrides the ``order``, ``symmetry``, and ``sector`` parameters. :type hilbert_space: HilbertSpace, optional :param dtype: The data type of the Hamiltonian. If None, a default dtype will be used, np.float64 for real and np.complex128 for complex. :type dtype: {None, str, type}, optional :param pauli_decompose: Whether to decompose the Hamiltonian into Pauli strings after Jordan-Wigner transforming. Default is False. :type pauli_decompose: bool, optional :returns: **H** -- The Hamiltonian as a SparseOperatorBuilder object. :rtype: SparseOperatorBuilder .. py:function:: fermi_hubbard_spinless_from_edges(edges, t=1.0, V=0.0, mu=0.0, delta=0.0, order=None, sector=None, symmetry=None, hilbert_space=None, dtype=None, pauli_decompose=False) Create a spinless Fermi-Hubbard Hamiltonian on the graph defined by ``edges``. The Hamiltonian is given by: .. math:: H = -t \sum_{\{i,j\}}^{|E|} \left( c_i^\dagger c_j + c_j^\dagger c_i \right) + V \sum_{\{i,j\}}^{|E|} n_i n_j - \mu \sum_{i}^{|V|} n_i + \Delta \sum_{\{i,j\}}^{|E|} \left( c_i^\dagger c_j^\dagger + c_j c_i \right) where :math:`\{i,j\}` are the edges of the graph, and :math:`c_i` is the fermionic annihilation operator acting on site :math:`i`. The Jordan-Wigner transformation is used to implement fermionic statistics. :param edges: The edges, as pairs of hashable 'sites', that define the graph. Multiple edges are allowed, but will be treated as a single edge. :type edges: Iterable[tuple[hashable, hashable]] :param t: The hopping amplitude. Default is 1.0. A dict or callable can be supplied to have edge-dependent hoppings. :type t: float or dict or callable, optional :param V: The nearest neighbor interaction strength. Default is 0.0. A dict or callable can be supplied to have edge-dependent interactions. :type V: float or dict or callable, optional :param mu: The chemical potential. Default is 0.0. A dict or callable can be supplied to have site-dependent chemical potentials. :type mu: float or dict or callable, optional :param delta: The superconducting pairing strength. Default is 0.0. A dict or callable can be supplied to have edge-dependent pairings. :type delta: float or dict or callable, optional :param order: If provided, use this to order the sites. If a callable, it should be a sorting key. If a sequence, it should be a permutation of the sites, and ``key=order.index`` will be used. :type order: callable or sequence of hashable objects, optional :param sector: The sector of the Hilbert space. If None, no sector is assumed. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space if any. If `None` and a `sector` is provided, the symmetry will be inferred from the sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param hilbert_space: The Hilbert space to use. If not given, one will be constructed automatically from the edges. This overrides the ``order``, ``symmetry``, and ``sector`` parameters. :type hilbert_space: HilbertSpace, optional :param dtype: The data type of the Hamiltonian. If None, a default dtype will be used, np.float64 for real and np.complex128 for complex. :type dtype: {None, str, type}, optional :param pauli_decompose: Whether to decompose the Hamiltonian into Pauli strings after Jordan-Wigner transforming. Default is False. :type pauli_decompose: bool, optional :returns: **H** -- The Hamiltonian as a SparseOperatorBuilder object. :rtype: SparseOperatorBuilder .. py:function:: heisenberg_from_edges(edges, j=1.0, b=0.0, order=None, sector=None, symmetry=None, hilbert_space=None, dtype=None) Create a Heisenberg Hamiltonian on the graph defined by ``edges``. .. math:: H = \sum_{\{i,j\}}^{|E|} \left( J_x S^x_i S^x_j + J_y S^y_i S^y_j + J_z S^z_i S^z_j \right) - \sum_{i}^{|V|} \left( B_x S^x_i + B_y S^y_i + B_z S^z_i \right) where :math:`\{i,j\}` are the edges of the graph, and :math:`S^x_i` is the spin-1/2 operator acting on site :math:`i` in the x-direction, etc. Note positive values of :math:`J` correspond to antiferromagnetic coupling here, and the magnetic field is in the z-direction by default. :param edges: The edges, as pairs of hashable 'sites', that define the graph. Multiple edges are allowed, and will be treated as a single edge. :type edges: Iterable[tuple[hashable, hashable]] :param j: The Heisenberg exchange coupling constant(s). If a single float is given, it is used for all three terms. If a tuple of three floats is given, they are used for the xx, yy, and zz terms respectively. Note that positive values of ``j`` correspond to antiferromagnetic coupling. A dict or callable can be supplied to have edge-dependent couplings. :type j: float or tuple[float, float, float] or dict or callable, optional :param b: The magnetic field strength(s). If a single float is given, it is used taken as a z-field. If a tuple of three floats is given, they are used for the x, y, and z fields respectively. A dict or callable can be supplied to have site-dependent fields. :type b: float or tuple[float, float, float] or dict or callable, optional :param order: If provided, use this to order the sites. If a callable, it should be a sorting key. If a sequence, it should be a permutation of the sites, and ``key=order.index`` will be used. :type order: callable or sequence of hashable objects, optional :param sector: The sector of the Hilbert space. If None, no sector is assumed. :type sector: {None, str, int, ((int, int), (int, int))}, optional :param symmetry: The symmetry of the Hilbert space if any. If `None` and a `sector` is provided, the symmetry will be inferred from the sector if possible. :type symmetry: {None, "Z2", "U1", "U1U1"}, optional :param hilbert_space: The Hilbert space to use. If not given, one will be constructed automatically from the edges. This overrides the ``order``, ``symmetry``, and ``sector`` parameters. :type hilbert_space: HilbertSpace, optional :param dtype: The data type of the Hamiltonian. If None, a default dtype will be used, np.float64 for real and np.complex128 for complex. :type dtype: {None, str, type}, optional :returns: **H** -- The Hamiltonian as a SparseOperatorBuilder object. :rtype: SparseOperatorBuilder .. py:function:: rand_operator(n, m, k, kmin=None, seed=None, ops='XYZ') Generate a random operator with n qubits and m terms. Each term is a sum of k operators acting on different qubits. The operators are chosen randomly from the set {X, Y, Z, +, -, n}. The coefficients are drawn from a normal distribution. :param n: The number of qubits. :type n: int :param m: The number of terms in the operator. :type m: int :param k: The number of operators in each term. :type k: int :param kmin: The minimum number of operators in each term. If not given, kmin = k. :type kmin: int, optional :param seed: The random seed for reproducibility. :type seed: int, optional :param ops: The set of operators to choose from. :type ops: str, optional :returns: The random operator as a SparseOperatorBuilder object. :rtype: SparseOperatorBuilder