From 85c1f5113b8aed1d36d353ff8142c286b303a088 Mon Sep 17 00:00:00 2001 From: Daniel Weindl Date: Fri, 26 May 2023 12:47:09 +0200 Subject: [PATCH] Warn if ASA is used in combination with events (#2097) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Warn if ASA is used in combination with events. Co-authored-by: Fabian Fröhlich --- python/sdist/amici/swig_wrappers.py | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/python/sdist/amici/swig_wrappers.py b/python/sdist/amici/swig_wrappers.py index 7146e818ee..65798cd6ac 100644 --- a/python/sdist/amici/swig_wrappers.py +++ b/python/sdist/amici/swig_wrappers.py @@ -1,6 +1,8 @@ """Convenience wrappers for the swig interface""" import logging import sys + +import warnings from contextlib import contextmanager, suppress from typing import Any, Dict, List, Optional, Sequence, Union @@ -102,6 +104,18 @@ def runAmiciSimulation( :returns: ReturnData object with simulation results """ + if ( + model.ne > 0 + and solver.getSensitivityMethod() + == amici_swig.SensitivityMethod.adjoint + and solver.getSensitivityOrder() == amici_swig.SensitivityOrder.first + ): + warnings.warn( + "Adjoint sensitivity analysis for models with discontinuous right hand sides (events/piecewise functions) has not been thoroughly tested." + "Sensitivities might be wrong. Tracked at https://github.com/AMICI-dev/AMICI/issues/18. " + "Adjoint sensitivity analysis may work if the location of the discontinuity is not parameter-dependent, but we still recommend testing accuracy of gradients." + ) + with _capture_cstdout(): rdata = amici_swig.runAmiciSimulation( _get_ptr(solver), _get_ptr(edata), _get_ptr(model) @@ -152,6 +166,18 @@ def runAmiciSimulations( :returns: list of simulation results """ + if ( + model.ne > 0 + and solver.getSensitivityMethod() + == amici_swig.SensitivityMethod.adjoint + and solver.getSensitivityOrder() == amici_swig.SensitivityOrder.first + ): + warnings.warn( + "Adjoint sensitivity analysis for models with discontinuous right hand sides (events/piecewise functions) has not been thoroughly tested. " + "Sensitivities might be wrong. Tracked at https://github.com/AMICI-dev/AMICI/issues/18. " + "Adjoint sensitivity analysis may work if the location of the discontinuity is not parameter-dependent, but we still recommend testing accuracy of gradients." + ) + with _capture_cstdout(): edata_ptr_vector = amici_swig.ExpDataPtrVector(edata_list) rdata_ptr_list = amici_swig.runAmiciSimulations(