DMRGEngine¶
full name: tenpy.algorithms.dmrg.DMRGEngine
parent module:
tenpy.algorithms.dmrg
type: class
Inheritance Diagram
Methods

Initialize self. 

Diagonalize the effective Hamiltonian represented by self. 

Perform N_sweeps sweeps without optimization to update the environment. 
Define the schedule of the sweep. 


(Re)initialize the environment. 
Set self.mixer to the class specified by engine_params[‘mixer’]. 

Cleanup the effects of a mixer. 


Plot 

Plot 

Perform postupdate actions. 
Prepare everything algorithmspecific to perform a local update. 

Reset the statistics, useful if you want to start a new sweep run. 

Run the DMRG simulation to find the ground state. 


One ‘sweep’ of a sweeper algorithm. 

Perform algorithmspecific local update. 

class
tenpy.algorithms.dmrg.
DMRGEngine
(psi, model, engine_params)[source]¶ Bases:
tenpy.algorithms.mps_sweeps.Sweep
Generic ‘Engine’ for the singlesite DMRG algorithm.
This engine is implemented as a subclass of
Sweep
. It contains all methods that are generic betweenSingleSiteDMRGEngine
andTwoSiteDMRGEngine
. Parameters
psi (
MPS
) – Initial guess for the ground state, which is to be optimized inplace.model (
MPOModel
) – The model representing the Hamiltonian for which we want to find the ground state.engine_params (dict) – Further optional parameters. These are usually algorithmspecific, and thus should be described in subclasses.

EffectiveH
¶ Class for the effective Hamiltonian (i.e., a subclass of
EffectiveH
. Has a length class attribute which specifies the number of sites updated at once (e.g., whether we do singlesite vs. twosite DMRG). Type
class type

chi_list
¶ 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. Type
dict 
None

eff_H
¶ Effective twosite Hamiltonian.
 Type

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

update_stats
¶ A dictionary with detailed statistics of the convergence at local updatelevel. For each key in the following table, the dictionary contains a list where one value is added each time
DMRGEngine.update_bond()
is called.key
description
i0
An update was performed on sites
i0, i0+1
.age
The number of physical sites involved in the simulation.
E_total
The total energy before truncation.
N_lanczos
Dimension of the Krylov space used in the lanczos diagonalization.
time
Wallclock time evolved since
time0
(in seconds).ov_change
1.  abs(<theta_guesstheta_diag>)
, wheretheta_guess>
is the initial guess for the wave function andtheta_diag>
is the untruncated wave function returned bydiag()
. Type

sweep_stats
¶ A dictionary with detailed statistics at the sweep level. For each key in the following table, the dictionary contains a list where one value is added each time
Engine.sweep()
is called (withoptimize=True
).key
description
sweep
Number of sweeps (excluding environment sweeps) performed so far.
N_updates
Number of updates (including environment sweeps) performed so far.
E
The energy before truncation (as calculated by Lanczos).
S
Maximum entanglement entropy.
time
Wallclock time evolved since
time0
(in seconds).max_trunc_err
The maximum truncation error in the last sweep
max_E_trunc
Maximum change or Energy due to truncation in the last sweep.
max_chi
Maximum bond dimension used.
norm_err
Error of canonical form
np.linalg.norm(psi.norm_test())
. Type

run
()[source]¶ Run the DMRG simulation to find the ground state.
 Returns
E (float) – The energy of the resulting ground state MPS.
psi (
MPS
) – The MPS representing the ground state after the simluation, i.e. just a reference topsi
.

post_update_local
(update_data, meas_E_trunc=False)[source]¶ Perform postupdate actions.
Compute truncation energy, remove LP/RP that are no longer needed and collect statistics.

diag
(theta_guess)[source]¶ Diagonalize the effective Hamiltonian represented by self.
The method used depends on the DMRG parameter diag_method.
diag_method
Function, comment
‘default’
Same as
'lanczos'
for large bond dimensions, but if the total dimension of the effective Hamiltonian does not exceed the DMRG parameter'max_N_for_ED'
it uses'ED_block'
.‘lanczos’
lanczos()
Default, the Lanczos implementation in TeNPy.‘arpack’
lanczos_arpack()
Based onscipy.linalg.sparse.eigsh()
. Slower than ‘lanczos’, since it needs to convert the npc arrays to numpy arrays during each matvec, and possibly does many more iterations.‘ED_block’
full_diag_effH()
Contract the effective Hamiltonian to a (large!) matrix and diagonalize the block in the charge sector of the initial state. Preserves the charge sector of the explicitly conserved charges. However, if you don’t preserve a charge explicitly, it can break it. For example if you use aSpinChain({'conserve': 'parity'})
, it could change the total “Sz”, but not the parity of ‘Sz’.‘ED_all’
full_diag_effH()
Contract the effective Hamiltonian to a (large!) matrix and diagonalize it completely. Allows to change the charge sector even for explicitly conserved charges. For example if you use aSpinChain({'conserve': 'Sz'})
, it can change the total “Sz”. Parameters
theta_guess (
Array
) – Initial guess for the ground state of the effective Hamiltonian. Returns
E0 (float) – Energy of the found ground state.
theta (
Array
) – Ground state of the effective Hamiltonian.N (int) – Number of Lanczos iterations used.
1
if unknown.ov_change (float) – Change in the wave function
1.  abs(<theta_guesstheta_diag>)

plot_update_stats
(axes, xaxis='time', yaxis='E', y_exact=None, **kwargs)[source]¶ Plot
update_stats
to display the convergence during the sweeps. Parameters
axes (
matplotlib.axes.Axes
) – The axes to plot into. Defaults tomatplotlib.pyplot.gca()
xaxis (
'N_updates'  'sweep'
 keys ofupdate_stats
) – Key ofupdate_stats
to be used for the xaxis of the plots.'N_updates'
is just enumerating the number of bond updates, and'sweep'
corresponds to the sweep number (including environment sweeps).yaxis (
'E'
 keys ofupdate_stats
) – Key ofupdate_stats
to be used for the yaxisof the plots. For ‘E’, use the energy (per site for infinite systems).y_exact (float) – Exact value for the quantity on the yaxis for comparison. If given, plot
abs((yy_exact)/y_exact)
on a logscale yaxis.**kwargs – Further keyword arguments given to
axes.plot(...)
.

plot_sweep_stats
(axes=None, xaxis='time', yaxis='E', y_exact=None, **kwargs)[source]¶ Plot
sweep_stats
to display the convergence with the sweeps. Parameters
axes (
matplotlib.axes.Axes
) – The axes to plot into. Defaults tomatplotlib.pyplot.gca()
yaxis (xaxis,) – Key of
sweep_stats
to be used for the xaxis and yaxis of the plots.y_exact (float) – Exact value for the quantity on the yaxis for comparison. If given, plot
abs((yy_exact)/y_exact)
on a logscale yaxis.**kwargs – Further keyword arguments given to
axes.plot(...)
.

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

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 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. Return type

init_env
(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. IfNone
, keep the model used before. Raises
ValueError – If the engine is reinitialized with a new model, which legs are incompatible with those of hte old model.

mixer_activate
()[source]¶ Set self.mixer to the class specified by engine_params[‘mixer’].
It is expected that different algorithms have differen ways of implementing mixers (with different defaults). Thus, this is algorithmspecific.

mixer_cleanup
()[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.

sweep
(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
 Returns
max_trunc_err (float) – 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.