ICB-DCM / pyPESTO

python Parameter EStimation TOolbox
https://pypesto.readthedocs.io
BSD 3-Clause "New" or "Revised" License
217 stars 47 forks source link

KeyError for parameter with amici prefix #1418

Open matthiaskoenig opened 3 months ago

matthiaskoenig commented 3 months ago

Hi all, it seems there are some issues with the amici prefixes on parameters. Example attached. I am trying to import a petab problem, but the importer fails with a KeyError. amici_k.zip

import petab
from pathlib import Path
import pypesto.petab
from petabunit.console import console
import logging

console.rule("Load PEtab", style="white")
petab_yaml: Path = Path(__file__).parent / "simple_pk.yaml"
petab_problem = petab.Problem.from_yaml(petab_yaml)
importer = pypesto.petab.PetabImporter(petab_problem)
problem = importer.create_problem(verbose=True)
/home/mkoenig/.virtualenvs/petabunit/lib/python3.12/site-packages/pypesto/petab/importer.py:487: RuntimeWarning: The following problem parameters were not used: {'k'}
  amici.petab.conditions.fill_in_parameters(
Traceback (most recent call last):
  File "/home/mkoenig/git/petabunit/examples/simple_pk/simple_pk_optimization.py", line 13, in <module>
    problem = importer.create_problem(verbose=True)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mkoenig/.virtualenvs/petabunit/lib/python3.12/site-packages/pypesto/petab/importer.py", line 735, in create_problem
    objective = self.create_objective(**kwargs)
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/mkoenig/.virtualenvs/petabunit/lib/python3.12/site-packages/pypesto/petab/importer.py", line 487, in create_objective
    amici.petab.conditions.fill_in_parameters(
  File "/home/mkoenig/.virtualenvs/petabunit/lib/python3.12/site-packages/amici/petab/conditions.py", line 76, in fill_in_parameters
    fill_in_parameters_for_condition(
  File "/home/mkoenig/.virtualenvs/petabunit/lib/python3.12/site-packages/amici/petab/conditions.py", line 175, in fill_in_parameters_for_condition
    map_sim_var[par_id] for par_id in amici_model.getParameterIds()
    ~~~~~~~~~~~^^^^^^^^
KeyError: 'amici_k'
dweindl commented 3 months ago

Sounds plausible. It's related to reserved names in amici (mostly some one-letter-IDs). It think this is not handled at all in pypesto. For a quick work-around, you can rename k to kk, k_, ...

dweindl commented 3 months ago

Best to be handled directly in AMICI. Will leave this open here for others until there is an amici release where this is fixed.