Skip to content

Commit

Permalink
Allow using RDataReporting::residuals with ASA
Browse files Browse the repository at this point in the history
So far, it is not supported to use `RDataReporting::residuals` with ASA.
However, there doesn't seem to be a good reason.
It's only that the respective sensitivities for y/sigmay/res won't be computed in this case.
  • Loading branch information
dweindl committed Dec 12, 2024
1 parent 2d58f54 commit 48bcb36
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 22 deletions.
22 changes: 8 additions & 14 deletions python/tests/test_pregenerated_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,20 +149,14 @@ def test_pregenerated_model(sub_test, case):
)

# test residuals mode
if solver.getSensitivityMethod() == amici.SensitivityMethod.adjoint:
with pytest.raises(RuntimeError):
solver.setReturnDataReportingMode(amici.RDataReporting.residuals)
else:
solver.setReturnDataReportingMode(amici.RDataReporting.residuals)
rdata = amici.runAmiciSimulation(model, solver, edata)
verify_simulation_results(
rdata,
expected_results[sub_test][case]["results"],
fields=["t", "res", "sres", "y", "sy", "sigmay", "ssigmay"],
**verify_simulation_opts,
)
with pytest.raises(RuntimeError):
solver.setSensitivityMethod(amici.SensitivityMethod.adjoint)
solver.setReturnDataReportingMode(amici.RDataReporting.residuals)
rdata = amici.runAmiciSimulation(model, solver, edata)
verify_simulation_results(
rdata,
expected_results[sub_test][case]["results"],
fields=["t", "res", "sres", "y", "sy", "sigmay", "ssigmay"],
**verify_simulation_opts,
)

chi2_ref = rdata.chi2

Expand Down
8 changes: 0 additions & 8 deletions src/solver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -735,10 +735,6 @@ void Solver::setSensitivityMethodPreequilibration(
void Solver::checkSensitivityMethod(
SensitivityMethod const sensi_meth, bool preequilibration
) const {
if (rdata_mode_ == RDataReporting::residuals
&& sensi_meth == SensitivityMethod::adjoint)
throw AmiException("Adjoint Sensitivity Analysis is not compatible with"
" only reporting residuals!");
if (!preequilibration && sensi_meth != sensi_meth_)
resetMutableMemory(nx(), nplist(), nquad());
}
Expand Down Expand Up @@ -1150,10 +1146,6 @@ RDataReporting Solver::getReturnDataReportingMode() const {
};

void Solver::setReturnDataReportingMode(RDataReporting rdrm) {
if (rdrm == RDataReporting::residuals
&& sensi_meth_ == SensitivityMethod::adjoint)
throw AmiException("Adjoint Sensitivity Analysis cannot report "
"residuals!");
rdata_mode_ = rdrm;
}

Expand Down

0 comments on commit 48bcb36

Please sign in to comment.