Sweep¶
full name: tenpy.algorithms.mps_sweeps.Sweep
parent module:
tenpy.algorithms.mps_sweeps
type: class
-
class
tenpy.algorithms.mps_sweeps.
Sweep
(psi, model, engine_params)[source]¶ Bases:
object
Prototype class for a ‘sweeping’ algorithm.
This is a superclass, intended to cover common procedures in all algorithms that ‘sweep’. This includes DMRG, TDVP, TEBD, etc. Only DMRG is currently implemented in this way.
- 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.
- engine_paramsdict
Further optional parameters. These are usually algorithm-specific, and thus should be described in subclasses.
- psi
- Attributes
- chi_listdict |
None
A dictionary to gradually increase the chi_max parameter of trunc_params. The key defines starting from which sweep chi_max is set to the value, e.g.
{0: 50, 20: 100}
useschi_max=50
for the first 20 sweeps andchi_max=100
afterwards. Overwrites trunc_params[‘chi_list’]`. By default (None
) this feature is disabled.- combinebool
Whether to combine legs into pipes as far as possible. This reduces the overhead of calculating charge combinations in the contractions. Makes the two-site DMRG engine equivalent to the old EngineCombine.
- E_trunc_listlist
List of truncation energies throughout a sweep.
- env
MPOEnvironment
Environment for contraction
<psi|H|psi>
.- finitebool
Whether the MPS boundary conditions are finite (True) or infinite (False)
- i0int
Only set during sweep. Left-most of the EffectiveH.length sites to be updated in
update_local()
.- lanczos_paramsdict
Parameters for the Lanczos algorithm.
- mixer
Mixer
|None
If
None
, no mixer is used (anymore), otherwise the mixer instance.- move_rightbool
Only set during sweep. Whether the next i0 of the sweep will be right or left of the current one.
- ortho_to_envslist of
MPSEnvironment
List of environments
<psi|psi_ortho>
, where psi_ortho is an MPS to orthogonalize against.- shelvebool
If a simulation runs out of time (time.time() - start_time > max_seconds), the run will terminate with shelve = True.
- sweepsint
The number of sweeps already performed. (Useful for re-start).
- time0float
Time marker for the start of the run.
- trunc_err_listlist
List of truncation errors.
- trunc_paramsdict
Parameters for truncations.
- update_LP_RP(bool, bool)
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
).- verbosebool | int
Level of verbosity (i.e. how much status information to print); higher=more output.
- chi_listdict |
Methods
environment_sweeps
(self, N_sweeps)Perform N_sweeps sweeps without optimization to update the environment.
get_sweep_schedule
(self)Define the schedule of the sweep.
init_env
(self[, model])(Re-)initialize the environment.
mixer_activate
(self)Set self.mixer to the class specified by engine_params[‘mixer’].
mixer_cleanup
(self)Cleanup the effects of a mixer.
post_update_local
(self, \*\*kwargs)Algorithm-specific actions to be taken after local update.
prepare_update
(self)Prepare everything algorithm-specific to perform a local update.
reset_stats
(self)Reset the statistics.
sweep
(self[, optimize, meas_E_trunc])One ‘sweep’ of a sweeper algorithm.
update_local
(self, theta, \*\*kwargs)Perform algorithm-specific local update.
-
init_env
(self, model=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.
- model
- Raises
- ValueError
If the engine is re-initialized with a new model, which legs are incompatible with those of hte old model.
-
reset_stats
(self)[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.
-
environment_sweeps
(self, N_sweeps)[source]¶ Perform N_sweeps sweeps without optimization to update the environment.
- Parameters
- N_sweepsint
Number of sweeps to run without optimization
-
sweep
(self, optimize=True, meas_E_trunc=False)[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
- optimizebool, optional
Whether we actually optimize to find the ground state of the effective Hamiltonian. (If False, just update the environments).
- meas_E_truncbool, optional
Whether to measure truncation energies.
- Returns
- max_trunc_errfloat
Maximal truncation error introduced.
- max_E_trunc
None
| float None
if meas_E_trunc is False, else the maximal change of the energy due to the truncation.
-
get_sweep_schedule
(self)[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
- scheduleiterable of (int, bool, (bool, bool))
Schedule for the sweep. Each entry is
(i0, move_right, (update_LP, update_RP))
, where i0 is the leftmost of theself.EffectiveH.length
sites to be updated inupdate_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.
-
mixer_cleanup
(self)[source]¶ Cleanup the effects of a mixer.
A
sweep()
with an enabledMixer
leaves the MPS psi with 2D arrays in S. To recover the originial form, this function simply performs one sweep with disabled mixer.