Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMICI failed to integrate the forward problem in PEtab problem, encountered NaN values #1796

Closed
matthiaskoenig opened this issue May 11, 2022 · 5 comments
Labels
new Newly created

Comments

@matthiaskoenig
Copy link

Hi all,
when running the attached PETab Problem I see failing forward integration.

icg_sd.zip

I tried to simulate the model with

petab_problem = petab.Problem.from_yaml(yaml_file)
model = import_petab_problem(petab_problem)
simulate_petab(petab_problem, model)

and get the following errors

[Warning] AMICI:NaN: AMICI encountered a NaN value for xdot[0] (Cre_plasma_icg)
[Warning] AMICI:NaN: AMICI encountered a NaN value for w[27]!
[Warning] AMICI:CVODES:CVode:OTHER: AMICI ERROR: in module CVODES in function CVode : The right-hand side routine failed at the first call. 
[Warning] AMICI:simulation: AMICI forward simulation failed at t = 0.000000:
AMICI failed to integrate the forward problem

[Warning] AMICI:CVODES:CVode:WARNING: AMICI ERROR: in module CVODES in function CVode : At the end of the first step, there are still some root functions identically 0. This warning will not be issued again. 
[Warning] AMICI:CVODES:CVode:WARNING: AMICI ERROR: in module CVODES in function CVode : At the end of the first step, there are still some root functions identically 0. This warning will not be issued again. 
[Warning] AMICI:NaN: AMICI encountered a NaN value for xdot[0] (Cre_plasma_icg)
[Warning] AMICI:NaN: AMICI encountered a NaN value for w[26]!
[Warning] AMICI:CVODES:CVode:OTHER: AMICI ERROR: in module CVODES in function CVode : The right-hand side routine failed at the first call. 
[Warning] AMICI:simulation: AMICI forward simulation failed at t = 0.000000:
AMICI failed to integrate the forward problem

Directly loading the model with AMICI and simulating it works without problems, i.e. the following code is successful for the model file

    sbml_importer = amici.SbmlImporter(model_file)
    model_dir = output_dir / "amici" / mid
    sbml_importer.sbml2amici(mid, model_dir)

    # load the model module
    model_module = amici.import_model_module(mid, model_dir)
    # instantiate model
    model = model_module.getModel()

    # model properties
    print("Model parameters:", list(model.getParameterIds()), "\n")
    print("Model const parameters:", list(model.getFixedParameterIds()), "\n")
    print("Model outputs:", list(model.getObservableIds()), "\n")
    print("Model states:", list(model.getStateIds()), "\n")

    # instantiate solver
    solver = model.getSolver()
    solver.setAbsoluteTolerance(1e-10)

    # run forward simulation
    t = np.linspace(0, 20, num=5)
    model.setTimepoints(t)
    rdata = amici.runAmiciSimulation(model, solver)
    print(t)
    print(rdata.x)

resulting in

--- amici ---
Model parameters: ['conversion_ml_per_l', 'conversion_l_per_ml', 'BW', 'HEIGHT', 'COBW', 'Fblood', 'HCT', 'FVgi', 'FVbi', 'FVli', 'FVlu', 'FVve', 'FVar', 'FVpo', 'FVhv', 'FQgi', 'FQh', 'FQlu', 'f_cirrhosis', 'f_shunts', 'f_tissue_loss', 'f_bloodflow', 'f_cardiac_output', 'f_exercise', 'resection_rate', 'Mr_icg', 'ti_icg', 'Ri_icg', 'LI__ICGIM_Vmax', 'LI__ICGIM_Km', 'LI__ICGIM_ki_bil', 'LI__f_oatp1b3', 'LI__ICGLI2CA_Vmax', 'LI__ICGLI2CA_Km', 'LI__ICGLI2BI_Vmax'] 

Model const parameters: [] 

