Skip to content
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

Changes to Systematics manager to support MABE #451

Merged
merged 142 commits into from
Mar 2, 2024
Merged

Conversation

emilydolson
Copy link
Collaborator

This pull request will eventually contain everything necessary on the Empirical side to make systematics tracking in MABE work. Depends on #419.

@codecov
Copy link

codecov bot commented Oct 6, 2021

Codecov Report

Attention: Patch coverage is 95.08197% with 36 lines in your changes are missing coverage. Please review.

Project coverage is 77.92%. Comparing base (0678db4) to head (9e7165a).

Files Patch % Lines
include/emp/Evolve/NK.hpp 0.00% 11 Missing ⚠️
include/emp/base/always_assert.hpp 0.00% 9 Missing ⚠️
include/emp/base/optional_throw.hpp 14.28% 6 Missing ⚠️
tests/Evolve/Systematics.cpp 99.26% 5 Missing ⚠️
include/emp/base/_optional_throw.hpp 0.00% 2 Missing ⚠️
tests/base/optional_throw.cpp 75.00% 2 Missing ⚠️
include/emp/base/_assert_macros.hpp 0.00% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #451      +/-   ##
==========================================
+ Coverage   77.56%   77.92%   +0.35%     
==========================================
  Files         334      337       +3     
  Lines       39631    40450     +819     
==========================================
+ Hits        30740    31519     +779     
- Misses       8891     8931      +40     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@emilydolson
Copy link
Collaborator Author

I'm going to close this PR since this branch is merged into MABE_devel, which will presumably eventually get merged into main (it would be useful to do that sometime in the near future)

@emilydolson
Copy link
Collaborator Author

Actually, I take that back - just noticed that checks aren't running on the main MABE_devel PR and it would be useful to be able to see them, so I'm going to re-open this for now (but the plan should be to merge MABE_devel, not this one)

@emilydolson emilydolson reopened this Feb 28, 2023
@emilydolson
Copy link
Collaborator Author

@mmore500 I thought this was all going to get merged in with master during the mega merge, but it looks like it didn't. Any chance I could get a review? The systematics on master is way out of date and buggy

@mmore500
Copy link
Member

On it!

@emilydolson
Copy link
Collaborator Author

Thanks so much!

@emilydolson
Copy link
Collaborator Author

(sorry, found one more tiny change hiding in my local phylotrackpy repo)

Copy link
Member

@mmore500 mmore500 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No major glaring issues. A few questions, a few suggestions.

include/emp/Evolve/Systematics.hpp Outdated Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Outdated Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Outdated Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Outdated Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Outdated Show resolved Hide resolved
fun_calc_info_t calc_info_fun; ///< Function that takes an organism and returns the unit being tracked by systematics
Ptr<taxon_t> next_parent; ///< The taxon that has been marked as parent for next new org
Ptr<taxon_t> most_recent; ///< The most-recently added taxon
bool num_orgs_wrong = false; ///< Keep track of whether we have loaded from a file that didn't
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could use std::optional for num_orgs and for total_offspring instead

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, I'm conflicted. I like the safety/clarity that optional would provide. However, it looks like it's a not insubstantial time/space hit for numbers that are used in every taxon and operated on a fair amount. It will also make the code potentially confusing to folks who are not familiar with std::optional. Particularly because it's actually very expedient to assume that trees loaded in without org counts have one of each org. It makes all of the topology stuff and tree modification operations work fine. It just makes a couple of metrics inaccurate.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so when num_orgs_wrong is true, num_orgs is still being used but just at a defaulted value? Maybe name these variables _defaulted instead of _wrong?

Copy link
Member

@mmore500 mmore500 Mar 2, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It should compile down to the same thing https://godbolt.org/z/M8j9fG7js To save space compared to std::optional you'd have to do something like pack the two bools into a flag field instead of having two separate bools.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm happy to switch to "defaulted" (although that kind of feels like a euphemism for wrong 😅) if you think that would be clearer.

I could be wrong here, but isn't part of the reason it's compiling down to the same thing on godbolt the fact that in that case the compiler knows everything ahead of time and so can optimize out branching introduced by std::optional?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That''s what I was guessing (which I think actually would be concerning, because if we're using optionals we're going to have be passing them around, etc. - it's semantically different, but representative of the scenarios we're comparing), but then I tested it out and it looks like it is really just the deref that makes the difference

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, that's fair for _defaulted.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Either way could be a good call!

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was almost convinced, but here's the problem. The dereference operator is undefined behavior if there's not actually a value in the optional object. So then you end up needing to use .value(). Which A) appears to be back to the slow speed (https://quick-bench.com/q/acv1zCs2Agso3yZKhfBolRQ8rx0) and B) potentially throws an exception, which we would love to avoid ever having happen in code compiled via emscripten.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to go ahead and just used _defaulted, because the cases where we care that its sometimes wrong are way rarer than the cases where we don't. If that balance shifts we can reconsider.

include/emp/Evolve/Systematics.hpp Show resolved Hide resolved
include/emp/Evolve/Systematics.hpp Show resolved Hide resolved
@emilydolson emilydolson merged commit e7ff3cd into master Mar 2, 2024
21 checks passed
@emilydolson emilydolson deleted the mabe-systematics branch March 2, 2024 05:08
@emilydolson emilydolson restored the mabe-systematics branch March 2, 2024 05:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants