MixedXKModel¶
full name: tenpy.models.mixed_xk.MixedXKModel
parent module:
tenpy.models.mixed_xk
type: class
Inheritance Diagram
Methods



Add twosite coupling terms to the Hamiltonian, summing over lattice sites. 

Add a twosite coupling term on given MPS sites. 
Add an exponentially decaying longrange coupling. 


Add hopping terms between different rings. 
Add interring interaction terms. 


Add hopping terms within each ring. 
Add intraring interaction terms. 


Add a single term to self. 

Add multisite coupling terms to the Hamiltonian, summing over lattice sites. 

Add a general Msite coupling term on given MPS sites. 

Add onsite terms to 

Add an onsite term on a given MPS site. 
Sum of all 

Sum of all 


Calculate MPO representation of the Hamiltonian. 

calculate H_bond from 

Calculate the bond Hamiltonian from the MPO Hamiltonian. 

Calculate H_onsite from self.onsite_terms. 
Shallow copy of self. 

Add an external flux to the coupling strength. 


Repeat the unit cell for infinite MPS boundary conditions; in place. 

Return a (shallow) copy with extracted segment of MPS. 

Load instance from a HDF5 file. 

Modify self in place to group sites. 
Initialize H_MPO (and H_bond) from the terms of the CouplingModel. 


Initialize a MixedXKLattice for the given model parameters. 

Define the local Hilbert space and operators; needs to be implemented in subclasses. 

Add the onsite and coupling terms to the model; subclasses should implement this. 
Terms to be measured in xkspace for real space correlation functions. 

Terms to be measured in xkspace for real space correlation functions. 


Terms to be measured in xk space for real space onsite observables. 
Terms to be measured in xkspace for real space correlation functions. 


Export self into a HDF5 file. 
Sanity check, raises ValueErrors, if something is wrong. 
Class Attributes and Properties
The default lattice class or class name to be used in 

If True, 

class attribute. 

Reproducible numpy pseudo random number generator. 


 class tenpy.models.mixed_xk.MixedXKModel(model_params)[source]¶
Bases:
CouplingMPOModel
Base class for a Hamiltonian represented in mixed xkspace on a cylinder.
All parameters are collected in a single dictionary model_params, which is turned into a
Config
object. Parameters
xy_lattice (
"Square"
) – Chooses Realspace lattice geometry. TODO: Currently, only “Square” is implemented.
 real_space_lattice¶
Realspace lattice geometry.
 Type
TODO ???
 init_lattice(model_params, N_orb, chinfo, charges)[source]¶
Initialize a MixedXKLattice for the given model parameters.
 Parameters
model_params (dict) – The model parameters given to
__init__
.N_orb (int) – The number of fermionic orbitals for each kvalue.
chinfo (
ChargeInfo
) – The charges to be conserved, excluding the momentum in y direction “ky”.charges (array_like of shape (N_orb, chinfo.qnumber)) – For each of the oribals the value of each charges (except
"ky"
), when the orbital is occupied.
 add_intra_ring_hopping(couplings)[source]¶
Add hopping terms within each ring.
 Parameters
couplings (ndarray, shape (Ly, N_orb, Ly, N_orb)) –
couplings[k1, l1, k2, l2]
is the prefactor for a hopping term of the form \(\sum_i c^\dagger_{x,k1,l1} c_{x,k2,l2}\). Should fulfillcouplings[k1, l1, k2, l2] == conj(couplings[k2, l2, k1, l1])
to make the Hamiltonian hermitian.
 add_inter_ring_hopping(couplings, dx=1)[source]¶
Add hopping terms between different rings.
 Parameters
couplings (ndarray, shape (Ly, N_orb, Ly, N_orb)) –
couplings[k1, j1, k2, j2]
is the prefactor for a hopping term of the form \(\sum_x c^\dagger_{x,k1,l1} c_{x+dx,k2,l2} + h.c.\).dx (int) – Distance between the rings; use dx > 1 for longrange hoppings.
 add_intra_ring_interaction(couplings, operators=('Cd', 'C', 'Cd', 'C'))[source]¶
Add intraring interaction terms.
 Parameters
