# Sweep¶

Inheritance Diagram

Methods

 Sweep.__init__(psi, model, options, *[, …]) Initialize self. Sweep.environment_sweeps(N_sweeps) Perform N_sweeps sweeps without optimization to update the environment. Return necessary data to resume a run() interrupted at a checkpoint. Define the schedule of the sweep. Sweep.init_env([model, resume_data, …]) (Re-)initialize the environment. Create new instance of self.EffectiveH at self.i0 and set it to self.eff_H. Sweep.post_update_local(update_data) Algorithm-specific actions to be taken after local update. Prepare everything algorithm-specific to perform a local update. Sweep.reset_stats([resume_data]) Reset the statistics. Resume a run that was interrupted. Actually run the algorithm. Sweep.sweep([optimize]) One ‘sweep’ of a sweeper algorithm. Sweep.update_LP(_) Sweep.update_RP(_) Sweep.update_local(theta, **kwargs) Perform algorithm-specific local update.

Class Attributes and Properties

 Sweep.engine_params Sweep.n_optimize the number of sites to be optimized over at once. Sweep.verbose
class tenpy.algorithms.mps_common.Sweep(psi, model, options, *, orthogonal_to=None, resume_data=None)[source]

Prototype class for a ‘sweeping’ algorithm.

This is a superclass, intended to cover common procedures in all algorithms that ‘sweep’. This includes DMRG, TDVP, etc.

Todo

TDVP is currently not implemented with the sweep class.

Parameters
• psi (MPS) – Initial guess for the ground state, which is to be optimized in-place.

• model (MPOModel) – The model representing the Hamiltonian for which we want to find the ground state.

• options (dict) – Further optional configuration parameters.

• resume_data (None | dict) – Can only be passed as keyword argument. By default (None) ignored. If a dict, it should contain the data returned by get_resume_data() when intending to continue/resume an interrupted run, in particular ‘init_env_data’.

• orthogonal_to (None | list of MPS) – States to orthogonalize against, see init_env().

Options

config Sweep
option summary

chi_list in Sweep.reset_stats

By default (None) this feature is disabled. [...]

combine

Whether to combine legs into pipes. This combines the virtual and [...]

init_env_data in DMRGEngine.init_env

Dictionary as returned by self.env.get_initialization_data() from [...]

lanczos_params

Lanczos parameters as described in :cfg:config:Lanczos.

orthogonal_to in DMRGEngine.init_env

