Modules in tensorNet

tensor module

Module containing the Tensor class.

@authors: Gerald E. Fux (gefux) & Dainius Kilda (dkilda)

class tensornet.tensor.Tensor(input_ndarray, description=None, name=None)[source]

Represents a tensor object.

Unlike a numpy.ndarray object an instance of this class can carry additional information. The legs of a Tensor can have names, two legs can be connected via a kronecker-delta (generalisation of a diagonal matrix), etc..

Note

about the previous version: gefux: self._tensor_data_rank seems to be redundant information. It is actually not always updated correctly (eg. after make_delta is called) We should remove it and use len(self.get_shape()) when needed.

__init__(input_ndarray, description=None, name=None)[source]

Constructor taking a numpy.ndarray as well as an optional leg description and a name.

Parameters:
  • input_ndarray – the initial numpy.ndarray object.
  • description – list of strings; leg names (e.g. ["W",None,"N"]).
  • name – sting; name of the tensor.
draw(left_of_drawing='\n\n\n\n\n')[source]

Returns a 5x5 characters string representing the tensor.

Parameters:left_of_drawing – ?? missing expl. ??
Returns:a 5x5 characters string representing the tensor.
Return type:string

Todo

complete docstring.

set_description(description=None)[source]

Sets the leg descriptions.

Parameters:description – list of strings; leg names (e.g. ["W",None,"N"]).
set_name(name=None)[source]

Sets the tensor name.

Parameters:name – string; name of the tensor.
get_ndarray()[source]

Generates and returns the numpy.ndarray object associated to the tensor.

Returns:the tensor exported as an numpy.ndarray object.
Return type:numpy.ndarray
get_description()[source]

Returns a list of the leg descriptions.

Returns:a list of all leg names (e.g. ["W",None,"N"]).
Return type:list of strings

Note

Simplified method compared to version 0.1.

get_legs_description()[source]

Returns a string with information about the tensor legs.

Returns:description of the tensor legs.
Return type:string
get_name()[source]

Returns the tensor name.

Returns:name of the tensor.
Return type:string
get_shape()[source]

Returns the shape of the tensor (dimensons of all legs).

Returns:shape of the tensor.
Return type:tupel of integers
get_dim(index)[source]

Return dimension of a specified leg.

Parameters:index – index of the specified leg.
Returns:dimension of the specified leg.
Return type:integer

Note

gefux: I changed “leg” -> “index” for consistency

get_index_deltas()[source]

Return a list of sets indicating the legs that are connected via a Kronecker delta.

Returns:the indices of the legs that are connected via a Kronecker deltas.
Return type:list of sets of integers
make_delta(source, target, description=None)[source]

Create a new leg connected to an existing leg with a Kronecker delta.

sum_over(indices=None)[source]

Sum over a leg.

merge_legs(legs, new_legs, descriptions=None)[source]

Merge legs.

private functions:

update(tensordata)[source]

Todo

gefux: If a tensornet user would use this method it would violate the abstraction principle, because _tensor_data is the internal storage that could be a space tensor or something else later. It’s name should therefor start with “_”.

Todo

gefux: I find the name “update” inappropriate because it only applies to the case were there is no extra abstract information (no deltas, or something else in the future).

Todo

gefux: In case we actually do want this to be a public method, should we copy the tensordata (like in the constructor) or reference it (like done here)?

_merge_legs(legs, new_leg=None, description='New')[source]

Todo

gefux: This seems to be not compatible with having deltas in the Tensor, i.e. it throws away this information by using self.get_ndarray().

_split_legs(old_leg, legs, dims, descriptions=('New-0', 'New-1'))[source]

Todo

gefux: This seems to be not compatible with having deltas in the Tensor, i.e. it throws away this information by using self.get_ndarray().

singlesite module

This module contains the tensornet.Tensor methods as functions.

Todo

rethink the name of this module.

@authors: Gerald E. Fux (gefux) & Dainius Kilda (dkilda)

tensornet.singlesite.make_delta(tensor, source, target, description=None, name=None)[source]

Create a new leg connected to an existing leg with a Kronecker delta.

tensornet.singlesite.merge_legs(tensor, legs, new_legs, descriptions=None, name=None)[source]

Merge legs.

tensornet.singlesite.sum_over(tensor, indices=None, name=None)[source]

Sum over a leg.

ncon module

A module for the function ncon, which does contractions of several tensors.

Copied and adapted from https://github.com/mhauru/ncon

tensornet.ncon.reasurement(n=None)[source]

Function of great importance. Feel free to call it as often as you want!

Returns:The truth
tensornet.ncon.plug_single(single, single_index, tensor, tensor_index, name=None)[source]

Contract N-D “tensor” and 1D/2D “single” by connecting their legs “tensor_index” and “single_index” – a contraction that doesn’t create new legs (hence “plug”).

Parameters:
  • single – bla bla ??
  • single_index – bla bla ??
  • tensor – bla bla ??
  • tensor_index – bla bla ??
  • name – bla bla ??
Returns:

the contracted tensor.

Return type:

tensornet.tensor.Tensor

Todo

complete docstring.

tensornet.ncon.ncon(tt, v, order=None, forder=None, check_indices=True)[source]

tt = [t1, t2, …, tp] list of tensors.

v = (v1, v2, …, vp) tuple of lists of indices e.g. v1 = [3 4 -1] labels the three indices of tensor t1, with -1 indicating an uncontracted index (open leg) and 3 and 4 being the contracted indices.

order, if present, contains a list of all positive indices - if not [1 2 3 4 …] by default. This is the order in which they are contracted.

forder, if present, contains the final ordering of the uncontracted indices - if not, [-1 -2 ..] by default.

There is some leeway in the way the inputs are given. For example, instead of giving a list of tensors as the first argument one can give some different iterable of tensors, such as a tuple, or a single tensor by itself (anything that has the attribute “shape” will be considered a tensor).

Todo

restructure docstring.

svds module

Module containing various functions to perform singular value decomposition on tensornet.Tensor objects.

@authors: Gerald E. Fux (gefux) & Dainius Kilda (dkilda)

Todo

We probably don’t really need scipy here. So we might have one dependency less for installing.

tensornet.svds.svd(tensor, u_indices, v_indices, chi=0, tol=0.0, relative=True, minimum=True, descriptions=[None, None, None, None], names=['u', 's', 'v'])[source]

Perform an singular value decomposition (svd) and truncate the result.

Todo

complete docstring.

tensornet.svds.svd_factorize(tensor, u_indices, v_indices, chi=0, tol=0.0, relative=True, minimum=True, ocenter='v', descriptions=[None, None, None, None], names=['u', 's', 'v'])[source]

Factorize tensor using SVD for a given orthogonality centre.

Todo

complete docstring

Todo

does not handle the descriptions and names correctly. Fix the bug!

Note

changed ocentre to ocenter (AE is sadly standard in coding)

tensornet.svds.single_svd_factorize(tensor, u_index, v_index=2, chi=0, tol=0.0, relative=True, minimum=True, ocenter='v', descriptions=[None, None, None, None], names=['u', 's', 'v'])[source]

Perform svd factorization on a single leg.

Todo

complete docstring.

tensornet.svds.contract_and_svd(first_tensor, first_index, second_tensor, second_index, chi=0, tol=0.0, relative=True, minimum=True, ocenter='v')[source]

Contract two tensors and split them up again using a svd.

Todo

use svd_factorize for ocenter.

Todo

complete docstring.

tensornet.svds.svd_and_plug(first_tensor, first_index, second_tensor, second_index, chi=0, tol=0.0, relative=True, minimum=True, ocenter='v')[source]

Perform SVD on the first tensor and then contract with second_tensor.

Todo

complete docstring.

Todo

write rest (most) of the documentation!

Todo

find a reasonable way of sorting the methods and functions (maybe alphabetically?).