Skip to content

Commit

Permalink
Optional warning in fill_in_parameters (#2578)
Browse files Browse the repository at this point in the history
`amici.petab.conditions.fill_in_parameters` emits a warnings if parameters are supplied that don't occur in the parameter mapping.
This is to point out potential issues with the parameter mapping.
However, sometimes it's more convenient to silently ignore those extra parameters. Therefore, make this warning optional.
  • Loading branch information
dweindl authored Nov 10, 2024
1 parent 2c362b4 commit 4083438
Showing 1 changed file with 19 additions and 3 deletions.
22 changes: 19 additions & 3 deletions python/sdist/amici/petab/conditions.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ def fill_in_parameters(
scaled_parameters: bool,
parameter_mapping: ParameterMapping,
amici_model: AmiciModel,
warn_unused: bool = True,
) -> None:
"""Fill fixed and dynamic parameters into the edatas (in-place).
Expand All @@ -59,9 +60,15 @@ def fill_in_parameters(
Parameter mapping for all conditions.
:param amici_model:
AMICI model.
:param warn_unused:
Whether a warning should be emitted if not all problem parameters
were used. I.e., if there are parameters in `problem_parameters`
that are not in `parameter_mapping`.
"""
if unused_parameters := (
set(problem_parameters.keys()) - parameter_mapping.free_symbols
if warn_unused and (
unused_parameters := (
set(problem_parameters.keys()) - parameter_mapping.free_symbols
)
):
warnings.warn(
"The following problem parameters were not used: "
Expand Down Expand Up @@ -223,6 +230,7 @@ def create_parameterized_edatas(
scaled_parameters: bool = False,
parameter_mapping: ParameterMapping = None,
simulation_conditions: pd.DataFrame | dict = None,
warn_unused: bool = True,
) -> list[amici.ExpData]:
"""Create list of :class:amici.ExpData objects with parameters filled in.
Expand All @@ -244,6 +252,11 @@ def create_parameterized_edatas(
:param simulation_conditions:
Result of :func:`petab.get_simulation_conditions`. Can be provided to
save time if this has been obtained before.
:param warn_unused:
Whether a warning should be emitted if not all problem parameters
were used. I.e., if there are parameters in `problem_parameters`
that are not in `parameter_mapping` or in the generated parameter
mapping.
:return:
List with one :class:`amici.amici.ExpData` per simulation condition,
Expand Down Expand Up @@ -282,6 +295,7 @@ def create_parameterized_edatas(
scaled_parameters=scaled_parameters,
parameter_mapping=parameter_mapping,
amici_model=amici_model,
warn_unused=warn_unused,
)

return edatas
Expand Down Expand Up @@ -387,7 +401,9 @@ def create_edatas(
:return:
List with one :class:`amici.amici.ExpData` per simulation condition,
with filled in timepoints and data.
with filled in timepoints and data, but without parameter values
(see :func:`create_parameterized_edatas` or
:func:`fill_in_parameters` for that).
"""
if simulation_conditions is None:
simulation_conditions = (
Expand Down

0 comments on commit 4083438

Please sign in to comment.