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

Validate case dictionaries #424

Closed
henryleberre opened this issue May 19, 2024 · 2 comments · Fixed by #437
Closed

Validate case dictionaries #424

henryleberre opened this issue May 19, 2024 · 2 comments · Fixed by #437
Assignees
Labels
enhancement New feature or request good first issue Good for newcomers

Comments

@henryleberre
Copy link
Member

henryleberre commented May 19, 2024

Currently, we have a file in the toolchain named toolchain/mfc/run/case_dicts.py that lists all the keys a case dictionary can have for each target. This is done by programmatically generating the lists on the fly. We need to do this because each target has its own set of inputs (keys) it accepts. If you specify one that it does not know about, it will fail to load the input data.

However, we do not check data-types. This can cause trouble when Fortran tries to read values from the .inp files we generate. Depending on the compiler, the error message can be very misleading, sometimes pointing to innocent lines in the .inp files.

To mitigate this issue, we could define a schema in Python for these case dictionaries and use them to validate the JSON we get from cases. There are a few libraries that do this. One of them is jsonschema. It might not be the most appropriate.

There might be a better way of doing this (that does not require too much work) I cannot think of (perhaps with a larger-scoped change).

@henryleberre henryleberre added the good first issue Good for newcomers label May 19, 2024
@sbryngelson sbryngelson added the enhancement New feature or request label May 19, 2024
@AiredaleDev
Copy link
Contributor

AiredaleDev commented May 21, 2024

I'd like to tackle this! Just so I understand correctly, is there somewhere that generates case_dicts.py, or is it manually updated to reflect all tunable, potentially comptime-known parameters? I've only been able to find code that generates the fpps using case_dicts.

@henryleberre
Copy link
Member Author

@AiredaleDev great! It's manually updated when new parameters are added/removed. You can find the "true" list of acceptable runtime parameters in the m_start_up modules. They use the namelist construct to read .inp files that contain the key/value pairs. If you run a case, you can find these files generated in the same directory as the case file itself.

Keep in mind that:

  • The inputs that are only known are runtime are kept in .inp files. These files are generated by the toolchain.
  • When --case-optimization is in use, we define some of these inputs are compile-time. The toolchain sets their values in a case.fpp file that is #:include'd by relevant files in the MFC source code. In this case, they become parameters (in the Fortran sense) and are no longer present in the namelist.

A bit of extra context: When you call ./mfc.sh run <filename> <case args..> the toolchain runs python3 <filename> [MFC toolchain's state here (you can ignore this)] <case args..>. This returns (well prints) a JSON object with all the key/value pairs for all codes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request good first issue Good for newcomers
Development

Successfully merging a pull request may close this issue.

3 participants