quimb.tensor.tensor_1d_tebd

Tools for performing TEBD like algorithms in 1D.

Attributes

NNI

Classes

continuous_progbar

A continuous version of tqdm, so that it can be updated with a float

LocalHamGen

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

LocalHam1D

An simple interacting hamiltonian object used, for instance, in TEBD.

TEBD

Class implementing Time Evolving Block Decimation (TEBD) [1].

Functions

ensure_dict(x)

Make sure x is a dict, creating an empty one if x is None.

deprecated(fn, old_name, new_name)

Mark a function as deprecated, and indicate the new name.

norm_fro(x)

The frobenius norm of an array.

OTOC_local(psi0, H, H_back, ts, i, A[, j, B, ...])

The out-of-time-ordered correlator (OTOC) generating by two local

Module Contents

quimb.tensor.tensor_1d_tebd.ensure_dict(x)[source]

Make sure x is a dict, creating an empty one if x is None.

class quimb.tensor.tensor_1d_tebd.continuous_progbar(*args, total=100, **kwargs)[source]

Bases: tqdm.tqdm

A continuous version of tqdm, so that it can be updated with a float within some pre-given range, rather than a number of steps.

Parameters:
  • args ((stop) or (start, stop)) – Stopping point (and starting point if len(args) == 2) of window within which to evaluate progress.

  • total (int) – The number of steps to represent the continuous progress with.

  • kwargs – Supplied to tqdm.tqdm

cupdate(x)[source]

‘Continuous’ update of progress bar.

Parameters:

x (float) – Current position within the range [self.start, self.stop].

quimb.tensor.tensor_1d_tebd.deprecated(fn, old_name, new_name)[source]

Mark a function as deprecated, and indicate the new name.

quimb.tensor.tensor_1d_tebd.norm_fro(x)[source]

The frobenius norm of an array.

class quimb.tensor.tensor_1d_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]

