tensorcircuit.mps_base#

FiniteMPS from tensornetwork with bug fixed

class tensorcircuit.mps_base.FiniteMPS(tensors: List[Any], center_position: Optional[int] = None, canonicalize: Optional[bool] = True, backend: Optional[Union[str, tensornetwork.backends.abstract_backend.AbstractBackend]] = None)[source]#

Bases: tensornetwork.matrixproductstates.finite_mps.FiniteMPS

__init__(tensors: List[Any], center_position: Optional[int] = None, canonicalize: Optional[bool] = True, backend: Optional[Union[str, tensornetwork.backends.abstract_backend.AbstractBackend]] = None) β†’ None[source]#
Initialize a FiniteMPS. If canonicalize is True the state

is brought into canonical form, with BaseMPS.center_position at center_position. if center_position is None and canonicalize = True, BaseMPS.center_position is set to 0.

Parameters
  • tensors – A list of Tensor objects.

  • center_position – The initial position of the center site.

  • canonicalize – If True the mps is canonicalized at initialization.

  • backend – The name of the backend that should be used to perform contractions. Available backends are currently β€˜numpy’, β€˜tensorflow’, β€˜pytorch’, β€˜jax’

apply_one_site_gate(gate: Any, site: int) β†’ None#

Apply a one-site gate to an MPS. This routine will in general destroy any canonical form of the state. If a canonical form is needed, the user can restore it using FiniteMPS.position :param gate: a one-body gate :param site: the site where the gate should be applied

apply_transfer_operator(site: int, direction: Union[str, int], matrix: Any) β†’ Any#

Compute the action of the MPS transfer-operator at site site.

Parameters
  • site – A site of the MPS

  • direction –

    • if 1, β€˜l’ or β€˜left’: compute the left-action of the MPS transfer-operator at site on the input matrix.

    • if -1, β€˜r’ or β€˜right’: compute the right-action of the MPS transfer-operator at site on the input matrix

  • matrix – A rank-2 tensor or matrix.

Returns

The result of applying the MPS transfer-operator to matrix

Return type

Tensor

apply_two_site_gate(gate: Any, site1: int, site2: int, max_singular_values: Optional[int] = None, max_truncation_err: Optional[float] = None, center_position: Optional[int] = None, relative: bool = False) β†’ Any[source]#

Apply a two-site gate to an MPS. This routine will in general destroy any canonical form of the state. If a canonical form is needed, the user can restore it using FiniteMPS.position.

Parameters
  • gate (Tensor) – A two-body gate.

  • site1 (int) – The first site where the gate acts.

  • site2 (int) – The second site where the gate acts.

  • max_singular_values (Optional[float], optional) – The maximum number of singular values to keep.

  • max_truncation_err (Optional[float], optional) – The maximum allowed truncation error.

  • center_position (Optional[int],optional) – An optional value to choose the MPS tensor at center_position to be isometric after the application of the gate. Defaults to site1. If the MPS is canonical (i.e.`BaseMPS.center_position != None`), and if the orthogonality center coincides with either site1 or site2, the orthogonality center will be shifted to center_position (site1 by default). If the orthogonality center does not coincide with (site1, site2) then MPS.center_position is set to None.

  • relative (bool) – Multiply max_truncation_err with the largest singular value.

Raises

ValueError – β€œrank of gate is {} but has to be 4”, β€œsite1 = {} is not between 0 <= site < N - 1 = {}”, β€œsite2 = {} is not between 1 <= site < N = {}”,”Found site2 ={}, site1={}. Only nearest neighbor gates are currently supported”, β€œf center_position = {center_position} not f in {(site1, site2)} β€œ, or β€œcenter_position = {}, but gate is applied at sites {}, {}. Truncation should only be done if the gate is applied at the center position of the MPS.”

Returns

A scalar tensor containing the truncated weight of the truncation.

Return type

Tensor

bond_dimension(bond) β†’ List#

The bond dimension of bond

property bond_dimensions: List#

A list of bond dimensions of BaseMPS

canonicalize(normalize: bool = True) β†’ numpy.number[source]#

Bring the MPS into canonical form according to center_position. If center_position is None, the MPS is canonicalized with center_position = 0.

Parameters

normalize – If True, normalize matrices when shifting the orthogonality center.

Returns

The norm of the MPS.

Return type

Tensor

center_position: Optional[int]#
check_canonical() β†’ Any[source]#

