Enable .json config saving and loading for ligo.p_astro models
Objective
Implement save and load methods for TwoComponentModel
and CompositeModel
that are compatible with .json files.
Problem
Currently we only save and load the FGMC model state of spiir.search.p_astro.models.TwoComponentModel
by writing a .pkl file to disk that serializes the state of all the Python objects. While this is easy and effective, it is not the ideal solution.
Code Version Conflicts
Firstly, pickle objects won't be able to be loaded if there are changes made to the Python class itself. This means if we add a feature or make a refactor to the model, but don't actually change how model parameters aren't input and output, we will still break the saved model state file.
Fork Dependency
Secondly, pickle compatibility has only been implemented in the feature/enable_pickle_compat branch of our ligo.p_astro fork. This is because dict_keys
and dict_values
objects cannot be serialized by pickle when saved as attributes to a Python class.So far this change has not been merged, and we would rather not have a long-lived branch/merge request that we rely on to run p_astro.
User Experience Improvements
Thirdly, a .json config file (or at least as similar config file, such as .yaml if preferred) allows the state of the model to be interrogated without additional documentation if the config parameters are understandable and well-written.
Where to start?
Note that spiir.search.p_astro.mchirp_area.ChirpMassAreaModel
already has .json config compatibility implemented. This may be a good framework to look at to make equivalent changes for the FGMC model.