-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Steady state sensitivity modes #1727
Changes from 7 commits
4d37031
ffec862
3e9df5b
9d31820
12eede5
2709d51
e4d9222
a515db3
f974f7f
2c2a793
f5d5e08
df6b96b
af8e0d6
ee0ba61
57f7fc4
5f8dce1
2c197a4
d32d64c
c6001d3
249f1a7
9fdcaf0
93e0431
b39b925
8a45940
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,7 +20,7 @@ constexpr realtype conv_thresh = 1.0; | |
|
||
namespace amici { | ||
|
||
SteadystateProblem::SteadystateProblem(const Solver &solver, Model &model) | ||
SteadystateProblem::SteadystateProblem(Solver &solver, Model &model) | ||
: delta_(model.nx_solver), ewt_(model.nx_solver), ewtQB_(model.nplist()), | ||
x_old_(model.nx_solver), xdot_(model.nx_solver), | ||
sdx_(model.nx_solver, model.nplist()), xB_(model.nJ * model.nx_solver), | ||
|
@@ -49,6 +49,14 @@ SteadystateProblem::SteadystateProblem(const Solver &solver, Model &model) | |
throw AmiException("Preequilibration using adjoint sensitivities " | ||
"is not compatible with using forward " | ||
"sensitivities during simulation"); | ||
|
||
/* Turn off Newton's method if SteadyStateSensitivityMode is integrationOnly | ||
in forward sensitivity case */ | ||
if (solver.getSensitivityMethod() == SensitivityMethod::forward && | ||
plakrisenko marked this conversation as resolved.
Show resolved
Hide resolved
|
||
model.getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::integrationOnly) { | ||
solver.setNewtonMaxSteps(0); | ||
} | ||
} | ||
|
||
void SteadystateProblem::workSteadyStateProblem(Solver *solver, Model *model, | ||
|
@@ -237,11 +245,16 @@ void SteadystateProblem::computeSteadyStateQuadrature(const Solver *solver, | |
We therefore compute the integral over xB first and then do a | ||
matrix-vector multiplication */ | ||
|
||
auto sensitivityMode = model->getSteadyStateSensitivityMode(); | ||
|
||
/* Try to compute the analytical solution for quadrature algebraically */ | ||
getQuadratureByLinSolve(model); | ||
if (sensitivityMode == SteadyStateSensitivityMode::newtonOnly | ||
|| sensitivityMode == SteadyStateSensitivityMode::integrateIfNewtonFails) | ||
getQuadratureByLinSolve(model); | ||
|
||
/* Analytical solution didn't work, perform simulation instead */ | ||
if (!hasQuadrature()) | ||
/* Perform simulation */ | ||
if (sensitivityMode == SteadyStateSensitivityMode::integrationOnly || | ||
(sensitivityMode == SteadyStateSensitivityMode::integrateIfNewtonFails && !hasQuadrature())) | ||
getQuadratureBySimulation(solver, model); | ||
|
||
/* If analytic solution and integration did not work, throw an Exception */ | ||
|
@@ -360,8 +373,10 @@ bool SteadystateProblem::getSensitivityFlag(const Model *model, | |
bool forwardSensisAlreadyComputed = | ||
solver->getSensitivityOrder() >= SensitivityOrder::first && | ||
steady_state_status_[1] == SteadyStateStatus::success && | ||
model->getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::simulationFSA; | ||
(model->getSteadyStateSensitivityMode() == | ||
FFroehlich marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SteadyStateSensitivityMode::integrationOnly || | ||
model->getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::integrateIfNewtonFails); | ||
|
||
bool simulationStartedInSteadystate = | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this code requires some updates as the newton solver can't check if we started in a steadystate if it is turned off. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When is this an issue? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For models that start in steady-state (e.g., computed outside of amici or extracted from other simulations), we don't want to be forced to deactivate the newton solver. See #1422. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. But thinking about it more carefully, we will only have misleading values if the newton solver is deactivated. In that case we will simply rextract sensitvities from the solver, which should be fine (but we probably perform a single, unnecessary simulaton step with sensitivities, which might be expensive). |
||
steady_state_status_[0] == SteadyStateStatus::success && | ||
|
@@ -386,9 +401,13 @@ bool SteadystateProblem::getSensitivityFlag(const Model *model, | |
!simulationStartedInSteadystate; | ||
|
||
/* When we're creating a new solver object */ | ||
bool needForwardSensiAtCreation = | ||
needForwardSensisPreeq && model->getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::simulationFSA; | ||
bool needForwardSensiAtCreation = | ||
needForwardSensisPreeq && | ||
(model->getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::integrationOnly || | ||
model->getSteadyStateSensitivityMode() == | ||
SteadyStateSensitivityMode::integrateIfNewtonFails | ||
); | ||
|
||
/* Check if we need to store sensis */ | ||
switch (context) { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we need some documentation of the behavior for the different values, for example in the function
Model::setSteadyStateSensitivityMode()
. https://github.com/AMICI-dev/AMICI/blob/master/python/examples/example_constant_species/ExampleEquilibrationLogic.ipynb also needs to be updated.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this notebook definitely needs to be updated.