-
Notifications
You must be signed in to change notification settings - Fork 6
Isolate Cereal #153
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
Isolate Cereal #153
Conversation
daec448 to
63f5273
Compare
63f5273 to
b11b7e5
Compare
|
I ended up using a strange pattern which seems to work quite nicely for this application. @jbangelo I'm curious if you have thoughts. Basically instead of using polymorphic pointers I switched to using variants which I then wrapped in a container. Ie, given a situation with instead of passing everything around as a which also inherits from The upside for this application is that it means I don't need to deal with registering polymorphic types and the mess that results from serializing pointers in make sense? |
include all of albatross if you only want serialization of one part. For example, #include <albatross/Core> would only need: #include <albatross/serialize/Core> without this including albatross/Serialization would require including everything (since some of the types would not have been defined for the `serialize()` methods.
feec0f3 to
fc8b4be
Compare
seth-swiftnav
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.
Things look a lot cleaner around the priors now that they use variants. I can't talk to the header refactors. If it passes all unit tests and is faster, I'm happy.
As for not being able to create custom Priors, I'm neither concerned for the loss of custom priors nor do I think they can't be introduced.
| archive(cereal::make_nvp("prior", param.prior)); | ||
| }; | ||
|
|
||
| // template <class Archive> |
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.
Remove if unused?
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!
| archive(cereal::make_nvp("indexing_function", strategy.indexing_function_)); | ||
| } | ||
|
|
||
| // template <typename Archive, typename ModelType, typename StrategyType> |
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.
Remove if unused?
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!
tests/test_serialize.cc
Outdated
| FullJointDistribution, MeanOnlyJointDistribution, | ||
| FullMarginalDistribution, MeanOnlyMarginalDistribution, | ||
| ParameterStoreType, Dataset, DatasetWithMetadata, | ||
| Dataset, DatasetWithMetadata, ParameterStoreType, |
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 curious, why was this reorder required? It seems like neither Datasets or Parameter Stores depend on the other.
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, that was just left over from when I was commenting out and rearranging the order to debug some compile errors. I'll revert it to avoid confusion.
jbangelo
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.
This seems like a reasonable approach. The only downside that I see is that your variant object will end up being large enough to store the largest value it could possibly contain. I can't easily tell from the PR, but if one or more of the possible values is significantly large it could be expensive copying it around, or at the very least would increase memory use. This probably isn't a problem though.
| variant<UninformativePrior, FixedPrior, NonNegativePrior, PositivePrior, | ||
| UniformPrior, LogScaleUniformPrior, GaussianPrior, LogNormalPrior>; | ||
|
|
||
| struct PriorContainer : Prior { |
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.
Nit: this looks more like a class with all that functionality.
include/albatross/Serialization
Outdated
|
|
||
|
|
||
|
|
||
| #endif No newline at end of file |
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.
Nit, missing final new line.
include/albatross/Serialization
Outdated
| #include "src/cereal/representations.hpp" | ||
| #include "src/cereal/variant.hpp" | ||
|
|
||
| //CEREAL_SPECIALIZE_FOR_ALL_ARCHIVES(albatross::ParameterStore, cereal::specialization::non_member_load_save ); |
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.
Nit: Is commented line still needed?
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.
Nope! thanks.
| to = DiagonalMatrixXd(x); | ||
| set_subset(from, idx, &to); | ||
| EXPECT_EQ(to, expected); | ||
| EXPECT_TRUE(to == expected); |
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.
Why was this needed? Doesn't EXPECT_EQ use ==?
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 have no clue why EXPECT_EQ doesn't work with Eigen::DiagonalMatrix<double, Dynamic>. It probably has something to do with the lack of == operator (I had to define a free standing one).
| #include <cereal/types/string.hpp> | ||
| #include <cereal/types/vector.hpp> | ||
|
|
||
| #include "../src/cereal/traits.hpp" |
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.
Relative paths like this in include paths aren't great (they tend to break when porting to different systems(, and cause generally be avoided by setting the include paths you want. Would a path like albatross/src/cereal/traits.hpp work?
It should be helpful to review each commit in order.
This change was motivated by discovering that 1)
cerealheaders are pretty heavy 2) using member serialization methods required including cereal in just about anyalbatrossinclude. 3) the use of polymorphic registration generates a TON of symbols (alluded to in the "Registering in a header file" section here: https://uscilab.github.io/cereal/polymorphism.html) which slows down linking.The change is effectively two parts, in the first we remove polymorphism from
priors.hppwhich was the only part ofalbatrossthat was actually using polymorphic pointers. This eliminates the need for makingcerealwork with polymorphism via theCEREAL_REGISTER_TYPEwhich blew up linking (it added ~10k symbols to our static libraries!!). Second all serialization methods were moved from member methods to free functions in a separate directory. The result is the ability to include albatross without including cereal, then only includealbatross/Serializationin.ccfiles which require serialization.NOTE: The result cut the unit test time in half!