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)[源代码]#
基类:
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 [源代码]#
- 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.
- 参数
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.
- 参数
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.
- 返回
The result of applying the MPS transfer-operator to matrix
- 返回类型
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 [源代码]#
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.
- 参数
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.
- 引发
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."
- 返回
A scalar tensor containing the truncated weight of the truncation.
- 返回类型
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 [源代码]#
Bring the MPS into canonical form according to center_position. If center_position is None, the MPS is canonicalized with center_position = 0.
- 参数
normalize -- If True, normalize matrices when shifting the orthogonality center.
- 返回
The norm of the MPS.
- 返回类型
Tensor
- center_position: Optional[int]#
- check_canonical() Any [源代码]#
Check whether the MPS is in the expected canonical form.
- 返回
The L2 norm of the vector of local deviations.
- check_orthonormality(which: str, site: int) Any #
Check orthonormality of tensor at site site.
- 参数
which --
if 'l' or 'left': check left orthogonality
if 'r' or 'right': check right orthogonality
site -- The site of the tensor.
- 返回
The L2 norm of the deviation from identity.
- 返回类型
scalar Tensor
- 引发
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.
- 参数
site -- The site for which to return the Node.
- 返回
The tensor at site.
- 返回类型
Tensor
- left_envs(sites: Sequence[int]) Dict [源代码]#
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.
- 参数
sites (list of int) -- A list of sites of the MPS.
- 返回
- The left-reduced density matrices
at each site in sites.
- 返回类型
dict mapping int to Tensor
- left_transfer_operator(A, l, Abar)#
- measure_local_operator(ops: List[Any], sites: Sequence[int]) List[Any] [源代码]#
Measure the expectation value of local operators ops site sites.
- 参数
ops (List[Tensor]) -- A list Tensors of rank 2; the local operators to be measured.
sites (Sequence[int]) -- Sites where ops act.
- 返回
measurements \(\langle\) ops[n]\(\rangle\) for n in sites
- 返回类型
List[Tensor]
- measure_two_body_correlator(op1: Any, op2: Any, site1: int, sites2: Sequence[int]) List[Any] [源代码]#
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.
- 参数
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.
- 返回
Correlator \(\langle\) op1[site1], op2[s]\(\rangle\) for s \(\in\) sites2.
- 返回类型
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.
- 参数
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.
- 返回
The norm of the tensor at FiniteMPS.center_position
- 返回类型
Tensor
- 引发
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 [源代码]#
Initialize a random FiniteMPS. The resulting state is normalized. Its center-position is at 0.
- 参数
d -- A list of physical dimensions.
D -- A list of bond dimensions.
dtype -- A numpy dtype.
backend -- An optional backend.
- 返回
FiniteMPS
- right_envs(sites: Sequence[int]) Dict [源代码]#
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.
- 参数
sites (list of int) -- A list of sites of the MPS.
- 返回
- The right-reduced density matrices
at each site in sites.
- 返回类型
dict mapping int to Tensor
- right_transfer_operator(B, r, Bbar)#