InitialStateBuilder

  • full name: tenpy.networks.mps.InitialStateBuilder

  • parent module: tenpy.networks.mps

  • type: class

Inheritance Diagram

Inheritance diagram of tenpy.networks.mps.InitialStateBuilder

Methods

InitialStateBuilder.__init__(lattice, options)

InitialStateBuilder.check_filling(p_state)

Ensure that the filling of the product state matches check_filling parameter.

InitialStateBuilder.check_total_charge(psi)

Assert that the given state has the expected charge.

InitialStateBuilder.fill_where()

Allow to specify a condition where sites should be filled.

InitialStateBuilder.fill_where__get_variables()

Define the variables which can be used in the condition of fill_where().

InitialStateBuilder.from_file()

Load the initial state from an existing file.

InitialStateBuilder.lat_product_state([p_state])

Initialize from a lattice product state.

InitialStateBuilder.mps_product_state([p_state])

Initialize from a product state.

InitialStateBuilder.randomized()

Initialize a state with another method and then apply a RandomUnitaryEvolution.

InitialStateBuilder.run()

Build an initial state from a specified method.

Class Attributes and Properties

InitialStateBuilder.logger

class attribute.

class tenpy.networks.mps.InitialStateBuilder(lattice, options, model_dtype=<class 'numpy.float64'>)[source]

Bases: object

Class to simplify providing common sets of initial states.

This class is used by the Simulation to initialize MPS. The idea is that you can fully specify the initial state by a few parameters and possibly a custom function (by inheriting from this class), as demonstrated in the examples below.

Parameters:
  • lattice (Lattice) – The lattice class defining the geometry and sites.

  • options (dict) – Parameter dictionary which specifies the initial state to be generated.

  • model_dtype (numpy.dtype) – Data type of the model hamiltonian, default for the dtype of the resulting psi.

Options

config InitialStateBuilder
option summary

allow_incommensurate in InitialStateBuilder.lat_product_state

See :meth:`MPS.from_lat_product_state`.

check_filling in InitialStateBuilder.check_filling

The desired filling as float ``p/q``, or by a tuple ``(p, q)``. [...]

data_key in InitialStateBuilder.from_file

Key within the file to be used for loading the data. [...]

filename in InitialStateBuilder.from_file

The filename from which to load the state

fill_where in InitialStateBuilder.fill_where

A string specifying the condition where to fill sites. [...]

full_empty in InitialStateBuilder.check_filling

Definition of which local states are "full" and "empty". [...]

method

Selects the category of the initial state, and in particular the [...]

product_state in InitialStateBuilder.lat_product_state

The `p_state` passed on to :meth:`MPS.from_lat_product_state`.

randomize_canonicalize in InitialStateBuilder.randomized

Whether to call :meth:`MPS.canonical_form` before returning the state.

randomize_params in InitialStateBuilder.randomized

