API Reference
This section contains the API documentation for pyQuTree.
Tree Tensor Network Optimization
- class qutree.ttn.ttnopt.Objective(Err, transformer=<function Objective.<lambda>>)[source]
Bases:
object
- qutree.ttn.ttnopt.ttnopt(G: DiGraph, O: Objective, nsweep: int = 6, primitive_grid: list[array] = None, start_grid=None)[source]
Run tensor network optimization on objective function using provided graph and grids.
Arguments: G (nx.DiGraph): tensor network (graph) O (Objective): objective function primitive grids (list[np.array[int]]): list of numpy arrays of
Network Structures
- qutree.ttn.network.balanced_tree(f, r=2, N=8)[source]
Generate a close-to balanced tree tensor network Node: odd f is implemented manually:
avoids adding unnecessary node by added code. See # odd-leaf tag
- qutree.ttn.network.collect(G, edges, key)[source]
Graph objects from edges that correspond to ‘key’ as a list
- qutree.ttn.network.tensor_train_graph(f, r=2, primitive_grid: int | list[int] = 8)[source]
Generate a tensor train network
Tensor Operations
- class qutree.ttn.tensor.quTensor(array, edges, flattened_to=None)[source]
Bases:
ndarrayDecorated tensor that keeps track of corresponding edges edges: those correspond to the tensor legs flattened_to: None or edge that the current tensor is flattened to. expanded_shape: shape if not permuted and flattened
Note: edges & expanded_shape is not permuted. Only
- flatten(order='C')[source]
Return a copy of the array collapsed into one dimension.
- Parameters:
order ({'C', 'F', 'A', 'K'}, optional) – ‘C’ means to flatten in row-major (C-style) order. ‘F’ means to flatten in column-major (Fortran- style) order. ‘A’ means to flatten in column-major order if a is Fortran contiguous in memory, row-major order otherwise. ‘K’ means to flatten a in the order the elements occur in memory. The default is ‘C’.
- Returns:
y – A copy of the input array, flattened to one dimension.
- Return type:
ndarray
See also
ravelReturn a flattened array.
flatA 1-D flat iterator over the array.
Examples
>>> import numpy as np >>> a = np.array([[1,2], [3,4]]) >>> a.flatten() array([1, 2, 3, 4]) >>> a.flatten('F') array([1, 3, 2, 4])
- transpose(*axes)[source]
Returns a view of the array with axes transposed.
Refer to numpy.transpose for full documentation.
- Parameters:
axes (None, tuple of ints, or n ints) –
None or no argument: reverses the order of the axes.
tuple of ints: i in the j-th place in the tuple means that the array’s i-th axis becomes the transposed array’s j-th axis.
n ints: same as an n-tuple of the same ints (this form is intended simply as a “convenience” alternative to the tuple form).
- Returns:
p – View of the array with its axes suitably permuted.
- Return type:
ndarray
See also
transposeEquivalent function.
ndarray.TArray property returning the array transposed.
ndarray.reshapeGive a new shape to an array without changing its data.
Examples
>>> import numpy as np >>> a = np.array([[1, 2], [3, 4]]) >>> a array([[1, 2], [3, 4]]) >>> a.transpose() array([[1, 3], [2, 4]]) >>> a.transpose((1, 0)) array([[1, 3], [2, 4]]) >>> a.transpose(1, 0) array([[1, 3], [2, 4]])
>>> a = np.array([1, 2, 3, 4]) >>> a array([1, 2, 3, 4]) >>> a.transpose() array([1, 2, 3, 4])
Tensor Network
- class qutree.ttn.tensor_network.TensorNetwork(incoming_graph_data=None, **attr)[source]
Bases:
DiGraph
Grid Operations
- qutree.ttn.grid.regularized_inverse(A: ndarray, lambda_reg: float, eps: float = 1e-15) ndarray[source]
- Tikhonov-regularized inverse via SVD:
sigma_inv = s / (s^2 + alpha), with alpha = (lambda_eff * s_max)^2
where lambda_eff = max(lambda_reg, eps). Denominator is clamped to >= eps. This prevents divide-by-zero/overflow and stays stable even if s_max <= 0.