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

ENH: add global meta data #873

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

mj-will
Copy link
Collaborator

@mj-will mj-will commented Dec 6, 2024

Based on the discussion in #867, I've made a start on a possible implementation of a global meta data object.

For now, it's just a singleton dictionary that, by default, tracks the rng. Things like the cosmology can then be added when they're set.

I still need to test this properly, but hopefully it gives us something to discuss.

@mj-will mj-will added the enhancement New feature or request label Dec 6, 2024
Copy link
Collaborator

@ColmTalbot ColmTalbot left a comment

Choose a reason for hiding this comment

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

This looks like a good start to me.

Generator.rng = default_rng(seed)
global_meta_data.add_to_meta_data("rng", Generator.rng)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is using this method instead of just doing global_meta_data[key] = value required, or some convention I haven't come across before?

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 thought we may want to add some form of check/validation when adding values, so this would make it easier in future. Happy to revert to something simpler though

@@ -11,7 +11,11 @@ class Generator:


def seed(seed):
from .meta_data import global_meta_data
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't necessarily have to hide these imports, the meta data will be initialized at import time anyway, right?

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 running into circular imports but that may have been an old thing, I'll have a look

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah, if I make this a top-level import, then I hit circular import issues. I think this is because everything is imported in the __init__.py files in bilby, bilby.core and bilby.core.utils. We could make an exception for meta_data file.

@mj-will
Copy link
Collaborator Author

mj-will commented Dec 9, 2024

The tests are going to fail until #867 is merged, since it adds support for properly saving the cosmology objects

@mj-will mj-will added this to the 2.5.0 milestone Jan 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants