quimb.tensor.tnag.tebd

Tools for performing TEBD like algorithms on arbitrary lattices.

Classes

TrotterGate

A single local gate within a Trotterized product formula, as generated

LocalHamGen

Representation of a local hamiltonian defined on a general graph. This

TEBDSweepMixin

Generic class for performing time evolving block decimation on an

ComputeEnergyMixin

ComputeEnergyClusterMixin

Mixin class to add basic cluster energy computation to TEBD like

GateBasicMixin

GateSimpleUpdateMixin

Mixin class to use simple update style gating, with separately

TEBDGen

Basic arbitrary geometry TEBD class, combining the basic gate

SimpleUpdateGen

Simple update for arbitrary geometry hamiltonians, storing gauges

Functions

edge_coloring(edges[, strategy, interchange, group])

Generate an edge coloring for the graph given by edges, using

trotter_schedule(nlayers[, order])

Get the sequence of layer applications making up a single Trotter step

Module Contents

quimb.tensor.tnag.tebd.edge_coloring(edges, strategy='smallest_last', interchange=True, group=True)[source]

Generate an edge coloring for the graph given by edges, using networkx.coloring.greedy_color.

Parameters:
  • edges (sequence[tuple[hashable, hashable]]) – The edges of the graph.

  • strategy (str or callable, optional) –

    The strategy to use for coloring the edges. Can be:

    • ’largest_first’

    • ’smallest_last’

    • ’random_sequential’

  • interchange (bool, optional) – Whether to use the interchange heuristic. Usually generates better colorings but can be slower.

  • group (bool, optional) – Whether to group the edges by color or return a flat list.

quimb.tensor.tnag.tebd.trotter_schedule(nlayers, order=2)[source]

Get the sequence of layer applications making up a single Trotter step of a product formula of the given order, for a hamiltonian split into nlayers groups of commuting terms.

Parameters:
  • nlayers (int) – The number of commuting layers the hamiltonian is split into.

  • order ({2, 1, 4}, optional) – The order of the product formula. Order 1 applies each layer once, order 2 is the symmetric (palindromic) formula, and order 4 the standard Suzuki recursion built from five order 2 steps.

Returns:

Pairs of layer index and the fraction of the overall exponent to apply that layer with, in the order they should be applied.

Return type:

list[tuple[int, float]]

Examples

>>> trotter_schedule(2, order=2)
[(0, 0.5), (1, 1.0), (0, 0.5)]
class quimb.tensor.tnag.tebd.TrotterGate(U, where, frac, layer, step)[source]

A single local gate within a Trotterized product formula, as generated by LocalHamGen.get_trotter_gates(). It unpacks as the pair U, where, matching the argument order of the gate application methods, so that for U, where in gates: psi.gate_(U, where) works. The remaining information is available as attributes.

U

The gate itself, expm(frac * x * H_where).

Type:

array

where

The sites the gate acts on.

Type:

tuple[node]

frac

The fraction of the overall exponent x this gate applies.

Type:

float

layer

Which layer of the sequence this gate belongs to. Gates sharing a layer act on disjoint sites and commute.

Type:

int

step

Which Trotter step this gate belongs to. A gate fused across a step boundary is labelled with the earlier step.

Type:

int

__slots__ = ('U', 'frac', 'layer', 'step', 'where')
U
where
frac
layer
step
__iter__()[source]
__repr__()[source]
class quimb.tensor.tnag.tebd.LocalHamGen(H2, H1=None)[source]

Representation of a local hamiltonian defined on a general graph. This combines all two site and one site terms into a single interaction per lattice pair, and caches operations on the terms such as getting their exponential. The sites (nodes) should be hashable and comparable.

Parameters:
  • H2 (dict[tuple[node], array_like]) – The interaction terms, with each key being an tuple of nodes defining an edge and each value the local hamilotonian term for those two nodes.

  • H1 (array_like or dict[node, array_like], optional) – The one site term(s). If a single array is given, assume to be the default onsite term for all terms. If a dict is supplied, the keys should represent specific coordinates like (i, j) with the values the array representing the local term for that site. A default term for all remaining sites can still be supplied with the key None.

terms

The total effective local term for each interaction (with single site terms appropriately absorbed). Each key is a pair of coordinates site_a, site_b with site_a < site_b.

Type:

dict[tuple, array_like]

_op_cache
terms
sites
_sites_to_covering_terms
property nsites

The number of sites in the system.

keys()[source]

Iterate over all terms in the hamiltonian. This is mostly for convenient compatibility with compute_local_expectation.

values()[source]

Iterate over all terms in the hamiltonian. This is mostly for convenient compatibility with compute_local_expectation.

items()[source]

Iterate over all terms in the hamiltonian. This is mostly for convenient compatibility with compute_local_expectation.

__iter__()[source]

Iterate over all terms in the hamiltonian. This is mostly for convenient compatibility with compute_local_expectation.

_convert_from_qarray_cached(x)[source]
_flip_cached(x)[source]
_add_cached(x, y)[source]
_div_cached(x, y)[source]
_op_id_cached(x)[source]
_id_op_cached(x)[source]
_expm_cached(G, x)[source]
get_gate(where)[source]

Get the local term for pair where, cached.

get_gate_expm(where, x)[source]

Get the local term for pair where, matrix exponentiated by x, and cached.

apply_to_arrays(fn)[source]

Apply the function fn to all the arrays representing terms.

get_auto_ordering(order='sort', group=False, **kwargs)[source]

Get an ordering of the terms to use with TEBD, for example. The default is to sort the coordinates then greedily group them into commuting sets.

Parameters:
  • order ({'sort', None, 'random', str}) –

    How to order the terms before greedily grouping them into commuting (non-coordinate overlapping) sets:

    • 'sort' will sort the coordinate pairs first.

    • None will use the current order of terms which should match the order they were supplied to this LocalHam2D instance.

    • 'random' will randomly shuffle the coordinate pairs before grouping them - not the same as returning a completely random order.

    • 'random-ungrouped' will randomly shuffle the coordinate pairs but not group them at all with respect to commutation. With group=True the shuffled pairs are aggregated only with commuting neighbors.

    Any other option will be passed as a strategy to networkx.coloring.greedy_color() to generate the ordering.

  • group (bool, optional) – If True, return a list of commuting layers (tuples of pairs), otherwise return a flat list of pairs.

Returns:

Sequence of coordinate pairs, or of layers of pairs if group.

Return type:

list[tuple[node]] or list[tuple[tuple[node]]]

get_trotter_gates(x, order=2, steps=1, ordering='sort', fuse_adjacent=True, alternate=True)[source]

Get the sequence of local gates for a Trotter approximation to \(\exp(x H)\) of the given order, repeated steps times. The terms are grouped into layers of commuting (non site overlapping) gates, then each layer is exponentiated for the fraction of x the product formula calls for.

Parameters:
  • x (float or complex) – The overall exponent, such that the sequence approximates expm(x * H). Note this does not include the imaginary prefactor of the Schrodinger equation, so real x corresponds to imaginary time evolution, and x = -1j * t to real time.

  • order ({2, 1, 4}, optional) – The order of the product formula. Order 1 applies each layer once per step, order 2 is the symmetric (palindromic) formula, and order 4 the standard Suzuki recursion built from five order 2 steps.

  • steps (int, optional) – How many Trotter steps to generate, each of exponent x. Note the total exponent is thus steps * x.

  • ordering (str, None or sequence[sequence[tuple[node]]], optional) – How to group the terms into commuting layers. A string or None is passed to get_auto_ordering(), else an explicit sequence of layers of pairs can be given.

  • fuse_adjacent (bool, optional) – Whether to merge consecutive applications of the same layer into a single gate. For order 2 this means the half layers appear only at the very start and end of the whole sequence, rather than at every step boundary. The merged gate is taken directly from the cached local exponential at the summed fraction, not by multiplying the two separate gates.

  • alternate (bool, optional) – Whether to flip the direction the pairs within each layer are iterated over, every other layer. Gates within a layer commute so this changes nothing numerically, but it keeps, for example, an MPS canonical center sweeping back and forth rather than jumping back each layer.

Returns:

Each gate unpacks as the pair U, where, with frac, layer and step available as attributes.

Return type:

tuple[TrotterGate]

Examples

Real time evolve an MPS by t = 1.0 in 100 steps:

>>> import quimb as qu
>>> import quimb.tensor as qtn
>>> H = qtn.LocalHam1D(L=16, H2=qu.ham_heis(2))
>>> psi = qtn.MPS_neel_state(16, dtype=complex)
>>> for U, where in H.get_trotter_gates(-1j * 0.01, steps=100):
...     psi.gate_split_(U, where, cutoff=1e-8)
__repr__()[source]
draw(ordering='sort', show_norm=True, figsize=None, fontsize=8, legend=True, ax=None, **kwargs)[source]

Plot this Hamiltonian as a network.

Parameters:
  • ordering ({'sort', None, 'random'}, optional) – An ordering of the termns, or an argument to be supplied to quimb.tensor.tnag.tebd.LocalHamGen.get_auto_ordering() to generate this automatically.

  • show_norm (bool, optional) – Show the norm of each term as edge labels.

  • figsize (None or tuple[int], optional) – Size of the figure, defaults to size of Hamiltonian.

  • fontsize (int, optional) – Font size for norm labels.

  • legend (bool, optional) – Whether to show the legend of which terms are in which group.

  • ax (None or matplotlib.Axes, optional) – Add to a existing set of axes.

graph[source]
class quimb.tensor.tnag.tebd.TEBDSweepMixin[source]

Generic class for performing time evolving block decimation on an arbitrary graph, i.e. applying the exponential of a Hamiltonian using a product formula that involves applying local exponentiated gates only. The gate and energy computation methods should be provided via other mixins to create different algorithms.

setup_sweep_opts(psi0: quimb.tensor.tnag.core.TensorNetworkGenVector, ham: LocalHamGen, tau=0.01, imag=True, ordering=None, second_order_reflect=False, tol=None, tol_energy_diff=None, callback=None, keep_best=False, plot_every=None, progbar=True)[source]
property state

Return a copy of the current state.

property n

The number of sweeps performed.

property D

The maximum bond dimension.

property ordering
sweep(tau)[source]

Perform a full sweep of gates at every pair.

\[\psi \rightarrow \prod_{\{ij\}} \exp(-\tau H_{ij}) \psi\]
_set_progbar_description(pbar)[source]
evolve(steps, tau=None, progbar=None)[source]

Evolve the state with the local Hamiltonian for steps steps with time step tau.

presweep()[source]

Perform any computations required before the sweep (and energy computation). For the basic update is nothing.

postgate(where)[source]

Perform any computations required after each gate. For the basic update this is nothing.

postlayer()[source]

Perform any computations required after each layer of commuting gates. For the basic update this is nothing.

postsweep()[source]

Perform any computations required after the sweep (but before the energy computation).

assemble_plot_data()[source]
plot(**kwargs)[source]

Plot an overview of the evolution of the energy and gauge diffs.

Parameters:
  • zoom (int or 'auto', optional) – The number of iterations to zoom in on, or ‘auto’ to automatically choose a reasonable zoom level.

  • figsize (tuple, optional) – The size of the figure.

Returns:

fig, axs

Return type:

matplotlib.Figure, tuple[matplotlib.Axes]

_get_repr_info()[source]
__repr__()[source]
class quimb.tensor.tnag.tebd.ComputeEnergyMixin[source]
setup_energy_opts(compute_energy_every=None, compute_energy_final=True, compute_energy_opts=None, compute_energy_fn=None, compute_energy_per_site=False)[source]
_check_energy()[source]

Logic for maybe computing the energy if needed.

property energy

Return the energy of current state, computing it only if necessary.

class quimb.tensor.tnag.tebd.ComputeEnergyClusterMixin[source]

Bases: ComputeEnergyMixin

Mixin class to add basic cluster energy computation to TEBD like classes, that works for arbitrary geometries.

compute_energy()[source]

Compute and return the energy of the current state using cluster methods.

class quimb.tensor.tnag.tebd.GateBasicMixin[source]
setup_gate_opts(D=None, cutoff=1e-10, gate_opts=None)[source]
gate(U, where)[source]

Perform single gate U at coordinate pair where. This is the the most common method to override.

get_state() quimb.tensor.tnag.core.TensorNetworkGenVector[source]

The default method for retrieving the current state - simply a copy. Subclasses can override this to perform additional transformations.

set_state(psi: quimb.tensor.tnag.core.TensorNetworkGenVector)[source]

The default method for setting the current state - simply a copy. Subclasses can override this to perform additional transformations.

class quimb.tensor.tnag.tebd.GateSimpleUpdateMixin[source]

Mixin class to use simple update style gating, with separately maintained gauges living on the bonds, which are optionally equilibrated periodically.

setup_gate_opts(D=None, cutoff=1e-10, gate_opts=None, gauge_smudge=1e-06, equilibrate_every=None, equilibrate_start=True, equilibrate_opts=None, gauge_diff_period=None, update='sequential')[source]
property gauges

Return a copy of the current gauges.

set_state(psi: quimb.tensor.tnag.core.TensorNetworkGenVector, gauges=None)[source]

Set the current state and possibly the gauges.

get_state(absorb_gauges=True)[source]

Return the current state, possibly absorbing the gauges.

