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

Saving result file after sampling fails if lal dict is passed #751

Open
bilby-bot opened this issue Jul 7, 2023 · 3 comments · May be fixed by #825
Open

Saving result file after sampling fails if lal dict is passed #751

bilby-bot opened this issue Jul 7, 2023 · 3 comments · May be fixed by #825
Labels
bug Something isn't working result/output

Comments

@bilby-bot
Copy link
Collaborator

In GitLab by @git.ligo:aditya.vijaykumar on Jul 7, 2023, 20:46

@git.ligo:ish.gupta recently found out that adding a lal_waveform_dictionary to the waveform_arguments works fine while sampling, but fails to save to file at the end of sampling with the following error traceback.

  File "/Users/aytida/work/rough/bilby/bilby/core/result.py", line 795, in save_to_file
    json.dump(dictionary, file, indent=2, cls=BilbyJsonEncoder)
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/__init__.py", line 179, in dump
    for chunk in iterable:
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 432, in _iterencode
    yield from _iterencode_dict(o, _current_indent_level)
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 406, in _iterencode_dict
    yield from chunks
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 439, in _iterencode
    o = _default(o)
        ^^^^^^^^^^^
  File "/Users/aytida/work/rough/bilby/bilby/core/utils/io.py", line 87, in default
    return json.JSONEncoder.default(self, obj)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/aytida/miniconda3/envs/bilby2/lib/python3.11/json/encoder.py", line 180, in default
    raise TypeError(f'Object of type {o.__class__.__name__} '
TypeError: Object of type Dict is not JSON serializable

<more stuff>

TypeError: cannot pickle 'lal.Dict' object

I created a patch that resolves this issue by ignoring the lal_waveform_dictionary altogether while saving the file, but I guess that isn't the nicest way to fix this. Happy to start an MR with any suggestions!

@bilby-bot
Copy link
Collaborator Author

In GitLab by @git.ligo:colm.talbot on Nov 13, 2023, 03:48

There are two possible solutions. My preference would be the first, but the second would be acceptable if this is an urgent issue.

  1. Write a serializer/deserializer for the laldict to convert it to a regular dictionary with the non-default values.

  2. Update the json and hdf encoders to omit these objects.

@bilby-bot
Copy link
Collaborator Author

In GitLab by @git.ligo:aditya.vijaykumar on Nov 20, 2023, 16:45

Thanks Colm. I do think the proposed solution in point 1 makes more sense, but I am finding that it is non-trivial to do that. To start with, do you know how to loop over items inside a LAL dict?

If there is no easy way, I will just resort to implementing solution 2, and keeping this issue open so that it can be dealt with at a later date.

@bilby-bot
Copy link
Collaborator Author

In GitLab by @git.ligo:colm.talbot on Nov 20, 2023, 16:47

We may be able to use this, https://git.ligo.org/lscsoft/lalsuite/-/blob/master/lalsimulation/python/lalsimulation/gwsignal/core/utils.py#L53-L123.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working result/output
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant