emilydolson / phylotrackpy

Python phylogeny tracker for in silico evolution experiments
MIT License
10 stars 2 forks source link

Creating a taxon manually can cause invalid snapshot files #48

Closed mmore500 closed 6 months ago

mmore500 commented 10 months ago
    tax1, tax2 = "hello", "hello2"
    sys = systematics.Systematics(taxon_info_fun, True, True, False, False)
    org = ExampleOrg(tax1)
    org2 = ExampleOrg(tax2)
    org_tax = systematics.Taxon(0, tax1)
    org2_tax = sys.add_org(org2, org_tax)
    org3_tax = sys.add_org(org2)
    org4_tax = sys.add_org(org, org2_tax)
    org5_tax = sys.add_org(org, org4_tax)

produces

id,ancestor_list,origin_time,destruction_time,num_orgs,tot_orgs,num_offspring,total_offspring,depth
3,[1],0,inf,2,2,0,0,2
2,[NONE],0,inf,1,1,0,0,0
1,[0],0,inf,1,1,1,1,1

Because org_tax is not registered through add_org it won't be included in the Snapshot file, leaving dangling ancestor references that segfault when you try to load the Snapshot file back up.

mmore500 commented 10 months ago

We might want to hide systematics.Taxon from users? What's the use case for manually constructing a Taxon?

emilydolson commented 9 months ago

Yeah, fundamentally no one should ever construct a Taxon object except through the systematics manager. It was in the tests mostly just to make sure things were working as they should, not because it's a good use pattern.

Is there a way to hide the Taxon constructor from users but not the setters/getters? The reason I left Taxon objects in the documentation is that there's lots of reason to interact with them, just never to directly construct them.