Skip to content

Commit 0d3c25a

Browse files
committed
skip cond ids set by arrays for all periods
1 parent 847b16f commit 0d3c25a

2 files changed

Lines changed: 43 additions & 6 deletions

File tree

petab/v2/converters.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@ def _convert_experiment(self, experiment: Experiment) -> None:
248248
# or the only non-equilibration period (handled above)
249249
continue
250250

251+
# Skip if condition ids are set by array data
252+
if self._array_data_condition_ids and set(
253+
period.condition_ids
254+
).issubset(self._array_data_condition_ids):
255+
continue
256+
251257
# Encode the period changes in the SBML model as events
252258
# that trigger at the start of the period or,
253259
# for the first period, as initial assignments.
@@ -258,12 +264,6 @@ def _convert_experiment(self, experiment: Experiment) -> None:
258264
# single-period experiments.
259265
if i_period == 0:
260266
exp_ind_id = self.get_experiment_indicator(experiment.id)
261-
# Skip if condition ids are set by array data
262-
# importers handle this
263-
if self._array_data_condition_ids and set(
264-
period.condition_ids
265-
).issubset(self._array_data_condition_ids):
266-
continue
267267

268268
for change in self._new_problem.get_changes_for_period(period):
269269
period0_assignments.setdefault(

tests/v2/test_sciml.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -463,6 +463,43 @@ def test_genuinely_missing_output_parameter_still_reported():
463463
assert not any("net1_output2" in issue.message for issue in results)
464464

465465

466+
# ---------------------------------------------------------------------------
467+
# Experiment -> SBML conversion
468+
# ---------------------------------------------------------------------------
469+
470+
def test_convert_experiments_with_array_data_condition_ids():
471+
"""Conditions defined only in array files are skipped in every period.
472+
"""
473+
from petab.v2.converters import ExperimentsToSbmlConverter
474+
475+
problem = _get_test_problem()
476+
assert not problem.conditions, "cond1 must not be in the condition table"
477+
array_condition_ids = (
478+
problem.extensions.sciml._get_array_data_condition_ids()
479+
)
480+
assert array_condition_ids == {"cond1"}
481+
482+
# Add preequilibration and simulation periods
483+
periods = [(-float("inf"), "cond1"), (0.0, "cond1")]
484+
problem.experiments[0].periods = [
485+
ExperimentPeriod(time=time, condition_ids=[condition_id])
486+
for time, condition_id in periods
487+
]
488+
489+
converted = ExperimentsToSbmlConverter(problem).convert()
490+
491+
# No events defined for conditions given by array data
492+
sbml_model = converted.model.sbml_model
493+
assigned_targets = {
494+
ia.getSymbol() for ia in sbml_model.getListOfInitialAssignments()
495+
} | {
496+
ea.getVariable()
497+
for event in sbml_model.getListOfEvents()
498+
for ea in event.getListOfEventAssignments()
499+
}
500+
assert "net1_input2" not in assigned_targets
501+
502+
466503
# ---------------------------------------------------------------------------
467504
# Full-problem integration
468505
# ---------------------------------------------------------------------------

0 commit comments

Comments
 (0)