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

Ramses read namelist #2347

Merged
merged 7 commits into from
Oct 28, 2019
Merged

Ramses read namelist #2347

merged 7 commits into from
Oct 28, 2019

Conversation

cphyc
Copy link
Member

@cphyc cphyc commented Oct 18, 2019

PR Summary

This adds the automatic loading of the namelist.txt file which contains the parameter file RAMSES used to produce the output.
This relies on the package f90nml being installed (for the tests). If the package is absent, ds.parameters['namelist'] contains an error message.

PR Checklist

  • Code passes flake8 checker
  • Adds a test for any bugs fixed. Adds tests for new features.

Copy link
Member

@matthewturk matthewturk left a comment

Choose a reason for hiding this comment

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

LGTM!

with open(namelist_file, 'r') as f:
nml = f90nml.read(f)
except ImportError as e:
nml = "An error occurred when reading the namelist: %s" % str(e)
Copy link
Member

Choose a reason for hiding this comment

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

If we make this an exception of some type, we might be more easily able to determine if it's the success or not, with an isinstance.

Copy link
Member Author

Choose a reason for hiding this comment

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

I am not sure I understand your comment.

However, the reason I settled for this is that reading namelist.nml is not required to properly load the simulation, so I was trying to avoid throwing errors at the user.

Copy link
Member

Choose a reason for hiding this comment

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

NBD, just thought if we had an object we could check if it read correctly without doing a string comparison. I agree about not throwing errors!

Copy link
Member Author

@cphyc cphyc Oct 18, 2019

Choose a reason for hiding this comment

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

I am still confused ; where do you see a string comparison? Here I am storing the content of the namelist in ds.parameters['namelist']. If we're missing the f90nml package, I store the error message instead.

That is probably not the best solution though.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, I meant -- let's pretend I wanted to know if the namelist had been parsed. I could do that with an isinstance or I could check the contents of the string, right? Or is it only going to be an instance of str if it succeeds?

Copy link
Member Author

@cphyc cphyc Oct 18, 2019

Choose a reason for hiding this comment

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

There are three cases:

  1. the file does not exists: ds.parameters['namelist'] is left unitialized,
  2. the file exists and f90nml is missing: ds.parameters['namelist'] then contains the error message as a string,
  3. the file exists and f90nml is installed: ds.parameters['namelist'] is a dict-like structure with the content of the namelist.

Any idea to make it better is welcome!

Copy link
Member Author

@cphyc cphyc Oct 18, 2019

Choose a reason for hiding this comment

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

So right now if I wanted to see if the namelist was parsed, I wouldn't have a proper way of doing it except checking isinstance(ds.parameters['namelist'], str).

@matthewturk
Copy link
Member

matthewturk commented Oct 18, 2019 via email

@cphyc
Copy link
Member Author

cphyc commented Oct 18, 2019

The tests fail because the new test assumes f90nml to be installed (which is not the case). Would it be possible to install it on jenkins?

@munkm
Copy link
Member

munkm commented Oct 18, 2019

@Xarthisius what do we need to do to get f90nml on Jenkins?

@Xarthisius
Copy link
Member

Xarthisius commented Oct 18, 2019

The tests fail because the new test assumes f90nml to be installed (which is not the case). Would it be possible to install it on jenkins?

Since it's a python package, all you need to do is add it to yt/tests/test_requirements.txt. However, those tests should be wrapped in @requires_module("f90nml") too to avoid that situation when someone's running it locally.


output_00080 = "output_00080/info_00080.txt"
@requires_ds(output_00080)
Copy link
Member

Choose a reason for hiding this comment

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

Because this test uses the f90nml module I think you need the @requires_module() decorator.

Copy link
Member

Choose a reason for hiding this comment

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

Ha nice mind-meld with @Xarthisius! 😎

Copy link
Member

@matthewturk matthewturk 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 ready to go to me!

EDIT: Whoops, I didn't read in detail the errors -- I don'tknow what's up, but it looks like a ValueError is being raised from the new tests. Do we need to update the dataset?

@cphyc
Copy link
Member Author

cphyc commented Oct 21, 2019

@matthewturk I think we should rather catch the error and display it as a warning to the user. There used to be a bug in RAMSES that would write the configuration file in binary format. I'm working on it.

@cphyc
Copy link
Member Author

cphyc commented Oct 22, 2019

@yt-fido test this please.

@cphyc
Copy link
Member Author

cphyc commented Oct 24, 2019

The tests seem to fail for unrelated reasons, don't they?

@munkm
Copy link
Member

munkm commented Oct 25, 2019

I'm working on a fix for the 3.6 answer tests on Travis.

@munkm
Copy link
Member

munkm commented Oct 25, 2019

@cphyc if you merge or rebase with master you should get the fix I pushed for the Travis tests.

@Xarthisius
Copy link
Member

@yt-fido test this please

Also add on-demand facilities for f90nml package
This happens with old version of RAMSES that produced malformed namelist.txt files
The tests were relying on output_00080 for a *correct* namelist. Changed it to a working one (ramses_new_format).
The path to namelist.txt was not computed correclty, resulting in a failing test.
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