AMICI-dev / AMICI

Advanced Multilanguage Interface to CVODES and IDAS
https://amici.readthedocs.io/
Other
108 stars 31 forks source link

Requesting sensitivities for algebraic equations breaks simulation #2102

Open dilpath opened 1 year ago

dilpath commented 1 year ago

What did you expect to happen? Sensitivities to be computed

What has happened instead? rdata.x and rdata.sx are zero matrices

To Reproduce Compile a model with algebraic expressions, e.g. SBML semantic test case 00039, simulate with and without computation of forward sensitivities.

sbml_file = "tests/sbml-test-suite/cases/semantic/00039/00039-sbml-l3v2.xml"

from pathlib import Path
model_name = "m00039"
model_dir = Path("amici_models") / model_name
model_dir.mkdir(parents=True, exist_ok=True)

import amici
import numpy as np

sbml_importer = amici.SbmlImporter(sbml_file)    
sbml_importer.sbml2amici(    
    model_name,    
    output_dir=model_dir,    
    generate_sensitivity_code=True,    
)    

model_module = amici.import_model_module(model_name, model_dir)
model = model_module.getModel()
solver = model.getSolver()

model.setTimepoints(np.linspace(0, 8, 51))
solver.setMaxSteps(int(1e6))

solver.setSensitivityOrder(amici.SensitivityOrder.first)
solver.setSensitivityMethod(amici.SensitivityMethod.forward)

rdata = amici.runAmiciSimulation(model, solver)
print(rdata.x) 
print(rdata.sx)

AMICI version and system environment

dweindl commented 1 year ago

I agree that this is not the desired behavior. In case of errors, x and sx (and others) should be NaN. It seems there is a call to ReturnData::invalidate missing. Since rdata.status is AMICI_ERROR, it wouldn't consider this high priority, and would rather have the root cause fixed via #2101. (Volunteers?)