-
Notifications
You must be signed in to change notification settings - Fork 89
Allow Demography init from provenance with preset pop IDs #2370
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
base: main
Are you sure you want to change the base?
Conversation
7403228 to
28bf96b
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #2370 +/- ##
=======================================
Coverage 91.23% 91.23%
=======================================
Files 20 20
Lines 11831 11836 +5
Branches 2296 2298 +2
=======================================
+ Hits 10794 10799 +5
Misses 568 568
Partials 469 469
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
|
With this in place, you can plot a demes demography from a tree seq generated by stdpopsim, without having to install stedpopsim, know the model etc., which is neat: |
jeromekelleher
left a comment
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 we need a different way of instantiating Demography objects
msprime/provenance.py
Outdated
| try: | ||
| demography_object.__init__(**obj) | ||
| except ValueError as e: | ||
| if str(e).startswith("Population ID should not be set"): |
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.
This control flow by exception logic is fragile and distributes the logic of creating Demography objects around different modules. We should add a Demography.fromdict method that does this, and can be tested independently;.
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'm returning to some of my open PRs, and realise that this one has an easy fix, because I just found out that you can pass an InitVar parameter to a dataclass. In this case we use it to flag not to worry about making new population IDs in this specific case. I think this is probably the minimally intrusive thing to do.
28bf96b to
dec2a42
Compare
The last step to allow demographies to be instantiated from provenance entries. We exceptionally allow a
demography.Populationobject to be created with an existing ID, but only if generated when decoding provenance JSON. This ensures that the IDs in the events etc match with what we expect. It's a slight hack in that we check for the error message. The alternative is to pick a different error (?RuntimeError) or make our own bespoke error that can be allowed through in this case.