tnpy.matrix_product_state.MatrixProductState
1.2. tnpy.matrix_product_state.MatrixProductState#
- class tnpy.matrix_product_state.MatrixProductState(*args, **kwargs)[source]#
Bases:
quimb.tensor.tensor_1d.MatrixProductState
Matrix product state (MPS) for a finite size system.
- Parameters
*args – Positional arguments for
quimb.tensor.MatrixProductState
.**kwargs – Keyword arguments for
quimb.tensor.MatrixProductState
.
Note
This class inherits directly from
quimb.tensor.MatrixProductState
, with some added features. But, note that the underlying tensors are in the shape ‘lpr’, which differs from the parent classquimb.tensor.MatrixProductState
.- __init__(*args, **kwargs)[source]#
Matrix product state (MPS) for a finite size system.
- Parameters
*args – Positional arguments for
quimb.tensor.MatrixProductState
.**kwargs – Keyword arguments for
quimb.tensor.MatrixProductState
.
Note
This class inherits directly from
quimb.tensor.MatrixProductState
, with some added features. But, note that the underlying tensors are in the shape ‘lpr’, which differs from the parent classquimb.tensor.MatrixProductState
.
Methods
__init__
(*args, **kwargs)Matrix product state (MPS) for a finite size system.
add
(t[, virtual, check_collisions])Add Tensor, TensorNetwork or sequence thereof to self.
add_MPS
(other[, inplace, compress])Add another MatrixProductState to this one.
add_MPS_
(other, *[, inplace, compress])add_tag
(tag[, where, which])Add tag to every tensor in this network, or if
where
is specified, the tensors matching those tags -- i.e. adds the tag to all tensors inself.select_tensors(where, which=which)
.add_tensor
(tensor[, tid, virtual])Add a single tensor to this network - mangle its tid if neccessary.
add_tensor_network
(tn[, virtual, ...])align
(*[, ind_ids, inplace])Align an arbitrary number of tensor networks in a stack-like geometry.
align_
(*[, ind_ids, inplace])all_inds
()Return a tuple of all indices (with repetition) in this network.
amplitude
(b)Compute the amplitude of configuration
b
.antidiag_gauge
([output_inds, atol, cache, ...])Flip the order of any bonds connected to antidiagonal tensors.
antidiag_gauge_
([output_inds, atol, cache, ...])apply_to_arrays
(fn)Modify every tensor's array inplace by applying
fn
to it.as_cyclic
([inplace])Convert this flat, 1D, TN into cyclic form by adding a dummy bond between the first and last sites.
aslinearoperator
(left_inds, right_inds[, ...])View this
TensorNetwork
as aTNLinearOperator
.astype
(dtype[, inplace])Convert the type of all tensors in this network to
dtype
.astype_
(dtype, *[, inplace])balance_bonds
([inplace])Apply
tensor_balance_bond()
to all bonds in this tensor network.balance_bonds_
(*[, inplace])bipartite_schmidt_state
(sz_a[, get, cur_orthog])Compute the reduced state for a bipartition of an OBC MPS, in terms of the minimal left/right schmidt basis.
bond
(i, j)Get the name of the index defining the bond between sites i and j.
bond_size
(i, j)Return the size of the bond between site
i
andj
.bond_sizes
()calc_current_orthog_center
()Calculate the site(s) of the current orthogonality center.
canonize
(where[, cur_orthog, bra])Mixed canonize this TN. If this is a MPS, this implies that::.
canonize_around
(tags[, which, min_distance, ...])Expand a locally canonical region around
tags
.canonize_around_
(tags[, which, ...])canonize_between
(tags1, tags2[, absorb])'Canonize' the bond between the two single tensors in this network specified by
tags1
andtags2
usingtensor_canonize_bond
.canonize_cyclic
(i[, bra, method, inv_tol])Bring this MatrixProductState into (possibly only approximate) canonical form at site(s)
i
.column_reduce
([output_inds, atol, cache, ...])Find bonds on this tensor network which have tensors where all but one column (of the respective index) is non-zero, allowing the 'cutting' of that bond.
column_reduce_
([output_inds, atol, cache, ...])compress
([form])Compress this 1D Tensor Network, possibly into canonical form.
compress_all
([inplace])Inplace compress all bonds in this network.
compress_all_
(*[, inplace])compress_between
(tags1, tags2[, max_bond, ...])Compress the bond between the two single tensors in this network specified by
tags1
andtags2
usingtensor_compress_bond()
.compress_simplify
([output_inds, atol, ...])compress_simplify_
([output_inds, atol, ...])compress_site
(i[, canonize, cur_orthog, bra])Compress the bonds adjacent to site
i
, by default first setting the orthogonality center to that site.compute_centralities
()compute_contracted_inds
(*tids[, output_inds])Get the indices describing the tensor contraction of tensors corresponding to
tids
.compute_hierarchical_linkage
([tids, method, ...])compute_hierarchical_ordering
([tids, ...])compute_hierarchical_ssa_path
([tids, ...])compute_shortest_distances
([tids, exclude_inds])Compute the minimum graph distances between all or some nodes
tids
.conj
([mangle_inner, mangle_outer])Create a conjugated copy of this
MatrixProductState
instance.conj_
([mangle_inner, inplace])contract
([tags, inplace])Contract some, or all, of the tensors in this network.
contract_
([tags, inplace])contract_around
(tags[, which, min_distance, ...])Perform a compressed contraction inwards towards the tensors identified by
tags
.contract_around_
(tags[, which, ...])contract_around_center
(**opts)contract_around_corner
(**opts)contract_between
(tags1, tags2, **contract_opts)Contract the two tensors specified by
tags1
andtags2
respectively.contract_compressed
(optimize[, output_inds, ...])contract_compressed_
(optimize[, ...])contract_cumulative
(tags_seq[, inplace])Cumulative contraction of tensor network.
contract_ind
(ind[, output_inds])Contract tensors connected by
ind
.contract_structured
(tag_slice[, ...])Perform a structured contraction, translating
tag_slice
from aslice
or ... to a cumulative sequence of tags.contract_tags
(tags[, which, inplace])Contract the tensors that match any or all of
tags
.contraction_cost
([optimize])Compute the 'contraction cost' of this tensor network.
contraction_info
([optimize])Compute the
opt_einsum.PathInfo
object decsribing the contraction of this entire tensor network using path optimizeroptimize
.contraction_path
([optimize])Compute the contraction path, a sequence of (int, int), for the contraction of this entire tensor network using path optimizer
optimize
.contraction_tree
([optimize, output_inds])Return the
cotengra.ContractionTree
corresponding to contracting this entire tensor network with path finderoptimize
.contraction_width
([optimize])Compute the 'contraction width' of this tensor network.
convert_to_zero
()Inplace conversion of this network to an all zero tensor network.
copy
([virtual, deep])Copy this
TensorNetwork
.correlation
(A, i, j[, B])Correlation of operator
A
betweeni
andj
.count_canonized
()cut_between
(left_tags, right_tags, left_ind, ...)Cut the bond between the tensors specified by
left_tags
andright_tags
, giving them the new indsleft_ind
andright_ind
respectively.cut_iter
(*inds)Cut and iterate over one or more indices in this tensor network.
delete
(tags[, which])Delete any tensors which match all or any of
tags
.diagonal_reduce
([output_inds, atol, cache, ...])Find tensors with diagonal structure and collapse those axes.
diagonal_reduce_
([output_inds, atol, cache, ...])distance
(tnB[, xAA, xAB, xBB, method])Compute the Frobenius norm distance between two tensor networks:
distribute_exponent
()Distribute the exponent
p
of this tensor network (i.e.draw
([color, output_inds, highlight_inds, ...])Plot this tensor network as a networkx graph using matplotlib, with edge width corresponding to bond dimension.
draw_tree_span
(tags[, which, min_distance, ...])Visualize a generated tree span out of the tensors tagged by
tags
.drop_tags
(tags)Remove a tag from any tensors in this network which have it.
enlarge_bond_dim
(new_bond_dim, method)entropy
(i[, cur_orthog, method])The entropy of bipartition between the left block of
i
sites and the rest.equalize_norms
([value, inplace])Make the Frobenius norm of every tensor in this TN equal without changing the overall value if
value=None
, or set the norm of every tensor tovalue
by scalar multiplication only.equalize_norms_
([value, inplace])expand_bond_dimension
(new_bond_dim[, ...])Expand the bond dimensions of this 1D tensor network to at least
new_bond_dim
.expec
(*[, compress, eps])Compute the expectation of several 1D TNs, using transfer matrix compression if any are periodic.
fit
(tn_target[, method, tol, inplace, progbar])Optimize the entries of this tensor network with respect to a least squares fit of
tn_target
which should have the same outer indices.fit_
(tn_target[, method, tol, inplace, progbar])flip
(inds[, inplace])Flip the dimension corresponding to indices
inds
on all tensors that share it.flip_
(inds, *[, inplace])from_TN
(tn[, like, inplace])Construct a specific tensor network subclass (i.e.
from_dense
(psi, dims[, site_ind_id, site_tag_id])Create a
MatrixProductState
directly from a dense vectorfull_simplify
([seq, output_inds, atol, ...])Perform a series of tensor network 'simplifications' in a loop until there is no more reduction in the number of tensors or indices.
full_simplify_
([seq, output_inds, atol, ...])fuse_multibonds
([inplace])Fuse any multi-bonds (more than one index shared by the same pair of tensors) into a single bond.
fuse_multibonds_
(*[, inplace])gate
(G, where[, contract, tags, ...])Act with the gate
g
on siteswhere
, maintaining the outer indices of the 1D tensor netowork.gate_
(G, where[, contract, tags, ...])gate_inds
(G, inds[, contract, tags, info, ...])Apply the 'gate'
G
to indicesinds
, propagating them to the outside, as if applyingG @ x
.gate_inds_
(G, inds[, contract, tags, info, ...])gate_split
(G, where[, inplace])Apply a two-site gate and then split resulting tensor to retrieve a MPS form.
gate_split_
(G, where, *[, inplace])gate_with_auto_swap
(G, where[, inplace, ...])Perform a two site gate on this MPS by, if necessary, swapping and compressing the sites until they are adjacent, using
gate_split
, then unswapping the sites back to their original position.gauge_all_canonize
([max_iterations, absorb, ...])Iterative gauge all the bonds in this tensor network with a basic 'canonization' strategy.
gauge_all_canonize_
([max_iterations, ...])gauge_all_random
([iterations, unitary, inplace])Gauge all the bonds in this network randomly.
gauge_all_random_
([iterations, unitary, inplace])gauge_all_simple
([max_iterations, tol, ...])Iterative gauge all the bonds in this tensor network with a 'simple update' like strategy.
gauge_all_simple_
([max_iterations, tol, ...])gauge_local
(tags[, which, max_distance, ...])Iteratively gauge all bonds in the tagged sub tensor network according to one of several strategies.
gauge_local_
(tags[, which, max_distance, ...])gauge_simple_insert
(gauges[, smudge])Insert the simple update style bond gauges found in
gauges
if they are present in this tensor network.gauge_simple_remove
([outer, inner])Remove the simple update style bond gauges inserted by
gauge_simple_insert
.gauge_simple_temp
(gauges[, smudge, ...])Context manager that temporarily inserts simple update style bond gauges into this tensor network, before optionally ungauging them.
gen_loops
([max_loop_length])Generate sequences of tids that represent loops in the TN.
gen_site_coos
()geometry_hash
([output_inds, strict_index_order])A hash of this tensor network's shapes & geometry.
get_equation
([output_inds])Get the 'equation' describing this tensor network, in
einsum
style with a single unicode letter per index.get_inputs_output_size_dict
([output_inds])Get a tuple of
inputs
,output
andsize_dict
suitable for e.g.get_symbol_map
()Get the mapping of the current indices to
einsum
style single unicode characters.get_tree_span
(tids[, min_distance, ...])Generate a tree on the tensor network graph, fanning out from the tensors identified by
tids
, up to a maximum ofmax_distance
away.graph
([color, output_inds, highlight_inds, ...])Plot this tensor network as a networkx graph using matplotlib, with edge width corresponding to bond dimension.
graph_tree_span
(tags[, which, min_distance, ...])Visualize a generated tree span out of the tensors tagged by
tags
.hyperinds_resolve
([mode, sorter, inplace])Convert this into a regular tensor network, where all indices appear at most twice, by inserting COPY tensor or tensor networks for each hyper index.
hyperinds_resolve_
([mode, sorter, inplace])ind_size
(ind)Find the size of
ind
.ind_sizes
()Get dict of each index mapped to its size.
inner_inds
()Tuple of interior indices, assumed to be any indices that appear twice or more (this only holds generally for non-hyper tensor networks).
insert_gauge
(U, where1, where2[, Uinv, tol])Insert the gauge transformation
U^-1 @ U
into the bond between the tensors,T1
andT2
, defined bywhere1
andwhere2
.insert_operator
(A, where1, where2[, tags, ...])Insert an operator on the bond between the specified tensors, e.g..
insert_operator_
(A, where1, where2[, tags, ...])iscomplex
()isel
(selectors[, inplace])Select specific values for some dimensions/indices of this tensor network, thereby removing them.
isel_
(selectors, *[, inplace])largest_element
()Return the 'largest element', in terms of absolute magnitude, of this tensor network.
least_central_tid
()left_canonize
([stop, start, normalize, bra])Left canonize all or a portion of this TN. If this is a MPS, this implies that::.
left_canonize_site
(i[, bra])Left canonize this TN's ith site, inplace.
left_compress
([start, stop, bra])Compress this 1D TN, from left to right, such that it becomes left-canonical (unless
absorb != 'right'
).left_compress_site
(i[, bra])Left compress this 1D TN's ith site, such that the site is then left unitary with its right bond (possibly) reduced in dimension.
load
(filename)Initialize the underlying tensors of
MatrixProductState
from a file.logneg_subsys
(sysa, sysb[, compress_opts, ...])Compute the logarithmic negativity between subsytem blocks, e.g..
loop_simplify
([output_inds, ...])Try and simplify this tensor network by identifying loops and checking for low-rank decompositions across groupings of the loops outer indices.
loop_simplify_
([output_inds, ...])magnetization
(i[, direction, cur_orthog])Compute the magnetization at site
i
.make_norm
([mangle_append, layer_tags, ...])Make the norm tensor network of this tensor network
tn.H & tn
.make_tids_consecutive
([tid0])Reset the tids - node identifies - to be consecutive integers.
mangle_inner_
([append, which])Generate new index names for internal bonds, meaning that when this tensor network is combined with another, there should be no collisions.
max_bond
()Return the size of the largest bond in this network.
maybe_convert_coo
(x)Check if
x
is an integer and convert to the corresponding site tag if so.measure
(site[, remove, outcome, renorm, ...])Measure this MPS at
site
, including projecting the state.measure_
(site[, remove, outcome, renorm, ...])most_central_tid
()multiply
(x[, inplace, spread_over])Scalar multiplication of this tensor network with
x
.multiply_
(x, *[, inplace, spread_over])multiply_each
(x[, inplace])Scalar multiplication of each tensor in this tensor network with
x
.multiply_each_
(x, *[, inplace])new_bond
(tags1, tags2, **opts)Inplace addition of a dummmy (size 1) bond between the single tensors specified by by
tags1
andtags2
.norm
(**contract_opts)Frobenius norm of this tensor network.
normalize
([bra, eps, insert])Normalize this MPS, optional with co-vector
bra
.outer_dims_inds
()Get the 'outer' pairs of dimension and indices, i.e. as if this tensor network was fully contracted.
outer_inds
()Tuple of exterior indices, assumed to be any lone indices (this only holds generally for non-hyper tensor networks).
pair_simplify
([cutoff, output_inds, ...])pair_simplify_
([cutoff, output_inds, ...])partial_trace
(keep[, upper_ind_id, ...])Partially trace this matrix product state, producing a matrix product operator.
partial_trace_compress
(sysa, sysb[, eps, ...])Perform a compressed partial trace using singular value lateral then vertical decompositions of transfer matrix products.
partition
(tags[, which, inplace])Split this TN into two, based on which tensors have any or all of
tags
.partition_tensors
(tags[, inplace, which])Split this TN into a list of tensors containing any or all of
tags
and aTensorNetwork
of the the rest.permute_arrays
([shape])Permute the indices of each tensor in this MPS to match
shape
.ptr
(keep[, upper_ind_id, rescale_sites])Alias of
partial_trace()
.random
(n, bond_dim, phys_dim, **kwargs)Create a randomly initialized
MatrixProductState
.randomize
([dtype, seed, inplace])Randomize every tensor in this TN - see
quimb.tensor.tensor_core.Tensor.randomize()
.randomize_
([dtype, seed, inplace])rank_simplify
([output_inds, equalize_norms, ...])Simplify this tensor network by performing contractions that don't increase the rank of any tensors.
rank_simplify_
([output_inds, ...])reduce_inds_onto_bond
(inda, indb[, tags, ...])Use QR factorization to 'pull' the indices
inda
andindb
off of their respective tensors and onto the bond between them.reindex
(index_map[, inplace])Rename indices for all tensors in this network, optionally in-place.
reindex_
(index_map, *[, inplace])reindex_all
(new_id[, inplace])Reindex all physical sites and change the
site_ind_id
.reindex_all_
(new_id, *[, inplace])reindex_sites
(new_id[, where, inplace])Update the physical site index labels to a new string specifier.
reindex_sites_
(new_id[, where, inplace])replace_section_with_svd
(start, stop, eps, ...)Take a 1D tensor network, and replace a section with a SVD.
replace_with_identity
(where[, which, inplace])Replace all tensors marked by
where
with an identity. E.g. ifX
denotewhere
tensors::.replace_with_svd
(where, left_inds, eps, *[, ...])Replace all tensors marked by
where
with an iteratively constructed SVD. E.g. ifX
denotewhere
tensors::.replace_with_svd_
(where, left_inds, eps, *)retag
(tag_map[, inplace])Rename tags for all tensors in this network, optionally in-place.
retag_
(tag_map, *[, inplace])retag_sites
(new_id[, where, inplace])Modify the site tags for all or some tensors in this 1D TN (without changing the
site_tag_id
).right_canonize
([stop, start, normalize, bra])Right canonize all or a portion of this TN. If this is a MPS, this implies that::.
right_canonize_site
(i[, bra])Right canonize this TN's ith site, inplace.
right_compress
([start, stop, bra])Compress this 1D TN, from right to left, such that it becomes right-canonical (unless
absorb != 'left'
).right_compress_site
(i[, bra])Right compress this 1D TN's ith site, such that the site is then right unitary with its left bond (possibly) reduced in dimension.
save
(filename)Save the underlying tensors of this
MatrixProductState
in the order of indices'lpr'
into file.schmidt_gap
(i[, cur_orthog, method])The schmidt gap of bipartition between the left block of
i
sites and the rest.schmidt_values
(i[, cur_orthog, method])Find the schmidt values associated with the bipartition of this MPS between sites on either site of
i
. In other words,i
is the number of sites in the left hand partition::.select
(tags[, which, virtual])Get a TensorNetwork comprising tensors that match all or any of
tags
, inherit the network properties/structure fromself
.select_all
(tags, *[, which, virtual])select_any
(tags, *[, which, virtual])select_local
(tags[, which, max_distance, ...])Select a local region of tensors, based on graph distance
max_distance
to any tagged tensors.select_neighbors
(tags[, which])Select any neighbouring tensors to those specified by
tags
.selfselect_tensors
(tags[, which])Return the sequence of tensors that match
tags
.shift_orthogonality_center
(current, new[, bra])Move the orthogonality center of this MPS.
show
([max_width])singular_values
(i[, cur_orthog, method])Find the singular values associated with the ith bond.
site_ind
(i)Get the physical index name of site
i
.site_tag
(i)The name of the tag specifiying the tensor at site
i
.slice2sites
(tag_slice)Take a slice object, and work out its implied start, stop and step, taking into account cyclic boundary conditions.
split
(left_inds[, method, get, absorb, ...])Decompose this tensor into two tensors.
split_simplify
([atol, equalize_norms, ...])Find tensors which have low rank SVD decompositions across any combination of bonds and perform them.
split_simplify_
([atol, equalize_norms, ...])split_tensor
(site, direction)Split the tensor at given
site
into two tensors, and multiply the one on left or rightdirection
into its neighbouring tensor.squeeze
([fuse, inplace])Drop singlet bonds and dimensions from this tensor network.
squeeze_
([fuse, inplace])strip_exponent
(tid_or_tensor[, value])Scale the elements of tensor corresponding to
tid
so that the norm of the array is some value, which defaults to1
.subgraphs
([virtual])Split this tensor network into disconneceted subgraphs.
swap_site_to
(i, f[, cur_orthog, inplace])Swap site
i
to sitef
, compressing the bond after each swap.swap_sites_with_compress
(i, j[, cur_orthog, ...])Swap sites
i
andj
by contracting, then splitting with the physical indices swapped.tensors_sorted
()Return a tuple of tensors sorted by their respective tags, such that the tensors of two networks with the same tag structure can be iterated over pairwise.
tids_are_connected
(tids)Check whether nodes
tids
are connected.to_dense
(*inds_seq, **contract_opts)Return the dense ket version of this 1D vector, i.e. a
qarray
with shape (-1, 1).trace
(left_inds, right_inds, **contract_opts)Trace over
left_inds
joined withright_inds
unitize
([method, allow_no_left_inds, inplace])unitize_
([method, allow_no_left_inds, inplace])view_as
(cls[, inplace])View this tensor network as subclass
cls
.view_as_
(cls, *[, inplace])view_like
(like[, inplace])View this tensor network as the same subclass
cls
aslike
inheriting its extra properties as well.view_like_
(like, *[, inplace])Attributes
H
Conjugate all the tensors in this network (leaves all indices).
L
The number of sites.
arrays
Get the tuple of raw arrays containing all the tensor network data.
The bond dimensions.
dtype
The dtype of this TensorNetwork, this is the minimal common type of all the tensors data.
nsites
The number of sites.
num_indices
The total number of indices in the tensor network.
num_tensors
The total number of tensors in the tensor network.
Physical dimensions of local state.
shape
Actual, i.e. exterior, shape of this TensorNetwork.
site_ind_id
The string specifier for the physical indices
site_inds
An ordered tuple of the actual physical indices.
site_tag_id
The string specifier for tagging each site of this 1D TN.
site_tags
An ordered tuple of the actual site tags.
sites
tags
tensors
Get the tuple of tensors in this tensor network.
- __init__(*args, **kwargs)[source]#
Matrix product state (MPS) for a finite size system.
- Parameters
*args – Positional arguments for
quimb.tensor.MatrixProductState
.**kwargs – Keyword arguments for
quimb.tensor.MatrixProductState
.
Note
This class inherits directly from
quimb.tensor.MatrixProductState
, with some added features. But, note that the underlying tensors are in the shape ‘lpr’, which differs from the parent classquimb.tensor.MatrixProductState
.
- property n_sites: int#
- property phys_dim: int#
Physical dimensions of local state.
- property bond_dim: int#
The bond dimensions.
Notes
The actual bond dimensions can be smaller than this one at the boundaries.
- permute_arrays(shape='lrp')[source]#
Permute the indices of each tensor in this MPS to match
shape
. This doesn’t change how the overall object interacts with other tensor networks but may be useful for extracting the underlying arrays consistently. This is an inplace operation.- Parameters
shape (str) – A permutation of
'lrp'
specifying the desired order of the left, right, and physical indices respectively.
- conj(mangle_inner=False, mangle_outer=False)[source]#
Create a conjugated copy of this
MatrixProductState
instance.- Parameters
mangle_inner (bool) – Whether to rename the inner indices, so that there will be no conflict with the original one when contracting the network.
mangle_outer (bool) – Whether to rename the outer indices, so that there will be no conflict with the original one when contracting the network.
- Return type
conj_mps
- save(filename)[source]#
Save the underlying tensors of this
MatrixProductState
in the order of indices'lpr'
into file. Only accepts suffix'.hdf5'
or'.npz'
as file extension.- Parameters
filename (str) – Absolute path to file in local disk.
Returns:
- classmethod load(filename)[source]#
Initialize the underlying tensors of
MatrixProductState
from a file. Tensors in the file should take the order of indices'lpr'
. Only accepts suffix'.hdf5'
or'.npz'
as file extension.- Parameters
filename (str) – Absolute path to file in local disk.
- Return type
mps
- classmethod random(n, bond_dim, phys_dim, **kwargs)[source]#
Create a randomly initialized
MatrixProductState
.- Parameters
n (int) – The system size.
bond_dim (int) – The bond dimensions.
phys_dim (int) – Physical dimensions of local state.
- Return type
Returns:
- split_tensor(site, direction)[source]#
Split the tensor at given
site
into two tensors, and multiply the one on left or rightdirection
into its neighbouring tensor. This is an inplace operation.- Parameters
site (int) –
direction (tnpy.matrix_product_state.Direction) –
Returns: