tnpy.operators.MatrixProductOperator
2.1. tnpy.operators.MatrixProductOperator#
- class tnpy.operators.MatrixProductOperator(*args, **kwargs)[source]#
Bases:
quimb.tensor.tensor_1d.MatrixProductOperator
Methods
__init__
(*args, **kwargs)add
(t[, virtual, check_collisions])Add Tensor, TensorNetwork or sequence thereof to self.
add_MPO
(other[, inplace, compress])Add another MatrixProductState to this one.
add_MPO_
(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
(other[, compress])Act with this MPO on another MPO or MPS, such that the resulting object has the same tensor network structure/indices as
other
.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])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, inplace])Conjugate all the tensors in this network (leaves all indices).
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
.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.dot
(other[, compress])Act with this MPO on another MPO or MPS, such that the resulting object has the same tensor network structure/indices as
other
.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.
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
.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.
full_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_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, ...])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])identity
(**mpo_opts)Get a identity matching this MPO.
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.
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, ...])lower_ind
(i)The name of the lower ('ket') index 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.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.
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_transpose
(sysa[, inplace])Perform the partial transpose on this MPO by swapping the bra and ket indices on sites in
sysa
.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 MPO to match
shape
.rand_state
(bond_dim, **mps_opts)Get a random vector matching this MPO.
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_lower_sites
(new_id[, where, inplace])Update the lower site index labels to a new string specifier.
reindex_lower_sites_
(new_id[, where, inplace])reindex_upper_sites
(new_id[, where, inplace])Update the upper site index labels to a new string specifier.
reindex_upper_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.
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_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
(tags, left_inds, **split_opts)Split the single tensor uniquely identified by
tags
, adding the resulting tensors from the decomposition back into the network.square
()Compute the square of
MatrixProductOperator
(MPO), which equivalently merges two MPO layers into one.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.
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 matrix version of this 1D operator, i.e. a
qarray
with shape (d, d).trace
([left_inds, right_inds])Take the trace of this MPO.
unitize
([method, allow_no_left_inds, inplace])unitize_
([method, allow_no_left_inds, inplace])upper_ind
(i)The name of the upper ('bra') index at site
i
.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.
dtype
The dtype of this TensorNetwork, this is the minimal common type of all the tensors data.
lower_ind_id
The string specifier for the lower phyiscal indices
lower_inds
An ordered tuple of the actual lower physical indices.
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.
Get a physical index size of this 1D operator.
shape
Actual, i.e. exterior, shape of this TensorNetwork.
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.
upper_ind_id
The string specifier for the upper phyiscal indices
upper_inds
An ordered tuple of the actual upper physical indices.
- property n_sites: int#
- property phys_dim: int#
Get a physical index size of this 1D operator.
- square()[source]#
Compute the square of
MatrixProductOperator
(MPO), which equivalently merges two MPO layers into one.- Return type
squared_mpo