couplings (ndarray, shape (Ly, N_orb, Ly, N_orb, Ly, N_orb, Ly, N_orb)) –
couplings[k1,j1, k2,j2, k3,j3, k4,j4]
is the prefactor for a hopping term of the form \(\sum_i A_{i,k1,j1} B_{i,k2,j2} C_{i,k3,j3} D_{i,k4,j4}\).operators (tuple of 4 str) – The 4 operators A,B,C,D to be used, ‘Cd’ for (fermionic) creation and ‘C’ for annihilation operators of given ring, momentum and orbital.
 add_inter_ring_interaction(couplings, dx, operators=('Cd', 'C', 'Cd', 'C'))[source]¶
Add interring interaction terms.
 Parameters
couplings (ndarray, shape (Ly, N_orb, Ly, N_orb, Ly, N_orb, Ly, N_orb)) –
couplings[k1, j1, k2, j2, k3, j3, k4, j4]
is the prefactor for a term\[\sum_i A_{i,k1,j1} B_{i,k2,j2} C_{i+dx,k3,j3} D_{i+dx,k4,j4}\]For the default operators, it should fulfill
coulings[k1,j1, k2,j2, k3,j3, k4,j4] = conj(coulings[k2,j2, k1,j1, k4,j4, k3,j3])
to make the Hamiltonian hermitian.dx (int) – Distance between the rings; use dx > 1 for longrange interactions.
operators (tuple of 4 str) – The 4 operators A,B,C,D to be used, ‘Cd’ for (fermionic) creation and ‘C’ for annihilation operators of given ring, momentum and orbital.
 real_to_mixed_onsite(A, A_coord)[source]¶
Terms to be measured in xk space for real space onsite observables.
Provide the necessary terms which can be measured in an MPS with
expectation_value_sum_terms()
to evaluate a onsite observable \(A_{x,y}\) in real space where \(A_{x,y} = \sum_{l1,l2} A_{l1,l2} c^\dagger_{x,y,l1} c_{x,y,l2}\) with the provided matrix elementsA[l1,l2]
and coordinatesx, y = A_coord
.
 real_to_mixed_two_site(A, A_coord, B, B_coord)[source]¶
Terms to be measured in xkspace for real space correlation functions.
Provide the necessary terms which can be measured in an MPS with
expectation_value_sum_terms()
to evaluate a correlation function \(A_{x1,y1} B_{x1,y2}\), where \(A_{x1,y1} = \sum_{l1,l2} A_{l1,l2} c^\dagger_{x1,y1,l1} c_{x1,y1,l2}\) with the provided matrix elementsA[l1,l2]
and coordinatesx1, y1 = A_coord
, and similar B. Parameters
A (array_like, shape (N_orb, N_orb)) – Matrix elements with respect to the orbitals for the first operator.
A_coord ((int, int)) –
x, y
coordinates of the operator in realspace.B (array_like, shape (N_orb, N_orb)) – Matrix elements with respect to the orbitals for the second operator.
B_coord ((int, int)) –
x, y
coordinates of the operator in realspace.
 Returns
terms – Terms representing the correlation function in xkspace.
 Return type
 real_to_mixed_n_site(orbital_coeffs, rs_coords)[source]¶
Terms to be measured in xkspace for real space correlation functions.
Provide the necessary terms which can be measured in an MPS with
expectation_value_sum_terms()
to evaluate a nsite correlation function \(A_{x1,y1} B_{x2,y2} C_{x3,y3} ...\), where \(A_{x,y} = \sum_{l1,l2} A_{l1,l2} c^\dagger_{x,y,l1} c_{x,y,l2}\) with the provided matrix elementsorbital_coeffs[0][l1,l2]
and coordinatesx1, y1 = rs_coords[0]
, and similar the other n operators B, C, …. Parameters
orbital_coeffs (list of array_like, shape (N_orb, N_orb)) – Matrix elements with respect to the orbitals for each of the operators.
rs_coord (list of tuple) – For each operator iin orbital_coeffs the according realspace coordinates
x, y
.
 Returns
terms – Terms representing the correlation function in xkspace.
 Return type
 real_to_mixed_correlations_any(ops, coeff_orbitals, rs_coords)[source]¶
Terms to be measured in xkspace for real space correlation functions.
Provide the necessary terms which can be measured in an MPS with
expectation_value_sum_terms()
to evaluate a realspace correlation function of creation and annihilation operators:sum([coeff * prod(ops[i]_{rs_coords[i],orbitals[i]} for i in len(ops)) for coeff, orbitals in coeff_orbitals]) # rs_coords[i] = pair of x, y coordinates
 Parameters
ops (list of
'C'  'Cd'
) – Operators to be measured, ‘Cd’ for creation, ‘C’ for annihilation operator. Each operator acts on a site x, y, l specified by an entryx, y
in rs_coords and a l in the orbitals of coeff_orbitals.coeff_orbitals (list of (coeff, orbitals)) – orbitals is a list with one orbital l index for each operator in ops, coeff is a prefactor for that orbital combination.
rs_coords (list of (int, int)) – realspace coordinates
x,y
where each of the operators act.
 Returns
terms – Terms representing the correlation function in xkspace.
 Return type
 add_coupling(strength, u1, op1, u2, op2, dx, op_string=None, str_on_first=True, raise_op2_left=False, category=None, plus_hc=False)[source]¶
Add twosite coupling terms to the Hamiltonian, summing over lattice sites.
Represents couplings of the form \(\sum_{x_0, ..., x_{dim1}} strength[shift(\vec{x})] * OP0 * OP1\), where
OP0 := lat.unit_cell[u0].get_op(op0)
acts on the site(x_0, ..., x_{dim1}, u1)
, andOP1 := lat.unit_cell[u1].get_op(op1)
acts on the site(x_0+dx[0], ..., x_{dim1}+dx[dim1], u1)
. Possible combinationsx_0, ..., x_{dim1}
are determined from the boundary conditions inpossible_couplings()
.The coupling strength may vary spatially if the given strength is a numpy array. The correct shape of this array is the coupling_shape returned by
tenpy.models.lattice.coupling_shape()
and depends on the boundary conditions. Theshift(...)
depends on dx, and is chosen such that the first entrystrength[0, 0, ...]
of strength is the prefactor for the first possible coupling fitting into the lattice if you imagine open boundary conditions.The necessary terms are just added to
coupling_terms
; this function does not rebuild the MPO.Deprecated since version 0.4.0: The arguments str_on_first and raise_op2_left will be removed in version 1.0.0.
 Parameters
