-
Notifications
You must be signed in to change notification settings - Fork 7
Update ExperimentsToEventsConverter
to changed initialization semantics
#443
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #443 +/- ##
==========================================
- Coverage 74.86% 74.79% -0.07%
==========================================
Files 62 62
Lines 6790 6845 +55
Branches 1204 1223 +19
==========================================
+ Hits 5083 5120 +37
- Misses 1251 1258 +7
- Partials 456 467 +11 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
17a3764
to
d524898
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good 👍
petab/v2/converters.py
Outdated
# combine all changes into a single piecewise expression | ||
if expr_cond_pairs := [ | ||
(target_value, sp.Symbol(exp_ind) > 0.5) | ||
for exp_ind, target_value in changes | ||
if target_value != default | ||
]: | ||
# only create the initial assignment if there is | ||
# actually something to change | ||
expr = sp.Piecewise( | ||
*expr_cond_pairs, | ||
(default, True), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comments above and below the if
are swapped.
Also is this check only relevant when the condition table happens to contain the same value as the SBML default? Or is there another case where this becomes relevant? IMO fine to skip this check if it's just about cases where the user coincidentally duplicates the SBML default into the condition table -- if they have redundant information in the table then redundant initial assignments can be the consequence 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the comments above and below the
if
are swapped.
🙈
Also is this check only relevant when the condition table happens to contain the same value as the SBML default? Or is there another case where this becomes relevant? IMO fine to skip this check if it's just about cases where the user coincidentally duplicates the SBML default into the condition table -- if they have redundant information in the table then redundant initial assignments can be the consequence 😅
Yes and no. Imagine you have 100 experiments, and only one of them changes the initial value of A
. This would result in A = Piecewise((default, exp1), (default, exp2), ..., (default, exp99) , (some_non_default, exp100))
, unless sympy will auto-simplify that.
Since it's not that complicated I prefer keeping that here to produce easier-to-digest models.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah nice, thanks 👍
if species_change := next( | ||
(c for c in changes if c.target_id == species_id), None | ||
): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fine as is, but I use more-itertools frequently for one
and only
.
https://more-itertools.readthedocs.io/en/stable/api.html#more_itertools.only
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Generally useful, agreed, but not sure if I want to pull in another dependency for that.
_add_assignment( | ||
event, | ||
species_id, | ||
# new_conc * new_volume / old_volume | ||
new_conc | ||
* change.target_value | ||
/ sp.Symbol(change.target_id), | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does SBML ensure that the compartment change and derived concentrations are implemented first in a set of event assignments, before event assignments for the derived concentrations explicitly? And is sp.Symbol(change.target_id)
necessarily the old compartment size, if the compartment change is implemented first?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For multiple event assignments of a single event (we don't care about simultaneous events here), the assigned expression is evaluated before any of the assignments.
I'd say there is no explicit order, but the updated concentrations will be computed based on the new expressions for the compartment size (which is kind of the same).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, looks good 👍
Co-authored-by: Dilan Pathirana <59329744+dilpath@users.noreply.github.com>
Due to PEtab-dev/PEtab#645 ...
Closes #452.