Skip to content

Commit

Permalink
Fix initial state issues with PEtab (#2382)
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 authored Mar 18, 2024
1 parent 41b4ce4 commit 790ab44
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
15 changes: 9 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

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

##########################################################################
# 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:
fixed_parameters.remove(fixed_parameter)
continue

Expand Down

0 comments on commit 790ab44

Please sign in to comment.