InitialStateBuilder
full name: tenpy.networks.mps.InitialStateBuilder
parent module:
tenpy.networks.mps
type: class
Inheritance Diagram
Methods
|
|
|
Ensure that the filling of the product state matches check_filling parameter. |
Assert that the given state has the expected charge. |
|
Initialize a trivial charge MPS with desired bond dimension. |
|
Allow to specify a condition where sites should be filled. |
|
Define the variables which can be used in the condition of |
|
Load the initial state from an existing file. |
|
|
Initialize from a lattice product state. |
|
Initialize from a product state. |
Initialize a state on a lattice already in a desired charge sector. |
|
Initialize a state with another method and then apply a RandomUnitaryEvolution. |
|
Build an initial state from a specified method. |
Class Attributes and Properties
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`.
charge_sector in InitialStateBuilder.mps_state_in_charge_sector
The `charge_sector` passed on to :meth:`MPS.project_onto_charge_sector`. [...]
check_filling in InitialStateBuilder.check_filling
The desired filling as float ``p/q``, or by a tuple ``(p, q)``. [...]
chi in InitialStateBuilder.desired_bond_dimension
The desired bond dimension passed on to :meth:`MPS.from_desired_bond_dimension`.
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". [...]
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 setmethod='lat_product_state'
to uselat_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 thelat
and MPO dtype. Let’s assume that we have a lattice lat withSpinHalfSite
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:
- 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
- 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()
.
- mps_state_in_charge_sector(charge_sector=None, p_state=None)[source]
Initialize a state on a lattice already in a desired charge sector.
See
MPS.project_onto_charge_sector()
for details.Options
- option InitialStateBuilder.charge_sector: tuple of int
The charge_sector passed on to
MPS.project_onto_charge_sector()
. Depending on the number of sites in a lattice, only specific charge sectors can be reached.
- option InitialStateBuilder.product_state: list | np.ndarray
Optional. A product_state as in
mps_product_state()
.
- desired_bond_dimension(chi=None)[source]
Initialize a trivial charge MPS with desired bond dimension.
See
MPS.from_desired_bond_dimension()
for details.Options
- option InitialStateBuilder.chi: int
The desired bond dimension passed on to
MPS.from_desired_bond_dimension()
.
- 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'
forlat_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.