pyblock.tensor¶
pyblock.tensor.tensor¶
Blocksparse tensor and tensor network.

class
pyblock.tensor.tensor.
SubTensor
(q_labels=None, reduced=None, cgs=None)¶ Bases:
object
A block in blocksparse tensor.
 Attributes:
 q_labels : tuple(DirectProdGroup..)
 Quantum labels for this subtensor block. Each element in the tuple corresponds one rank of the tensor.
 rank : int
 Rank of the tensor.
rank == len(q_labels)
.  ng : int
 Number of subsymmetry groups.
ng == q_labels[0].ng
.  reduced : numpy.ndarray
 Rank
rank
dense reduced matrix.  reduced_shape : tuple(int..)
 Shape of
reduced
 cgs : list(numpy.ndarray)
 A list of CG factors of length
ng
with each element being Rankrank
dense reduced matrix representing CG coefficients for projected quantum numbers in each subsymmetry group.

T
¶ Transpose.

add_noise
(noise)¶ Add noise to reduced matrix by random numbers in [0.5 * noise, 0.5 * noise).
 Args:
 noise : float
 prefactor for the noise.

build_random
()¶ Set reduced matrix with random numbers in [0, 1).

build_rank3_cg
()¶ Generate
cgs
for rank3 tensor.

build_zero
()¶ Set reduced matrix to zero.

equal_shape
(o)¶

class
pyblock.tensor.tensor.
Tensor
(blocks=None, tags=None, contractor=None)¶ Bases:
object
Blocksparse tensor.
 Attributes:
 blocks : list(SubTensor)
 A list of (nonzero) blocks.
 tags : set(str or int)
 Tags of the tensor for labeling the type or site index of the tensor.
 contractor :
 If not None, this is used to perform specialized tensor contraction and diagonalization.

add_noise
(noise)¶ Add noise to reduced matrix by random numbers in [0.5 * noise, 0.5 * noise).
 Args:
 noise : float
 prefactor for the noise.
Add the tags, return
self
for chain notation.

align
(o)¶

build_identity
()¶ Set the reduced matrix to identity. Not work for general situations.

build_random
()¶ Fill the reduced matrix with random numbers in [0, 1).

build_rank3_cg
()¶ Generate CG coefficients for rank3 tensor.

build_zero
()¶ Fill the reduced matrix with zero.

static
contract
(tsa, tsb, idxa, idxb, target_q_labels=None)¶ Contract two Tensor to form a new Tensor.
 Args:
 tsa : Tensor
 Tensor a, as left operand.
 tsb : Tensor
 Tensor b, as right operand.
 idxa : list(int)
 Indices to be contracted in tensor a.
 idxb : list(int)
 Indices to be contracted in tensor b.
 target_q_labels : None or DirectProdGroup or [DirectProdGroup]
 If None, this is contraction of states. For all other cases, this is contraction of operators. If DirectProdGroup, the resulting direct product operator will have the specific quantum label. If [DirectProdGroup], the resulting direct product operator will have mixed quantum labels (not very useful).
 Returns:
 tensor : Tensor
 The contracted Tensor.

copy
()¶ Shallow copy.

deep_copy
()¶ Deep copy.

diag_eigs
(k=1, limit=None)¶

equal_shape
(o)¶

fit
(o, v)¶

fuse_index
(idxl, fused, target=None, equal=None)¶

get_diag_density_matrix
(trace_right, noise=0.0)¶

left_canonicalize
(mode='reduced')¶ Left canonicalization (using QR factorization).
 Returns:
 r_blocks : dict((DirectProdGroup, ) > numpy.ndarray)
 The R matrix for each rightindex quantum label.

left_multiply
(mats)¶ Left Multiplication. Currently only used for multiplying R obtained from rightcanonicalization.
 Args:
 mats : dict((DirectProdGroup, ) > numpy.ndarray)
 The R matrix for each rightindex quantum label.

modify
(other)¶ Modify the blocks according to another Tensor’s blocks.

n_blocks
¶ Number of (nonzero) blocks.

ng
¶ Number of subsymmetry groups.

norm
()¶

static
operator_init
(basis, repr, op_q_labels)¶ Build tensor for singlesite primiary operator. When this is a tensor operator,
repr
andop_q_labels
will contain multiple items.cgs
andreduced
will be calculated. Args:
 basis : list(DirectProdGroup)
 Site basis.
 repr : list(numpy.ndarray)
 A list of dense matrices for different
op_q_label
s.  op_q_labels : list(DirectProdGroup)
 A list of operator quantum labels.
 Returns:
 tensor : Tensor
 Operator Tensor.

static
partial_trace
(ts, idx_l, idx_r, target_q_labels=None)¶ Partial trace of a tensor. The indices in
idx_l
will be combined. The indices inidx_r
will also be combined. Then for each tensor block with q_label[idx_l] == q_label[idx_r], the term will be included, with its reduced matrix traced in corresponding indices. Args:
 ts : Tensor
 Tensor to be traced.
 idx_l : list(int)
 Left traced indices.
 idx_r : list(int)
 Right traced indices.
 target_q_labels : None
 Defaults to None. Currently only the default is implemented.
 Returns:
 tensor : Tensor
 The resulting Tensor with indices
idx_l
andidx_r
are traced.

rank
¶ Rank of the tensor.

static
rank2_init_target
(left, right, target)¶

static
rank3_init_left
(pre, basis, post)¶ Build the MPS rank3 tensor by coupling states in
pre
andbasis
into states inpost
.cgs
andreduced
will not be calculated. Args:
 pre : dict(DirectProdGroup > int)
 Left basis.
 basis : dict(DirectProdGroup > int)
 Site basis.
 post : dict(DirectProdGroup > int)
 Right basis. Right basis should be obtained from truncating the direct product of left and site basis.
 Returns:
 tensor : Tensor

static
rank3_init_right
(pre, basis, post)¶ Build the MPS rank3 tensor by coupling states in
pre
andbasis
into states inpost
.cgs
andreduced
will not be calculated. Args:
 pre : dict(DirectProdGroup > int)
 Right basis.
 basis : dict(DirectProdGroup > int)
 Site basis.
 post : dict(DirectProdGroup > int)
 Left basis. Left basis should be obtained from truncating the direct product of right and site basis.
 Returns:
 tensor : Tensor

right_canonicalize
(mode='reduced')¶ Right canonicalization (using LQ factorization).
 Returns:
 l_blocks : dict((DirectProdGroup, ) > numpy.ndarray)
 The L matrix for each leftindex quantum label.

right_multiply
(mats)¶ Right Multiplication. Currently only used for multiplying L obtained from rightcanonicalization.
 Args:
 mats : dict((DirectProdGroup, ) > numpy.ndarray)
 The L matrix for each leftindex quantum label.

set_contractor
(contractor)¶ Change the contractor, return
self
for chain notation.
Change the tags, return
self
for chain notation.

sort
()¶ Sort nonzero blocks in increasing order of quantum labels.

split
(absorb_right, k=1)¶ Split rank2 blockdiagonal Tensor to two tensors (using SVD).
 Args:
 absorb_right : bool
 If absorb_right is True, singlular values will be multiplied into right Tensor. Otherwise, They will be multiplied into left Tensor.
 k : int
 Maximal bond length. Defaults to 1 (no truncation).
 Returns:
 left_tensor : Tensor
 Left tensor.
 right_tensor : Tensor
 Right tensor.
 error : float
 Sum of Discarded weights.

split_using_density_matrix
(dm, absorb_right, k=1, limit=None)¶

svd
(q_label_left, k=1)¶ Singular Value Decomposition of rank2 blockdiagonal Tensor.
 Args:
 k : int
 Maximal bond length. Defaults to 1 (no truncation).
 Returns:
 left_tensor : Tensor
 Left tensor.
 right_tensor : Tensor
 Right tensor.
 svd_s : list(numpy.ndarray)
 A list including singular values for each tensor block.
 error : float
 Sum of Discarded weights (square of singular values).

to_dict
(idx)¶

unfuse_index
(idx, left, right)¶

zero_copy
()¶ A deep copy with zero reduced matrices.

class
pyblock.tensor.tensor.
TensorNetwork
(tensors=None)¶ Bases:
object
An inefficient implementation for Quimb TensorNetwork.
 Attributes:
 tensors : list(Tensor)
 List of tensors in the network.

add
(tn)¶ Add a Tensor or TensorNetwork to the tensor network.
Add tags to all tensors in the tensor network.

contract
(tags, in_place=False)¶ Contract a sub tensor network specified by tags. If any Tensor in the sub tensor network has a
contractor
, the specialized contraction will be used. Currently the general contraction is not implemented. Args:
 tags : tuple(str or int..)
 Tags of sub tensor network.
 Kwargs:
 in_place : bool
 Defaults to False. Indicating whether the current tensor network should be changed.
 Returns:
 tn : TensorNetwork
 The tensor network with selected sub tensor network replaced by its contraction.

copy
()¶ Shallow copy.

deep_copy
()¶ Deep copy.

remove
(tags, which='all', in_place=False)¶ Remove a sub tensor network specified by tags.
 Args:
 tags : set(str or int)
 Tags of sub tensor network.
 Kwargs:
 which : ‘all’ or ‘any’ or ‘exact’
 Defaults to ‘all’. Indicating how the
tags
should be applied for selection.  in_place : bool
 Defaults to False. Indicating whether the current tensor network should be changed.
 Returns:
 tn : TensorNetwork
 The remaining tensor network.
Remove tags from all tensors in the tensor network.

replace
(tags, tn, which='all')¶

select
(tags, which='all', inverse=False)¶ Extract a sub tensor network specified by tags.
 Args:
 tags : set(str or int)
 Tags of sub tensor network.
 Kwargs:
 which : ‘all’ or ‘any’ or ‘exact’
 Defaults to ‘all’. Indicating how the
tags
should be applied for selection.  inverse : bool
 Defaults to False. Indicating whether the selection should be inversed.
 Returns:
 tn : TensorNetwork
 The selected tensor network.

set_contractor
(contractor)¶ Set contractor for all tensors in the tensor network.
Return a list of tags collected from all tensors in the tensor network.

zero_copy
()¶ Deep copy with zeros.

exception
pyblock.tensor.tensor.
TensorNetworkError
¶ Bases:
Exception