seemps.state.MPS#

class seemps.state.MPS#

Bases: TensorArray

MPS (Matrix Product State) class.

This implements a bare-bones Matrix Product State object with open boundary conditions. The tensors have three indices, A[α,d,β], where α,β are the internal labels and d is the physical state of the given site.

Parameters:
dataIterable[Tensor3]

Sequence of three-legged tensors A[α,si,β]. The dimensions are not verified for consistency.

errorfloat, default=0.0

Accumulated truncation error in the previous tensors.

all_expectation1(operator: TypeAliasForwardRef('~seemps.typing.Operator') | list[TypeAliasForwardRef('~seemps.typing.Operator')]) Vector[source]#

Vector of expectation values of the given operator acting on all possible sites of the MPS.

Parameters:
operatorOperator | list[Operator]

If operator is an observable, it is applied on each possible site. If it is a list, the expectation value of operator[i] is computed on the i-th site.

Returns:
Vector

Numpy array of expectation values.

bond_dimensions() list[int][source]#

List of bond dimensions for the matrix product state.

Returns a list or vector of N+1 integers, for an MPS of size N. The integers 1 to N-1 are the bond dimensions between the respective pairs of tensors. The first and last index are 1, as it corresponds to a matrix product state with open boundary conditions.

Returns:
list[int]

List of virtual bond dimensions between MPS tensors, including the boundary ones.

Examples

>>> A = np.ones(1,2,3)
>>> B = np.ones(3,2,1)
>>> mps = MPS([A, B])
>>> mps.bond_dimensions()
[1, 3, 1]
conj() MPS[source]#

Return the complex-conjugate of this quantum state.

copy() MPS[source]#

Return a shallow copy of the MPS, without duplicating the tensors.

dimension() int[source]#

Hilbert space dimension of this quantum system.

error() float[source]#

Upper bound of the accumulated truncation error on this state.

If this quantum state results from N steps in which we have obtained truncation errors \(\delta_i\), this function returns the estimate \(\sum_{i}\delta_i\).

Returns:
float

Upper bound for the actual error when approximating this state.

expectation1(O: Operator, site: int) Weight[source]#

Compute the expectation value \(\langle\psi|O_i|\psi\rangle\) of an operator O acting on the i-th site

Parameters:
stateMPS

Quantum state \(\psi\) used to compute the expectation value.

OOperator

Local observable acting onto the i-th subsystem

iint

Index of site, in the range [0, state.size)

Returns:
float | complex

Expectation value.

expectation2(Opi: Operator, Opj: Operator, i: int, j: int | None = None) Weight[source]#

Compute the expectation value \(\langle\psi|O_i Q_j|\psi\rangle\) of two operators O and Q acting on the i-th and j-th subsystems.

Parameters:
stateMPS

Quantum state \(\psi\) used to compute the expectation value.

O, QOperator

Local observables

iint
jint, default=`i+1`

Indices of sites, in the range [0, state.size)

Returns:
float | complex

Expectation value.

extend(L: int, sites: Sequence[int] | None = None, dimensions: int | list[int] = 2, state: Vector | None = None)[source]#

Enlarge an MPS so that it lives in a Hilbert space with L sites.

Parameters:
Lint

The new size of the MPS. Must be strictly larger than self.size.

sitesIterable[int], optional

Sequence of integers describing the sites that occupied by the tensors in this state.

dimensionsint | list[int], default = 2

Dimension of the added sites. It can be the same integer or a list of integers with the same length as sites.

Returns:
MPS

The extended MPS.

Examples

>>> import seemps.state
>>> mps = seemps.state.random_uniform_mps(2, 10)
>>> mps.physical_dimensions()
[2, 2, 2, 2, 2, 2, 2, 2, 2, 2]
>>> mps = mps.extend(12, [0, 2, 4, 5, 6, 7, 8, 9, 10, 11], 3)
>>> mps.physical_dimensions()
[2, 3, 2, 3, 2, 2, 2, 2, 2, 2, 2, 2]
classmethod from_tensor(state: ndarray, strategy: Strategy = DEFAULT_STRATEGY, normalize: bool = True) MPS[source]#

Create a matrix-product state from a tensor that represents a composite quantum system.

The tensor state must have N>=1 indices, each of them associated to an individual quantum system, in left-to-right order. This function decomposes the tensor into a contraction of N three-legged tensors as expected from an MPS.

Parameters:
statenp.ndarray

Real or complex tensor with N legs.

strategyStrategy, default = DEFAULT_STRATEGY

Default truncation strategy for algorithms working on this state.

normalizebool, default = True

Whether the state is normalized to compensate truncation errors.

Returns:
MPS

A valid matrix-product state approximating this state vector.

classmethod from_vector(ψ: VectorLike, dimensions: Sequence[int], strategy: Strategy = DEFAULT_STRATEGY, normalize: bool = True, center: int = -1) MPS[source]#

Create a matrix-product state from a state vector.

Parameters:
ψVectorLike

Real or complex vector of a wavefunction.

dimensionsSequence[int]

Sequence of integers representing the dimensions of the quantum systems that form this state.

strategyStrategy, default = DEFAULT_STRATEGY

Default truncation strategy for algorithms working on this state.

normalizebool, default = True

Whether the state is normalized to compensate truncation errors.

centerint, default = -1

Center of the canonicalized matrix product state

Returns:
MPS

A valid matrix-product state approximating this state vector.

left_environment(site: int) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Environment matrix for systems to the left of site.

max_bond_dimension() int[source]#

Return the largest bond dimension.

norm() float[source]#

Norm-2 \(\Vert{\psi}\Vert^2\) of this MPS.

norm2() float[source]#

Deprecated alias for norm_squared().

norm_squared() float[source]#

Norm-2 squared \(\Vert{\psi}\Vert^2\) of this MPS.

physical_dimensions() list[int][source]#

List of physical dimensions for the quantum subsystems.

reverse() MPS[source]#

Reverse the sites and tensors.

Creates a new matrix product operator where tensors 0, 1, …, N-1 are mapped to N-1, N-2, …, 0. For the MPS to be consistent, this also implies reversing the order of the intermediate indices. Thus, if we label as A and B the tensors of the original and of the reversed MPOs, we have

\[B_{a_{n-1},i_n,a_n} = A_{a_{N-n-1},i_{N-n-1},a_{N-n-2}}\]
right_environment(site: int) ndarray[tuple[Any, ...], dtype[_ScalarT]][source]#

Environment matrix for systems to the right of site.

to_tensor() Vector[source]#

Convert this MPS to a multidimensional tensor.

to_vector() Vector[source]#

Convert this MPS to a state vector.

update_error(delta: float) None[source]#

Register an increase in the truncation error.

Parameters:
deltafloat

Error increment in norm-2

See also

error()

Total accumulated error after this update.

zero_state() MPS[source]#

Return a zero wavefunction with the same physical dimensions.