Repository navigation
Auto-assign event priority to a single unprioritized event - #562
Conversation
e5b1b36 to
6946c4d
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #562 +/- ##
==========================================
+ Coverage 78.20% 78.44% +0.23%
==========================================
Files 68 68
Lines 7845 7876 +31
Branches 1400 1406 +6
==========================================
+ Hits 6135 6178 +43
+ Misses 1224 1214 -10
+ Partials 486 484 -2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
6946c4d to
c0ba478
Compare
| @@ -31,10 +35,14 @@ class ExperimentsToSbmlConverter: | |||
| experiments to initial assignments and events as far as possible. | |||
|
|
|||
| If the model already contains events, PEtab events are added with a higher | |||
There was a problem hiding this comment.
| If the model already contains events, PEtab events are added with a higher | |
| If the model already contains events, SBML events are added with a higher |
| If the model already contains events, PEtab events are added with a higher | ||
| priority than the existing events to guarantee that PEtab condition changes | ||
| are applied before any pre-existing assignments. | ||
| priority than the existing events, so that PEtab condition changes are |
There was a problem hiding this comment.
| priority than the existing events, so that PEtab condition changes are | |
| priority than the pre-existing events, so that PEtab condition changes are |
| E0_PRIO = "E0: at time >= 10, priority=-2, fromTrigger=false: C = C * 2" | ||
| E1 = "E1: at time >= 20, fromTrigger=false: C = C" | ||
| E1_PRIO = "E1: at time >= 20, priority=5, fromTrigger=false: C = C" | ||
| E1_PRIO_INF = "E1: at time >= 20, priority=-inf, fromTrigger=false: C = C" |
There was a problem hiding this comment.
Also test the priority=inf case, where it becomes impossible to create the new SBML event?
| assert _event_priorities(problem.model.sbml_model) == {"E0": None} | ||
|
|
||
|
|
||
| def test_explicit_default_priority(): |
There was a problem hiding this comment.
Also test that default priority only affects events with undefined priority?
There was a problem hiding this comment.
Extended the test. Includes an event with defined priority which is confirmed to be preserved.
| if not math.isfinite(priority): | ||
| # no distinct lower priority available | ||
| return |
There was a problem hiding this comment.
If only a lower priority is required here, then I guess +inf is fine here?
| if priority.free_symbols: | ||
| # raises NotImplementedError in _preprocess | ||
| return |
There was a problem hiding this comment.
Raise here too, or will it be fixed here automatically when it's fixed in _preprocess?
There was a problem hiding this comment.
Now handled in _get_event_priorities
`ExperimentsToSbmlConverter` now assigns a priority to a pre-existing model event without priority if it is the only such event, so that the condition-change events are executed before it. The assigned priority is lower than all other finite priorities in the model, so no ties are introduced. This only applies if `default_priority` is not provided, and not if any other event has priority `-inf` or `NaN`. Previously, the order of such events relative to the condition-change events was undefined (e.g., PEtab test suite case 0030). Additionally, warn if a pre-existing event has priority `+inf` or `NaN`, since the condition-change events cannot be assigned a higher priority. References PEtab-dev#526 Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
c0ba478 to
4002964
Compare
ExperimentsToSbmlConverternow assigns a priority to a pre-existing model event without priority if it is the only such event anddefault_priorityis not provided. The assigned priority is lower than all other finite priorities in the model (or0if there are none), and the condition-change events getmax + 1as before. This way, the condition-change events are executed before this event, e.g., in PEtab test suite case 0030, where previously the order was undefined.Per SBML L3V2 §4.12.3/§8.2.5, the order of events without priority is undefined, so assigning a priority only selects one admissible order. Since the assigned value is distinct from all other priorities, no ties are introduced, which would require random execution order. With multiple unprioritized events, nothing is assigned automatically, as this would impose an arbitrary order on them if they are executed simultaneously.
This implements step 1 of #526, generalized to the case of one unprioritized event among prioritized ones (the partial-priority example in the issue). For the automatic assignment, a
<priority>without math is treated as unset. If any other event has priority-inforNaN, nothing is assigned, as no distinct lower priority exists. If any pre-existing event has priority+inforNaN, a warning is emitted, since the condition-change events cannot be assigned a higher priority. The warning for unprioritized events is left for #525.References #526
🤖 Generated with Claude Code