# EngineFracture¶

Inheritance Diagram

Methods

 EngineFracture.__init__(psi, model, DMRG_params) Initialize self. EngineFracture.diag(theta_guess) Diagonalize the effective Hamiltonian represented by self. Perform N_sweeps sweeps without optimization to update the environment. Define the schedule of the sweep. EngineFracture.init_env([model]) (Re-)initialize the environment. Get (truncated) B from the new theta (as returned by diag). Set self.mixer to the class specified by engine_params[‘mixer’]. Cleanup the effects of a mixer. EngineFracture.plot_sweep_stats([axes, …]) Plot sweep_stats to display the convergence with the sweeps. EngineFracture.plot_update_stats(axes[, …]) Plot update_stats to display the convergence during the sweeps. EngineFracture.post_update_local(update_data) Perform post-update actions. Transform theta into matrix for svd. Prepare self to represent the effective Hamiltonian on sites (i0, i0+1). Reset the statistics, useful if you want to start a new sweep run. Run the DMRG simulation to find the ground state. EngineFracture.set_B(U, S, VH) Update the MPS with the U, S, VH returned by self.mixed_svd. EngineFracture.sweep([optimize, meas_E_trunc]) One ‘sweep’ of a sweeper algorithm. Update left part of the environment. Update right part of the environment. EngineFracture.update_local(theta[, …]) Perform bond-update on the sites (i0, i0+1).
class tenpy.algorithms.dmrg.EngineFracture(psi, model, DMRG_params)[source]

Engine which keeps the legs separate.

Due to a different contraction order in matvec(), this engine might be faster than EngineCombine, at least for large physical dimensions and if the MPO is sparse. One matvec() is $$O(2 \chi^3 d^2 W + 2 \chi^2 d^3 W^2 )$$.

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 on scipy.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 a SpinChain({'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 a SpinChain({'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_guess|theta_diag>)

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 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))

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. If None, keep the model used before.

Raises

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

mixed_svd(theta)[source]

Get (truncated) B from the new theta (as returned by diag).

The goal is to split theta and truncate it:

|   -- theta --   ==>    -- U -- S --  VH -
|      |   |                |          |


Without a mixer, this is done by a simple svd and truncation of Schmidt values.

With a mixer, the state is perturbed before the SVD. The details of the perturbation are defined by the Mixer class.

Note that the returned S is a general (not diagonal) matrix, with labels 'vL', 'vR'.

Parameters

theta (Array) – The optimized wave function, prepared for svd.

Returns

• U (Array) – Left-canonical part of theta. Labels '(vL.p0)', 'vR'.

• S (1D ndarray | 2D Array) – Without mixer just the singluar values of the array; with mixer it might be a general matrix with labels 'vL', 'vR'; see comment above.

• VH (Array) – Right-canonical part of theta. Labels 'vL', '(p1.vR)'.

• err (TruncationError) – The truncation error introduced.

mixer_activate()[source]

Set self.mixer to the class specified by engine_params[‘mixer’].

mixer_cleanup()[source]

Cleanup the effects of a mixer.

A sweep() with an enabled Mixer leaves the MPS psi with 2D arrays in S. To recover the originial form, this function simply performs one sweep with disabled mixer.

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 to matplotlib.pyplot.gca()

• yaxis (xaxis,) – Key of sweep_stats to be used for the x-axis and y-axis of the plots.

• y_exact (float) – Exact value for the quantity on the y-axis for comparison. If given, plot abs((y-y_exact)/y_exact) on a log-scale yaxis.

• **kwargs – Further keyword arguments given to axes.plot(...).

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 to matplotlib.pyplot.gca()

• xaxis ('N_updates' | 'sweep' | keys of update_stats) – Key of update_stats to be used for the x-axis 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 of update_stats) – Key of update_stats to be used for the y-axisof the plots. For ‘E’, use the energy (per site for infinite systems).

• y_exact (float) – Exact value for the quantity on the y-axis for comparison. If given, plot abs((y-y_exact)/y_exact) on a log-scale yaxis.

• **kwargs – Further keyword arguments given to axes.plot(...).

post_update_local(update_data, meas_E_trunc=False)[source]

Perform post-update actions.

Compute truncation energy, remove LP/RP that are no longer needed and collect statistics.

Parameters
• update_data (dict) – Data computed during the local update, as described in the following list.

• meas_E_trunc (bool, optional) – Wheter to measure the energy after truncation.

prepare_svd(theta)[source]

Transform theta into matrix for svd.

prepare_update()[source]

Prepare self to represent the effective Hamiltonian on sites (i0, i0+1).

Returns

theta – Current best guess for the ground state, which is to be optimized. Labels 'vL', 'p0', 'vR', 'p1'.

Return type

Array

reset_stats()[source]

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

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 to psi.

set_B(U, S, VH)[source]

Update the MPS with the U, S, VH returned by self.mixed_svd.

Parameters
• VH (U,) – Left and Right-canonical matrices as returned by the SVD.

• S (1D array | 2D Array) – The middle part returned by the SVD, theta = U S VH. Without a mixer just the singular values, with enabled mixer a 2D array.

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
• optimize (bool, optional) – Whether we actually optimize to find the ground state of the effective Hamiltonian. (If False, just update the environments).

• meas_E_trunc (bool, optional) – Whether to measure truncation energies.

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.

update_LP(U)[source]

Update left part of the environment.

We always update the environment at site i0 + 1: this environment then contains the site where we just performed a local update (when sweeping right).

Parameters

U (Array) – The U as returned by the SVD, with combined legs, labels 'vL.p0', 'vR'.

update_RP(VH)[source]

Update right part of the environment.

We always update the environment at site i0: this environment then contains the site where we just performed a local update (when sweeping left).

Parameters

VH (Array) – The VH as returned by SVD, with combined legs, labels 'vL', '(vR.p1)'.

update_local(theta, optimize=True, meas_E_trunc=False)[source]

Perform bond-update on the sites (i0, i0+1).

Parameters
• theta (Array) – Initial guess for the ground state of the effective Hamiltonian.

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

• meas_E_trunc (bool) – Wheter to measure the energy after truncation.

Returns

update_data – Data computed during the local update, as described in the following:

E0float

Total energy, obtained before truncation (if optimize=True), or after truncation (if optimize=False) (but never None).

Nint

Dimension of the Krylov space used for optimization in the lanczos algorithm. 0 if optimize=False.

ageint

Current size of the DMRG simulation: number of physical sites involved into the contraction.

U, VH: Array

U and VH returned by mixed_svd().

ov_change: float

Change in the wave function 1. - abs(<theta_guess|theta>) induced by diag(), not including the truncation!

Return type

dict