Check whether the MPS is in the expected canonical form.

Returns

The L2 norm of the vector of local deviations.

check_orthonormality(which: str, site: int) β†’ Any#

Check orthonormality of tensor at site site.

Parameters
  • which –

    • if β€˜l’ or β€˜left’: check left orthogonality

    • if β€˜r’ or β€˜right’: check right orthogonality

  • site – The site of the tensor.

Returns

The L2 norm of the deviation from identity.

Return type

scalar Tensor

Raises

ValueError – If which is different from β€˜l’,’left’, β€˜r’ or β€˜right’.

conj() β†’ tensorcircuit.mps_base.FiniteMPS[source]#
copy() β†’ tensorcircuit.mps_base.FiniteMPS[source]#
property dtype: Type[numpy.number]#
get_tensor(site: int) β†’ Any#

Returns the Tensor object at site.

If site==len(self) - 1 BaseMPS.connector_matrix is absorbed fromt the right-hand side into the returned Tensor object.

Parameters

site – The site for which to return the Node.

Returns

The tensor at site.

Return type

Tensor

left_envs(sites: Sequence[int]) β†’ Dict[source]#

Compute left reduced density matrices for site sites. This returns a dict left_envs mapping sites (int) to Tensors. left_envs[site] is the left-reduced density matrix to the left of site site.

Parameters

sites (list of int) – A list of sites of the MPS.

Returns

The left-reduced density matrices

at each site in sites.

Return type

dict mapping int to Tensor

left_transfer_operator(A, l, Abar)#
measure_local_operator(ops: List[Any], sites: Sequence[int]) β†’ List[Any][source]#

Measure the expectation value of local operators ops site sites.

Parameters
  • ops (List[Tensor]) – A list Tensors of rank 2; the local operators to be measured.

  • sites (Sequence[int]) – Sites where ops act.

Returns

measurements \(\langle\) ops[n]\(\rangle\) for n in sites

Return type

List[Tensor]

measure_two_body_correlator(op1: Any, op2: Any, site1: int, sites2: Sequence[int]) β†’ List[Any][source]#

Compute the correlator \(\langle\) op1[site1], op2[s]\(\rangle\) between site1 and all sites s in sites2. If s == site1, op2[s] will be applied first.

Parameters
  • op1 (Tensor) – Tensor of rank 2; the local operator at site1.

  • op2 (Tensor) – Tensor of rank 2; the local operator at sites2.

  • site1 (int) – The site where op1 acts

  • sites2 (Sequence[int]) – Sites where operator op2 acts.

Returns

Correlator \(\langle\) op1[site1], op2[s]\(\rangle\) for s \(\in\) sites2.

Return type

List[Tensor]

property physical_dimensions: List#

A list of physical Hilbert-space dimensions of BaseMPS

position(site: int, normalize: Optional[bool] = True, D: Optional[int] = None, max_truncation_err: Optional[float] = None) β†’ numpy.number#

Shift center_position to site.

Parameters
  • site – The site to which FiniteMPS.center_position should be shifted

  • normalize – If True, normalize matrices when shifting.

  • D – If not None, truncate the MPS bond dimensions to D.

  • max_truncation_err – if not None, truncate each bond dimension, but keeping the truncation error below max_truncation_err.

Returns

The norm of the tensor at FiniteMPS.center_position

Return type

Tensor

Raises

ValueError – If center_position is None.

classmethod random(d: List[int], D: List[int], dtype: Type[numpy.number], canonicalize: bool = True, backend: Optional[Union[str, tensornetwork.backends.abstract_backend.AbstractBackend]] = None) β†’ tensornetwork.matrixproductstates.finite_mps.FiniteMPS[source]#

Initialize a random FiniteMPS. The resulting state is normalized. Its center-position is at 0.

Parameters
  • d – A list of physical dimensions.

  • D – A list of bond dimensions.

  • dtype – A numpy dtype.

  • backend – An optional backend.

Returns

FiniteMPS

right_envs(sites: Sequence[int]) β†’ Dict[source]#

Compute right reduced density matrices for site sites. This returns a dict `right_envs mapping sites (int) to Tensors. right_envs[site] is the right-reduced density matrix to the right of site site.

Parameters

sites (list of int) – A list of sites of the MPS.

Returns

The right-reduced density matrices

at each site in sites.

Return type

dict mapping int to Tensor

right_transfer_operator(B, r, Bbar)#
save(path: str)[source]#