quimb.tensor.tensor_builder =========================== .. py:module:: quimb.tensor.tensor_builder .. autoapi-nested-parse:: Build specific tensor networks, including states and operators. Attributes ---------- .. autoapisummary:: quimb.tensor.tensor_builder.TN_rand_from_edges quimb.tensor.tensor_builder.SpinHam quimb.tensor.tensor_builder.NNI_ham_ising quimb.tensor.tensor_builder.NNI_ham_XY quimb.tensor.tensor_builder.NNI_ham_heis quimb.tensor.tensor_builder.NNI_ham_XXZ quimb.tensor.tensor_builder.NNI_ham_bilinear_biquadratic quimb.tensor.tensor_builder.NNI_ham_mbl Classes ------- .. autoapisummary:: quimb.tensor.tensor_builder._TermAdder quimb.tensor.tensor_builder.SpinHam1D Functions --------- .. autoapisummary:: quimb.tensor.tensor_builder.delta_array quimb.tensor.tensor_builder.rand_tensor quimb.tensor.tensor_builder.rand_phased quimb.tensor.tensor_builder.rand_symmetric_array quimb.tensor.tensor_builder.rand_tensor_symmetric quimb.tensor.tensor_builder.TN_from_sites_product_state quimb.tensor.tensor_builder.TN_from_sites_computational_state quimb.tensor.tensor_builder.gen_unique_edges quimb.tensor.tensor_builder.compute_string_edge_frequencies quimb.tensor.tensor_builder.TN_from_edges_and_fill_fn quimb.tensor.tensor_builder.TN_from_edges_empty quimb.tensor.tensor_builder.TN_from_edges_with_value quimb.tensor.tensor_builder.TN_from_edges_rand quimb.tensor.tensor_builder.TN_rand_reg quimb.tensor.tensor_builder.TN_rand_tree quimb.tensor.tensor_builder.TN_from_strings quimb.tensor.tensor_builder.HTN_rand quimb.tensor.tensor_builder.HTN_CP_from_inds_and_fill_fn quimb.tensor.tensor_builder.HTN_CP_from_sites_and_fill_fn quimb.tensor.tensor_builder.HTN_CP_operator_from_products quimb.tensor.tensor_builder.HTN_dual_from_edges_and_fill_fn quimb.tensor.tensor_builder.convert_to_2d quimb.tensor.tensor_builder.TN2D_from_fill_fn quimb.tensor.tensor_builder.TN2D_empty quimb.tensor.tensor_builder.TN2D_with_value quimb.tensor.tensor_builder.TN2D_rand quimb.tensor.tensor_builder.TN2D_rand_symmetric quimb.tensor.tensor_builder.TN2D_corner_double_line quimb.tensor.tensor_builder.TN2D_rand_hidden_loop quimb.tensor.tensor_builder.convert_to_3d quimb.tensor.tensor_builder.TN3D_from_fill_fn quimb.tensor.tensor_builder.TN3D_empty quimb.tensor.tensor_builder.TN3D_with_value quimb.tensor.tensor_builder.TN3D_rand quimb.tensor.tensor_builder.TN3D_corner_double_line quimb.tensor.tensor_builder.TN3D_rand_hidden_loop quimb.tensor.tensor_builder.classical_ising_S_matrix quimb.tensor.tensor_builder.classical_ising_H_matrix quimb.tensor.tensor_builder.classical_ising_sqrtS_matrix quimb.tensor.tensor_builder.classical_ising_T_matrix quimb.tensor.tensor_builder.parse_j_coupling_to_function quimb.tensor.tensor_builder.HTN2D_classical_ising_partition_function quimb.tensor.tensor_builder.HTN3D_classical_ising_partition_function quimb.tensor.tensor_builder.TN2D_classical_ising_partition_function quimb.tensor.tensor_builder.TN3D_classical_ising_partition_function quimb.tensor.tensor_builder.HTN_classical_partition_function_from_edges quimb.tensor.tensor_builder.TN_classical_partition_function_from_edges quimb.tensor.tensor_builder.make_couplings_matrix_symmetric quimb.tensor.tensor_builder.TN2D_embedded_classical_ising_partition_function quimb.tensor.tensor_builder.dimer_data quimb.tensor.tensor_builder.TN_dimer_covering_from_edges quimb.tensor.tensor_builder.clause_negmask quimb.tensor.tensor_builder.or_clause_data quimb.tensor.tensor_builder.or_clause_tensor quimb.tensor.tensor_builder.or_clause_mps_tensors quimb.tensor.tensor_builder.or_clause_parafac_data quimb.tensor.tensor_builder.clause_parafac_tensors quimb.tensor.tensor_builder.HTN_from_clauses quimb.tensor.tensor_builder.cnf_file_parse quimb.tensor.tensor_builder.HTN_from_cnf quimb.tensor.tensor_builder.random_ksat_instance quimb.tensor.tensor_builder.HTN_random_ksat quimb.tensor.tensor_builder.TN_matching quimb.tensor.tensor_builder.MPS_rand_state quimb.tensor.tensor_builder.MPS_product_state quimb.tensor.tensor_builder.MPS_computational_state quimb.tensor.tensor_builder.MPS_neel_state quimb.tensor.tensor_builder.MPS_COPY quimb.tensor.tensor_builder.MPS_ghz_state quimb.tensor.tensor_builder.MPS_w_state quimb.tensor.tensor_builder.MPS_rand_computational_state quimb.tensor.tensor_builder.MPS_zero_state quimb.tensor.tensor_builder.MPS_sampler quimb.tensor.tensor_builder.MPO_identity quimb.tensor.tensor_builder.MPO_identity_like quimb.tensor.tensor_builder.MPO_zeros quimb.tensor.tensor_builder.MPO_zeros_like quimb.tensor.tensor_builder.MPO_product_operator quimb.tensor.tensor_builder.MPO_rand quimb.tensor.tensor_builder.MPO_rand_herm quimb.tensor.tensor_builder.maybe_make_real quimb.tensor.tensor_builder.spin_ham_mpo_tensor quimb.tensor.tensor_builder._ham_ising quimb.tensor.tensor_builder.MPO_ham_ising quimb.tensor.tensor_builder.ham_1d_ising quimb.tensor.tensor_builder._ham_XY quimb.tensor.tensor_builder.MPO_ham_XY quimb.tensor.tensor_builder.ham_1d_XY quimb.tensor.tensor_builder._ham_heis quimb.tensor.tensor_builder.MPO_ham_heis quimb.tensor.tensor_builder.ham_1d_heis quimb.tensor.tensor_builder.MPO_ham_XXZ quimb.tensor.tensor_builder.ham_1d_XXZ quimb.tensor.tensor_builder._ham_bilinear_biquadratic quimb.tensor.tensor_builder.MPO_ham_bilinear_biquadratic quimb.tensor.tensor_builder.ham_1d_bilinear_biquadratic quimb.tensor.tensor_builder._ham_mbl quimb.tensor.tensor_builder.MPO_ham_mbl quimb.tensor.tensor_builder.ham_1d_mbl quimb.tensor.tensor_builder.ham_2d_ising quimb.tensor.tensor_builder.ham_2d_heis quimb.tensor.tensor_builder.ham_2d_j1j2 quimb.tensor.tensor_builder.ham_3d_heis Module Contents --------------- .. py:function:: delta_array(shape, dtype='float64') Get the delta symbol AKA COPY-tensor as an ndarray. :param shape: The shape of the array, not all dimensions have to match. :type shape: tuple[int] :param dtype: The data type of the array. :type dtype: str, optional :rtype: numpy.ndarray .. py:function:: rand_tensor(shape, inds, tags=None, dtype='float64', dist='normal', scale=1.0, loc=0.0, left_inds=None, **randn_opts) Generate a random tensor with specified shape and inds. :param shape: Size of each dimension. :type shape: sequence of int :param inds: Names of each dimension. :type inds: sequence of str :param tags: Labels to tag this tensor with. :type tags: sequence of str :param dtype: The underlying data type. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param left_inds: Which, if any, indices to group as 'left' indices of an effective matrix. This can be useful, for example, when automatically applying unitary constraints to impose a certain flow on a tensor network but at the atomistic (Tensor) level. :type left_inds: sequence of str, optional :rtype: Tensor .. py:function:: rand_phased(shape, inds, tags=None, dtype=complex) Generate a random tensor with specified shape and inds, and randomly 'phased' (distributed on the unit circle) data, such that ``T.H @ T == T.norm()**2 == T.size``. :param shape: Size of each dimension. :type shape: sequence of int :param inds: Names of each dimension. :type inds: sequence of str :param tags: Labels to tag this tensor with. :type tags: sequence of str :param dtype: The underlying data type - can only be complex. :type dtype: {'complex128', 'complex64'}, optional :rtype: Tensor .. py:function:: rand_symmetric_array(d, ndim, dist='normal', loc=0.0, scale=1.0, seed=None, dtype='float64', fill_fn=None) Get a random symmetric array, i.e. one that is invariant under permutation of its indices. It has `(ndim + d - 1) choose (d - 1)` unique elements. :param d: The size of each dimension. :type d: int :param ndim: The number of dimensions. :type ndim: int :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param seed: A random seed. :type seed: int, optional :param dtype: The underlying data type. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :param fill_fn: A function that takes a shape (here always `()`) and returns an array, rather that using the random number generator. :type fill_fn: callable, optional :rtype: numpy.ndarray .. py:function:: rand_tensor_symmetric(d, inds, tags=None, dist='normal', loc=0.0, scale=1.0, seed=None) Generate a random symmetric tensor with specified local dimension and inds. :param d: Size of each dimension. :type d: int :param inds: Names of each dimension. :type inds: sequence of str :param tags: Labels to tag this tensor with. :type tags: sequence of str :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param seed: A random seed. :type seed: int, optional :rtype: Tensor .. py:function:: TN_from_sites_product_state(site_map, site_tag_id='I{}', site_ind_id='k{}') A product state in general tensor network form. :param site_map: Mapping of site to local state. :type site_map: dict[hashable, array_like] :param site_tag_id: Format string for site tag labels. :type site_tag_id: str, optional :param site_ind_id: Format string for site index labels. :type site_ind_id: str, optional :rtype: TensorNetworkGenVector .. py:function:: TN_from_sites_computational_state(site_map, site_tag_id='I{}', site_ind_id='k{}', dtype='float64') A computational basis state in general tensor network form. :param site_map: Mapping of site to computational state, which should be one of ``('0', '1', '+', '-')``. :type site_map: dict[hashable, str] :param site_tag_id: Format string for site tag labels. :type site_tag_id: str, optional :param site_ind_id: Format string for site index labels. :type site_ind_id: str, optional :param dtype: The data type to use for the array representation. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :rtype: TensorNetworkGenVector .. py:function:: gen_unique_edges(edges) .. py:function:: compute_string_edge_frequencies(strings) Compute a dictionary of edge frequencies for a list of strings, including plaquettes. .. py:function:: TN_from_edges_and_fill_fn(fill_fn, edges, D, phys_dim=None, site_tag_id='I{}', site_ind_id='k{}') Create a tensor network from a sequence of edges defining a graph, and a 'fill' function that maps shapes to data. :param fill_fn: A function with signature ``fill_fn(shape) -> array``, used to fill each tensor. :type fill_fn: callable :param edges: The graph edges, as a sequence of pairs of hashable objects, for example integers, representing the nodes. You can redundantly specify ``(u, v)`` and ``(v, u)`` and only one edge will be added. :type edges: sequence of tuple[hashable, hashable] :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size at each node. :type phys_dim: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). If a single str is supplied, the tensor network will have a single index at each site, representing a vector. If a pair of strings is supplied, the tensor network will have two indices at each site, representing an operator with upper and lower indices. :type site_ind_id: str or (str, str), optional :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:function:: TN_from_edges_empty(edges, D, phys_dim=None, site_tag_id='I{}', site_ind_id='k{}', dtype='float64') Create a tensor network from a sequence of edges defining a graph, initialized with empty tensors. :param edges: The graph edges, as a sequence of pairs of hashable objects, for example integers, representing the nodes. You can redundantly specify ``(u, v)`` and ``(v, u)`` and only one edge will be added. :type edges: sequence of tuple[hashable, hashable] :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size at each node. :type phys_dim: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :param dtype: The data type of the tensors. :type dtype: str, optional :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:function:: TN_from_edges_with_value(value, edges, D, phys_dim=None, site_tag_id='I{}', site_ind_id='k{}', dtype=None) Create a tensor network from a sequence of edges defining a graph, initialized with a constant value. This uses ``numpy.broadcast_to`` and therefore essentially no memory. :param value: The value to fill the tensors with. :type value: scalar :param edges: The graph edges, as a sequence of pairs of hashable objects, for example integers, representing the nodes. You can redundantly specify ``(u, v)`` and ``(v, u)`` and only one edge will be added. :type edges: sequence of tuple[hashable, hashable] :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size at each node. :type phys_dim: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :param dtype: The data type of the tensors. :type dtype: str, optional :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:function:: TN_from_edges_rand(edges, D, phys_dim=None, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', **randn_opts) Create a random tensor network with geometry defined from a sequence of edges defining a graph. :param G: The edges defining a graph, each element should be a pair of nodes described by hashable objects. :type G: sequence of tuple[node, node] :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size to mimic a wavefunction of ``len(G)`` sites. :type phys_dim: int, optional :param seed: A random seed. :type seed: int, optional :param dtype: The data type of the tensors. :type dtype: str, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :param randn_opts: Supplied to :func:`~quimb.gen.rand.randn`. :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:data:: TN_rand_from_edges .. py:function:: TN_rand_reg(n, reg, D, phys_dim=None, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', **randn_opts) Create a random regular tensor network. :param n: The number of tensors. :type n: int :param reg: The degree of the tensor network (how many tensors each tensor connects to). :type reg: int :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size to mimic a wavefunction of ``n`` sites. :type phys_dim: int, optional :param seed: A random seed. :type seed: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:function:: TN_rand_tree(n, D, phys_dim=None, max_degree=None, seed=None, dtype='float64', site_tag_id='I{}', site_ind_id='k{}', **randn_opts) Create a random tree tensor network. :param n: The number of tensors. :type n: int :param D: The bond dimension connecting tensors. :type D: int :param phys_dim: If not ``None``, give each tensor a 'physical', free index of this size to mimic a wavefunction of ``n`` sites. :type phys_dim: int, optional :param max_degree: The maximum degree of any node in the tree, for example 3 means that each tensor can connect to at most 3 other tensors - creating a binary tree (1 parent and two children). :type max_degree: int, optional :param seed: A random seed. :type seed: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :rtype: TensorNetworkGen, TensorNetworkGenVector or TensorNetworkGenOperator .. py:function:: TN_from_strings(strings, fill_fn=None, line_dim=2, allow_plaquettes=True, site_tag_id='I{}', random_rewire=False, random_rewire_seed=None, join=False, join_avoid_self_loops=True, normalize=False, contract_sites=True, fuse_multibonds=True, **contract_opts) .. py:function:: HTN_rand(n, reg, n_out=0, n_hyper_in=0, n_hyper_out=0, d_min=2, d_max=3, seed=None, dtype='float64', dist='normal', scale=1.0, loc=0.0, site_ind_id='k{}') Create a random, possibly hyper, tensor network, with a mix of normal and hyper inner and outer indices. Useful for testing edges cases. :param n: The number of tensors. :type n: int :param reg: The average degree (number of dimensions per tensor) of the tensor network (prior to placing extra indices). :type reg: int :param n_out: The number of normal outer indices to add (i.e. appear exactly once). :type n_out: int, optional :param n_hyper_in: The number of hyper inner indices to add (i.e. appear on three or more tensors). :type n_hyper_in: int, optional :param n_hyper_out: The number of hyper outer indices to add (i.e. appear in output and two or more tensors). :type n_hyper_out: int, optional :param d_min: The minimum size of any dimension. :type d_min: int, optional :param d_max: The maximum size of any dimension. :type d_max: int, optional :param seed: A random seed. :type seed: int, optional :rtype: TensorNetwork .. py:function:: HTN_CP_from_inds_and_fill_fn(fill_fn, inds, sizes, D, tags=None, bond_ind=None) reate a CP-decomposition structured hyper tensor network from a sequence of indices and a fill function. :param fill_fn: A function that takes a shape and returns an array. :type fill_fn: callable :param inds: The outer indices of the network. :type inds: sequence of str :param sizes: The outer sizes of the network. :type sizes: sequence of int :param D: The bond dimension of the inner hyper index. :type D: int :param tags: A tag for each tensor if supplied. :type tags: sequence of str, optional :param bond_ind: If given, a specific name for the inner hyper index. :type bond_ind: str, optional .. py:function:: HTN_CP_from_sites_and_fill_fn(fill_fn, sites, D, phys_dim=2, site_tag_id='I{}', site_ind_id='k{}', bond_ind=None) Create a CP-decomposition structured hyper tensor network state from a sequence of sites and a fill function. :param fill_fn: A function that takes a shape and returns an array. :type fill_fn: callable :param sites: The sites of the tensor network. :type sites: sequence of hashable :param D: The hyper bond dimension connecting tensors. :type D: int :param phys_dim: The size of the outer, physical indices. :type phys_dim: int, optional :param site_tag_id: String with formatter to tag sites. :type site_tag_id: str, optional :param site_ind_id: String with formatter to tag indices (if ``phys_dim`` specified). :type site_ind_id: str, optional :rtype: TensorNetworkGenVector .. py:function:: HTN_CP_operator_from_products(array_seqs, upper_inds, lower_inds, tags_each=None, tags_all=None, bond_ind=None) Construct a CP form hyper tensor network of the sum of matrix strings: .. math:: \sum_i A_i B_i C_i \ldots using a single hyper index to enumerate each sequence of operators. :param array_seqs: The arrays to use in each product, each of which should be 2D. :type array_seqs: sequence[arrays_like] :param upper_inds: The upper indices to use for each array in each product. :type upper_inds: sequence[sequence[str]] :param lower_inds: The lower indices to use for each array in each product. :type lower_inds: sequence[sequence[str]] :param tags_each: The tags to use for each array in each product. :type tags_each: sequence[sequence[str]], optional :param tags_all: The tags to use for the whole hyper tensor network. :type tags_all: sequence[str], optional :param bond_ind: The name of the hyper index to use, by default randomly generated. :type bond_ind: str, optional :returns: **htn** :rtype: TensorNetwork .. py:function:: HTN_dual_from_edges_and_fill_fn(fill_fn, edges, D, phys_dim=None, site_tag_id='I{}', site_ind_id='k{}') Create a hyper tensor network with a tensor on each bond and a hyper index on each node. .. py:function:: convert_to_2d(tn, Lx=None, Ly=None, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', inplace=False) Convert ``tn`` to a :class:`~quimb.tensor.tensor_2d.TensorNetwork2D`, assuming that is has a generic geometry with sites labelled by (i, j) coordinates already. Useful for constructing 2D tensor networks from functions that only require a list of edges etc. .. py:function:: TN2D_from_fill_fn(fill_fn, Lx, Ly, D, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}') A scalar 2D lattice tensor network with tensors filled by a function. :param fill_fn: A function with signature ``fill_fn(shape) -> array``, used to fill each tensor. :type fill_fn: callable :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :rtype: TensorNetwork2D .. py:function:: TN2D_empty(Lx, Ly, D, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', dtype='float64') A scalar 2D lattice tensor network initialized with empty tensors. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param dtype: The data type of the tensors. :type dtype: str, optional :rtype: TensorNetwork2D .. py:function:: TN2D_with_value(value, Lx, Ly, D, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', dtype=None) A scalar 2D lattice tensor network with every element set to ``value``. This uses ``numpy.broadcast_to`` and therefore essentially no memory. :param value: The value to fill the tensors with. :type value: scalar :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param dtype: The data type of the tensors. :type dtype: str, optional :rtype: TensorNetwork2D .. py:function:: TN2D_rand(Lx, Ly, D, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', dist='normal', loc=0, scale=1, seed=None, dtype='float64') A random scalar 2D lattice tensor network. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param seed: A random seed. :type seed: int, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :rtype: TensorNetwork2D .. py:function:: TN2D_rand_symmetric(Lx, Ly, D, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', dist='normal', loc=0, scale=1, seed=None, dtype='float64') Create a random 2D lattice tensor network where every tensor is symmetric up to index permutations. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param seed: A random seed. :type seed: int, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :rtype: TensorNetwork2D .. py:function:: TN2D_corner_double_line(Lx, Ly, line_dim=2, tiling=2, fill_missing_edges=True, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', **kwargs) Build a 2D 'corner double line' (CDL) tensor network. Each plaquette contributes a matrix (by default the identity) at each corner, connected in a loop. The corners for each site are then grouped and optionally contracted. Such a tensor network has strong local correlations. See https://arxiv.org/abs/1412.0732. If the sites are not contracted, the resulting network is a product of loops that can be easily and exactly contracted. Note that if identity matrices are used, the contracted value of the tensor network is ``line_dim**num_plaquettes``. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param line_dim: The dimension of the matrices at each corner. If `contract` is True, then the resulting bonds with have dimension `line_dim**tiling`. :type line_dim: int, optional :param tiling: How to tile the plaquettes. If ``1``, the plaquettes are tiled in a checkerboard pattern resulting in a single line per edge. If ``2``, the plaquettes are tiled in a dense pattern resulting in two lines per edge. :type tiling: {1, 2}, optional :param fill_missing_edges: Whether to fill in the missing edges around the border with open strings, ensuring every bond exists and has the same dimension. :type fill_missing_edges: bool, optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param kwargs: Additional keyword arguments are passed to :func:`TN_from_strings`. :rtype: TensorNetwork2D .. seealso:: :obj:`TN_from_strings` .. py:function:: TN2D_rand_hidden_loop(Lx, Ly, *, cyclic=False, line_dim=2, line_density=2, seed=None, dist='normal', dtype='float64', loc=0.0, scale=1.0, gauge_random=True, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', **kwargs) .. py:function:: convert_to_3d(tn, Lx=None, Ly=None, Lz=None, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', inplace=False) Convert ``tn`` to a :class:`~quimb.tensor.tensor_3d.TensorNetwork3D`, assuming that is has a generic geometry with sites labelled by (i, j, k) coordinates already. Useful for constructing 3D tensor networks from functions that only require a list of edges etc. .. py:function:: TN3D_from_fill_fn(fill_fn, Lx, Ly, Lz, D, cyclic=False, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}') A scalar 3D lattice tensor network with tensors filled by a function. :param fill_fn: A function with signature ``fill_fn(shape) -> array``, used to fill each tensor. :type fill_fn: callable :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :rtype: TensorNetwork3D .. py:function:: TN3D_empty(Lx, Ly, Lz, D, cyclic=False, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', dtype='float64') A scalar 3D lattice tensor network initialized with empty tensors. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :param seed: Random seed. :type seed: int, optional :rtype: TensorNetwork3D .. py:function:: TN3D_with_value(value, Lx, Ly, Lz, D, cyclic=False, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', dtype=None) A scalar 2D lattice tensor network with every element set to ``value``. This uses ``numpy.broadcast_to`` and therefore essentially no memory. :param value: The value to fill the tensors with. :type value: scalar :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :param seed: Random seed. :type seed: int, optional :rtype: TensorNetwork3D .. py:function:: TN3D_rand(Lx, Ly, Lz, D, cyclic=False, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', dist='normal', loc=0.0, scale=1.0, seed=None, dtype='float64') A random scalar 3D lattice tensor network. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param D: The bond dimension connecting sites. :type D: int :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param dtype: Data type of the random arrays. :type dtype: dtype, optional :param seed: Random seed. :type seed: int, optional :rtype: TensorNetwork .. py:function:: TN3D_corner_double_line(Lx, Ly, Lz, line_dim=2, tiling=2, fill_missing_edges=True, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', **kwargs) .. py:function:: TN3D_rand_hidden_loop(Lx, Ly, Lz, *, cyclic=False, line_dim=2, line_density=2, seed=None, dist='normal', dtype='float64', loc=0.0, scale=1.0, gauge_random=True, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', **kwargs) .. py:function:: classical_ising_S_matrix(beta, j=1.0) The interaction term for the classical ising model. .. py:function:: classical_ising_H_matrix(beta, h=0.0) The magnetic field term for the classical ising model. .. py:function:: classical_ising_sqrtS_matrix(beta, j=1.0, asymm=None) The sqrt factorized interaction term for the classical ising model. If ``j`` is negative you can supply ``asymm='l'`` or ``'r'`` to keep the matrix real, but it must be paired with the opposite in a tensor network. .. py:function:: classical_ising_T_matrix(beta, j=1.0, h=0.0, directions='lrud', output=False, asymm=None) The single effective TN site for the classical ising model. .. py:function:: parse_j_coupling_to_function(j) Parse the ``j`` argument to a function that can be called to get the coupling strength between two nodes. The input can be a constant, dict or function. .. py:function:: HTN2D_classical_ising_partition_function(Lx, Ly, beta, h=0.0, j=1.0, cyclic=False, ind_id='s{},{}', site_tag_id='I{},{}') Hyper tensor network representation of the 2D classical ising model partition function. The indices will be shared by 4 or 5 tensors depending on whether ``h`` is non-zero. As opposed to the 'normal' tensor network, here each classical spin is still a single index, which is easier to contract exactly. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param beta: The inverse temperature. :type beta: float :param h: The magnetic field strength. :type h: float, optional :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param ind_id: How to label the indices i.e. ``ind_id.format(i, j)``, each of which corresponds to a single classical spin. :type ind_id: str, optional :param site_tag_id: How to label the site tags, note that in the hyper tensor network representation each tensor will have two site tags for the two sites it connects. :type site_tag_id: str, optional :rtype: TensorNetwork .. seealso:: :obj:`TN2D_classical_ising_partition_function` .. py:function:: HTN3D_classical_ising_partition_function(Lx, Ly, Lz, beta, j=1.0, h=0.0, cyclic=False, ind_id='s{},{},{}', site_tag_id='I{},{},{}') Hyper tensor network representation of the 3D classical ising model partition function. The indices will be shared by 6 or 7 tensors depending on whether ``h`` is non-zero. As opposed to the 'normal' tensor network, here each classical spin is still a single index, which is easier to contract exactly. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param beta: The inverse temperature. :type beta: float :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param h: The magnetic field strength. :type h: float, optional :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param ind_id: How to label the indices i.e. ``ind_id.format(i, j, k)``, each of which corresponds to a single classical spin. :type ind_id: str, optional :param site_tag_id: How to label the site tags, note that in the hyper tensor network representation each tensor will have two site tags for the two sites it connects. :type site_tag_id: str, optional :rtype: TensorNetwork .. seealso:: :obj:`TN3D_classical_ising_partition_function` .. py:function:: TN2D_classical_ising_partition_function(Lx, Ly, beta, j=1.0, h=0.0, cyclic=False, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', outputs=(), ind_id='s{},{}') The tensor network representation of the 2D classical ising model partition function. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param beta: The inverse temperature. :type beta: float :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param h: The magnetic field strength. :type h: float, optional :param cyclic: Whether to use periodic boundary conditions. X and Y can be specified separately using a tuple. :type cyclic: bool or (bool, bool), optional :param site_tag_id: String specifier for naming convention of site tags. :type site_tag_id: str, optional :param x_tag_id: String specifier for naming convention of row tags. :type x_tag_id: str, optional :param y_tag_id: String specifier for naming convention of column tags. :type y_tag_id: str, optional :param outputs: Which sites to generate output indices (i.e. dangling legs) for. The index is named according to ``ind_id``. :type outputs: sequence of tuple[int, int], optional :param ind_id: How to label the indices i.e. ``ind_id.format(i, j)``, each of which corresponds to a single classical spin in ``outputs``. :type ind_id: str, optional :rtype: TensorNetwork2D .. seealso:: :obj:`HTN2D_classical_ising_partition_function` .. py:function:: TN3D_classical_ising_partition_function(Lx, Ly, Lz, beta, j=1.0, h=0.0, cyclic=False, site_tag_id='I{},{},{}', x_tag_id='X{}', y_tag_id='Y{}', z_tag_id='Z{}', outputs=(), ind_id='s{},{},{}') Tensor network representation of the 3D classical ising model partition function. :param Lx: Length of side x. :type Lx: int :param Ly: Length of side y. :type Ly: int :param Lz: Length of side z. :type Lz: int :param beta: The inverse temperature. :type beta: float :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param h: The magnetic field strength. :type h: float, optional :param cyclic: Whether to use periodic boundary conditions. X, Y and Z can be specified separately using a tuple. :type cyclic: bool or (bool, bool, bool), optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param x_tag_id: String formatter specifying how to label each x-plane. :type x_tag_id: str, optional :param y_tag_id: String formatter specifying how to label each y-plane. :type y_tag_id: str, optional :param z_tag_id: String formatter specifying how to label each z-plane. :type z_tag_id: str, optional :param outputs: Which sites to generate output indices (i.e. dangling legs) for. The index is named according to ``ind_id``. :type outputs: sequence of tuple[int, int, int], optional :param ind_id: How to label the indices i.e. ``ind_id.format(i, j, k)``, each of which corresponds to a single classical spin in ``outputs``. :type ind_id: str, optional :rtype: TensorNetwork .. seealso:: :obj:`HTN3D_classical_ising_partition_function` .. py:function:: HTN_classical_partition_function_from_edges(edges, beta, j=1.0, h=0.0, site_ind_id='s{}', site_tag_id='I{}', bond_tag_id='B{},{}') Build a hyper tensor network representation of a classical ising model partition function by specifying graph edges. There will be a single tensor *per interaction* rather than per site, as well as a single tensor for each site, if ``h != 0.0``. :param edges: The graph edges, as a sequence of pairs of hashable objects, for example integers, representing the nodes. You can redundantly specify ``(u, v)`` and ``(v, u)`` and only one edge will be added. :type edges: sequence of tuple[hashable, hashable] :param beta: The inverse temperature. :type beta: float, optional :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param h: The magnetic field strength. If a callable should have the signature ``h(node)`` and return a float. :type h: float, or callable, optional :param site_ind_id: A string formatter for naming tensor indices like ``site_ind_id.format(node)``. :type site_ind_id: str, optional :param site_tag_id: A string formatter for naming tensor tags like ``site_tag_id.format(node)``. :type site_tag_id: str, optional :param bond_tag_id: A string formatter for naming tensor tags like ``bond_tag_id.format(node_a, node_b)``. :type bond_tag_id: str, optional :rtype: TensorNetwork .. py:function:: TN_classical_partition_function_from_edges(edges, beta, j=1.0, h=0.0, site_tag_id='I{}', bond_ind_id='b{},{}', outputs=(), ind_id='s{}') Build a regular tensor network representation of a classical ising model partition function by specifying graph edges. There will be a single tensor per site. :param edges: The graph edges, as a sequence of pairs of hashable objects, for example integers, representing the nodes. You can redundantly specify ``(u, v)`` and ``(v, u)`` and only one edge will be added. :type edges: sequence of tuple[hashable, hashable] :param beta: The inverse temperature. :type beta: float, optional :param j: The interaction strength, positive being *ferromagnetic*. If a dict should contain entries for each edge, keyed by the edge. If a callable should have the signature ``j(node_a, node_b)`` and return a float. :type j: float, dict, or callable, optional :param h: The magnetic field strength. If a callable should have the signature ``h(node)`` and return a float. :type h: float, or callable, optional :param site_tag_id: A string formatter for naming tensor tags like ``site_ind_id.format(node)``. :type site_tag_id: str, optional :param bond_ind_id: A string formatter for naming the indices bewteen tensors like ``bond_ind_id.format(node_a, node_b)``. :type bond_ind_id: str, optional :rtype: TensorNetwork .. py:function:: make_couplings_matrix_symmetric(J, UPLO='auto') Take a coupling matrix or dict of pairwise strengths in either upper or lower triangular form and return a symmetric matrix. :param J: The couplings, as a square matrix or explicit dict. If a matrix, the upper or lower triangle (corresponding to ``UPLO``) should the pairwise interaction strengths. If a dict, then each non-zero interaction can be specified explicitly. :type J: array_like or dict[(int, int), float] :param UPLO: Whether to read the couplings in from ``J`` in lower ('L': ``i >= j``) or upper ('U': ``i <= j``) form. If ``J`` is a dict then this only matters if both are present and in that case acts as a preference. If ``"auto"`` then either the lower or upper, or symmetric distances can be supplied, but an error is raised if both are. :type UPLO: {"auto", "L", "U"}, optional :returns: **J** -- The couplings as a symmetric matrix. :rtype: array_like .. py:function:: TN2D_embedded_classical_ising_partition_function(Jij, beta, outputs=(), ordering=None, sites_location='side', UPLO='auto', contract_sites=True, site_tag_id='I{},{}', x_tag_id='X{}', y_tag_id='Y{}', ind_id='s{}') Construct a (triangular) '2D' tensor network representation of the classical ising model partition function with all-to-all interactions, by embedding it in a 2D lattice. For `N` spins this will have `N(N-1)/2` tensors, present at sites `(i, j)` where `i > j`. If `outputs` is supplied, then dangling indices will be added for each output, to give a 'standard' TN representation of the unnormalized marginal distribution over those outputs. Since each spin is effectively "delocalized" into a COPY-tensor MPS spanning the lattice, there is a choice of where to put the outputs, specified by `sites_location`. ``sites_location="side"``:: ... . . . ╭── │ j=2 . . ╭──O──... │ │ j=1 . ╭──O──O──... │ │ │ j=0 ╭──O──O──O──... │ │ │ │ s0 s1 s2 s3 <- site indices i=0, 1, 2, 3, ... ``sites_location="diag"``:: ... . . s3 ╭── ╲│ j=2 . s2 ╭──O──... ╲│ │ j=1 s1 ╭──O──O──... ╲│ │ │ j=0 s0──O──O──O──... i=0, 1, 2, 3, ... :param Jij: The couplings, as a square matrix or explicit dict. If a matrix, the upper or lower triangle (corresponding to ``UPLO``) should the pairwise interaction strengths. If a dict, then each non-zero interaction can be specified explicitly. :type Jij: array_like or dict[(int, int), float] :param beta: The inverse temperature. :type beta: float :param outputs: Which sites to generate output indices (i.e. dangling legs) for. The index is named according to ``ind_id``. The location of the output depends on ``sites_location``. :type outputs: sequence of int, optional :param ordering: If supplied, the ordering of the embedded spins into the lattice. :type ordering: sequence of int, optional :param sites_location: Whether to place the output indices on the side or diagonally. If ``"side"`` then the output indices will be placed along the 'y-min' border, i.e. ``[(j, 0) for j in range(1, N)]``, with two on the first tensor. If ``"diag"`` then the output indices will be placed along the central diagonal fold of the lattice, i.e. ``[(j + 1, j) for j in range(1, N)]``, with two on the first tensor. :type sites_location: {"side", "diag"}, optional :param UPLO: Whether to read the couplings in from ``J`` in lower ('L': ``i >= j``) or upper ('U': ``i <= j``) form. If ``J`` is a dict then this only matters if both are present and in that case acts as a preference. If ``"auto"`` then either the lower or upper, or symmetric distances can be supplied, but an error is raised if both are. :type UPLO: {"auto", "L", "U"}, optional :param contract_sites: Whether to contract the sites of the TN, which after initial construction will have one horizontol spin-rail, one vertical spin-rail and one interaction tensor per site. :type contract_sites: bool, optional :param site_tag_id: String formatter specifying how to label each site. :type site_tag_id: str, optional :param x_tag_id: String formatter specifying how to label each x-plane. :type x_tag_id: str, optional :param y_tag_id: String formatter specifying how to label each y-plane. :type y_tag_id: str, optional :param ind_id: How to label the indices i.e. ``ind_id.format(i)``, each of which corresponds to a single classical spin in ``outputs``. :type ind_id: str, optional :rtype: TensorNetwork2D .. py:function:: dimer_data(d, cover_count=1, dtype=float) .. py:function:: TN_dimer_covering_from_edges(edges, cover_count=1, site_tag_id='I{}', bond_ind_id='b{},{}', dtype=float) Make a tensor network from sequence of graph edges that counts the number of ways to cover the graph exactly with dimers. See https://arxiv.org/abs/1805.10598 for the construction. :param edges: The edges, each item should be a pair of hashable objects describing nodes linked. :type edges: sequence of tuple :param cover_count: The exact number of times each node must be 'covered'. For example 1 for a standard dimer covering or 2 for 'ice rules'. :type cover_count: int, optional :param site_tag_id: A string formatter for naming tensor tags like ``site_ind_id.format(node)``. :type site_tag_id: str, optional :param bond_ind_id: A string formatter for naming the indices bewteen tensors like ``bond_ind_id.format(node_a, node_b)``. :type bond_ind_id: str, optional :rtype: TensorNetwork .. py:function:: clause_negmask(clause) Encode a clause as a single integer ``m``. .. py:function:: or_clause_data(ndim, m=0, dtype=float, q=2) Get the array representing satisfiability of ``ndim`` clauses with unsatisfied condition encoded in ``m``. .. py:function:: or_clause_tensor(ndim, m, inds, tags=None, dtype='float64') Get the tensor representing satisfiability of ``ndim`` clauses with unsatisfied condition encoded in ``m`` labelled by ``inds`` and ``tags``. .. py:function:: or_clause_mps_tensors(ndim, m, inds, tags=None, dtype='float64') Get the set of MPS tensors representing satisfiability of ``ndim`` clauses with unsatisfied condition encoded in ``m`` labelled by ``inds`` and ``tags``. .. py:function:: or_clause_parafac_data(ndim, m, dtype='float64') Get the set of PARAFAC arrays representing satisfiability of ``ndim`` clauses with unsatisfied condition encoded in ``m``. .. py:function:: clause_parafac_tensors(ndim, m, inds, tags=None, dtype='float64') Get the set of PARAFAC tensors representing satisfiability of ``ndim`` clauses with unsatisfied condition encoded in ``m`` labelled by ``inds`` and ``tags``. .. py:function:: HTN_from_clauses(clauses, weights=None, mode='parafac', dtype='float64', clause_tag_id='CLAUSE{}', var_ind_id='var{}', weight_tag_id='WEIGHT{}') Given a list of clauses, create a hyper tensor network, with a single hyper index for each variable, and single tensor or tensor decomposition for each clause. If weights are given, there will also be a single tensor for each non-trivially weighted variable. :param clauses: The clauses as a sequence of tuples of integers. Each integer represents a variable, and the sign indicates whether it is negated. The variables thus must be non-zero integers. :type clauses: sequence of tuple[int] :param weights: The weights for each variable. Each key should be a signed variable integer, such that relative weights for a variable ``v`` are ``(weights[-v], weights[v])``. If only one is given of this pair, the other is assumed to sum to 1. If a variable is not supplied, or ``weights=None``, then both weights are assumed to be 1 and no tensor is created for the variable. :type weights: dict[int, float], optional :param mode: How to represent the clauses: * 'parafac' - `N` rank-2 tensors connected by a single hyper index. You could further call :meth:`hyperinds_resolve` for more options to convert the hyper index into a (decomposed) COPY-tensor. * 'mps' - `N` rank-3 tensors connected along a 1D line. * 'dense' - contract the hyper index. * int - use the 'parafac' mode, but only if the length of a clause is larger than this threshold. Note that variables are always represented by a single (hyper) index, which is like an implicit PARAFAC decomposition. :type mode: {'parafac', 'mps', 'dense', int}, optional :param dtype: The data type of the tensors. :type dtype: str :param clause_tag_id: The tag to use for the clause tensors. The tag will be formatted with the clause index. :type clause_tag_id: str :param var_ind_id: The index to use for the variable tensors. The index will be formatted with the variable index. :type var_ind_id: str :param weight_tag_id: The tag to use for the weight tensors. The tag will be formatted with the variable index. :type weight_tag_id: str :returns: **htn** :rtype: TensorNetwork .. py:function:: cnf_file_parse(fname) Parse a DIMACS style 'cnf' file into a list of clauses, and possibly a dictionary of weights. The weights, if present, can be specified either as: - (CACHET format): a line per weight like ``w {signed_var} {weight}``, where ``signed_var`` is an integer whose sign specifies the sign of the weight being set. - (MC2021 competition format): the same as above, but with each line specified as ``c p weight {signed_var} {weight}``. - (MINIC2D format): a single line of the form ``c weights {wp_1} {wm_1} {wp_2} {wm_2}... ``, where ``wp_i`` and ``wn_i`` are the positive and negative weights for variable ``i``. Weights specified this way are overriden by the previous two formats. :param fname: Path to a '.cnf' or '.wcnf' file. :type fname: str :returns: **instance** :rtype: dict .. py:function:: HTN_from_cnf(fname, mode='parafac', dtype='float64', clause_tag_id='CLAUSE{}', var_ind_id='var{}', weight_tag_id='WEIGHT{}', **kwargs) Create a hyper tensor network from a '.cnf' or '.wcnf' file - i.e. a model counting or weighted model counting instance specification. :param fname: Path to a '.cnf' or '.wcnf' file. :type fname: str :param mode: How to represent the clauses: * 'parafac' - `N` rank-2 tensors connected by a single hyper index. You could further call :meth:`hyperinds_resolve` for more options to convert the hyper index into a (decomposed) COPY-tensor. * 'mps' - `N` rank-3 tensors connected along a 1D line. * 'dense' - contract the hyper index. * int - use the 'parafac' mode, but only if the length of a clause is larger than this threshold. :type mode: {'parafac', 'mps', 'dense', int}, optional :param dtype: Data type of the tensors. :type dtype: str or dtype, optional :param clause_tag_id: Format string for clause tags. :type clause_tag_id: str, optional :param var_ind_id: Format string for variable indices. :type var_ind_id: str, optional :param weight_tag_id: Format string for weight tags. :type weight_tag_id: str, optional :param kwargs: Additional keyword arguments passed to :func:`HTN_from_clauses`. :returns: **htn** :rtype: TensorNetwork .. py:function:: random_ksat_instance(k, num_variables, num_clauses=None, alpha=None, seed=None, allow_repeat_variables=False) Create a random k-SAT instance. :param k: Number of variables per clause. :type k: int :param num_variables: Number of variables in the instance. :type num_variables: int :param num_clauses: Number of clauses in the instance. If not specified, will be determined from `alpha`. :type num_clauses: int, optional :param alpha: If `num_clauses` is not directly specified then the average number of clauses *per variable*. Taken as a Poisson parameter. Either this or `num_clauses` must be specified. :type alpha: float, optional :param seed: Random seed. :type seed: int, optional :param allow_repeat_variables: Whether to allow the same variable to appear multiple times in a single clause. :type allow_repeat_variables: bool, optional :returns: **instance** -- Dictionary with keys 'num_variables', 'num_clauses', 'clauses'. The 'clauses' key contains a list of tuples, each tuple representing a clause. Within each tuple, each element is an integer representing a variable, with the sign of the integer representing the sign of the variable in the clause. :rtype: dict .. py:function:: HTN_random_ksat(k, num_variables, num_clauses=None, alpha=None, seed=None, allow_repeat_variables=False, mode='parafac', dtype='float64', clause_tag_id='CLAUSE{}', variable_ind_id='var{}') Create a random k-SAT instance encoded as a hyper tensor network. :param k: Number of variables per clause. :type k: int :param num_variables: Number of variables in the instance. :type num_variables: int :param num_clauses: Number of clauses in the instance. If not specified, will be determined from `alpha`. :type num_clauses: int, optional :param alpha: If `num_clauses` is not directly specified then the average number of clauses *per variable*. Taken as a Poisson parameter. Either this or `num_clauses` must be specified. :type alpha: float, optional :param seed: Random seed. :type seed: int, optional :param allow_repeat_variables: Whether to allow the same variable to appear multiple times in a single clause. :type allow_repeat_variables: bool, optional :param mode: How to represent the clauses: * 'parafac' - `N` rank-2 tensors connected by a single hyper index. You could further call :meth:`hyperinds_resolve` for more options to convert the hyper index into a (decomposed) COPY-tensor. * 'mps' - `N` rank-3 tensors connected along a 1D line. * 'dense' - contract the hyper index. * int - use the 'parafac' mode, but only if the length of a clause is larger than this threshold. Note that variables are always represented by a single (hyper) index, which is like an implicit PARAFAC decomposition. :type mode: {'parafac', 'mps', 'dense', int}, optional :param dtype: Data type of the tensors. :type dtype: str, optional :param clause_tag_id: Format string for clause tags. Should contain a single `{}` which will be replaced by the clause number. :type clause_tag_id: str, optional :param variable_ind_id: Format string for variable indices. Should contain a single `{}` which will be replaced by the variable number. :type variable_ind_id: str, optional :rtype: TensorNetwork .. py:function:: TN_matching(tn, max_bond, site_tags=None, fill_fn=None, dtype=None, **randn_opts) Create a tensor network with the same outer indices as ``tn`` but with a single tensor per site with bond dimension ``max_bond`` between each connected site. Generally to be used as an initial guess for fitting. :param tn: The tensor network to match, it can have arbitrary local structure and output indices, as long as ``site_tags`` effectively partitions it. :type tn: TensorNetwork :param max_bond: The bond dimension to use between each site. :type max_bond: int :param site_tags: The tags to use to select the tensors from ``tn``. If not given, uses ``tn.site_tags``. The tensor network built will have one tensor per site, in the order given by ``site_tags``. :type site_tags: sequence of str, optional :param dtype: The data type to use for the new tensors, if not given uses the same as the original tensors. :type dtype: dtype, optional :param randn_opts: Supplied to :func:`~quimb.gen.rand.randn`. :rtype: TensorNetwork .. py:function:: MPS_rand_state(L, bond_dim, phys_dim=2, normalize=True, cyclic=False, dist='normal', loc=0.0, scale=1.0, dtype='float64', trans_invar=False, **mps_opts) Generate a random matrix product state. :param L: The number of sites. :type L: int :param bond_dim: The bond dimension. :type bond_dim: int :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param normalize: Whether to normalize the state. :type normalize: bool, optional :param cyclic: Generate a MPS with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param trans_invar: Whether to generate a translationally invariant state, requires cyclic=True. :type trans_invar: bool (optional) :param mps_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState`. .. py:function:: MPS_product_state(arrays, cyclic=False, **mps_opts) Generate a product state in MatrixProductState form, i,e, with bond dimension 1, from single site vectors described by ``arrays``. .. py:function:: MPS_computational_state(binary, dtype='float64', cyclic=False, **mps_opts) A computational basis state in Matrix Product State form. :param binary: String specifying the state, e.g. ``'00101010111'`` or ``[0, 0, 1]``. :type binary: str or sequence of int :param dtype: The data type to use for the array representation. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :param cyclic: Generate a MPS with periodic boundary conditions or not, default open boundary conditions. :type cyclic: bool, optional :param mps_opts: Supplied to MatrixProductState constructor. .. py:function:: MPS_neel_state(L, down_first=False, dtype='float64', **mps_opts) Generate the neel state in Matrix Product State form. :param L: The number of spins. :type L: int :param down_first: Whether to start with '1' (down) or '0' (up) first. :type down_first: bool, optional :param mps_opts: Supplied to MatrixProductState constructor. .. py:function:: MPS_COPY(L, phys_dim=2, dtype='float64', **mps_opts) Build a matrix product state representation of the COPY tensor. :param L: The number of sites. :type L: int :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param dtype: The data type of the tensor network, defaults to 'float64'. :type dtype: str or dtype, optional :rtype: MatrixProductState .. py:function:: MPS_ghz_state(L, dtype='float64', **mps_opts) Build the chi=2 OBC MPS representation of the GHZ state. :param L: Number of qubits. :type L: int :param dtype: The underlying data type. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :param mps_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState`. .. py:function:: MPS_w_state(L, dtype='float64', **mps_opts) Build the chi=2 OBC MPS representation of the W state. :param L: Number of qubits. :type L: int :param dtype: The underlying data type. :type dtype: {'float64', 'complex128', 'float32', 'complex64'}, optional :param mps_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState`. .. py:function:: MPS_rand_computational_state(L, dtype='float64', **mps_opts) Generate a random computation basis state, like '01101001010'. :param L: The number of qubits. :type L: int :param seed: The seed to use. :type seed: int, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param mps_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState`. .. py:function:: MPS_zero_state(L, bond_dim=1, phys_dim=2, cyclic=False, dtype='float64', **mps_opts) The all-zeros MPS state, of given bond-dimension. :param L: The number of sites. :type L: int :param bond_dim: The bond dimension, defaults to 1. :type bond_dim: int, optional :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param cyclic: Generate a MPS with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param mps_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductState`. .. py:function:: MPS_sampler(L, dtype=complex, squeeze=True, **mps_opts) A product state for sampling tensor network traces. Seen as a vector it has the required property that ``psi.H @ psi == d`` always for hilbert space size ``d``. .. py:function:: MPO_identity(L, sites=None, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts) Generate an identity MPO of size ``L``. :param L: The number of sites. :type L: int :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. .. py:function:: MPO_identity_like(mpo, **mpo_opts) Return an identity matrix operator with the same physical index and inds/tags as ``mpo``. .. py:function:: MPO_zeros(L, phys_dim=2, dtype='float64', cyclic=False, **mpo_opts) Generate a zeros MPO of size ``L``. :param L: The number of sites. :type L: int :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: MPO_zeros_like(mpo, **mpo_opts) Return a zeros matrix product operator with the same physical index and inds/tags as ``mpo``. :param mpo: The MPO to copy the shape of. :type mpo: MatrixProductOperator :rtype: MatrixProductOperator .. py:function:: MPO_product_operator(arrays, cyclic=False, **mpo_opts) Return an MPO of bond dimension 1 representing the product of raw operators given in ``arrays``. :param arrays: The operators to form a tensor product of. :type arrays: sequence of 2D array_like :param cyclic: Whether to generate a cyclic MPO or not. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: MPO_rand(L, bond_dim, phys_dim=2, normalize=True, cyclic=False, herm=False, dtype='float64', dist='normal', loc=0.0, scale=1.0, **mpo_opts) Generate a random matrix product state. :param L: The number of sites. :type L: int :param bond_dim: The bond dimension. :type bond_dim: int :param phys_dim: The physical (site) dimensions, defaults to 2. :type phys_dim: int, optional :param normalize: Whether to normalize the operator such that ``trace(A.H @ A) == 1``. :type normalize: bool, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param dtype: Data type of the tensor network. :type dtype: {float, complex} or numpy dtype, optional :param dist: Type of random number to generate, defaults to 'normal'. :type dist: {'normal', 'uniform', 'rademacher', 'exp'}, optional :param loc: An additive offset to add to the random numbers. :type loc: float, optional :param scale: A multiplicative factor to scale the random numbers by. :type scale: float, optional :param herm: Whether to make the matrix hermitian (or symmetric if real) or not. :type herm: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. .. py:function:: MPO_rand_herm(L, bond_dim, phys_dim=2, normalize=True, dtype='float64', **mpo_opts) Generate a random hermitian matrix product operator. See :class:`~quimb.tensor.tensor_builder.MPO_rand`. .. py:function:: maybe_make_real(X) Check if ``X`` is real, if so, convert to contiguous array. .. py:function:: spin_ham_mpo_tensor(one_site_terms, two_site_terms, S=1 / 2, left_two_site_terms=None, which=None, cyclic=False) Generate tensor(s) for a spin hamiltonian MPO. :param one_site_terms: The terms that act on a single site, each ``operator`` can be a string suitable to be sent to :func:`spin_operator` or an actual 2d-array. :type one_site_terms: sequence of (scalar, operator) :param two_site_terms: The terms that act on two neighbouring sites, each ``operator`` can be a string suitable to be sent to :func:`spin_operator` or an actual 2d-array. :type two_site_terms: sequence of (scalar, operator operator) :param S: What size spin to use, defaults to spin-1/2. :type S: fraction, optional :param left_two_site_terms: If the interaction to the left of this site has different spin terms then the equivalent list of terms for that site. :type left_two_site_terms: sequence of (scalar, operator operator), optional :param which: If ``None``, generate the middle tensor, if 'L' a left-end tensor, if 'R' a right-end tensor and if 'A' all three. :type which: {None, 'L', 'R', 'A'}, optional :param cyclic: Whether to use periodic boundary conditions - default False. :type cyclic: bool, optional :returns: The middle, left, right or all three MPO tensors. :rtype: numpy.ndarray[, numpy.ndarray, numpy.ndarray] .. py:class:: _TermAdder(terms, nsite) Simple class to allow ``SpinHam1D`` syntax like ``builder[i, j] += (1/2, 'Z', 'X')``. This object is temporarily created by the getitem call, accumulates the new term, then has its the new combined list of terms extracted in the setitem call. .. py:attribute:: terms .. py:attribute:: nsite .. py:method:: __iadd__(new) .. py:class:: SpinHam1D(S=1 / 2, cyclic=False) Class for easily building custom spin hamiltonians in MPO or LocalHam1D form. Currently limited to nearest neighbour interactions (and single site terms). It is possible to set 'default' translationally invariant terms, but also terms acting on specific sites only (which take precedence). It is also possible to build a sparse matrix version of the hamiltonian (obviously for small sizes only). :param S: The type of spin, defaults to 1/2. :type S: float, optional :param cyclic: Whether to use periodic boundary conditions - default is False. :type cyclic: bool, optional .. rubric:: Examples Initialize the spin hamiltonian builder: >>> builder = SpinHam1D(S=3 / 2) Add some two-site terms: >>> builder += 0.5, '+', '-' >>> builder += 0.5, '-', '+' >>> builder += 1.0, 'Z', 'Z' Add a single site term: >>> builder -= 0.3, 'Z' Build a MPO version of the hamiltonian for use with DMRG: >>> mpo_ham = builder.build_mpo(100) >>> mpo_ham Build a LocalHam1D version of the hamiltonian for use with TEBD: >>> builder.build_local_ham(100) You can also set terms for specific sites (this overides any of the 'default', translationally invariant terms set as above): >>> builder[10, 11] += 0.75, '+', '-' >>> builder[10, 11] += 0.75, '-', '+' >>> builder[10, 11] += 1.5, 'Z', 'Z' Or specific one-site terms (which again overides any default single site terms set above): >>> builder[10] += 3.7, 'Z' >>> builder[11] += 0.0, 'I' # '0' term turns off field .. py:attribute:: S :value: 0.5 .. py:attribute:: one_site_terms :value: [] .. py:attribute:: two_site_terms :value: [] .. py:attribute:: cyclic :value: False .. py:attribute:: var_one_site_terms .. py:attribute:: var_two_site_terms .. py:method:: add_term(factor, *operators) Add another term to the expression to be built. :param factor: Scalar factor to multiply this term by. :type factor: scalar :param \*operators: The operators to use. Can specify one or two for single or two site terms respectively. Can use strings, which are supplied to :func:`~quimb.spin_operator`, or actual arrays as long as they have the correct dimension. :type \*operators: str or array .. py:method:: sub_term(factor, *operators) Subtract a term - simple alias that flips sign of ``factor``. .. py:method:: __iadd__(term) .. py:method:: __isub__(term) .. py:method:: __getitem__(sites) Part of the machinery that allows terms to be added to specific sites like:: >>> builder[i] += 1/2, 'X' >>> builder[45, 46] += 1/2, 'Z', 'Z' .. py:method:: __setitem__(sites, value) Part of the machinery that allows terms to be added to specific sites like:: >>> builder[i] += 1/2, 'X' >>> builder[45, 46] += 1/2, 'Z', 'Z' Could also be called directly with a list of terms like:: >>> builder[13, 14] = [(1, 'Z', 'Z'), (0.5, 'X', 'Y')] Which would overide any terms set so far. .. py:method:: build_mpo(L, upper_ind_id='k{}', lower_ind_id='b{}', site_tag_id='I{}', tags=None) Build an MPO instance of this spin hamiltonian of size ``L``. See also ``MatrixProductOperator``. .. py:method:: build_sparse(L, **ikron_opts) Build a sparse matrix representation of this Hamiltonian. :param L: The number of spins to build the matrix for. :type L: int, optional :param ikron_opts: Supplied to :func:`~quimb.core.ikron`. :returns: **H** :rtype: matrix .. py:method:: _get_spin_op(factor, *ss) .. py:method:: _sum_spin_ops(terms) .. py:method:: build_local_ham(L=None, **local_ham_1d_opts) Build a nearest neighbour interactor instance of this spin hamiltonian of size ``L``. See also :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D`. :param L: The number of spins, if the hamiltonian only has two-site terms this is optional. :type L: int, optional :rtype: LocalHam1D .. py:data:: SpinHam .. py:function:: _ham_ising(j=1.0, bx=0.0, *, S=1 / 2, cyclic=False) .. py:function:: MPO_ham_ising(L, j=1.0, bx=0.0, *, S=1 / 2, cyclic=False, **mpo_opts) Ising Hamiltonian in MPO form. .. math:: H_\mathrm{Ising} = J \sum_{i} S^Z_i S^Z_{i + 1} - B_x \sum_{i} S^X_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The ZZ interaction strength. Positive is antiferromagnetic. :type j: float, optional :param bx: The X-magnetic field strength. :type bx: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts or local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_ising(L=None, j=1.0, bx=0.0, *, S=1 / 2, cyclic=False, **local_ham_1d_opts) Ising Hamiltonian in :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form. .. math:: H_\mathrm{Ising} = J \sum_{i} S^Z_i S^Z_{i + 1} - B_x \sum_{i} S^X_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The ZZ interaction strength. Positive is antiferromagnetic. :type j: float, optional :param bx: The X-magnetic field strength. :type bx: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts or local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d.LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_ising .. py:function:: _ham_XY(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False) .. py:function:: MPO_ham_XY(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts) XY-Hamiltonian in MPO form. .. math:: H_\mathrm{XY} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} ) - B_x \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The XX and YY interaction strength. Positive is antiferromagnetic. :type j: float or (float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts or local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_XY(L=None, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **local_ham_1d_opts) XY-Hamiltonian in :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form. .. math:: H_\mathrm{XY} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} ) - B_Z \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The XX and YY interaction strength. Positive is antiferromagnetic. :type j: float or (float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d.LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_XY .. py:function:: _ham_heis(j=1.0, bz=0.0, *, S=1 / 2, cyclic=False) .. py:function:: MPO_ham_heis(L, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **mpo_opts) Heisenberg Hamiltonian in MPO form. .. math:: H_\mathrm{Heis} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + J_Z S^Z_i S^Z_{i + 1} ) - B_Z \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j: float or (float, float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_heis(L=None, j=1.0, bz=0.0, *, S=1 / 2, cyclic=False, **local_ham_1d_opts) Heisenberg Hamiltonian in :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form. .. math:: H_\mathrm{Heis} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + J_Z S^Z_i S^Z_{i + 1} ) - B_Z \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param j: The XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j: float or (float, float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_heis .. py:function:: MPO_ham_XXZ(L, delta, jxy=1.0, *, S=1 / 2, cyclic=False, **mpo_opts) XXZ-Hamiltonian in MPO form. .. math:: H_\mathrm{XXZ} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + \Delta S^Z_i S^Z_{i + 1} ) - B_Z \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param delta: The ZZ-interaction strength. Positive is antiferromagnetic. :type delta: float :param jxy: The X- and Y- interaction strength, defaults to 1. Positive is antiferromagnetic. :type jxy: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a MPO with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_XXZ(L=None, delta=None, jxy=1.0, *, S=1 / 2, cyclic=False, **local_ham_1d_opts) XXZ-Hamiltonian in :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form. .. math:: H_\mathrm{XXZ} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + \Delta S^Z_i S^Z_{i + 1} ) - B_Z \sum_{i} S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: The number of sites. :type L: int :param delta: The ZZ-interaction strength. Positive is antiferromagnetic. :type delta: float :param jxy: The X- and Y- interaction strength, defaults to 1. Positive is antiferromagnetic. :type jxy: float, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_XXZ .. py:function:: _ham_bilinear_biquadratic(theta, *, S=1 / 2, cyclic=False) .. py:function:: MPO_ham_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2, cyclic=False, compress=True, **mpo_opts) Hamiltonian of one-dimensional bilinear biquadratic chain in MPO form, see PhysRevB.93.184428. :param L: The number of sites. :type L: int :param theta: The parameter for linear and non-linear term of interaction strength, defaults to 0. :type theta: float or (float, float), optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param mpo_opts: Supplied to :class:`~quimb.tensor.tensor_1d.MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_bilinear_biquadratic(L=None, theta=0, *, S=1 / 2, cyclic=False, **local_ham_1d_opts) Hamiltonian of one-dimensional bilinear biquadratic chain in LocalHam1D form, see PhysRevB.93.184428. :param L: The number of sites. :type L: int :param theta: The parameter for linear and non-linear term of interaction strength, defaults to 0. :type theta: float or (float, float), optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Generate a hamiltonian with periodic boundary conditions or not, default is open boundary conditions. :type cyclic: bool, optional :param local_ham_1d_opts: Supplied to :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_bilinear_biquadratic .. py:function:: _ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False, dh_dist='s', dh_dim=1, beta=None) .. py:function:: MPO_ham_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False, dh_dist='s', dh_dim=1, beta=None, **mpo_opts) The many-body-localized spin hamiltonian in MPO form. .. math:: H_\mathrm{MBL} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + J_Z S^Z_i S^Z_{i + 1} ) - \sum_{i} h_i S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: Number of spins. :type L: int :param dh: Random noise strength. :type dh: float :param j: Interaction strength(s) e.g. 1 or (1., 1., 0.5). Positive is antiferromagnetic. :type j: float, or (float, float, float), optional :param seed: Random number to seed the noise with. :type seed: int, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Whether to use periodic boundary conditions - default is False. :type cyclic: bool, optional :param dh_dist: Whether to use sqaure, guassian or quasiperiodic noise. :type dh_dist: {'s', 'g', 'qp'}, optional :param beta: Frequency of the quasirandom noise, only if ``dh_dist='qr'``. :type beta: float, optional :param mpo_opts: Supplied to :class:`MatrixProductOperator`. :rtype: MatrixProductOperator .. py:function:: ham_1d_mbl(L, dh, j=1.0, seed=None, S=1 / 2, *, cyclic=False, dh_dist='s', dh_dim=1, beta=None, **local_ham_1d_opts) The many-body-localized spin hamiltonian in :class:`~quimb.tensor.tensor_1d_tebd.LocalHam1D` form. .. math:: H_\mathrm{MBL} = \sum_{i} ( J_X S^X_i S^X_{i + 1} + J_Y S^Y_i S^Y_{i + 1} + J_Z S^Z_i S^Z_{i + 1} ) - \sum_{i} h_i S^Z_i Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param L: Number of spins. :type L: int :param dh: Random noise strength. :type dh: float :param j: Interaction strength(s) e.g. 1 or (1., 1., 0.5). Positive is antiferromagnetic. :type j: float, or (float, float, float), optional :param seed: Random number to seed the noise with. :type seed: int, optional :param S: The underlying spin of the system, defaults to 1/2. :type S: {1/2, 1, 3/2, ...}, optional :param cyclic: Whether to use periodic boundary conditions - default is False. :type cyclic: bool, optional :param dh_dist: Whether to use sqaure, guassian or quasiperiodic noise. :type dh_dist: {'s', 'g', 'qp'}, optional :param beta: Frequency of the quasirandom noise, only if ``dh_dist='qr'``. :type beta: float, optional :param local_ham_1d_opts: Supplied to :class:`LocalHam1D`. :rtype: LocalHam1D .. py:data:: NNI_ham_mbl .. py:function:: ham_2d_ising(Lx, Ly, j=1.0, bx=0.0, **local_ham_2d_opts) Ising Hamiltonian in :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D` form. .. math:: H_\mathrm{Ising} = J \sum_{} S^Z_i S^Z_{j} - B_x \sum_{i} S^X_i for nearest neighbors :math:``. Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param j: The ZZ interaction strength. Positive is antiferromagnetic. :type j: float, optional :param bx: The X-magnetic field strength. :type bx: float, optional :param local_ham_2d_opts: Supplied to :class:`~quimb.tensor.tensor_2d.LocalHam2D`. :rtype: LocalHam2D .. py:function:: ham_2d_heis(Lx, Ly, j=1.0, bz=0.0, **local_ham_2d_opts) Heisenberg Hamiltonian in :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form. .. math:: H_\mathrm{Heis} = \sum_{} ( J_X S^X_i S^X_{j} + J_Y S^Y_i S^Y_{j} + J_Z S^Z_i S^Z_{j} ) - B_Z \sum_{i} S^Z_{i} for nearest neighbors :math:``. Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param j: The XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j: float or (float, float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param local_ham_2d_opts: Supplied to :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. :rtype: LocalHam2D .. py:function:: ham_2d_j1j2(Lx, Ly, j1=1.0, j2=0.5, bz=0.0, **local_ham_2d_opts) Heisenberg Hamiltonian in :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. form. .. math:: H_\mathrm{Heis} = \sum_{} ( J_{1,X} S^X_i S^X_{j} + J_{1,Y} S^Y_i S^Y_{j} + J_{1,Z} S^Z_i S^Z_{j} ) + \sum_{<>} ( J_{2,X} S^X_i S^X_{j} + J_{2,Y} S^Y_i S^Y_{j} + J_{2,Z} S^Z_i S^Z_{j} ) - B_Z \sum_{i} S^Z_{i} for nearest neighbors :math:`` and diagonal next nearest neighbors :math:`<>`. Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param Lx: The number of rows. :type Lx: int :param Ly: The number of columns. :type Ly: int :param j2: The nearest neighbor XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j2: float or (float, float, float), optional :param j2: The diagonal next nearest nearest XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j2: float or (float, float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param local_ham_2d_opts: Supplied to :class:`~quimb.tensor.tensor_2d_tebd.LocalHam2D`. :rtype: LocalHam2D .. py:function:: ham_3d_heis(Lx, Ly, Lz, j=1.0, bz=0.0, **local_ham_3d_opts) Heisenberg Hamiltonian in :class:`~quimb.tensor.tensor_3d_tebd.LocalHam3D`. form. .. math:: H_\mathrm{Heis} = \sum_{} ( J_X S^X_i S^X_{j} + J_Y S^Y_i S^Y_{j} + J_Z S^Z_i S^Z_{j} ) - B_Z \sum_{i} S^Z_{i} for nearest neighbors :math:``. Note the default convention of antiferromagnetic interactions and spin operators not Pauli matrices. :param Lx: The number of x-planes. :type Lx: int :param Ly: The number of y-planes. :type Ly: int :param Ly: The number of z-planes. :type Ly: int :param j: The XX, YY and ZZ interaction strength. Positive is antiferromagnetic. :type j: float or (float, float, float), optional :param bz: The Z-magnetic field strength. :type bz: float, optional :param local_ham_3d_opts: Supplied to :class:`~quimb.tensor.tensor_3d_tebd.LocalHam3D`. :rtype: LocalHam3D