Run DuMuX simulation inside container via Snakemake#49
Run DuMuX simulation inside container via Snakemake#49Sarbani-Roy wants to merge 6 commits intomainfrom
Conversation
dabd6b9 to
91fd400
Compare
|
We believe this is ready from our side. @joergfunger or @jpthiele, could you please review and merge this? We are looking forward to your feedback. |
joergfunger
left a comment
There was a problem hiding this comment.
Thanks, a couple of comments from my side.
|
|
||
| configurations.append(config_name) | ||
| config_to_param[config_name] = f"params_{config_name}.input" | ||
| config_to_vtu[config_name] = [ |
There was a problem hiding this comment.
The parameter files are mapped to the config {Path("parameters_1.json"): "1", ...} and the inverse map has to be stored. But is that true here, just use the config string when creating the output.
There was a problem hiding this comment.
The configuration layer is defined explicitly through two mappings, for example:
"configuration_to_parameter_file": {
"10_80": "params_10_80.input"
},
"configuration_to_solution_vtu_files": {
"10_80": [
"dumux/test_rotatingcylinders_10_80-00000.vtu",
"dumux/test_rotatingcylinders_10_80-00001.vtu"
]
}With this structure, the config string (10_80) serves as the single key that links the parameter file and the corresponding set of solution files. This avoids the need for an explicit inverse map while still preserving a clear and deterministic association between inputs and outputs.
There was a problem hiding this comment.
true, but in the same way you could just write in you Snakefile something like below, where you would not need that additional variables. IMO, this is easier to read, because the definition of these additional variables is at another place than the actual usage.
rule postprocess_dumux_results:
input:
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
result_vtk0 = f"{result_dir}/{tool}/{{configuration}}/test_rotatingcylinders_10_80-00000.vtu",
result_vtk1 = f"{result_dir}/{tool}/{{configuration}}/test_rotatingcylinders_10_80-00001.vtu",
script = f"{tool}/postprocess_results.py",
output:
zip = f"{result_dir}/{tool}/solution_field_data_{{configuration}}.zip",
metrics = f"{result_dir}/{tool}/solution_metrics_{{configuration}}.json",
conda:
"environment_simulation.yml",
shell:
"""
python3 {input.script} \
--input_parameter_file {input.parameters} \
--input_result_vtk0 {input.result_vtk0} \
--input_result_vtk1 {input.result_vtk1} \
--output_solution_file_zip {output.zip} \
--output_metrics_file {output.metrics}
"""
| input: | ||
| expand(f"{result_dir}/{{tool}}/summary.json", tool=tools) | ||
|
|
||
| rule generate_dumux_inputs: |
There was a problem hiding this comment.
How general is that meshing? (see comment above, when being implemented by another CFD code
There was a problem hiding this comment.
This will work for any DUNE-based solvers.
There was a problem hiding this comment.
But it is in the general Snakefile (which would also be true for openFOAM, or any other CFD solver).
There was a problem hiding this comment.
@berndflemisch this is the general snakefile (for all tools the same), so IMO generate_dumux_input feels wrong to me.
| config_name = f"{cells0}_{cells1}" | ||
|
|
||
| configurations.append(config_name) | ||
| config_to_param[config_name] = f"params_{config_name}.input" |
There was a problem hiding this comment.
these parameter files should be json. At a later stage, we would like to replace this generation of the parameter files by automatically extracting it from the benchmark knowledge graph
There was a problem hiding this comment.
According to my best knowledge DuMuX does not natively use JSON as its primary input format. It uses DUNE’s parameter system, which expects a .input file (INI-like / key–value format). However, we can use JSON as a preprocessing layer and convert it into a DuMuX-compatible .input file before running the simulation. If this is okay I can certainly do this.
There was a problem hiding this comment.
The goal is that these parameter files are tool-independent definitions. We replace the key/values in these json that are converted to dict in the tool-specific input_template. So you would have to create a native DuMuX input template, write the variable/parameters that are to be replaced by some
There was a problem hiding this comment.
I agree with Jörg. It seems a bit overkill for the first benchmark but we should make it extensible.
The idea with the template is good and the python package jinja2 works well for these things, so you can convert a currently generated DuMuX input file into a jinja2 template and write a relatively short preprocessing scripts that takes the generic JSON and inserts the values into the template.
But I would first check if Dune added the functionality of reading JSON. I know that in deal.II it is a relatively new addition, so maybe. And that would possibly be the easiest way
| rule generate_dumux_inputs: | ||
| input: | ||
| grid_t = f"{dumux_dir}/grid_files/grid_template.json", | ||
| dumux_t = f"{dumux_dir}/input_files/dumux_config.json" |
There was a problem hiding this comment.
Why are those dumux config files (rather than tool independent configurations that define what is to be computed in the benchmark)?
There was a problem hiding this comment.
Sorry but can you please explain a bit more.
There was a problem hiding this comment.
This is the general Snakefile that is supposed to be valid for all tools, and then there is the tool-specific part, that is integrated right after this part that does the tool-specific stuff. I was just wondering, why the apparently tool-specific files are handled in the general snakefile.
srosenbu
left a comment
There was a problem hiding this comment.
Nice work. I have a few comments regarding the conda environments.
There was a problem hiding this comment.
In the other benchmarks, we use the https://github.com/BAMresearch/NFDI4IngModelValidationPlatform/blob/main/environment_benchmarks.yml file to start snakemake. Ich each of the rules,we then define the environment or container used to run the rule. So I tthink this file should be removed
| """ | ||
|
|
||
| # Rule 2: Post-processing | ||
| rule postprocess_dumux: |
There was a problem hiding this comment.
If you use anything in the postprocessing that is not in the environment_benchmarks.yml, this rule needs a different environment. Otherwise it's fine.
| apptainer-version: 1.4.5 | ||
|
|
||
| - name: Update environment | ||
| run: mamba env update -n rc-dumux -f $GITHUB_WORKSPACE/benchmarks/rotating-cylinders/environment_dumux.yaml |
There was a problem hiding this comment.
here you should activate the environment_benchmarks.yml. If you think that we need anything else in this environment, we can think about adding it instead of each tool having their own environment for snakemake
Related to #48
This pull request adds the complete DuMux rotating-cylinders benchmark.
snakemake_results.Once this is validated, we will proceed to parameterize most of the remaining input parameters.