Skip to content

Commit

Permalink
Fix initial state issues with PEtab
Browse files Browse the repository at this point in the history
* Ensure initial state parameters are always fixed parameters
* Ensure initial concentration for preequilibration and simulation are both set in both phases to avoid NaN issues
* Fix initialAssignment handling during PEtab import (missed in #2359)
  • Loading branch information
dweindl committed Mar 13, 2024
1 parent 032fb6c commit 7615819
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
14 changes: 8 additions & 6 deletions python/sdist/amici/petab/parameter_mapping.py
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,11 @@ def create_parameter_mapping_for_condition(
condition_scale_map_preeq,
preeq_value,
)
else:
# need to set dummy value for preeq parameter anyways, as it
# is expected below (set to 0, not nan, because will be
# multiplied with indicator variable in initial assignment)
condition_map_sim[init_par_id] = 0.0
condition_scale_map_sim[init_par_id] = LIN
# need to set dummy value for preeq parameter anyways, as it
# is expected below (set to 0, not nan, because will be
# multiplied with indicator variable in initial assignment)
condition_map_sim[init_par_id] = 0.0
condition_scale_map_sim[init_par_id] = LIN

Check warning on line 493 in python/sdist/amici/petab/parameter_mapping.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/parameter_mapping.py#L492-L493

Added lines #L492 - L493 were not covered by tests

# for simulation
condition_id = condition[SIMULATION_CONDITION_ID]
Expand All @@ -505,6 +504,9 @@ def create_parameter_mapping_for_condition(
condition_scale_map_sim,
value,
)
# set dummy value as above
condition_map_preeq[init_par_id] = 0.0
condition_scale_map_preeq[init_par_id] = LIN

Check warning on line 509 in python/sdist/amici/petab/parameter_mapping.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/parameter_mapping.py#L508-L509

Added lines #L508 - L509 were not covered by tests

##########################################################################
# separate fixed and variable AMICI parameters, because we may have
Expand Down
4 changes: 3 additions & 1 deletion python/sdist/amici/petab/sbml_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,8 @@ def import_model_sbml(
init_par = sbml_model.createParameter()
init_par.setId(init_par_id)
init_par.setName(init_par_id)
# must be a fixed parameter in any case to allow reinitialization
fixed_parameters.append(init_par_id)
assignment = sbml_model.getInitialAssignment(assignee_id)
if assignment is None:
assignment = sbml_model.createInitialAssignment()
Expand Down Expand Up @@ -535,7 +537,7 @@ def _get_fixed_parameters_sbml(
ia.getMath(), parser_settings
)
)
if not sym_math.is_Number:
if not sym_math.evalf().is_Number:

Check warning on line 540 in python/sdist/amici/petab/sbml_import.py

View check run for this annotation

Codecov / codecov/patch

python/sdist/amici/petab/sbml_import.py#L540

Added line #L540 was not covered by tests
fixed_parameters.remove(fixed_parameter)
continue

Expand Down

0 comments on commit 7615819

Please sign in to comment.