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

Fixes for multimessenger analysis #252

Conversation

haukekoehn
Copy link
Contributor

No description provided.

Bug fix data_dump instead of data-dump
When interpolation type is tf, we only want to get the _tf model when we can access the remote models. 

This hack works for now, but maybe we should think about a new system of naming conventions.
Copy link
Member

@mcoughlin mcoughlin left a comment

Choose a reason for hiding this comment

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

I do not quite understand the reason for the changes in this PR yet.

@@ -12,7 +12,7 @@ def create_nmma_analysis_parser(sampler="dynesty"):

analysis_parser = argparse.ArgumentParser(prog="nmma_analysis", parents=[parser])
analysis_parser.add_argument(
"data-dump",
Copy link
Member

Choose a reason for hiding this comment

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

This just means --data-dump is the argument and then the argument is args.data_dump already.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

but the data-dump is a positional argument and therefore it gets passed as args.data-dump which causes trouble

Copy link
Member

Choose a reason for hiding this comment

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

No I think it turns into data_dump. Can @sahiljhawar confirm the behavior perhaps?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

well i just checked again and when i change it back to data-dump it becomes args.data-dump at least in pbilby/analysis/main.
Screenshot from 2023-09-28 20-14-35

Copy link
Member

Choose a reason for hiding this comment

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

No, it does not gets changed to data_dump. It remains data-dump and it cannot be accessed as an attribute of args

Copy link
Member

@sahiljhawar sahiljhawar Sep 28, 2023

Choose a reason for hiding this comment

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

I would suggest to change data_dump from position argument (data_dump) to a normal argument (--data-dump) and see if that works.

Copy link
Member

Choose a reason for hiding this comment

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

@haukekoehn @sahiljhawar Ah that is presumably the difference. Sorry, I didn't realize that it maintains its name if positional.

Copy link
Member

@sahiljhawar sahiljhawar Sep 28, 2023

Choose a reason for hiding this comment

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

@haukekoehn args.data-dump is not a valid syntax. In case the value of data-dump needs to be extracted it should be done as such getattr(args, "data-dump")). Also, if positional arguments (such as data-dump) are being used CLI, then only the order matters and none of the these works: --data-dump, --data_dump, data_dump, data-dump.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yeah now i changed it to --data-dump

nmma/em/model.py Outdated
@@ -291,7 +291,7 @@ def __init__(
if filters is None:
self.filters = model_filters

if os.path.isfile(modelfile):
elif os.path.isfile(modelfile):
Copy link
Member

Choose a reason for hiding this comment

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

This if statement is meant to stand on its own. Maybe the local_only flag is not doing what you want?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, i think the local_only flag is alright, i think. This was just a quick fix from my side, where I use the Bu2022Ye model.
I wanted to prevent it from jumping in to the else statement below, where it tries to read in the _mag_tf model, which doesn't exist for Bu2022Ye.

As i said this is rather hacky and now that i look at it again probably inappropriate. I think the issue is that for Bu2022Ye os.path.isfile(modelfile) is False, because modelfile actually does not point to Bu2022Ye_tf.pkl but rather to Bu2022Ye.pkl which does not exist. But I don't know how to fix this consistently for the entirety of the models out there.

Copy link
Member

@sahiljhawar sahiljhawar Sep 28, 2023

Choose a reason for hiding this comment

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

@haukekoehn If _tf.pkl is the problem, maybe try stripping off the _tf from Bu2022Ye_tf.pkl and then use it with --local-only

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i did it the other way around, where now _tf is added to the modelfile variable, when the interpolation type is tensorflow. Maybe we can chat tomorrow about this.

changed so it no longer is a positional argument.
nmma/em/model.py Outdated
@@ -280,7 +280,7 @@ def __init__(
self.svd_lbol_model = None
elif self.interpolation_type == "tensorflow":
import tensorflow as tf

modelfile = os.path.join(self.svd_path, f"{core_model_name}_tf.pkl")
Copy link
Member

Choose a reason for hiding this comment

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

@bfhealy Maybe we need a check here for the old style? For folks already with the stack downloaded?

Copy link
Member

@mcoughlin mcoughlin left a comment

Choose a reason for hiding this comment

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

I am mostly ok with this as long as it works. Just unsure given the move away from the _tf pickle files.

@sahiljhawar
Copy link
Member

@mcoughlin @bfhealy Maybe for now keep support for _tf and raise deprecation warning until the zenodo models are updated. And then release a minor version after this issue is patched?

@mcoughlin
Copy link
Member

@sahiljhawar @bfhealy @haukekoehn I agree. Can we add an if else at the _tf check instead of just always looking for _tf?

@bfhealy
Copy link
Collaborator

bfhealy commented Oct 2, 2023

@mcoughlin @sahiljhawar I agree with this as well. I can add a temporary check for <model>_tf.pkl if <model>.pkl can't be found. This may also require a temporary modification to get_model in models.py, which currently strips the _tf suffix off of the .pkl files it attempts to download.

@bfhealy
Copy link
Collaborator

bfhealy commented Oct 2, 2023

@mcoughlin @sahiljhawar Just pushed a commit - the default modelfile remains <model>.pkl, but if that file is not found and --interpolation-type is tensorflow, the code will look for <model>_tf.pkl locally before downloading the same from Zenodo. New comments in model.py and models.py list what to remove once files on Zenodo are updated.

@sahiljhawar
Copy link
Member

@mcoughlin Merge-ready?

@mcoughlin
Copy link
Member

@sahiljhawar good for me!

@sahiljhawar sahiljhawar merged commit 32bd04e into nuclear-multimessenger-astronomy:main Oct 2, 2023
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants