From 48bcb36a4d30e3976f6992c9e915ab31eb5f84ca Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Thu, 12 Dec 2024 11:11:12 +0100 Subject: [PATCH] Allow using `RDataReporting::residuals` with ASA 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. --- python/tests/test_pregenerated_models.py | 22 ++++++++-------------- src/solver.cpp | 8 -------- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/python/tests/test_pregenerated_models.py b/python/tests/test_pregenerated_models.py index e9daf13ba8..027f2d7f50 100755 --- a/python/tests/test_pregenerated_models.py +++ b/python/tests/test_pregenerated_models.py @@ -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 diff --git a/src/solver.cpp b/src/solver.cpp index 298caaf774..4c68837ed9 100644 --- a/src/solver.cpp +++ b/src/solver.cpp @@ -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()); } @@ -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; }