Deprecated in favor of the orthogonal_to function argument (forwarded fro [...]

start_env in DMRGEngine.init_env

Number of sweeps to be performed without optimization to update [...]

sweep_0 in Sweep.reset_stats

Number of sweeps that have already been performed.

trunc_params (from Algorithm) in Algorithm

Truncation parameters as described in :cfg:config:truncation.

option combine: bool

Whether to combine legs into pipes. This combines the virtual and physical leg for the left site (when moving right) or right side (when moving left) into pipes. This reduces the overhead of calculating charge combinations in the contractions, but one matvec() is formally more expensive, $$O(2 d^3 \chi^3 D)$$.

option lanczos_params: dict

Lanczos parameters as described in Lanczos.

EffectiveH

Class attribute; a sublcass of EffectiveH. It’s length attribute determines how many sites are optimized/updated at once, see also n_optimize.

Type

class

options

Optional parameters.

Type

Config

E_trunc_list

List of truncation energies throughout a sweep.

Type

list

env

Environment for contraction <psi|H|psi>.

Type

MPOEnvironment

finite

Whether the MPS boundary conditions are finite (True) or infinite (False)

Type

bool

i0

Only set during sweep. Left-most of the EffectiveH.length sites to be updated in update_local().

Type

int

move_right

Only set during sweep. Whether the next i0 of the sweep will be right or left of the current one.

Type

bool

ortho_to_envs

List of environments <psi|psi_ortho>, where psi_ortho is an MPS to orthogonalize against.

Type

list of MPSEnvironment

shelve

If a simulation runs out of time (time.time() - start_time > max_seconds), the run will terminate with shelve = True.

Type

bool

sweeps

The number of sweeps already performed.

Type

int

time0

Time marker for the start of the run.

Type

float

trunc_err_list

List of truncation errors.

Type

list

update_LP_RP

Only set during a sweep. Whether it is necessary to update the LP and RP. The latter are chosen such that the environment is growing for infinite systems, but we only keep the minimal number of environment tensors in memory (inside env).

Type

(bool, bool)

chi_list

A dictionary to gradually increase the chi_max parameter of trunc_params. See Sweep.chi_list

Type

dict | None

get_resume_data()[source]

Return necessary data to resume a run() interrupted at a checkpoint.

At a checkpoint, you can save psi, model and options along with the data returned by this function. When the simulation aborts, you can resume it using this saved data with:

eng = AlgorithmClass(psi, model, options, resume_data=resume_data)
eng.resume_run()


An algorithm which doesn’t support this should override resume_run to raise an Error.

Returns

resume_data – Dictionary with necessary data (apart from copies of psi, model, options) that allows to continue the simulation from where we are now.

Return type

dict

property n_optimize

the number of sites to be optimized over at once.

Indirectly set by the class attribute EffectiveH and it’s length. For example, TwoSiteDMRGEngine uses the TwoSiteH and hence has n_optimize=2, while the SingleSiteDMRGEngine has n_optimize=1.

init_env(model=None, resume_data=None, orthogonal_to=None)[source]

(Re-)initialize the environment.

This function is useful to (re-)start a Sweep with a slightly different model or different (engine) parameters. Note that we assume that we still have the same psi. Calls reset_stats().

Parameters
• model (MPOModel) – The model representing the Hamiltonian for which we want to find the ground state. If None, keep the model used before.

• resume_data (None | dict) – Given when resuming a simulation, as returned by get_resume_data().

• orthogonal_to (None | list of MPS) – List of other matrix product states to orthogonalize against. Works only for finite or segment MPS; for infinite MPS it must be None. This can be used to find (a few) excited states as follows. First, run DMRG to find the ground state, and then run DMRG again while orthogonalizing against the ground state, which yields the first excited state (in the same symmetry sector), and so on. Note that resume_data[‘orthogonal_to’] takes precedence over the argument.

Options

Deprecated since version 0.6.0: Options LP, LP_age, RP and RP_age are now collected in a dictionary init_env_data with different keys init_LP, init_RP, age_LP, age_RP

Deprecated since version 0.8.0: Instead of passing the init_env_data as a option, it should be passed as dict entry of resume_data.

option Sweep.init_env_data: dict

Dictionary as returned by self.env.get_initialization_data() from get_initialization_data(). Deprecated.

option Sweep.orthogonal_to: list of MPS

Deprecated in favor of the orthogonal_to function argument (forwarded from the class argument) with the same effect.

option Sweep.start_env: int

Number of sweeps to be performed without optimization to update the environment.

Raises

ValueError – If the engine is re-initialized with a new model, which legs are incompatible with those of hte old model.

reset_stats(resume_data=None)[source]

Reset the statistics. Useful if you want to start a new Sweep run.

This method is expected to be overwritten by subclass, and should then define self.update_stats and self.sweep_stats dicts consistent with the statistics generated by the algorithm particular to that subclass.

option Sweep.sweep_0: int

Number of sweeps that have already been performed.

option Sweep.chi_list: None | dict(int -> int)

By default (None) this feature is disabled. A dict allows to gradually increase the chi_max. An entry at_sweep: chi states that starting from sweep at_sweep, the value chi is to be used for trunc_params['chi_max']. For example chi_list={0: 50, 20: 100} uses chi_max=50 for the first 20 sweeps and chi_max=100 afterwards.

environment_sweeps(N_sweeps)[source]

Perform N_sweeps sweeps without optimization to update the environment.

Parameters

N_sweeps (int) – Number of sweeps to run without optimization

sweep(optimize=True)[source]

One ‘sweep’ of a sweeper algorithm.

Iteratate over the bond which is optimized, to the right and then back to the left to the starting point. If optimize=False, don’t actually diagonalize the effective hamiltonian, but only update the environment.

Parameters

optimize (bool, optional) – Whether we actually optimize to find the ground state of the effective Hamiltonian. (If False, just update the environments).

Returns

max_trunc_err – Maximal truncation error introduced.

Return type

float

get_sweep_schedule()[source]

Define the schedule of the sweep.

One ‘sweep’ is a full sequence from the leftmost site to the right and back. Only those LP and RP that can be used later should be updated.

Returns

schedule – Schedule for the sweep. Each entry is (i0, move_right, (update_LP, update_RP)), where i0 is the leftmost of the self.EffectiveH.length sites to be updated in update_local(), move_right indicates whether the next i0 in the schedule is rigth (True) of the current one, and update_LP, update_RP indicate whether it is necessary to update the LP and RP. The latter are chosen such that the environment is growing for infinite systems, but we only keep the minimal number of environment tensors in memory.

Return type

iterable of (int, bool, (bool, bool))

prepare_update()[source]

Prepare everything algorithm-specific to perform a local update.

update_local(theta, **kwargs)[source]

Perform algorithm-specific local update.

post_update_local(update_data)[source]

Algorithm-specific actions to be taken after local update.

An example would be to collect statistics.

make_eff_H()[source]

Create new instance of self.EffectiveH at self.i0 and set it to self.eff_H.

resume_run()[source]

Resume a run that was interrupted.

In case we saved an intermediate result at a checkpoint, this function allows to resume the run() of the algorithm (after re-initialization with the resume_data). Since most algorithms just have a while loop with break conditions, the default behaviour implemented here is to just call run().

run()[source]

Actually run the algorithm.

Needs to be implemented in subclasses.