AMICI icon indicating copy to clipboard operation
AMICI copied to clipboard

Requesting sensitivities for algebraic equations breaks simulation

Open dilpath opened this issue 2 years ago • 1 comments

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

  • OS and version: Ubuntu 22.04
  • AMICI interface: Python
  • AMICI version: latest develop branch
  • Additional information: GCC 10.4.0, Python 3.10.6

dilpath avatar May 22 '23 18:05 dilpath

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?)

dweindl avatar May 23 '23 07:05 dweindl