pyUni10.UniTensor

class pyUni10.UniTensor

Proxy of C++ uni10::UniTensor class.

Class for symmetric tensors.

pyUni10.UniTensor([val])

Construct a rank-0 tensor (scalar)

Parameters:var (float) – initial value
Returns:a rank-0 tensor (scalar)
Return type:UniTensor
pyUni10.UniTensor(bds, labels, name="")

Construct a UniTensor

Parameters:
  • bds (array of Bond) – list of bonds
  • labels (array of int) – list of labels
  • name (str) – name of the tensor
Returns:

a UniTensor object

Return type:

UniTensor

Methods

UniTensor.assign(bds)

Restructures the UniTensor with bonds bds, and clear all the content.

Parameters:bds (array of Bonds) – list of bonds
Returns:a UniTensor with bonds bds
Return type:UniTensor
UniTensor.blockNum()

Returns the number of blocks in UniTensor

Returns:total number of blocks
Return type:int
UniTensor.blockQnum([idx])

Returns the quantum number of the idx-th block.

If no input is given, returns full list of quantum numbers associated with blocks in UniTensor.

Parameters:idx (int) – block index
Returns:quantum number(s)
Return type:(array of) Qnum
UniTensor.bond([idx])

Returns the idx-th bond in UniTensor.

If no input is given, returns an array of bonds associated with UniTensor.

Returns:bond(s)
Return type:(array of) Bond
UniTensor.bondNum()

Returns the number of bonds in UniTensor.

Returns:number of bonds
Return type:int
UniTensor.combineBond(labels)

Combines bonds with labels. The resulting bond has the same label and bondType as the bond with the first label in labels.

Parameters:labels (list) – array of labels
Returns:combined bond with the same label and bondType as first bond in labels
Return type:Bond
UniTensor.elemCmp(Tb)

Tests whether the elements of the UniTensor are the same as in Tb.

Parameters:Tb (UniTensor) –
Returns:True if the elements of UniTensor is the same as in Tb, False otherwise.
Rtyoe:bool
UniTensor.elemNum()

Returns the number of elements in UniTensor.

Returns:number of elements
Return type:int
UniTensor.getBlock([qnum, ]diag=false)

Returns the block elements of quantum number qnum as a Matrix. If the diag flag is set, only the diagonal elements of the block will be picked out to a diagonal Matrix. If qnum is not given, returns the Qnum(0) block.

Parameters:
  • qnum (Qnum) – blcok quantum number
  • diag (bool) – If True, output a diagnoal part only
Returns:

a Matrix of block of qnum

Return type:

Matrix

UniTensor.getBlocks()

Returns the a dictionary {qnum:block} of the mapping from Qnum to Matrix .

Returns:mapping from Qnum to Matrix
Return type:dict
UniTensor.getElem()

Returns the reference to th elements of UniTensor

Returns:Reference to the elements
Return type:float *
UniTensor.getName()

Returns the name of UniTensor

Returns:Name of UniTensor
Return type:str
UniTensor.getRawElem()

Returns the raw elements of UniTensor with row(column) basis defined by the incoming (outgoing) bonds.

Returns:raw elements of UniTensor
Return type:Matrix
UniTensor.identity([qnum])

Set the diagonal elements to 1 and the off-diagonal elements to 0 in all blocks. If qnum is given, only set the elements in the block with quantum number equal to qnum.

param Qnum qnum:
 quantum number
UniTensor.inBondNum()

Returns the number of incoming bonds in UniTensor

Returns:number of incoming bonds
Return type:int
UniTensor.label([idx])

Returns the label of the idx-th bond. If no input is given, returns an array of labels.

Parameters:idx (int) – bond index
Returns:(array of) label(s)
Return type:int
UniTensor.orthoRand()

Randomly generates orthogonal bases and assigns to blocks.

UniTensor.partialTrace(la, lb)

Traces out bonds of label la and lb, and returns a reference to resulting tensor.

Returns:reference to the partial trace of UniTensor
Return type:float *
UniTensor.permute([new_label, ]inBondNum)

Permutes the order the bonds according to new_label, and changes the number of incoming bonds to inBondNum.

Returns:reference to the permuted UniTensor
Return type:float *
UniTensor.printRawElem()

Prints the raw elements of UniTensor

static UniTensor.profile()

Prints the memory usage of all the existing UniTensors .

UniTensor.putBlock([qnum, ]mat)

Assigns the elements of Matrix mat into the block with Qnum qnum of UniTensor. If qnum is not give, assigns to Qnum(0) block.

Parameters:
  • qnum (Qnum) – quantum number of the block being assigned to
  • mat (Matrix) – matrix to be assigned.
UniTensor.randomize()

Assigns random numbers between 0 and 1 to the elements of UniTensor.

UniTensor.save(filename)

Saves the content of UniTensor to the binary file filename.

UniTensor.setElem(elem)

Assigns the elements to UniTensor, replacing the originals.

Parameters:elem (array of float) – elements
UniTensor.setLabel(new_labels)

Assigns new_labels to the bonds of UniTensor, replacing the orinals.

Parameters:new_labels (array of int) – new labels
UniTensor.setName(name)

Assigns name to UniTensor

Parameters:name (str) – name to be assigned
UniTensor.setRawElem(rawElem)

Assigns raw elements (non-block-diagonal) to UniTensor.

Parameters:rawElem (array of float) – input elements
UniTensor.set_zero()

Sets the elements of UniTensor to zero.

UniTensor.similar(Tb)

Tests whether the UniTensor is similar to input tensor Tb. Two tensors are said to be similar if the bonds of the tensors are exactly the same.

Parameters:Tb (UniTensor) – tensor to be compared to.
Returns:True if UniTensor and Tb are similar.
Return type:bool
UniTensor.trace()

Traces out incoming and outgoing bonds, and returns the trace value.

Returns:trace of UniTensor.
Return type:float
UniTensor.transpose()

Transposes all blocks associated with quantum numbers. The bonds are changed from incoming to outcoming or vice versa while the quantum numbers remain the same on the bonds.

Returns:reference to the transposed tensor.
Return type:UniTensor &
UniTensor.hosvd(group_labels, groups, groupsSize, Ls)

Performs High-order SVD of UniTensor.

Parameters:
  • group_labels (array of int) – Ordered labels of the bonds
  • list (groups) – Number of external bonds in each mode
  • groupSize (int) – Number of modes
  • Ls (array of Matrix) – Singular values in each direction
Returns:

array of unitaries, and the core tensor

UniTensor.hosvd(modeNum, fixedNum, Ls)

Performs High-order SVD of UniTensor

Parameters:
  • modeNum (int) – Number of output modes
  • fixedNum (int) – Number of bonds to remain unchanged
Returns:

array of unitaries, and the core tensor