property nsites
The number of sites in the system.
items()[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(x, y)[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.

_nx_color_ordering(strategy='smallest_first', interchange=True)[source]

Generate a term ordering based on a coloring on the line graph.

get_auto_ordering(order='sort', **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.

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

Returns:

Sequence of coordinate pairs.

Return type:

list[tuple[node]]

__repr__()[source]

Return repr(self).

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.tensor_arbgeom_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.tensor_1d_tebd.LocalHam1D(L, H2, H1=None, cyclic=False)[source]

Bases: quimb.tensor.tensor_arbgeom_tebd.LocalHamGen

An simple interacting hamiltonian object used, for instance, in TEBD. Once instantiated, the LocalHam1D hamiltonian stores a single term per pair of sites, cached versions of which can be retrieved like H.get_gate_expm((i, i + 1), -1j * 0.5) etc.

Parameters:
  • L (int) – The size of the hamiltonian.

  • H2 (array_like or dict[tuple[int], array_like]) – The sum of interaction terms. If a dict is given, the keys should be nearest neighbours like (10, 11), apart from any default term which should have the key None, and the values should be the sum of interaction terms for that interaction.

  • H1 (array_like or dict[int, array_like], optional) – The sum of single site terms. If a dict is given, the keys should be integer sites, apart from any default term which should have the key None, and the values should be the sum of single site terms for that site.

  • cyclic (bool, optional) – Whether the hamiltonian has periodic boundary conditions or not.

terms

The terms in the hamiltonian, combined from the inputs such that there is a single term per pair.

Type:

dict[tuple[int], array]

Examples

A simple, translationally invariant, interaction-only LocalHam1D:

>>> XX = pauli('X') & pauli('X')
>>> YY = pauli('Y') & pauli('Y')
>>> ham = LocalHam1D(L=100, H2=XX + YY)

The same, but with a translationally invariant field as well:

>>> Z = pauli('Z')
>>> ham = LocalHam1D(L=100, H2=XX + YY, H1=Z)

Specifying a default interaction and field, with custom values set for some sites:

>>> H2 = {None: XX + YY, (49, 50): (XX + YY) / 2}
>>> H1 = {None: Z, 49: 2 * Z, 50: 2 * Z}
>>> ham = LocalHam1D(L=100, H2=H2, H1=H1)

Specifying the hamiltonian entirely through site specific interactions and fields:

>>> H2 = {(i, i + 1): XX + YY for i in range(99)}
>>> H1 = {i: Z for i in range(100)}
>>> ham = LocalHam1D(L=100, H2=H2, H1=H1)

See also

SpinHam1D

mean_norm()[source]

Computes the average frobenius norm of local terms.

build_mpo_propagator_trotterized(x, site_tag_id='I{}', tags=None, upper_ind_id='k{}', lower_ind_id='b{}', shape='lrud', contract_sites=True, **split_opts)[source]

Build an MPO representation of expm(H * x), i.e. the imaginary or real time propagator of this local 1D hamiltonian, using a first order trotterized decomposition.

Parameters:
  • x (float) – The time to evolve for. Note this does not include the imaginary prefactor of the Schrodinger equation, so real x corresponds to imaginary time evolution, and vice versa.

  • site_tag_id (str) – A string specifiying how to tag the tensors at each site. Should contain a '{}' placeholder. It is used to generate the actual tags like: map(site_tag_id.format, range(len(arrays))).

  • tags (str or sequence of str, optional) – Global tags to attach to all tensors.

  • upper_ind_id (str) – A string specifiying how to label the upper physical site indices. Should contain a '{}' placeholder. It is used to generate the actual indices like: map(upper_ind_id.format, range(len(arrays))).

  • lower_ind_id (str) – A string specifiying how to label the lower physical site indices. Should contain a '{}' placeholder. It is used to generate the actual indices like: map(lower_ind_id.format, range(len(arrays))).

  • shape (str, optional) – String specifying layout of the tensors. E.g. ‘lrud’ (the default) indicates the shape corresponds left-bond, right-bond, ‘up’ physical index, ‘down’ physical index. End tensors have either ‘l’ or ‘r’ dropped from the string if not periodic.

  • contract_sites (bool, optional) – Whether to contract all the decomposed factors at each site to yield a single tensor per site, by default True.

  • split_opts – Supplied to tensor_split().

__repr__()[source]

Return repr(self).

quimb.tensor.tensor_1d_tebd.NNI[source]
class quimb.tensor.tensor_1d_tebd.TEBD(p0, H, dt=None, tol=None, t0=0.0, split_opts=None, progbar=True, imag=False)[source]

Class implementing Time Evolving Block Decimation (TEBD) [1].

[1] Guifré Vidal, Efficient Classical Simulation of Slightly Entangled Quantum Computations, PRL 91, 147902 (2003)

Parameters:
  • p0 (MatrixProductState) – Initial state.

  • H (LocalHam1D or array_like) – Dense hamiltonian representing the two body interaction. Should have shape (d * d, d * d), where d is the physical dimension of p0.

  • dt (float, optional) – Default time step, cannot be set as well as tol.

  • tol (float, optional) – Default target error for each evolution, cannot be set as well as dt, which will instead be calculated from the trotter orderm length of time, and hamiltonian norm.

  • t0 (float, optional) – Initial time. Defaults to 0.0.

  • split_opts (dict, optional) – Compression options applied for splitting after gate application, see tensor_split().

  • imag (bool, optional) – Enable imaginary time evolution. Defaults to false.

See also

quimb.Evolution

property pt
The MPS state of the system at the current time.
property err
choose_time_step(tol, T, order)[source]

Trotter error is ~ (T / dt) * dt^(order + 1). Invert to find desired time step, and scale by norm of interaction term.

_get_gate_from_ham(dt_frac, sites)[source]

Get the unitary (exponentiated) gate for fraction of timestep dt_frac and sites sites, cached.

sweep(direction, dt_frac, dt=None, queue=False)[source]

Perform a single sweep of gates and compression. This shifts the orthonognality centre along with the gates as they are applied and split.

Parameters:
  • direction ({'right', 'left'}) – Which direction to sweep. Right is even bonds, left is odd.

  • dt_frac (float) – What fraction of dt substep to take.

  • dt (float, optional) – Overide the current dt with a custom value.

_step_order2(tau=1, **sweep_opts)[source]

Perform a single, second order step.

_step_order4(**sweep_opts)[source]

Perform a single, fourth order step.

step(order=2, dt=None, progbar=None, **sweep_opts)[source]

Perform a single step of time self.dt.

_compute_sweep_dt_tol(T, dt, tol, order)[source]
TARGET_TOL = 1e-13
update_to(T, dt=None, tol=None, order=4, progbar=None)[source]

Update the state to time T.

Parameters:
  • T (float) – The time to evolve to.

  • dt (float, optional) – Time step to use. Can’t be set as well as tol.

  • tol (float, optional) – Tolerance for whole evolution. Can’t be set as well as dt.

  • order (int, optional) – Trotter order to use.

  • progbar (bool, optional) – Manually turn the progress bar off.

_set_progbar_desc(progbar)[source]
at_times(ts, dt=None, tol=None, order=4, progbar=None)[source]

Generate the time evolved state at each time in ts.

Parameters:
  • ts (sequence of float) – The times to evolve to and yield the state at.

  • dt (float, optional) – Time step to use. Can’t be set as well as tol.

  • tol (float, optional) – Tolerance for whole evolution. Can’t be set as well as dt.

  • order (int, optional) – Trotter order to use.

  • progbar (bool, optional) – Manually turn the progress bar off.

Yields:

pt (MatrixProductState) – The state at each of the times in ts. This is a copy of internal state used, so inplace changes can be made to it.

quimb.tensor.tensor_1d_tebd.OTOC_local(psi0, H, H_back, ts, i, A, j=None, B=None, initial_eigenstate='check', **tebd_opts)[source]

The out-of-time-ordered correlator (OTOC) generating by two local operator A and B acting on site ‘i’, note it’s a function of time.

Parameters:
  • psi0 (MatrixProductState) – The initial state in MPS form.

  • H (LocalHam1D) – The Hamiltonian for forward time-evolution.

  • H_back (LocalHam1D) – The Hamiltonian for backward time-evolution, should have only sign difference with ‘H’.

  • ts (sequence of float) – The time to evolve to.

  • i (int) – The site where the local operators acting on.

  • A (array) – The operator to act with.

  • initial_eigenstate ({'check', Flase, True}) – To check the psi0 is or not eigenstate of operator B. If psi0 is the eigenstate of B, it will run a simpler version of OTOC calculation automatically.

Return type:

The OTOC <A(t)B(0)A(t)B(0)>