pytreenet.time_evolution package

This module contains classes and functions for simulation of time-evolutions.

The focus of simulated quantum systems are those represented by a tree tensor network. Although, an exact state vector time simulation exists for testing purposes.

Subpackages

Submodules

pytreenet.time_evolution.exact_time_evolution module

An exact time evolution.

class pytreenet.time_evolution.exact_time_evolution.ExactTimeEvolution(initial_state: ndarray, hamiltonian: ndarray, time_step_size: float, final_time: float, operators: List[ndarray] | ndarray)

Bases: TimeEvolution

An exact time evolution working with state vectors and matrix operators.

Note that this time evolution is very limited in the number of sites it can simulate.

hamiltonian

The Hamiltonian controlling the time time-evolution of the system.

Type:

np.ndarray

evaluate_operator(operator: Any) complex

Evaluate an operator at the current time step.

Parameters:

operator (Any) – The operator to evaluate.

Returns:

The expectation value of the operator.

Return type:

complex

run_one_time_step(**kwargs)

Run one time step of the exact time evolution.

This is achieved by multiplying the time evolution operator with the current state of the system.

pytreenet.time_evolution.tdvp module

Module to create a builder function for the TDVP algorithms.

class pytreenet.time_evolution.tdvp.TDVPConfig(order: int = 2, sites: int = 1, svd_params: SVDParameters | None = None, time_evo_config: TTNTimeEvolutionConfig | None = None)

Bases: object

A configuration file for TDVP algorithms.

Contains all possible parameters for the TDVP algorithms.apart from the time evolution configuration.

oder

The order of the TDVP algorithm. Can be 1 or 2.

Type:

int

sites

The number of sites that are updated in each step. Can be 1 or 2.

Type:

int

svd_params

The parameters for the SVD decomposition. If None, the default parameters are used.

Type:

Union[SVDParameters,None]

time_evo_config

The time evolution configuration for the general tree tensor network time evolution algorithm. If None, the default configuration is used.

Type:

Union[TTNTimeEvolutionConfig,None]

pytreenet.time_evolution.tdvp.tdvp(intitial_state: TreeTensorNetworkState, hamiltonian: TreeTensorNetworkOperator, time_step_size: float, final_time: float, operators: List[TensorProduct] | TensorProduct, config: TDVPConfig) TDVPAlgorithm

Utility function to create a TDVP algorithm.

Parameters:
  • intitial_state (TreeTensorNetworkState) – The initial state of the system.

  • hamiltonian (TTNO) – The Hamiltonian of the system.

  • time_step_size (float) – The time step size.

  • final_time (float) – The final time.

  • operators (Union[List[TensorProduct],TensorProduct]) – The operators that are used to calculate the expectation values.

  • config (TDVPConfig) – The configuration for the TDVP algorithm.

pytreenet.time_evolution.tebd module

Module implementing the TEBD time-evolution for TTNS.

class pytreenet.time_evolution.tebd.TEBD(initial_state: TreeTensorNetworkState, trotter_splitting: TrotterSplitting, time_step_size: float, final_time: float, operators: List[TensorProduct | TreeTensorNetworkOperator] | Dict[str, TensorProduct | TreeTensorNetworkOperator] | TensorProduct | TreeTensorNetworkOperator, svd_parameters: SVDParameters | None = None, config: TTNTimeEvolutionConfig | None = None)

Bases: TTNTimeEvolution

Runs the TEBD algorithm on a TTNS.

The TEBD algorithm uses a trotterised version of a Hamiltonian time evolution. The different Trotter operators are contracted into the system one by one. A truncation happens, if it is desired.

trotter_splitting

A splitting of a Hamiltonian into different few site operators. Currently only one and two site operators are considered.

Type:

TrotterSplitting

property exponents: List[NumericOperator]

Returns the exponentiated Trotter operators.

run_one_time_step(**kwargs)

Runs one TEBD time step.

This means every Trotter operator is applied once to the TTNS.

property trotter_splitting: TrotterSplitting

Returns the Trotter splitting.

pytreenet.time_evolution.time_evolution module

This module provides the abstract TimeEvolution class

class pytreenet.time_evolution.time_evolution.TimeEvolution(initial_state: Any, time_step_size: float, final_time: float, operators: List[Any] | Dict[str, Any] | Any)

Bases: object

An abstract class that can be used for various time-evolution algorithms.

Contains all methods required to cover common discrete time evolutions and avoid code duplication. The algorithms runs a number of time steps of given size until a specified final time is reached.

While results can be called directly as a big martix using the results attribute, there are convenience functions to easily extract the desired results.

initial_state

The initial state of the system to be time evolved.

Type:

Any

time_step_size

The size of each discreet time step.

Type:

float

final_time

The time at which to conclude the time-evolution.

Type:

float

operators

A list of operators to be evaluated.

Type:

List[Any]

check_result_exists()

Checks if results have been obtained.

evaluate_operator(operator: Any) complex

Abstract method to evaluate the expectation value of a single operator.

Parameters:

operator (Any) – The operator for which to compute the expectation value.

Returns:

The expectation value of the operator.

Return type:

complex

evaluate_operators() ndarray

Evaluate the expectation value for all operators for the current state.

Returns:

The expectation values with indeces corresponding to those in

operators.

Return type:

List

property final_time: float

Returns the final time.

property initial_state: Any

Returns the initial state.

property num_time_steps: int

Returns the current number of time steps.

operator_result(operator_id: str | int, realise: bool = False) ndarray

Returns the result of a single operator.

The operator can be a string, if the operators were originally provided with strings as keys. Otherwise one has to provide the correct index at which the operator was saved.

Parameters:
  • operator_id (Union[str, int]) – The index or key of the operator.

  • realise (bool, optional) – If the imaginary part of the results should be discarded. Defaults to False.

Returns:

The result of the operator as a vector.

Return type:

np.ndarray

operator_results(realise: bool = False) ndarray

Returns all of the operator results.

Parameters:

realise (bool, optional) – If the imaginary part of the results should be discarded. Defaults to False.

Returns:

The operator results in the same order as the operators

were given.

Return type:

np.ndarray

reset_to_initial_state()

Resets the current state to the intial state

property results: ndarray

Returns the currently obtained results

results_real() bool

Returns if the results are real.

run(evaluation_time: int | 'inf' = 1, filepath: str = '', pgbar: bool = True)

Runs this time evolution algorithm for the given parameters.

The desired operator expectation values are evaluated and saved.

Parameters:
  • evaluation_time (int, optional) – The difference in time steps after which to evaluate the operator expectation values, e.g. for a value of 10 the operators are evaluated at time steps 0,10,20,… If it is set to “inf”, the operators are only evaluated at the end of the time. Defaults to 1.

  • filepath (str, optional) – If results are to be saved in an external file, the path to that file can be specified here. Defaults to “”.

  • pgbar (bool, optional) – Toggles the progress bar. Defaults to True.

run_one_time_step(**kwargs)

Abstract method to run one time step.

save_results_to_file(filepath: str)

Saves the data of self.results into a .npz file.

Parameters:

filepath (str) – The path of the file.

set_num_time_steps(num_time_steps: int)

Set the number of time steps to be run.

Sometimes it is more convenient to define the size of the time steps and the number of steps to be run, rather than using a final time. This method modifies the internal attributes accordingly.

set_num_time_steps_constant_final_time(num_time_steps: int)

Sets the number of time-steps and keeps the final time constant.

The internal attributes are modified accordingly.

property time_step_size: float

Returns the size of one time step.

times() ndarray

Returns the times at which the operators were evaluated.

pytreenet.time_evolution.time_evolution.time_evolve(psi: ndarray, hamiltonian: ndarray, time_difference: float, forward: bool = True) ndarray

Time evolves a state psi via a Hamiltonian.

The evolution can be either forward or backward in time:

psi(t +/- dt) = exp(-/+ i*h*dt) @ psi(t) -iHdt: forward = True +iHdt: forward = False

Parameters:
  • psi (np.ndarray) – The initial state as a vector.

  • hamiltonian (np.ndarray) – The Hamiltonian determining the dynamics as a matrix.

  • time_difference (float) – The duration of the time-evolution

  • forward (bool, optional) – If the time evolution should be forward or backward in time. Defaults to True.

