Skip to content
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

Fix misleading preequilibration failure messages #2181

Merged
merged 2 commits into from
Oct 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 9 additions & 2 deletions include/amici/steadystateproblem.h
Original file line number Diff line number Diff line change
Expand Up @@ -208,8 +208,15 @@ class SteadystateProblem {

/**
* @brief Stores state and throws an exception if equilibration failed
*/
[[noreturn]] void handleSteadyStateFailure();
* @param tried_newton_1 Whether any Newton step was attempted before
* simulation
* @param tried_simulation Whether simulation was attempted
* @param tried_newton_2 Whether any Newton step was attempted after
* simulation
*/
[[noreturn]] void handleSteadyStateFailure(
bool tried_newton_1, bool tried_simulation, bool tried_newton_2
);

/**
* @brief Assembles the error message to be thrown.
Expand Down
34 changes: 22 additions & 12 deletions src/steadystateproblem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,9 +60,9 @@ SteadystateProblem::SteadystateProblem(Solver const& solver, Model const& model)
"sensitivities during simulation");
if (solver.getSensitivityMethod() == SensitivityMethod::forward
&& model.getSteadyStateComputationMode()
== SteadyStateComputationMode::newtonOnly
== SteadyStateComputationMode::newtonOnly
&& model.getSteadyStateSensitivityMode()
== SteadyStateSensitivityMode::integrationOnly)
== SteadyStateSensitivityMode::integrationOnly)
throw AmiException("For forward sensitivity analysis steady-state "
"computation mode 'newtonOnly' and steady-state "
"sensitivity mode 'integrationOnly' are not "
Expand Down Expand Up @@ -152,7 +152,10 @@ void SteadystateProblem::findSteadyState(

/* Nothing worked, throw an as informative error as possible */
if (!checkSteadyStateSuccess())
handleSteadyStateFailure();
handleSteadyStateFailure(
!turnOffNewton, !turnOffSimulation,
!turnOffNewton && !turnOffSimulation
);
}

void SteadystateProblem::findSteadyStateByNewtonsMethod(
Expand Down Expand Up @@ -394,16 +397,23 @@ void SteadystateProblem::getQuadratureBySimulation(
}
}

[[noreturn]] void SteadystateProblem::handleSteadyStateFailure() {
[[noreturn]] void SteadystateProblem::handleSteadyStateFailure(
bool tried_newton_1, bool tried_simulation, bool tried_newton_2
) {
/* Throw error message according to error codes */
std::string errorString = "Steady state computation failed. "
"First run of Newton solver failed";
writeErrorString(&errorString, steady_state_status_[0]);
errorString.append(" Simulation to steady state failed");
writeErrorString(&errorString, steady_state_status_[1]);
errorString.append(" Second run of Newton solver failed");
writeErrorString(&errorString, steady_state_status_[2]);

std::string errorString = "Steady state computation failed.";
if (tried_newton_1) {
errorString.append(" First run of Newton solver failed");
writeErrorString(&errorString, steady_state_status_[0]);
}
if (tried_simulation) {
errorString.append(" Simulation to steady state failed");
writeErrorString(&errorString, steady_state_status_[1]);
}
if (tried_newton_2) {
errorString.append(" Second run of Newton solver failed");
writeErrorString(&errorString, steady_state_status_[2]);
}
throw AmiException(errorString.c_str());
}

Expand Down