Parameters:

absorb_gauges (bool or "return", optional) – Whether to absorb the gauges into the state or not. If True, a standard PEPS is returned with the gauges absorbed. If False`, the gauges are added to the tensor network but uncontracted. If “return”, the gauges are returned separately.

Returns:

  • psi (TensorNetwork) – The current state.

  • gauges (dict) – The current gauges, if absorb_gauges == "return".

gate(G, where)[source]

Application of a single gate G at where.

normalize()[source]

Normalize the state and simple gauges.

equilibrate(**kwargs)[source]

Equilibrate the gauges with the current state (like evolving with tau=0).

postgate(where)[source]
postlayer()[source]

Performed after each layer of commuting gates.

postsweep()[source]

Performed after every full sweep.

assemble_plot_data()[source]
class quimb.tensor.tnag.tebd.TEBDGen(psi0: quimb.tensor.tnag.core.TensorNetworkGenVector, ham: LocalHamGen, tau=0.01, D=None, cutoff=1e-10, imag=True, gate_opts=None, ordering=None, second_order_reflect=False, compute_energy_every=None, compute_energy_final=True, compute_energy_opts=None, compute_energy_fn=None, compute_energy_per_site=False, tol=None, tol_energy_diff=None, callback=None, keep_best=False, plot_every=None, progbar=True)[source]

Bases: ComputeEnergyClusterMixin, GateBasicMixin, TEBDSweepMixin

Basic arbitrary geometry TEBD class, combining the basic gate application with cluster energy computation. This basic version might not perform very well and instead should be customized (either via gate_opts or via subclassing) for better performance.

Parameters:
  • psi0 (TensorNetworkGenVector) – The initial state.

  • ham (LocalHamGen) – The local hamiltonian.

  • tau (float, optional) – The default time step to use.

  • D (int, optional) – The maximum bond dimension, by default the current maximum bond of psi0.

  • cutoff (float, optional) – The singular value cutoff to use when applying gates.

  • imag (bool, optional) – Whether to evolve in imaginary time (default) or real time.

  • gate_opts (dict, optional) – Other options to supply to the gate application method, quimb.tensor.tnag.core.TensorNetworkGenVector.gate_().

  • ordering (None, str or callable, optional) – The ordering of the terms to apply, by default this will be determined automatically. It can be a string to be supplied to quimb.tensor.tnag.tebd.LocalHamGen.get_auto_ordering(), a callable which returns an ordering when called, or a fixed sequence of coordinate pairs.

  • second_order_reflect (bool, optional) – Whether to use a second order Trotter decomposition by reflecting the ordering.

  • compute_energy_every (int, optional) – Compute the energy every this many steps.

  • compute_energy_final (bool, optional) – Whether to compute the energy at the end.

  • compute_energy_opts (dict, optional) – Options to supply to the energy computation method, quimb.tensor.tnag.core.TensorNetworkGenVector.compute_local_expectation_cluster().

  • compute_energy_fn (callable, optional) – A custom function to compute the energy, with signature fn(su: TEBDGen), where su is this instance.

  • compute_energy_per_site (bool, optional) – Whether to compute the energy per site.

  • tol (float, optional) – If not None, stop when either energy difference falls below this value, or maximum singluar value changes fall below this value.

  • tol_energy_diff (float, optional) – If not None, stop when specifically the energy difference falls below this value.

  • callback (callable, optional) – A function to call after each step, with signature fn(su: TEBDGen), where su is this instance.

  • keep_best (bool, optional) – Whether to keep track of the best state and energy. If True, the best state found during evolution will be stored in the best attribute.

  • plot_every (int, optional) – Whether to plot the energy and energy difference every this many steps.

  • progbar (bool, optional) – Whether to show a progress bar during evolution.

state

The current state.

Type:

TensorNetworkGenVector

D

The maximum bond dimension.

Type:

int

n

The number of sweeps performed.

Type:

int

energy

The energy of the current state, computed only if necessary.

Type:

float

energies

The history of computed energies.

Type:

list[float]

energy_diffs

The history of energy differences.

Type:

list[float]

energy_ns

The iteration numbers at which energies were computed.

Type:

list[int]

taus

The time steps used at each energy computation.

Type:

list[float]

best

If keep_best is True, this dictionary will contain the best energy found during evolution under the key 'energy', the state which achieved this energy under the key 'state', and the iteration number under the key 'it'.

Type:

dict

See also

SimpleUpdateGen

class quimb.tensor.tnag.tebd.SimpleUpdateGen(psi0: quimb.tensor.tnag.core.TensorNetworkGenVector, ham: LocalHamGen, tau=0.01, D=None, cutoff=1e-10, imag=True, gate_opts=None, gauge_smudge=1e-06, ordering=None, second_order_reflect=False, update='sequential', compute_energy_every=None, compute_energy_final=True, compute_energy_opts=None, compute_energy_fn=None, compute_energy_per_site=False, tol=None, tol_energy_diff=None, equilibrate_every=None, equilibrate_start=True, equilibrate_opts=None, gauge_diff_period=None, callback=None, keep_best=False, plot_every=None, progbar=True)[source]

Bases: ComputeEnergyClusterMixin, GateSimpleUpdateMixin, TEBDSweepMixin

Simple update for arbitrary geometry hamiltonians, storing gauges separately and using them and the cluster approximation to compute energies. Reference: https://arxiv.org/abs/0806.3719.

Parameters:
  • psi0 (TensorNetworkGenVector) – The initial state.

  • ham (LocalHamGen) – The local hamiltonian.

  • tau (float, optional) – The default time step to use.

  • D (int, optional) – The maximum bond dimension, by default the current maximum bond of psi0.

  • cutoff (float, optional) – The singular value cutoff to use when applying gates.

  • imag (bool, optional) – Whether to evolve in imaginary time (default) or real time.

  • gate_opts (dict, optional) – Other options to supply to the gate application method, quimb.tensor.tnag.core.TensorNetworkGenVector.gate_simple_().

  • ordering (None, str or callable, optional) – The ordering of the terms to apply, by default this will be determined automatically. It can be a string to be supplied to quimb.tensor.tnag.tebd.LocalHamGen.get_auto_ordering(), a callable which returns an ordering when called, or a fixed sequence of coordinate pairs.

  • second_order_reflect (bool, optional) – Whether to use a second order Trotter decomposition by reflecting the ordering.

  • compute_energy_every (int, optional) – Compute the energy every this many steps.

  • compute_energy_final (bool, optional) – Whether to compute the energy at the end.

  • compute_energy_opts (dict, optional) – Options to supply to the energy computation method, quimb.tensor.tnag.core.TensorNetworkGenVector.compute_local_expectation_cluster().

  • compute_energy_fn (callable, optional) – A custom function to compute the energy, with signature fn(su: SimpleUpdateGen), where su is this instance.

  • compute_energy_per_site (bool, optional) – Whether to compute the energy per site.

  • tol (float, optional) – If not None, stop when either energy difference falls below this value, or maximum singluar value changes fall below this value.

  • tol_energy_diff (float, optional) – If not None, stop when specifically the energy difference falls below this value.

  • equilibrate_every (int, optional) – Equilibrate the gauges every this many steps.

  • equilibrate_start (bool, optional) – Whether to equilibrate the gauges at the start, regardless of equilibrate_every.

  • equilibrate_opts (dict, optional) – Default options to supply to the gauge equilibration method, see quimb.tensor.tensor_core.TensorNetwork.gauge_all_simple(). By default max_iterations is set to 100 and tol to 1e-3.

  • callback (callable, optional) – A function to call after each step, with signature fn(su: SimpleUpdateGen).

  • keep_best (bool, optional) – Whether to keep track of the best state and energy. If True, the best state found during evolution will be stored in the best attribute.

  • plot_every (int, optional) – Whether to plot the energy and energy difference every this many steps.

  • progbar (bool, optional) – Whether to show a progress bar during evolution.

state

The current state.

Type:

TensorNetworkGenVector

D

The maximum bond dimension.

Type:

int

n

The number of sweeps performed.

Type:

int

energy

The energy of the current state, computed only if necessary.

Type:

float

energies

The history of computed energies.

Type:

list[float]

energy_diffs

The history of energy differences.

Type:

list[float]

energy_ns

The iteration numbers at which energies were computed.

Type:

list[int]

taus

The time steps used at each energy computation.

Type:

list[float]

best

If keep_best is True, this dictionary will contain the best energy found during evolution under the key 'energy', the state which achieved this energy under the key 'state', and the iteration number under the key 'it'.

Type:

dict

equilibration_ns

The iteration numbers at which gauge equilibration was performed.

Type:

list[int]

equilibration_iterations

The number of iterations taken during each gauge equilibration.

Type:

list[int]

equilibration_max_sdiffs

The maximum singular value difference during each gauge equilibration.

Type:

list[float]

gauge_diffs

The history of maximum gauge differences after each sweep.

Type:

list[float]

See also

TEBDGen