Returns:

The time evolved state

Return type:

np.ndarray

pytreenet.time_evolution.trotter module

This module provides all classes required to define arbitrary trotterisations.

A trotterisation is a splitting of an operator/matrix exponential into factors even though the exponents are non-commuting. This does cause an error.

class pytreenet.time_evolution.trotter.SWAPlist(swap_list: List[Tuple[str, str]] | None = None)

Bases: List

A list of symbolic SWAP gates.

As the name suggests a SWAP gates swaps the state of two neighbouring nodes. This class represents a list of such SWAP gates. It is used to represent a consecutive application of SWAPs of neighbouring nodes.

into_operators(ttn: TreeTensorNetwork | None = None, dim: None | int = None) List[NumericOperator]

Turns the list of abstract swaps into a list of numeric operators.

Parameters:
  • ttn (TreeTensorNetwork) – A tree tensor network from which the dimensions can be determined. Default to None.

  • dim (Union[int, None], optional) – Can be given, if all nodes that have to be swapped have the same dimension. Defaults to None.

Returns:

A list of numeric operators corresponding to the

swaps defined in this instance.

Return type:

List[NumericOperator]

Raises:

ValueError – If ttn and dim are both None.

is_compatible_with_ttn(ttn: TreeTensorNetwork) bool

Returns, if a SWAPlist is compatible with a given TreeTensorNetwork.

This means it checks if all nodes in the SWAP-list are actually neighbours with the same open leg dimension.

Parameters:

ttn (TreeTensorNetwork) – A TTN for which to check compatability.

Returns:

True if the SWAPlist is compatible with the TTN and False,

if not.

Return type:

bool

class pytreenet.time_evolution.trotter.TrotterSplitting(trotter_steps: List[TrotterStep] | None = None)

Bases: List

A trotter splitting allows the approximate breaking of exponentials of operators.

Different kinds of splitting lead to different error sizes.

exponentiate_splitting(delta_time: float, ttn: TreeTensorNetwork | None = None, dim: None | int = None) List[NumericOperator]

Turns the list into a series of unitary operators

Computes all operators, which are to actually be applied in a time- evolution algorithm. This includes SWAP gates and exponentiated unitary operators.

Parameters:
  • delta_time (float) – The time step size for the trotter-splitting.

  • ttn (Union[TreeTensorNetwork,None],optional) – A TTN which is compatible with this splitting. Can provide the physical dimensions of the SWAPgates. Defaults to None.

  • dim (Union[int,None],optional) – If all nodes have the same open dimension, this dimension can be given here, to speed up computation.

Returns:

All unitary operators that make up one

time-step of the Trotter splitting. They are to be applied according to the order in the list.

Return type:

List[NumericOperators]

classmethod from_lists(tensor_products: List[TensorProduct], splitting: List[Tuple[int, int], int] | None = None, swaps_before: List[SWAPlist] | None = None, swaps_after: List[SWAPlist] | None = None) TrotterSplitting

Creates a TrotterSplitting instance from lists.

The lists contain the required parameters to build trotter steps that form the trotter splitting.

Parameters:
  • tensor_products (List[TensorProduct]) – The tensor_products to be considered.

  • splitting (Union[List[Tuple[int, int], int], None], optional) – Gives the order of the splitting. The first tuple entry is the index of an operator in the list of tensor products and the second entry is a factor, which will be multiplied to the operator once exponentiated. If only an integer is given, it is assumed to be the index in the list of tensor products and the factor is set to 1. In case of no given splitting the splitting is assumed to be in the order as given in the list of operators and all factors are set to 1. Defaults to None.

  • swaps_before (Union[List[SWAPlist], None], optional) – The swaps to be applied before an exponentiated operator is applied. The indices are the same as in the splitting. So the SWAP gates given with index i will be applied before the operator specified with the `i`th element of splitting happens. Defaults to None.

  • swaps_after (Union[List[SWAPlist], None], optional) – The swaps to be applied after an exponentiated operator is applied. The indices are the same as in the splitting. So the SWAP gates given with index i will be applied after the operator specified with the `i`th element of splitting happens. Defaults to None.

class pytreenet.time_evolution.trotter.TrotterStep(operator: TensorProduct, factor: float, swaps_before: SWAPlist | List[Tuple[str, str]] | None = None, swaps_after: SWAPlist | List[Tuple[str, str]] | None = None)

Bases: object

A single trotter step of a trotterisation.

A trotterisation splits a multi term exponent into multiple smaller operator exponents inccurring an error. A single trotter step is one such smaller operator, including swap gates before and after the exponented operator.

operator

The operator that should become the exponent.

Type:

TensorProduct

factor

A factor to be included in the exponent.

Type:

float

swaps_before

The swaps that should occur, before the exponentiated operator is applied.

Type:

Swaplist

swaps_after

The swaps that should occur, after the exponentiated operator is applied.

Type:

Swaplist

exponentiate_operator(delta_time: float, ttn: TreeTensorNetwork | None = None, dim: None | int = None) NumericOperator

Exponentiates the operator part of this trotter step.

Parameters:
  • delta_time (float) – The time factor that should be multiplied to the exponent operator.

  • dim (Union[int, None], optional) – If all nodes have the same open dimension it can be given here. Defaults to None.

  • ttn (Union[TreeTensorNetwork, None], optional) – If not all nodes have the same open dimension a TTN is needed as a reference. Defaults to None.

realise_swaps(ttn: TreeTensorNetwork | None = None, dim: None | int = None) Tuple[List[NumericOperator], List[NumericOperator]]

Turns the SWAP gates into numeric operators.

The gates are only saved with a simplified representation. This method turns them into actual gates.

Parameters:
  • dim (Union[int, None], optional) – If all nodes have the same open dimension it can be given here. Defaults to None.

  • ttn (Union[TreeTensorNetwork, None], optional) – If not all nodes have the same open dimension a TTN is needed as a reference. Defaults to None.

pytreenet.time_evolution.ttn_time_evolution module

class pytreenet.time_evolution.ttn_time_evolution.TTNTimeEvolution(initial_state: TreeTensorNetworkState, time_step_size: float, final_time: float, operators: List[TensorProduct | TreeTensorNetworkOperator] | Dict[str, TensorProduct | TreeTensorNetworkOperator] | TensorProduct | TreeTensorNetworkOperator, config: TTNTimeEvolutionConfig | None = None)

Bases: TimeEvolution

A time evolution for tree tensor networks.

Provides functionality to compute expectation values of operators during the time evolution and record bond dimensions of the current state.

bond_dims

If a recording of the bond dimension is intended, they are recorded here.

Type:

Union[None,Dict[str,int]]

evaluate_operator(operator: TensorProduct | TreeTensorNetworkOperator) complex

Evaluate the expectation value of a single operator.

Parameters:

operator (TensorProduct) – The operator for which to compute the expectation value.

Returns:

The expectation value of the operator with respect to

the current state.

Return type:

np.ndarray

evaluate_operators() ndarray

Evaluates the operator including the recording of bond dimensions.

obtain_bond_dims() Dict[Tuple[str, str], int]

Obtains a dictionary of all bond dimensions in the current state.

operator_result(operator_id: str | int, realise: bool = False) ndarray

Includes the possibility to obtain the bond dimension from the results.

Parameters:
  • operator_id (Union[str,int]) – The identifier or position of the operator, whose expectation value results should be returned.

  • realise (bool, optional) – Whether the results should be transformed into real numbers.

Returns:

The expectation value results over time.

Return type:

ndarray

record_bond_dimensions()

Records the bond dimensions of the current state, if desired to do so.

property records_bond_dim: bool

Are the bond dimensions recorded or not.

class pytreenet.time_evolution.ttn_time_evolution.TTNTimeEvolutionConfig(record_bond_dim: bool = False)

Bases: object

Configuration for the TTN time evolution.

In this configuration class additional parameters for the time evolution of a tree tensor network can be specified and entered. This allows for the same extendability as **kwargs but with the added benefit of type hints and better documentation.

record_bond_dim: bool = False