strength (scalar  array) – Prefactor of the coupling. May vary spatially (see above). If an array of smaller size is provided, it gets tiled to the required shape. A single scalar number can be given to indicate a coupling which is uniform accross the lattice.
u1 (int) – Picks the site
lat.unit_cell[u1]
for OP1.op1 (str) – Valid operator name of an onsite operator in
lat.unit_cell[u1]
for OP1.u2 (int) – Picks the site
lat.unit_cell[u2]
for OP2.op2 (str) – Valid operator name of an onsite operator in
lat.unit_cell[u2]
for OP2.dx (iterable of int) – Translation vector (of the unit cell) between OP1 and OP2. For a 1D lattice, a single int is also fine.
op_string (str  None) – Name of an operator to be used between the OP1 and OP2 sites. Typical use case is the phase for a JordanWigner transformation. The operator should be defined on all sites in the unit cell. If
None
, autodetermine whether a JordanWigner string is needed, usingop_needs_JW()
.str_on_first (bool) – Whether the provided op_string should also act on the first site. This option should be chosen as
True
for JordanWigner strings. When handling JordanWigner strings we need to extend the op_string to also act on the ‘left’, first site (in the sense of the MPS ordering of the sites given by the lattice). In this case, there is a welldefined ordering of the operators in the physical sense (i.e. which of op1 or op2 acts first on a given state). We follow the convention that op2 acts first (in the physical sense), independent of the MPS ordering. Deprecated.raise_op2_left (bool) – Raise an error when op2 appears left of op1 (in the sense of the MPS ordering given by the lattice). Deprecated.
category (str) – Descriptive name used as key for
coupling_terms
. Defaults to a string of the form"{op1}_i {op2}_j"
.plus_hc (bool) – If True, the hermitian conjugate of the terms is added automatically.
Examples
When initializing a model, you can add a term \(J \sum_{<i,j>} S^z_i S^z_j\) on all nearestneighbor bonds of the lattice like this:
>>> J = 1. # the strength >>> for u1, u2, dx in self.lat.pairs['nearest_neighbors']: ... self.add_coupling(J, u1, 'Sz', u2, 'Sz', dx)
The strength can be an array, which gets tiled to the correct shape. For example, in a 1D
Chain
with an even number of sites and periodic (or infinite) boundary conditions, you can add alternating strong and weak couplings with a line like:>>> self.add_coupling([1.5, 1.], u1, 'Sz', u2, 'Sz', dx)
Make sure to use the plus_hc argument if necessary, e.g. for hoppings:
>>> t = 1. # hopping strength >>> for u1, u2, dx in self.lat.pairs['nearest_neighbors']: ... self.add_coupling(t, u1, 'Cd', u2, 'C', dx, plus_hc=True)
Alternatively, you can add the hermitian conjugate terms explictly. The correct way is to complex conjugate the strength, take the hermitian conjugate of the operators and swap the order (including a swap u1 <> u2), and use the opposite direction
dx
, i.e. the h.c. ofadd_coupling(t, u1, 'A', u2, 'B', dx)
isadd_coupling(np.conj(t), u2, hc('B'), u1, hc('A'), dx)
, where hc takes the hermitian conjugate of the operator names, seeget_hc_op_name()
. For spinless fermions (FermionSite
), this would be>>> for u1, u2, dx in self.lat.pairs['nearest_neighbors']: ... self.add_coupling(t, u1, 'Cd', u2, 'C', dx) ... self.add_coupling(np.conj(t), u2, 'Cd', u1, 'C', dx) # h.c.
With spinfull fermions (
SpinHalfFermions
), it could be:>>> for u1, u2, dx in self.lat.pairs['nearest_neighbors']: ... self.add_coupling(t, u1, 'Cdu', u2, 'Cd', dx) # Cdagger_up C_down ... self.add_coupling(np.conj(t), u2, 'Cdd', u1, 'Cu', dx) # h.c. Cdagger_down C_up
Note that the JordanWigner strings for the fermions are added automatically!
See also
add_onsite
Add terms acting on one site only.
add_multi_coupling_term
for terms on more than two sites.
add_coupling_term
Add a single term without summing over \(\vec{x}\).
 add_coupling_term(strength, i, j, op_i, op_j, op_string='Id', category=None, plus_hc=False)[source]¶
Add a twosite coupling term on given MPS sites.
Wrapper for
self.coupling_terms[category].add_coupling_term(...)
.Warning
This function does not handle JordanWigner strings! You might want to use
add_local_term()
instead. Parameters
strength (float) – The strength of the coupling term.
i (int) – The MPS indices of the two sites on which the operator acts. We require
0 <= i < N_sites
andi < j
, i.e., op_i acts “left” of op_j. If j >= N_sites, it indicates couplings between unit cells of an infinite MPS.j (int) – The MPS indices of the two sites on which the operator acts. We require
0 <= i < N_sites
andi < j
, i.e., op_i acts “left” of op_j. If j >= N_sites, it indicates couplings between unit cells of an infinite MPS.op1 (str) – Names of the involved operators.
op2 (str) – Names of the involved operators.
op_string (str) – The operator to be inserted between i and j.
category (str) – Descriptive name used as key for
coupling_terms
. Defaults to a string of the form"{op1}_i {op2}_j"
.plus_hc (bool) – If True, the hermitian conjugate of the term is added automatically.
 add_exponentially_decaying_coupling(strength, lambda_, op_i, op_j, subsites=None, op_string=None, plus_hc=False)[source]¶
Add an exponentially decaying longrange coupling.
\[strength \sum_{i < j} \lambda^{ij} A_{subsites[i]} B_{subsites[j]}\]Where the operator A is given by op_i, and B is given by op_j. Note that the sum over i,j is longrange, for infinite systems going beyond the MPS unit cell. Moreover, note that the distance in the exponent is the distance within subsites.
 Parameters
