Skip to content

Commit 342e743

Browse files
Fabian Fröhlichdweindl
andauthored
Improve efficiency of newton step conv check (#1775)
* improve efficiency of newton step conv check * Update src/steadystateproblem.cpp Co-authored-by: Daniel Weindl <[email protected]> * fix test by increasing tolerance Co-authored-by: Daniel Weindl <[email protected]>
1 parent 8d19766 commit 342e743

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

include/amici/solver.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -897,7 +897,8 @@ class Solver {
897897
}
898898

899899
/**
900-
* @brief Returns how convergence checks for steadystate computation are performed.
900+
* @brief Returns how convergence checks for steadystate computation are performed. If activated,
901+
* convergence checks are limited to every 25 steps in the simulation solver to limit performance impact.
901902
* @return boolean flag indicating newton step (true) or the right hand side (false)
902903
*/
903904
bool getNewtonStepSteadyStateCheck() const {

python/tests/test_preequilibration.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -338,6 +338,7 @@ def test_newton_solver_equilibration(preeq_fixture):
338338
amici.SteadyStateSensitivityMode.newtonOnly]
339339

340340
solver.setNewtonStepSteadyStateCheck(True)
341+
solver.setRelativeToleranceSteadyState(1e-12)
341342

342343
for equil_meth in settings:
343344
# set sensi method

src/steadystateproblem.cpp

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,12 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver,
630630
/* If run after Newton's method checks again if it converged */
631631
wrms_ = getWrms(model, sensitivityFlag);
632632
int sim_steps = 0;
633-
633+
634+
int convergence_check_frequency = 1;
635+
636+
if (newton_step_conv_)
637+
convergence_check_frequency = 25;
638+
634639
while (true) {
635640
/* One step of ODE integration
636641
reason for tout specification:
@@ -654,7 +659,8 @@ void SteadystateProblem::runSteadystateSimulation(const Solver &solver,
654659
/* getWrms needs to be called before getWrmsFSA such that the linear
655660
system is prepared for newton type convergence check */
656661
if (wrms_ < conv_thresh && check_sensi_conv_ &&
657-
sensitivityFlag == SensitivityMethod::forward) {
662+
sensitivityFlag == SensitivityMethod::forward &&
663+
sim_steps % convergence_check_frequency == 0) {
658664
updateSensiSimulation(solver);
659665
wrms_ = getWrmsFSA(model);
660666
}

0 commit comments

Comments
 (0)