Skip to content
Open
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
12 changes: 6 additions & 6 deletions petab/v2/converters.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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(
Expand Down
37 changes: 37 additions & 0 deletions tests/v2/test_sciml.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
# ---------------------------------------------------------------------------
Expand Down