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

PEtab parameter mapping: minor speedup #2640

Merged
merged 1 commit into from
Feb 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions python/sdist/amici/petab/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,16 +134,21 @@ def _get_par(model_par, value, mapping):
# condition table overrides must have been handled already,
# e.g. by the PEtab parameter mapping, but parameters from
# InitialAssignments may still be present.
if mapping[value] == model_par:
if (mapped_value := mapping[value]) == model_par:
# prevent infinite recursion
raise
return _get_par(value, mapping[value], mapping)
if model_par in problem_parameters:
return _get_par(value, mapped_value, mapping)

try:
# user-provided
return problem_parameters[model_par]
except KeyError:
pass

# prevent nan-propagation in derivative
if np.isnan(value):
return 0.0

# constant value
return value

Expand Down
9 changes: 4 additions & 5 deletions python/sdist/amici/petab/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ def get_states_in_condition_table(
if petab_problem.model.type_id not in (MODEL_TYPE_SBML, MODEL_TYPE_PYSB):
raise NotImplementedError()

species_check_funs = {
species_check_fun = {
MODEL_TYPE_SBML: lambda x: _element_is_sbml_state(
petab_problem.sbml_model, x
),
MODEL_TYPE_PYSB: lambda x: _element_is_pysb_pattern(
petab_problem.model.model, x
),
}
}[petab_problem.model.type_id]

states = {
resolve_mapping(petab_problem.mapping_df, col): (None, None)
if condition is None
Expand All @@ -48,9 +49,7 @@ def get_states_in_condition_table(
else None,
)
for col in petab_problem.condition_df.columns
if species_check_funs[petab_problem.model.type_id](
resolve_mapping(petab_problem.mapping_df, col)
)
if species_check_fun(resolve_mapping(petab_problem.mapping_df, col))
}

if petab_problem.model.type_id == MODEL_TYPE_PYSB:
Expand Down
Loading