strength (float) – Overall prefactor.
lambda (float) – Decayrate
op_i (string) – Names for the operators.
op_j (string) – Names for the operators.
subsites (None  1D array) – Selects a subset of sites within the MPS unit cell on which the operators act. Needs to be sorted.
None
selects all sites.op_string (None  str) – The operator to be inserted between A and B; If
None
, this function checks whether a fermionic"JW"
string is needed for the given operators; in this case the right op_j acts first.plus_hc (bool) – If True, the hermitian conjugate of the term is added automatically.
Examples
At least for simple enough 1D chains (or ladders), you can use
fit_with_sum_of_exp()
to approximate a longrange function with a few sum of exponentials and then add them with this function.>>> def decay(x): ... return np.exp(0.1*x) / x**2 >>> from tenpy.tools.fit import fit_with_sum_of_exp, sum_of_exp >>> n_exp = 5 >>> fit_range = 50 >>> lam, pref = fit_with_sum_of_exp(decay, n_exp, fit_range) >>> x = np.arange(1, fit_range + 1) >>> print('error in fit: {0:.3e}'.format(np.sum(np.abs(decay(x)  sum_of_exp(lam, pref, x))))) error in fit: 1.073e04 >>> for pr, la in zip(pref, lam): ... self.add_exponentially_decaying_coupling(pr, la, 'N', 'N')
 add_local_term(strength, term, category=None, plus_hc=False)[source]¶
Add a single term to self.
The repesented term is strength times the product of the operators given in terms. Each operator is specified by the name and the site it acts on; the latter given by a lattice index, see
Lattice
.Depending on the length of term, it can add an onsite term or a coupling term to
onsite_terms
orcoupling_terms
, respectively. Parameters
strength (float/complex) – The prefactor of the term.
term (list of (str, array_like)) – List of tuples
(opname, lat_idx)
where opname is a string describing the operator acting on the site given by the lattice index lat_idx. Here, lat_idx is for example [x, y, u] for a 2D lattice, with u being the index within the unit cell.category – Descriptive name used as key for
onsite_terms
orcoupling_terms
.plus_hc (bool) – If True, the hermitian conjugate of the terms is added automatically.
 add_multi_coupling(strength, ops, _deprecate_1='DEPRECATED', _deprecate_2='DEPRECATED', op_string=None, category=None, plus_hc=False, switchLR='middle_i')[source]¶
Add multisite coupling terms to the Hamiltonian, summing over lattice sites.
Represents couplings of the form \(sum_{\vec{x}} strength[shift(\vec{x})] * OP_0 * OP_1 * ... * OP_{M1}\), involving M operators. Here, \(OP_m\) stands for the operator defined by the mth tuple
(opname, dx, u)
given in the argument ops, which determines the position \(\vec{x} + \vec{dx}\) and unitcell index u of the site it acts on; the actual operator is given by self.lat.unit_cell[u].get_op(opname).The coupling strength may vary spatially if the given strength is a numpy array. The correct shape of this array is the coupling_shape returned by
tenpy.models.lattice.possible_multi_couplings()
and depends on the boundary conditions. Theshift(...)
depends on the dx entries of ops and is chosen such that the first entrystrength[0, 0, ...]
of strength is the prefactor for the first possible coupling fitting into the lattice if you imagine open boundary conditions.The necessary terms are just added to
coupling_terms
; this function does not rebuild the MPO.Deprecated since version 0.6.0: We switched from the three arguments u0, op0 and other_op with
other_ops=[(u1, op1, dx1), (op2, u2, dx2), ...]
to a single, equivalent argment ops which should now readops=[(op0, dx0, u0), (op1, dx1, u1), (op2, dx2, u2), ...]
, wheredx0 = [0]*self.lat.dim
. Note the changed order inside the tuples! Parameters
strength (scalar  array) – Prefactor of the coupling. May vary spatially, and is tiled to the required shape.
ops (list of
(opname, dx, u)
) – Each tuple determines one operator of the coupling, see the description above. opname (str) is the name of the operator, dx (list of length lat.dim) is a translation vector, and u (int) is the index of lat.unit_cell on which the operator acts. The first entry of ops corresponds to \(OP_0\) and acts last in the physical sense.op_string (str  None) –
If a string is given, we use this as the name of an operator to be used inbetween the operators, excluding the sites on which any operators act. This operator should be defined on all sites in the unit cell.
If
None
, autodetermine whether a JordanWigner string is needed (usingop_needs_JW()
) for each of the segments inbetween the operators and also on the sites of the left operators.switchLR (int 
"middle_i"  "middle_op"
) – Seeadd_multi_coupling()
for details on possible choices.category (str) – Descriptive name used as key for
coupling_terms
. Defaults to a string of the form"{op0}_i {other_ops[0]}_j {other_ops[1]}_k ..."
.plus_hc (bool) – If True, the hermitian conjugate of the terms is added automatically.
Examples
A call to
add_coupling()
with argumentsadd_coupling(strength, u1, 'A', u2, 'B', dx)
is equivalent to the following:>>> dx_0 = [0] * self.lat.dim # = [0] for a 1D lattice, [0, 0] in 2D >>> self.add_multi_coupling(strength, [('A', dx_0, u1), ('B', dx, u2)])
To explicitly add the hermitian conjugate (instead of simply using plus_hc = True), you need to take the complex conjugate of the strength, reverse the order of the operators and take the hermitian conjugates of the individual operator names (indicated by the
hc(...)
, seeget_hc_op_name()
):>>> self.add_multi_coupling(np.conj(strength), [(hc('B'), dx, u2), (hc('A'), dx_0, u1)])
See also
add_onsite
Add terms acting on one site only.
add_coupling
Add terms acting on two sites.
add_multi_coupling_term
Add a single term, not summing over the possible \(\vec{x}\).
 add_multi_coupling_term(strength, ijkl, ops_ijkl, op_string, category=None, plus_hc=False, switchLR='middle_i')[source]¶
Add a general Msite coupling term on given MPS sites.
Wrapper for
self.coupling_terms[category].add_multi_coupling_term(...)
.Warning
This function does not handle JordanWigner strings! You might want to use
add_local_term()
instead. Parameters
strength (float) – The strength of the coupling term.
ijkl (list of int) – The MPS indices of the sites on which the operators acts. With i, j, k, … = ijkl, we require that they are ordered ascending,
i < j < k < ...
and that0 <= i < N_sites
. Inidces >= N_sites indicate couplings between different unit cells of an infinite MPS.ops_ijkl (list of str) – Names of the involved operators on sites i, j, k, ….
op_string (list of str) – Names of the operator to be inserted between the operators, e.g., op_string[0] is inserted between i and j.
category (str) – Descriptive name used as key for
coupling_terms
. Defaults to a string of the form"{op0}_i {op1}_j {op2}_k ..."
.plus_hc (bool) – If True, the hermitian conjugate of the term is added automatically.
switchLR (int 
"middle_i"  "middle_op"
) – Seeadd_multi_coupling()
for details on possible choices.
 add_onsite(strength, u, opname, category=None, plus_hc=False)[source]¶
Add onsite terms to
onsite_terms
.Adds \(\sum_{\vec{x}} strength[\vec{x}] * OP\) to the represented Hamiltonian, where the operator
OP=lat.unit_cell[u].get_op(opname)
acts on the site given by a lattice index(x_0, ..., x_{dim1}, u)
,The necessary terms are just added to
onsite_terms
; doesn’t rebuild the MPO. Parameters
strength (scalar  array) – Prefactor of the onsite term. May vary spatially. If an array of smaller size is provided, it gets tiled to the required shape.
u (int) – Picks a
Site
lat.unit_cell[u]
out of the unit cell.opname (str) – valid operator name of an onsite operator in
lat.unit_cell[u]
.category (str) – Descriptive name used as key for
onsite_terms
. Defaults to opname.plus_hc (bool) – If True, the hermitian conjugate of the terms is added automatically.
See also
add_coupling
Add a terms acting on two sites.
add_onsite_term
Add a single term without summing over \(vec{x}\).
 add_onsite_term(strength, i, op, category=None, plus_hc=False)[source]¶
