Contains classes and functions to deal with autodifferentiation of STensor objects. More...
Classes | |
class | ComputeNode |
Describes an individual function call as part of a computation. More... | |
Typedefs | |
using | AdjointEvaluator = std::function< STensor(ComputeNode &node, Size input_number, STensorId const result_id)> |
Type of the input adjoint evaluator which can access the adjoints of all output values as well as the stored input and output tensors of the node to evaluate an output adjoint of an upstream node. More... | |
using | ComputeNodePtr = std::shared_ptr< ComputeNode > |
Type of a shared pointer to a compute node. More... | |
using | ComputeNodeWPtr = std::weak_ptr< ComputeNode > |
Type of a weak pointer to a compute node, used for the "downstream" direction. More... | |
using | STensorId = std::uint64_t |
Randomly-generated ID of an STensor , to be used during automatic differentiation. More... | |
Functions | |
ComputeNodePtr | create (std::string &&opname_, Vec< Pair< ComputeNodePtr, Size > > &&input_nodes_, Vec< STensorId > &&output_ids_, AdjointEvaluator &&func_, Vec< STensor > &&output_shapes_, Vec< AsyncCached< STensor > > &&cached_tensors_={}) |
Helper to create a new ComputeNode and return a shared pointer to it. More... | |
ComputeNodePtr | create_primer (ComputeNodePtr input_node_ptr, Size input_node_number, STensorId output_id, std::int8_t value, SBasis basis_on_tensor, STensor const &shapelike) |
Helper to create a priming ComputeNode and a return a shared pointer to it. More... | |
void | create_product_differentiable (STensorProxy const &a, STensorProxy const &b, STensor &return_value) |
Sets the compute nodes of the tensor return_value to represent the product of tensor proxies a and b . More... | |
STensorId | new_id () |
Generates a new tensor ID larger than 999 to be used by auto-generated tensors. More... | |
STensor | qr_adjoint_evaluator (ComputeNode &node, STensorId const result_id, SBasisId const &int_leg) |
Evaluates the adjoint of a QR decomposition identified by ComputeNode node . More... | |
STensor | return_first_output_adjoint (ComputeNode &node, Size input_number, STensorId const result_id) |
AdjointEvaluator-typed function which simply returns the output adjoint of the first output. More... | |
STensor | svd_adjoint_evaluator (ComputeNode &node, STensorId const result_id, SBasisId const &us_basis, SBasisId const &sv_basis) |
Evaluates the adjoint of a SVD identified by ComputeNode node . More... | |
Contains classes and functions to deal with autodifferentiation of STensor objects.
Autodifferentiation is a method to automatically calculate exact derivatives of functions at specific values. This is done by tracing along a calculation and storing all data necessary to evaluate partial derivates. Later, the derivative can be obtained by walking backwards in this history and evaluating the individual partial derivates, accumulating them to a total derivative.
Here, this is implemented in three parts:
Multiple caveats apply here:
A[i,j]
and B[j,i1]
the product A[i,j]·B[j,i1] = C[i,i1]
is well-defined. We can then also further prime the second index and afterwards the first to give C[i1,i2]
. However, now differentiating this object with respect to B[j,i1]
would create a new tensor with four open indices: i1
, i2
from C
, j
from A
and a new i1
which belongs to a vitual δ[i1,i1]
tensor used to prime the old index of B. As a result, this tensor would have two legs with identical indices. This problem mostly occurs with ‘interestingly’ primed tensor legs and taking derivatives of not fully contracted tensor networks.To use:
STensor::get_autodiff_node()->draw(std::cout)
on the result. This will cause a dot-compatible compute graph to be printed to the supplied stream. In the graph, nodes are compute nodes, edges are outputs from one node being used in another. Those outputs are labelled by numbers starting at 1000.