NearestNeighborModel

  • full name: tenpy.models.model.NearestNeighborModel

  • parent module: tenpy.models.model

  • type: class

Inheritance Diagram

Inheritance diagram of tenpy.models.model.NearestNeighborModel

Methods

NearestNeighborModel.__init__(lattice, H_bond)

NearestNeighborModel.bond_energies(psi)

Calculate bond energies <psi|H_bond|psi>.

NearestNeighborModel.calc_H_MPO_from_bond([...])

Calculate the MPO Hamiltonian from the bond Hamiltonian.

NearestNeighborModel.copy()

Shallow copy of self.

NearestNeighborModel.enlarge_mps_unit_cell([...])

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

NearestNeighborModel.estimate_RAM_saving_factor()

Returns the expected saving factor for RAM based on charge conservation.

NearestNeighborModel.extract_segment(*args, ...)

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

NearestNeighborModel.from_MPOModel(mpo_model)

Initialize a NearestNeighborModel from a model class defining an MPO.

NearestNeighborModel.from_hdf5(hdf5_loader, ...)

Load instance from a HDF5 file.

NearestNeighborModel.get_extra_default_measurements()

Get list of model-dependent extra default measurements.

NearestNeighborModel.group_sites([n, ...])

Modify self in place to group sites.

NearestNeighborModel.save_hdf5(hdf5_saver, ...)

Export self into a HDF5 file.

NearestNeighborModel.test_sanity()

NearestNeighborModel.trivial_like_NNModel()

Return a NearestNeighborModel with same lattice, but trivial (H=0) bonds.

NearestNeighborModel.update_time_parameter(...)

Reconstruct Hamiltonian for time-dependent models, potentially (!) in-place.

Class Attributes and Properties

NearestNeighborModel.logger

class attribute.

NearestNeighborModel.rng

Reproducible numpy pseudo random number generator.

class tenpy.models.model.NearestNeighborModel(lattice, H_bond)[source]

Bases: Model

Base class for a model of nearest neighbor interactions w.r.t. the MPS index.

In this class, the Hamiltonian \(H = \sum_{i} H_{i,i+1}\) is represented by “bond terms” \(H_{i,i+1}\) acting only on two neighboring sites i and i+1, where i is an integer. Instances of this class are suitable for tebd.

Note that the “nearest-neighbor” in the name refers to the MPS index, not the lattice. In short, this works only for 1-dimensional (1D) nearest-neighbor models: A 2D lattice is internally mapped to a 1D MPS “snake”, and even a nearest-neighbor coupling in 2D becomes long-range in the MPS chain.

Parameters:
  • lattice (tenpy.model.lattice.Lattice) – The lattice defining the geometry and the local Hilbert space(s).

  • H_bond (list of {Array | None}) – The Hamiltonian rewritten as sum_i H_bond[i] for MPS indices i. H_bond[i] acts on sites (i-1, i); we require len(H_bond) == lat.N_sites. Legs of each H_bond[i] are ['p0', 'p0*', 'p1', 'p1*'].

H_bond

The Hamiltonian rewritten as sum_i H_bond[i] for MPS indices i. H_bond[i] acts on sites (i-1, i), None represents 0. Legs of each H_bond[i] are ['p0', 'p0*', 'p1', 'p1*']. H_bond is not affected by the explicit_plus_hc flag of a CouplingModel.

Type:

list of {Array | None}

classmethod from_MPOModel(mpo_model)[source]

Initialize a NearestNeighborModel from a model class defining an MPO.

This is especially useful in combination with MPOModel.group_sites().

Parameters:

mpo_model (MPOModel) – A model instance implementing the MPO. Does not need to be a NearestNeighborModel, but should only have nearest-neighbor couplings.

Examples

The SpinChainNNN2 has next-nearest-neighbor couplings and thus only implements an MPO:

>>> from tenpy.models.spins_nnn import SpinChainNNN2
>>> nnn_chain = SpinChainNNN2({'L': 20, 'sort_charge': True})
>>> print(isinstance(nnn_chain, NearestNeighborModel))
False
>>> print("range before grouping:", nnn_chain.H_MPO.max_range)
range before grouping: 2

By grouping each two neighboring sites, we can bring it down to nearest neighbors.

>>> grouped_sites = nnn_chain.group_sites(2)
>>> print("range after grouping:", nnn_chain.H_MPO.max_range)
range after grouping: 1

Yet, TEBD will not yet work, as the model doesn’t define H_bond. However, we can initialize a NearestNeighborModel from the MPO:

>>> nnn_chain_for_tebd = NearestNeighborModel.from_MPOModel(nnn_chain)
>>> isinstance(nnn_chain_for_tebd, NearestNeighborModel)
True
trivial_like_NNModel()[source]

Return a NearestNeighborModel with same lattice, but trivial (H=0) bonds.

bond_energies(psi)[source]

Calculate bond energies <psi|H_bond|psi>.

Parameters:

psi (MPS) – The MPS for which the bond energies should be calculated.

Returns:

E_bond – List of bond energies: for finite bc, E_Bond[i] is the energy of bond i, i+1. (i.e. we omit bond 0 between sites L-1 and 0); for infinite bc E_bond[i] is the energy of bond i-1, i.

Return type:

1D ndarray

extract_segment(*args, **kwargs)[source]

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

Parameters:
Returns:

cp – A shallow copy of self with MPO and lattice extracted for the segment.

Return type:

Model

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 x-direction in our convention, the lattice shape goes from (Lx, Ly, ..., Lu) to (Lx*factor, Ly, ..., Lu).

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

calc_H_MPO_from_bond(tol_zero=1e-15)[source]

Calculate the MPO Hamiltonian from the bond Hamiltonian.

Parameters:

tol_zero (float) – Arrays with norm < tol_zero are considered to be zero.

Returns:

H_MPO – MPO representation of the Hamiltonian.

Return type:

MPO

get_extra_default_measurements()[source]

Get list of model-dependent extra default measurements.

Extra measurements for a Simulation, which depend on the model itself - subclasses should override this method). E.g., a MPOModel should measure the energy w.r.t. the MPO (See m_energy_MPO()). However, a NearestNeighborModel should use the function m_bond_energies(). The extra measurements are added to the default measurements in _connect_measurements().

Returns:

m_extra_default_list

Return type:

list

copy()[source]

Shallow copy of self.

estimate_RAM_saving_factor()[source]

Returns the expected saving factor for RAM based on charge conservation.

Returns:

factor – saving factor, due to conservation

Return type:

int

Options

mem_saving_factor :: None | float

Quantizes the RAM saving, due to conservation laws, to be used by estimate_simulation_RAM(). By default it is 1/mod, or 1/4 in case of mod=1. However, for some classes this factor might be overwritten, if a better approximation is known. In the best case, the user can adjust this model parameter to enhance the estimate.

classmethod from_hdf5(hdf5_loader, h5gr, subpath)[source]

Load instance from a HDF5 file.

Same as from_hdf5(), but handle rng.

logger = <Logger tenpy.models.model.Model (WARNING)>

class attribute.

Type:

logging.Logger

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 time-dependence, you can/will otherwise end up generating a new disordered at each time-step!

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 handle rng.

update_time_parameter(new_time)[source]

Reconstruct Hamiltonian for time-dependent models, potentially (!) in-place.

For TimeDependentHAlgorithm, we assume that the model reads out the parameter self.options['time'], and reinitialize/update the model calling this method.

Parameters:

new_time (float) – Time at which the (time-dependent) Hamiltonian should be constructed.

Returns:

updated_model – Model of the same class as self with Hamiltonian at time new_time. Note that it can just be a reference to self if modified in place, or an entirely new constructed model.

Return type:

model