MFlowCode / MFC

Exascale simulation of multiphase/physics fluid dynamics
https://mflowcode.github.io
MIT License
132 stars 56 forks source link

Validate case dictionaries #424

Closed henryleberre closed 1 month ago

henryleberre commented 1 month ago

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).

AiredaleDev commented 1 month ago

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 commented 1 month ago

@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:

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.