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

YAML utilization tool #149

Open
AaronDonahue opened this issue Oct 1, 2021 · 4 comments
Open

YAML utilization tool #149

AaronDonahue opened this issue Oct 1, 2021 · 4 comments

Comments

@AaronDonahue
Copy link
Contributor

Would it be possible to generate a tool, most likely in EKAT, that could check if all valid entries in a YAML file are used, and then issue a warning to screen if any entries are ignored?

Maybe a general approach would be to store all entries in a yaml file as a map to a bool and trigger true the first time an entry is gotten with param_list.get?

The use case I can think of is that currently the YAML parser will ignore anything that isn't requested, and in a lot of cases we use "if" statements to check if something is in the YAML file at all before taking some action. A typo in the yaml file is enough to cause the "if" statement to be false which can make a user believe something is happening when it isn't. A warning printed to screen would be enough to alert a user to the fact that they've made a mistake in the YAML file.

@bartgol
Copy link
Contributor

bartgol commented Oct 1, 2021

A better approach (which is what Trilinos ParameterList offers) would be to have a "valid" parameter list, to compare against the input one. The comparison can then error out if some of the input keys are not in the valid PL, and, possibly, if some valid PL entries are not in the input PL.

So something like this:

   ekat::ParameterList validPL;
   validPL.set<std::string>("Filename","");
   validPL.sublist("Options").set<int>("Value",0);
   
   ekat::ParameterList my_pl;
   my_pl.set<std::string>("Fname","blah");
   my_pl.sublist("Options").set<int>("Val",1);
   
   my_pl.validate(validPL); // throws b/c of Fname instead of Filename, and for Val instead of Value

The 'validate' routine could also give the option of recurse or not into sublists, and to make sure all keys in the valid PL are set in the input PL (not by default though).

@bartgol
Copy link
Contributor

bartgol commented Oct 1, 2021

Note: Trilinos' ParameterList also offers my_pl.validateAndSetDefaults(validPL), which on top of checking that my_pl does not contain invalid keys, it also sets any missing entry to the values stored in validPL.

It also has some mechanism to check that the values associated to some keys satisfy user-defined checks, but I find that way too advanced, and not needed for ekat's purposes.

@bartgol
Copy link
Contributor

bartgol commented Oct 1, 2021

I'm gonna transfer the issue in EKAT.

@welcome
Copy link

welcome bot commented Oct 1, 2021

Thanks for opening your first issue here! Be sure to follow the issue template!

@bartgol bartgol transferred this issue from E3SM-Project/scream Oct 1, 2021
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

No branches or pull requests

2 participants