Add an onsite term on a given MPS site.
Wrapper for
self.onsite_terms[category].add_onsite_term(...)
. Parameters
strength (float) – The strength of the term.
i (int) – The MPS index of the site on which the operator acts. We require
0 <= i < L
.op (str) – Name of the involved operator.
category (str) – Descriptive name used as key for
onsite_terms
. Defaults to op.plus_hc (bool) – If True, the hermitian conjugate of the term is added automatically.
 calc_H_MPO(tol_zero=1e15)[source]¶
Calculate MPO representation of the Hamiltonian.
Uses
onsite_terms
andcoupling_terms
to build an MPOGraph (and then an MPO).
 calc_H_bond(tol_zero=1e15)[source]¶
calculate H_bond from
coupling_terms
andonsite_terms
. Parameters
tol_zero (float) – prefactors with
abs(strength) < tol_zero
are considered to be zero. Returns
H_bond – Bond terms as required by the constructor of
NearestNeighborModel
. Legs are['p0', 'p0*', 'p1', 'p1*']
 Return type
list of
Array
:raises ValueError : if the Hamiltonian contains longerrange terms.:
 calc_H_bond_from_MPO(tol_zero=1e15)[source]¶
Calculate the bond Hamiltonian from the MPO Hamiltonian.
 Parameters
tol_zero (float) – Arrays with norm < tol_zero are considered to be zero.
 Returns
H_bond – Bond terms as required by the constructor of
NearestNeighborModel
. Legs are['p0', 'p0*', 'p1', 'p1*']
 Return type
list of
Array
:raises ValueError : if the Hamiltonian contains longerrange terms.:
 calc_H_onsite(tol_zero=1e15)[source]¶
Calculate H_onsite from self.onsite_terms.
Deprecated since version 0.4.0: This function will be removed in 1.0.0. Replace calls to this function by
self.all_onsite_terms().remove_zeros(tol_zero).to_Arrays(self.lat.mps_sites())
. You might also want to takeexplicit_plus_hc
into account. Parameters
tol_zero (float) – prefactors with
abs(strength) < tol_zero
are considered to be zero. Returns
H_onsite (list of npc.Array)
onsite terms of the Hamiltonian. If
explicit_plus_hc
is True, – Hermitian conjugates of the onsite terms will be included.
 coupling_strength_add_ext_flux(strength, dx, phase)[source]¶
Add an external flux to the coupling strength.
When performing DMRG on a “cylinder” geometry, it might be useful to put an “external flux” through the cylinder. This means that a particle hopping around the cylinder should pick up a phase given by the external flux [resta1998]. This is also called “twisted boundary conditions” in literature. This function adds a complex phase to the strength array on some bonds, such that particles hopping in positive direction around the cylinder pick up exp(+i phase).
Warning
For the sign of phase it is important that you consistently use the creation operator as op1 and the annihilation operator as op2 in
add_coupling()
. Parameters
strength (scalar  array) – The strength to be used in
add_coupling()
, when no external flux would be present.dx (iterable of int) – Translation vector (of the unit cell) between op1 and op2 in
add_coupling()
.phase (iterable of float) – The phase of the external flux for hopping in each direction of the lattice. E.g., if you want flux through the cylinder on which you have an infinite MPS, you should give
phase=[0, phi]
souch that particles pick up a phase phi when hopping around the cylinder.
 Returns
strength – The strength array to be used as strength in
add_coupling()
with the given dx. Return type
complex array
Examples
Let’s say you have an infinite MPS on a cylinder, and want to add nearestneighbor hopping of fermions with the
FermionSite
. The cylinder axis is the xdirection of the lattice, so to put a flux through the cylinder, you want particles hopping around the cylinder to pick up a phase phi given by the external flux.>>> strength = 1. # hopping strength without external flux >>> phi = np.pi/4 # determines the external flux strength >>> for u1, u2, dx in self.lat.pairs['nearest_neighbors']: ... strength_with_flux = self.coupling_strength_add_ext_flux(strength, dx, [0, phi]) ... self.add_coupling(strength_with_flux, u1, 'Cd', u2, 'C', dx) ... self.add_coupling(np.conj(strength_with_flux), u2, 'Cd', u1, 'C', dx)
 default_lattice = 'Chain'¶
