Template Class TensorNetworkSerializer

Class Documentation

template<class TensorType>
class Jet::TensorNetworkSerializer

TensorNetworkSerializer is a functor class for serializing and deserializing TensorNetwork and PathInfo to/from a JSON document.

If called with an instance of TensorNetwork and, optionally, PathInfo, will return a JSON string representing the tensor network and the path.

If called with a string, it will parse it as a JSON object and return a TensorNetworkFile. The object must contain a "tensors" key containing an array of tensors. It may optionally contain a "path" key describing a contraction path.

The elements of "tensors" are arrays which contain 4 arrays specifying the tensors. The arrays contain the tags, ordered indices, shape and elements of the tensor, respectively. Each element is an array of size two representing the real and imaginary components of a complex number. For example, the array

[
 ["A", "hermitian"],
 ["a", "b"],
 [2, 2],
 [[1.0, 0.0], [0.0, 1.0], [0.0, -1.0], [1.0, 0.0]]
]

corresponds to the 2x2 matrix:

\(\begin{bmatrix}1 & i \\ -i & 1 \end{bmatrix}\)

where “a” is the row index and “b” is the column index.

The “path” value is a list of integer pairs e.g [i, j] where i and j are the indexes of two tensors in the tensor array (or the index of an intermediate tensor).

tparam Tensor

Type of the tensor in the tensor network.

Public Functions

inline TensorNetworkSerializer(int indent = -1)

Constructs a new TensorNetworkSerializer.

Parameters

indent – Indent level to use when serializing to json. Default value will use the most compact representation.

inline std::string operator()(const TensorNetwork<TensorType> &tn, const PathInfo &path)

Dump tensor network and path to string.

Returns

JSON string representing tensor network and path

inline std::string operator()(const TensorNetwork<TensorType> &tn)

Dump tensor network to string.

Returns

JSON string representing tensor network.

inline TensorNetworkFile<TensorType> operator()(std::string js_str, bool col_major = false)

Load tensor network file from JSON string.

Raises exception if string is invalid JSON, or if it does not describe a valid tensor network.

The loader assumes data is available in row-major format, but also allows it to be loaded onto a column-major backend (e.g. such as for the CudaTensor class).

Parameters
  • js_str – String of JSON data.

  • col_major – Option to load the data for use by a column-major backend contractor.

Returns

Tensor network file containing the tensor network and optional contraction path represented by the given JSON data.