From 0d3c25a32ac8c19e2e0c088be9a4b9c1b38f21ce Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Wed, 19 Aug 2026 15:04:49 +0100 Subject: [PATCH 1/2] skip cond ids set by arrays for all periods --- petab/v2/converters.py | 12 ++++++------ tests/v2/test_sciml.py | 37 +++++++++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+), 6 deletions(-) diff --git a/petab/v2/converters.py b/petab/v2/converters.py index e5e9c4f4..33f6f550 100644 --- a/petab/v2/converters.py +++ b/petab/v2/converters.py @@ -248,6 +248,12 @@ def _convert_experiment(self, experiment: Experiment) -> None: # or the only non-equilibration period (handled above) continue + # Skip if condition ids are set by array data + if self._array_data_condition_ids and set( + period.condition_ids + ).issubset(self._array_data_condition_ids): + continue + # Encode the period changes in the SBML model as events # that trigger at the start of the period or, # for the first period, as initial assignments. @@ -258,12 +264,6 @@ def _convert_experiment(self, experiment: Experiment) -> None: # single-period experiments. if i_period == 0: exp_ind_id = self.get_experiment_indicator(experiment.id) - # Skip if condition ids are set by array data - # importers handle this - if self._array_data_condition_ids and set( - period.condition_ids - ).issubset(self._array_data_condition_ids): - continue for change in self._new_problem.get_changes_for_period(period): period0_assignments.setdefault( diff --git a/tests/v2/test_sciml.py b/tests/v2/test_sciml.py index f6cedc28..74ed2737 100644 --- a/tests/v2/test_sciml.py +++ b/tests/v2/test_sciml.py @@ -463,6 +463,43 @@ def test_genuinely_missing_output_parameter_still_reported(): assert not any("net1_output2" in issue.message for issue in results) +# --------------------------------------------------------------------------- +# Experiment -> SBML conversion +# --------------------------------------------------------------------------- + +def test_convert_experiments_with_array_data_condition_ids(): + """Conditions defined only in array files are skipped in every period. + """ + from petab.v2.converters import ExperimentsToSbmlConverter + + problem = _get_test_problem() + assert not problem.conditions, "cond1 must not be in the condition table" + array_condition_ids = ( + problem.extensions.sciml._get_array_data_condition_ids() + ) + assert array_condition_ids == {"cond1"} + + # Add preequilibration and simulation periods + periods = [(-float("inf"), "cond1"), (0.0, "cond1")] + problem.experiments[0].periods = [ + ExperimentPeriod(time=time, condition_ids=[condition_id]) + for time, condition_id in periods + ] + + converted = ExperimentsToSbmlConverter(problem).convert() + + # No events defined for conditions given by array data + sbml_model = converted.model.sbml_model + assigned_targets = { + ia.getSymbol() for ia in sbml_model.getListOfInitialAssignments() + } | { + ea.getVariable() + for event in sbml_model.getListOfEvents() + for ea in event.getListOfEventAssignments() + } + assert "net1_input2" not in assigned_targets + + # --------------------------------------------------------------------------- # Full-problem integration # --------------------------------------------------------------------------- From a91d621a76dc0fbcf76e861c77e77cb6b21d437a Mon Sep 17 00:00:00 2001 From: Branwen Snelling Date: Wed, 19 Aug 2026 15:08:25 +0100 Subject: [PATCH 2/2] reformat ruff --- tests/v2/test_sciml.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/v2/test_sciml.py b/tests/v2/test_sciml.py index 74ed2737..a6cdf098 100644 --- a/tests/v2/test_sciml.py +++ b/tests/v2/test_sciml.py @@ -467,9 +467,9 @@ def test_genuinely_missing_output_parameter_still_reported(): # Experiment -> SBML conversion # --------------------------------------------------------------------------- + def test_convert_experiments_with_array_data_condition_ids(): - """Conditions defined only in array files are skipped in every period. - """ + """Conditions defined only in array files are skipped in every period.""" from petab.v2.converters import ExperimentsToSbmlConverter problem = _get_test_problem()