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β.
- 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)#