Parameters given to the :class:`~tenpy.algorithms.tebd.RandomUnitaryEvoluti [...]

randomized_from_method in InitialStateBuilder.randomized

Selects another method to initialize the starting state to be randomized, [...]

option method: str

Selects the category of the initial state, and in particular the name of the method called by build() to generate the state, for example you can set method='lat_product_state' to use lat_product_state(). The available other parameters depend on the chosen method.

Examples

If you use the Simulation setup, it will extract the lattice and model_dtype from the lat and MPO dtype. Let’s assume that we have a lattice lat with SpinHalfSite on a square lattices. Then you could initialize a Neel state like this:

>>> options = {'method': 'lat_product_state',
...            'product_state' : [[['up'], ['down']],
...                               [['down'], ['up']]],
...            }
>>> psi = InitialStateBuilder(lat, options).run()

Note that the method options is mandatory, it selects which other method run() calls. This allows to define custom initial states with the same interface by defining your own subclass, e.g. to get a short-hand for the Neel state:

>>> class MyInitialStateBuilderForSquare(InitialStateBuilder):
...     def neel(self):
...         # my_option = self.options.get('opt_name', default) # not necessary here
...         product_state = [[['up'], ['down']], [['down'], ['up']]]
...         return self.lat_product_state(product_state)
>>> options = {'method': 'neel'}
>>> psi = MyInitialStateBuilderForSquare(lat, options).run()

If you define such a custom class, you can activate it in simulations by explicitly setting the Simulation.initial_state_builder_class to the name of it.

logger = <Logger tenpy.networks.mps.InitialStateBuilder (WARNING)>

class attribute.

Type:

logger

Type:

An instance of a logger; see Logging and terminal output. NB

run()[source]

Build an initial state from a specified method.

Reads out the option InitialStateBuilder.method to choose a method of the class which generates the state.

Returns:

psi – The generated MPS.

Return type:

MPS

check_total_charge(psi)[source]

Assert that the given state has the expected charge.

Parameters:
  • psi (MPS) – The final, generated state.

  • cfg (..) –

    check_total_chargetuple of int

    Check that the MPS.get_total_charge() returns these values.

from_file()[source]

Load the initial state from an existing file.

Options

option InitialStateBuilder.filename: str

The filename from which to load the state

option InitialStateBuilder.data_key: str

Key within the file to be used for loading the data. Can be recursive (separated by ‘/’), see tenpy.tools.misc.get_recursive().

lat_product_state(p_state=None)[source]

Initialize from a lattice product state.

See MPS.from_lat_product_state() for details.

Options

option InitialStateBuilder.product_state: array of str

The p_state passed on to MPS.from_lat_product_state().

option InitialStateBuilder.allow_incommensurate: bool

See MPS.from_lat_product_state().

mps_product_state(p_state=None)[source]

Initialize from a product state.

See MPS.from_product_state() for details.

Options

option InitialStateBuilder.product_state: list of str

The p_state passed on to MPS.from_product_state().

check_filling(p_state)[source]

Ensure that the filling of the product state matches check_filling parameter.

Options

option InitialStateBuilder.check_filling: None | (int, int) or float

The desired filling as float p/q, or by a tuple (p, q). None (default) disables the check.

option InitialStateBuilder.full_empty: (str, str)

Definition of which local states are “full” and “empty”. For example you can use full_empty=('up', 'down') if you have spin sites.

fill_where()[source]

Allow to specify a condition where sites should be filled.

Warning

The fill_where string is parsed with the python function eval; this is unsafe if the variable comes from an untrusted source (e.g. the internet).

Options

option InitialStateBuilder.fill_where: str

A string specifying the condition where to fill sites. See examples in fill_where().

option InitialStateBuilder.full_empty: (str, str)

Definition of which local states are “full” and “empty”. For example you can use full_empty=('up', 'down') if you have spin sites.

Examples

Possible variables for conditions are specified in fill_where__get_variables(), for example x_ind, y_ind, u_ind.

You can do arbitrary logical expressions. Example conditions: - "x_ind == 0" - "AND(x_ind == 0, y_ind == 0)" - "AND(x_ind == 0, IN(y_ind, [0, 2])" - "WITHIN(x_ind, 0.25*Lx, 0.75*Lx )" # 0.25*Lx <= x <= 0.75&Lx

fill_where__get_variables()[source]

Define the variables which can be used in the condition of fill_where().

Here, the following variables get defined.

x_ind, y_ind, u_indint

Lattice indices of the

epsfloat

Cutoff 1.e-12 that can get used when it is necessary to compare floats

np :

Numpy module, allowing to use any function from numpy.

AND, OR, XOR, NOT, ANY, ALL, CLOSE, EQUAL, IN, WITHIN

Function aliases to allow logical combinations. Use for example as AND(x_ind == 0, IN(y_ind, [0, 2, 5])).

randomized()[source]

Initialize a state with another method and then apply a RandomUnitaryEvolution.

Options

option InitialStateBuilder.randomized_from_method: str

Selects another method to initialize the starting state to be randomized, e.g., 'lat_product_state' for lat_product_state().

option InitialStateBuilder.randomize_params: dict-like

Parameters given to the RandomUnitaryEvolution. In particular, you might want to set the N_steps and trunc_params[‘chi_max’]. The default is {'N_steps': 10, 'trunc_params': {'chi_max': max(100, max(psi.chi))}}.

option InitialStateBuilder.randomize_canonicalize: bool

Whether to call MPS.canonical_form() before returning the state.