Model outputs: ['yCre_plasma_icg', 'yCgi_plasma_icg', 'yCli_plasma_icg', 'yClu_plasma_icg', 'yCve_icg', 'yCar_icg', 'yCpo_icg', 'yChv_icg', 'yAfeces_icg', 'yLI__bil_ext', 'yLI__icg', 'yLI__icg_bi', 'yIVDOSE_icg', 'ycum_dose_icg', 'yFVre', 'yFQre', 'yBSA', 'yCO', 'yQC', 'yQlu', 'yQre', 'yQh', 'yQgi', 'yQpo', 'yQha', 'yKi_icg', 'yAre_plasma_icg', 'yXre_plasma_icg', 'yMre_plasma_icg', 'yAgi_plasma_icg', 'yXgi_plasma_icg', 'yMgi_plasma_icg', 'yAli_plasma_icg', 'yXli_plasma_icg', 'yMli_plasma_icg', 'yAlu_plasma_icg', 'yXlu_plasma_icg', 'yMlu_plasma_icg', 'yAve_icg', 'yXve_icg', 'yMve_icg', 'yAar_icg', 'yXar_icg', 'yMar_icg', 'yApo_icg', 'yXpo_icg', 'yMpo_icg', 'yAhv_icg', 'yXhv_icg', 'yMhv_icg', 'yER_icg', 'yCLinfusion_icg', 'yVbi', 'yVgi', 'yVli', 'yVlu', 'yVre', 'yVve', 'yVar', 'yVpo', 'yVhv', 'yVre_plasma', 'yVre_tissue', 'yVgi_plasma', 'yVgi_tissue', 'yVli_plasma', 'yVli_tissue', 'yVlu_plasma', 'yVlu_tissue', 'yVfeces'] 

Model states: ['Cre_plasma_icg', 'Cgi_plasma_icg', 'Cli_plasma_icg', 'Clu_plasma_icg', 'Cve_icg', 'Car_icg', 'Cpo_icg', 'Chv_icg', 'Afeces_icg', 'LI__bil_ext', 'LI__icg', 'LI__icg_bi', 'IVDOSE_icg', 'cum_dose_icg'] 

[ 0.  5. 10. 15. 20.]
[[0.   0.   0.   0.   0.   0.   0.   0.   0.   0.01 0.   0.   0.   0.  ]
 [0.   0.   0.   0.   0.   0.   0.   0.   0.   0.01 0.   0.   0.   0.  ]
 [0.   0.   0.   0.   0.   0.   0.   0.   0.   0.01 0.   0.   0.   0.  ]
 [0.   0.   0.   0.   0.   0.   0.   0.   0.   0.01 0.   0.   0.   0.  ]
 [0.   0.   0.   0.   0.   0.   0.   0.   0.   0.01 0.   0.   0.   0.  ]]

Best Matthias

@matthiaskoenig matthiaskoenig added the new Newly created label May 11, 2022
@FFroehlich
Copy link
Member

I would guess that having empty cells in the condition table will lead to issues. They are interpreted as NaNs which amici seems to complain about.

@matthiaskoenig
Copy link
Author

Thanks. Makes sense. I thought it just takes the default model value if nothing is provided and only the changes should be written in the condition table. Will close this after testing.

@dweindl
Copy link
Member

dweindl commented May 16, 2022

I thought it just takes the default model value if nothing is provided and only the changes should be written in the condition table.

@matthiaskoenig : Yes, that is what is supposed to happen. If this is not the case, please re-open. I didn't get to run your example yet.

@matthiaskoenig
Copy link
Author

I thought that writing the NaN values is expected behavior of PETab, because it is not documented in the specification.
I.e. on
https://petab.readthedocs.io/en/latest/documentation_data_format.html#condition-table
The NaN case is listed for speciesID but not for compartmentID and parameterID. The sentence

the values will override any parameter values specified in the model.

reads for me, that you have to set the NaN. I just opened an issue for that
PEtab-dev/PEtab#542

@dweindl
Copy link
Member

dweindl commented May 19, 2022

Should be fixed in the PEtab library via PEtab-dev/libpetab-python#150

@dweindl dweindl closed this as completed Jul 18, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
new Newly created
Projects
None yet
Development

No branches or pull requests

3 participants