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

Model configuration output in HDF #1299

Merged
merged 8 commits into from
Sep 25, 2020

Conversation

andrewfullard
Copy link
Contributor

@andrewfullard andrewfullard commented Sep 11, 2020

Description

Unit test added for a to_hdf method of the configuration namespace. Successfully converts a configuration to a YAML-formatted string.

Motivation and Context

Required to output simulation input parameters as part of the HDF in the standard HDF output from simulations.

How Has This Been Tested?

Unit test added and fails

Screenshots (if appropriate):

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)

Checklist:

  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have assigned/requested two reviewers for this pull request.

Unit test moved to the config reader tests and the Configuration class
is now subclassed to with ConfigWriterMixin, itself a subclass of
HDFWriterMixin. get_properties has been overridden to obtain properties
from configuration dict keys.
Config is now returned as a dict of dicts instead of a dict containing configurationnamespace objects. Test doesn't need the pytest fixture any more.
Test still fails, but the HDF contains configuration information in CGS units. Scalar output means that some entries are not well formatted. Pandas still cannot read the HDF.
@andrewfullard
Copy link
Contributor Author

andrewfullard commented Sep 14, 2020

Convert ConfigurationNameSpace to YAML and then dump to string instead?

Turn config into string for comparison to the read-in HDF

Rewrote ConfigWriterMixin, moved it to util.py to match PlasmaWriterMixin, added static method override for to_hdf_util to handle the string output, updated test to do string-to-string comparison
@codecov
Copy link

codecov bot commented Sep 15, 2020

Codecov Report

Merging #1299 into master will increase coverage by 1.03%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #1299      +/-   ##
==========================================
+ Coverage   80.54%   81.57%   +1.03%     
==========================================
  Files          41       46       +5     
  Lines        3423     3799     +376     
==========================================
+ Hits         2757     3099     +342     
- Misses        666      700      +34     
Impacted Files Coverage Δ
tardis/plasma/standard_plasmas.py
tardis/io/parsers/blondin_toymodel.py
tardis/plasma/properties/nlte.py
tardis/montecarlo/formal_integral.py
tardis/io/model_reader.py
tardis/io/util.py
tardis/io/config_validator.py
tardis/io/parsers/stella.py
tardis/widgets/base.py
tardis/plasma/properties/j_blues.py
... and 76 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 862025e...4b95173. Read the comment docs.

@andrewfullard andrewfullard marked this pull request as ready for review September 15, 2020 19:01
@marxwillia marxwillia self-requested a review September 16, 2020 14:47
Comment on lines 402 to 403


Copy link
Member

@wkerzendorf wkerzendorf Sep 16, 2020

Choose a reason for hiding this comment

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

Suggested change
def quantity_representer(dumper, data):
"""
docu goes here
"""
return dumper.represent_data(str(data))
def cns_representer(dumper, data):
"""
docu goes here
"""
return dumper.represent_dict(dict(data))
yaml.add_representer(u.Quantity, quantity_representer)
yaml.add_representer(ConfigurationNameSpace, cns_representer)
yaml.add_representer(Configuration, cns_representer)

@wkerzendorf
Copy link
Member

pd.Series({'config':x})

Simplifies ConfigWriterMixin using YAML representers to read Quantities and Configuration objects
tardis_config_verysimple, validate=True, config_dirname="test"
)
expected.to_hdf(hdf_file_path)
actual = pd.read_hdf(hdf_file_path, key="/config/config")
Copy link
Member

Choose a reason for hiding this comment

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

why config/config?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed in next commit

@wkerzendorf wkerzendorf merged commit 983213b into tardis-sn:master Sep 25, 2020
atharva-2001 pushed a commit to atharva-2001/tardis that referenced this pull request Oct 1, 2021
* Added test for config -> HDF

* Unit test moved and HDFMixin subclassed

Unit test moved to the config reader tests and the Configuration class
is now subclassed to with ConfigWriterMixin, itself a subclass of
HDFWriterMixin. get_properties has been overridden to obtain properties
from configuration dict keys.

* Improved test and config reading

Config is now returned as a dict of dicts instead of a dict containing configurationnamespace objects. Test doesn't need the pytest fixture any more.

* Mostly valid HDF is now written out

Test still fails, but the HDF contains configuration information in CGS units. Scalar output means that some entries are not well formatted. Pandas still cannot read the HDF.

* Test passes, config written to string

Rewrote ConfigWriterMixin, moved it to util.py to match PlasmaWriterMixin, added static method override for to_hdf_util to handle the string output, updated test to do string-to-string comparison

* Cleanup of unused imports

* Rewrite to use yaml representer

Simplifies ConfigWriterMixin using YAML representers to read Quantities and Configuration objects

* Moved the config to the simulation part of HDF
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants