Open keileg opened 3 months ago
Will there be functionality reuse between value
and value_and_jacobian
? If yes, how do you envision this? Also, will the AdParser
be the natural candidate to do consistency checks on dimension compatibility?
Note to self: Operator evaluation will also be needed as part of the solution process (test case: the line search methods being introduced in #1208). We need to make sure that the AdParser
class can be invoked also in these cases.
NOTE: For debugging purposes, it should always be possible to switch off all caching.
Background
In the current code, the evaluation of a
pp.ad.Operator
is implemented in theOperator
class itself. The parsing of a tree of an operator (which is really a computational graph) is implemented as a depth-first traversal which identifies leaves in the tree, parses these to numerical values, and then propagates the values through the graph in a bottom-up fashion. While this works, there are shortcomings with the approach:Suggested changes
The following large-scale changes are suggested - specifications are needed before implementation:
def graph_traversal(list[pp.ad.Operator]) -> Iterator[pp.ad.Operator]
. The motivation for accepting a list of operators is given in the outline of the Ad parser class below.AdParser
, which takes over responsibility for parsing from theOperator
class. This will use the graph traversal function to iterate over the computational graph and convert it to numerical values. Moreover, the parser should contain functionality for chaching of operator values to reduce evaluation time.Thoughts on the
AdParser
classBelow is an outline of the class:
Access to the
AdParser
While it is tempting to make the
AdParser
a singleton accessible aspp.AdParser
or similar, there is no clear reason to do so. Instead, it is suggested that all models are equipped with anAdParser
, just as they have anEquationSystem
. It should also be possible to parse outside a model, by a callpp.ad.AdParser(mdg).value_and_jacobian([operator])
, though such operations will not be very common.The role of the
EquationSystem
While the functionality of the
AdParser
could have been integrated into theEquationSystem
, it is preferable not to add more functionality into this (arguably already overloaded) class. Instead, theEquationSystem
can be given the model-wideAdParser
as an attribute and call this for evaluation of equations.Dependencies
This should not be started until completion of #1179 and #1180