/ pymor Public
add compute() to Model #1113
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge.
With this PR,
Modelgets a new
computemethod which realizes the computation of the model's solution and of derived quantities such as outputs or error estimates.
estimate_errorare implemented by calling
computewith appropriate arguments.
By relying on a central method, we can avoid having to pass computed values from the outside, e.g. the solution to
estimate_error. (Note that it might depend on the
Modelwhich values have to be passed.)
computereturns a dict of all computed values.
solve, etc. remain as convenience methods.
computecan be easily extended to return further quantities of interest. E.g. an optional
stagesargument might indicate to return intermediate Newton stages as an additional item of the return value.
Model.computehas a default implementation which relays individual computational tasks to dedicated
_compute_output, etc. methods which allow to more easily customize
computewhen subclassing. Before these methods are called
_computeis called in which, e.g., simultaneous solution and output computation can be realized. For values that already have been computed, the respective
_compute_...methods will then be skipped.
The signature of
computeshould stay stable for the foreseeable future. The base class implementation may change in the future.
I decided to keep automatic caching of the solution in the default implementation of
compute. In particular, for models using
_compute_solution, a call to
m.output(mu)will not trigger an additional solution of the model, when
m.solve(mu)has been called before for the same
muand caching is enabled.
output_d_mumethods from Towards linear optimization (dual problem, sensitivity problem, output gradient) #1110 will also make use of
See discussion in #1095.
Documentation still needs to be updated.
@pymor/pymor-devs, @HenKlei, @TiKeil, while not much has changed internally, this PR will significantly affect the user expercience. Please take a close look.