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

Reading compatibility #425

Merged
merged 5 commits into from
Sep 11, 2024
Merged

Reading compatibility #425

merged 5 commits into from
Sep 11, 2024

Conversation

daviesje
Copy link
Contributor

There is currently a behaviour in global_params.use() which, unlike other parameter structures, raises an error when a keyword not in the parameter set is passed. This made it impossible to read in boxes from different versions that had differing parameters. I've made it behave like the other parameter sets now, which simply send out a warning.

However, to keep things safer, I've added a flag to the high-level output reading functions which ensure that all the parameters are there, if the flag is on and the parameters are mismatched it raises an error. if the flag is off it emits a warning detailing which parameters are missing / extra.

Tests have also been written to ensure the desired behaviour.

@@ -56,6 +57,81 @@ def ang_lightcone(ic, lc):
)


Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ideally I would also test for gaps and gluts in the data structures themselves, but the different way coevals and lightcones are structured make this difficult.

Lightcones are agnostic to the types of the lightcone fields, so missing fields are ignored and extra ones are simply loaded in.

Coevals on the other hand rely on the output structs, so both missing and extra output fields will raise errors, and changing this behaviour requires adding safe flags to all the lower level reading as well.

@@ -936,10 +936,23 @@ def save(self, fname=None, direc=".", clobber: bool = False):
return self._write(direc=direc, fname=fname, clobber=clobber)

@classmethod
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 had a question here. Where does the Coeval object read in the parameter structures? The Coeval __init__ takes them directly from the BrightnessTemp struct, but these don't seem to be saved with the structures looking at the _write_particulars function.


# check that missing fields are set to default
assert lc2.user_params.BOX_LEN == UserParams._defaults_["BOX_LEN"]
assert lc2.global_params["OPTIMIZE_MIN_MASS"] == global_params.OPTIMIZE_MIN_MASS
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This assert would be more useful if I changed the global_params in the lc/coeval fixtures

tests/test_high_level_io.py Outdated Show resolved Hide resolved
@daviesje daviesje marked this pull request as draft September 10, 2024 17:31
@daviesje daviesje marked this pull request as ready for review September 11, 2024 09:59
Copy link

codecov bot commented Sep 11, 2024

Codecov Report

Attention: Patch coverage is 92.30769% with 2 lines in your changes missing coverage. Please review.

Project coverage is 82.23%. Comparing base (2414803) to head (6f1ab6b).
Report is 7 commits behind head on master.

Files with missing lines Patch % Lines
src/py21cmfast/cache_tools.py 66.66% 1 Missing ⚠️
src/py21cmfast/outputs.py 95.23% 0 Missing and 1 partial ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #425      +/-   ##
==========================================
+ Coverage   82.19%   82.23%   +0.04%     
==========================================
  Files          13       13              
  Lines        3140     3153      +13     
  Branches      854      861       +7     
==========================================
+ Hits         2581     2593      +12     
  Misses        400      400              
- Partials      159      160       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@daviesje daviesje merged commit 16db064 into master Sep 11, 2024
21 checks passed
@daviesje daviesje deleted the reading_compatibility branch September 11, 2024 13:07
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.

2 participants