The default lattice class or class name to be used in
init_lattice()
. Type
class or str
 enlarge_mps_unit_cell(factor=2)[source]¶
Repeat the unit cell for infinite MPS boundary conditions; in place.
This has to be done after finishing initialization and can not be reverted.
 Parameters
factor (int) – The new number of sites in the MPS unit cell will be increased from N_sites to
factor*N_sites_per_ring
. Since MPS unit cells are repeated in the xdirection in our convetion, the lattice shape goes from(Lx, Ly, ..., Lu)
to(Lx*factor, Ly, ..., Lu)
.
 extract_segment(*args, **kwargs)[source]¶
Return a (shallow) copy with extracted segment of MPS.
 Parameters
first (int) – See
extract_segment()
.last (int) – See
extract_segment()
.enlarge (int) – See
extract_segment()
.
 Returns
cp – A shallow copy of self with MPO and lattice extracted for the segment.
 Return type
Model
 force_default_lattice = False¶
If True,
init_lattice()
asserts that the initialized lattice is (a subclass of) default_lattice Type
 classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]¶
Load instance from a HDF5 file.
Same as
from_hdf5()
, but handlerng
.
 group_sites(n=2, grouped_sites=None)[source]¶
Modify self in place to group sites.
Group each n sites together using the
GroupedSite
. This might allow to do TEBD with a Trotter decomposition, or help the convergence of DMRG (in case of too long range interactions).This has to be done after finishing initialization and can not be reverted.
 Parameters
n (int) – Number of sites to be grouped together.
grouped_sites (None  list of
GroupedSite
) – The sites grouped together.
 Returns
grouped_sites – The sites grouped together.
 Return type
list of
GroupedSite
 init_H_from_terms()[source]¶
Initialize H_MPO (and H_bond) from the terms of the CouplingModel.
This function is called automatically during CouplingMPOModel.__init__.
If you use one of the add_* methods of the CouplingModel after initialization, you will need to call init_H_from_terms in the end by yourself, in order to update the H_MPO (and possibly H_bond) representations. (You should get a warning about this… The way to avoid it is to initialize all the terms in init_terms by defining your own model, as outlined in Models.
 init_sites(model_params)[source]¶
Define the local Hilbert space and operators; needs to be implemented in subclasses.
This function gets called by
init_lattice()
to get theSite
for the lattice unit cell.Note
Initializing the sites requires to define the conserved quantum numbers. All predefined sites accept
conserve=None
to disable using quantum numbers. Many models in TeNPy read out the conserve model parameter, which can be set to"best"
to indicate the optimal parameters.If you need to initialize more than one site, the function
tenpy.networks.site.set_common_charges()
should be helpful. Parameters
model_params (dict) – The model parameters given to
__init__
. Returns
sites ((tuple of)
Site
) – The local sites of the lattice, defining the local basis states and operators.optional_species_names (not set  list of str  None) – You should usually just return the (tuple of) sites. However, you can aditionally return a list species_names to indicate that the
MultiSpeciesLattice
should be used.
 init_terms(model_params)[source]¶
Add the onsite and coupling terms to the model; subclasses should implement this.
 logger = <Logger tenpy.models.model.Model (WARNING)>¶
class attribute.
 Type
 Type
An instance of a logger; see Logging and terminal output. NB
 property rng¶
Reproducible numpy pseudo random number generator.
If you want to add randomness/disorder to your model, it is recommended use this random number generator for reproducibility of the model:
self.rng.random(size=[3, 5])
Especially for models with timedependence, you can/will otherwise end up generating a new disordered at each timestep!
Options
 random_seed :: None  int
Defaults to 123456789. Seed for numpy pseudo random number generator which can be used as e.g.
self.rng.random(...)
.
 save_hdf5(hdf5_saver, h5gr, subpath)[source]¶
Export self into a HDF5 file.
Same as
save_hdf5()
, but handlerng
.