Skip to content

Commit eef9765

Browse files
author
dtyagi
committed
one ro-crate per tool, automatic creation of snakefile for a tool workflow
1 parent 8a03d3b commit eef9765

File tree

10 files changed

+186
-149
lines changed

10 files changed

+186
-149
lines changed

.github/workflows/run-benchmark.yml

Lines changed: 38 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -44,31 +44,52 @@ jobs:
4444
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/
4545
python generate_config.py
4646
47+
- name: generate-snakemake-fenics-workflow
48+
shell: bash -l {0}
49+
run: |
50+
cd $GITHUB_WORKSPACE/benchmarks/common/
51+
python simulation_tool_snakefile_generator.py --tool fenics --simulation_script run_fenics_simulation.py --environment_file environment_simulation.yml
52+
4753
- name: run_linear-elastic-plate-with-hole-benchmarks_snakemake
4854
shell: bash -l {0}
4955
run: |
5056
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/
51-
snakemake --use-conda --force --cores 'all'
52-
snakemake --use-conda --force --cores all \
57+
snakemake --use-conda --force --cores 'all' --config tool="fenics"
58+
snakemake --use-conda --force --cores all --config tool="fenics" \
5359
--reporter metadata4ing \
5460
--report-metadata4ing-paramscript ../common/parameter_extractor.py \
55-
--report-metadata4ing-filename snakemake_provenance
56-
unzip snakemake_provenance -d snakemake_provenance
61+
--report-metadata4ing-filename snakemake_provenance_fenics
62+
unzip snakemake_provenance_fenics -d snakemake_provenance_fenics
63+
64+
snakemake --use-conda --force --cores 'all' --config tool="kratos"
65+
snakemake --use-conda --force --cores all --config tool="kratos" \
66+
--reporter metadata4ing \
67+
--report-metadata4ing-paramscript ../common/parameter_extractor.py \
68+
--report-metadata4ing-filename snakemake_provenance_kratos
69+
unzip snakemake_provenance_kratos -d snakemake_provenance_kratos
5770
5871
- name: run_linear-elastic-plate-with-hole-benchmarks_nextflow
5972
shell: bash -l {0}
6073
run: |
6174
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/
62-
nextflow run main.nf -params-file workflow_config.json -c ../common/nextflow.config -plugins [email protected]
75+
nextflow run main.nf -params-file workflow_config.json --tool="fenics" -c ../common/nextflow.config -plugins [email protected]
76+
nextflow run main.nf -params-file workflow_config.json --tool="kratos" -c ../common/nextflow.config -plugins [email protected]
77+
78+
- name: Archive Linear Elastic plate with a hole benchmark data for snakemake fenics
79+
uses: actions/upload-artifact@v4
80+
with:
81+
name: snakemake_fenics_result_linear-elastic-plate-with-hole
82+
path: |
83+
benchmarks/linear-elastic-plate-with-hole/snakemake_provenance_fenics/
6384
64-
- name: Archive Linear Elastic plate with a hole benchmark data for snakemake
85+
- name: Archive Linear Elastic plate with a hole benchmark data for snakemake kratos
6586
uses: actions/upload-artifact@v4
6687
with:
67-
name: snakemake_results_linear-elastic-plate-with-hole
88+
name: snakemake_kratos_result_linear-elastic-plate-with-hole
6889
path: |
69-
benchmarks/linear-elastic-plate-with-hole/snakemake_provenance/
90+
benchmarks/linear-elastic-plate-with-hole/snakemake_provenance_kratos/
7091
71-
- name: Archive Linear Elastic plate with a hole benchmark data for nextflow
92+
- name: Archive Linear Elastic plate with a hole benchmark data for nextflow fenics
7293
uses: actions/upload-artifact@v4
7394
with:
7495
name: nextflow_results_linear-elastic-plate-with-hole
@@ -82,10 +103,16 @@ jobs:
82103
- name: Checkout repo content
83104
uses: actions/checkout@v2
84105

85-
- name: Download artifact
106+
- name: Download snakemake fenics artifact
107+
uses: actions/download-artifact@v4
108+
with:
109+
name: snakemake_fenics_result_linear-elastic-plate-with-hole
110+
path: ./snakemake_provenance
111+
112+
- name: Download snakemake kratos artifact
86113
uses: actions/download-artifact@v4
87114
with:
88-
name: snakemake_results_linear-elastic-plate-with-hole
115+
name: snakemake_kratos_result_linear-elastic-plate-with-hole
89116
path: ./snakemake_provenance
90117

91118
- name: Setup Mambaforge with postprocessing env

.gitignore

Lines changed: 0 additions & 2 deletions
This file was deleted.

benchmarks/common/nextflow.config

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,24 @@ conda {
33
}
44

55
params.result_dir = "nextflow_results/${params.benchmark}"
6+
params.tool = "kratos" // default tool
67

78
prov {
89
formats {
910
dag {
10-
file = "${params.result_dir}/nf_prov_dag.html"
11+
file = "${params.result_dir}/${params.tool}/nf_prov_dag.html"
1112
overwrite = true
1213
}
1314
legacy {
14-
file = "${params.result_dir}/nf_prov_legacy.json"
15+
file = "${params.result_dir}/${params.tool}/nf_prov_legacy.json"
1516
overwrite = true
1617
}
1718
wrroc {
1819
agent {
1920
name = 'Firstname Lastname'
2021
orcid = 'https://orcid.org/0000-0000-0000-0000'
2122
}
22-
file = "${params.result_dir}/ro-crate-metadata.json"
23+
file = "${params.result_dir}/${params.tool}/ro-crate-metadata.json"
2324
license = 'https://spdx.org/licenses/MIT'
2425
overwrite = true
2526
}
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
#!/usr/bin/env python3
2+
"""
3+
Script to generate a Snakefile for simulation tools in the benchmark workflow.
4+
5+
This script creates a standardized Snakefile that follows the expected output format
6+
for integration with the main benchmark workflow.
7+
"""
8+
9+
import argparse
10+
import os
11+
from pathlib import Path
12+
13+
14+
def generate_snakefile(tool_name: str, environment_file: str, simulation_script: str, output_path: str = None):
15+
"""
16+
Generate a Snakefile for a simulation tool.
17+
18+
Args:
19+
tool_name: Name of the simulation tool (e.g., 'fenics', 'kratos')
20+
environment_file: Path to the conda environment YAML file (relative to tool directory)
21+
simulation_script: Path to the simulation Python script (relative to tool directory)
22+
output_path: Optional path where to save the Snakefile. If None, saves to {tool_name}/Snakefile
23+
"""
24+
25+
# Template for the Snakefile
26+
27+
snakefile_template = f'''import json
28+
import os
29+
30+
tool = "{tool_name}"
31+
result_dir = "snakemake_results/" + config["benchmark"]
32+
configuration_to_parameter_file = config["configuration_to_parameter_file"]
33+
configurations = config["configurations"]
34+
35+
36+
rule run_{tool_name}_simulation:
37+
input:
38+
script = "{{tool}}/{simulation_script}",
39+
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
40+
mesh = f"{{result_dir}}/mesh/mesh_{{{{configuration}}}}.msh",
41+
output:
42+
zip = f"{{result_dir}}/{{{{tool}}}}/solution_field_data_{{{{configuration}}}}.zip",
43+
metrics = f"{{result_dir}}/{{{{tool}}}}/solution_metrics_{{{{configuration}}}}.json",
44+
conda:
45+
"{environment_file}",
46+
shell:
47+
"""
48+
python3 {{input.script}} --input_parameter_file {{input.parameters}} --input_mesh_file {{input.mesh}} --output_solution_file_zip {{output.zip}} --output_metrics_file {{output.metrics}}
49+
"""
50+
'''
51+
52+
# Determine output path
53+
if output_path is None:
54+
output_path = f"../linear-elastic-plate-with-hole/{tool_name}/Snakefile"
55+
56+
# Write the Snakefile
57+
with open(output_path, 'w') as f:
58+
f.write(snakefile_template)
59+
60+
print(f"Snakefile generated successfully: {output_path}")
61+
62+
def main():
63+
parser = argparse.ArgumentParser(
64+
description="Generate a simulation-tool-specific Snakefile for running the simulation.",
65+
formatter_class=argparse.RawDescriptionHelpFormatter,
66+
epilog=
67+
"""
68+
!IMPORTANT!:The scripts to be stored inside the tool's sub-directory in the benchmark folder. E.g., benchmarks/linear-elastic-plate-with-hole/tool_name/
69+
70+
Execution example for fenics:
71+
python generate_tool_snakefile.py --tool fenics --env environment_simulation.yml --script run_fenics_simulation.py
72+
73+
The simulation script must accept these command-line arguments:
74+
--input_parameter_file: JSON file with simulation parameters
75+
--input_mesh_file: Input mesh file (.msh format)
76+
--output_solution_file_zip: Output ZIP file containing solution visualization files (VTK)
77+
--output_metrics_file: Output JSON file with computed metrics
78+
79+
"""
80+
)
81+
82+
parser.add_argument(
83+
'--tool',
84+
type=str,
85+
required=True,
86+
help='Name of the simulation tool (e.g., fenics, kratos, abaqus)'
87+
)
88+
89+
parser.add_argument(
90+
'--environment_file',
91+
type=str,
92+
required=True,
93+
help='Conda environment YAML file name'
94+
)
95+
96+
parser.add_argument(
97+
'--simulation_script',
98+
type=str,
99+
required=True,
100+
help='Simulation script name'
101+
)
102+
103+
args = parser.parse_args()
104+
105+
generate_snakefile(
106+
tool_name=args.tool,
107+
environment_file=args.environment_file,
108+
simulation_script=args.simulation_script
109+
)
110+
111+
if __name__ == "__main__":
112+
main()
113+
114+

benchmarks/linear-elastic-plate-with-hole/README.md

Lines changed: 0 additions & 59 deletions
This file was deleted.

benchmarks/linear-elastic-plate-with-hole/Snakefile

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ configfile: "workflow_config.json"
44
result_dir = "snakemake_results/" + config["benchmark"]
55
configuration_to_parameter_file = config["configuration_to_parameter_file"]
66
configurations = config["configurations"]
7-
tools = config["tools"]
7+
tool = config["tool"]
88
benchmark = config["benchmark"]
99
benchmark_uri = config["benchmark_uri"]
1010

1111

1212
rule all:
1313
input:
14-
expand(f"{result_dir}/{{tool}}/summary.json", tool=tools),
14+
expand(f"{result_dir}/{{tool}}/summary.json", tool=tool),
1515

1616
rule create_mesh:
1717
input:
@@ -34,8 +34,8 @@ rule create_mesh:
3434
# solution_metrics_{configuration}.json and
3535
# and solution_field_data_{configuration}.zip whee all the visualization files are stored
3636
# (e.g. vtk)
37-
for tool in tools:
38-
include: f"{tool}/Snakefile"
37+
#for tool in tools:
38+
include: f"{tool}/Snakefile"
3939

4040

4141
rule summary:
@@ -70,12 +70,6 @@ rule summary:
7070
"""
7171

7272
"""
73-
Steps to add a new simulation tool to the workflow:
74-
75-
1. Write the tool-specific workflow, scripts, environment file and store them in the benchmarks/linear-elastic-plate-with-hole/tool_name/.
76-
2. Add the tool name to "tools" workflow_config.json (generated here using generate_config.py)
77-
78-
------------------------------------------------------------------------------------------------------------------------
7973
"rule all" defines the final target of the workflow. Knowing the final target, the snakemake determines
8074
the dependency chain automatically.
8175

benchmarks/linear-elastic-plate-with-hole/fenics/Snakefile

Lines changed: 0 additions & 23 deletions
This file was deleted.

benchmarks/linear-elastic-plate-with-hole/fenics/environment_simulation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
- python=3.12
1111
- fenics-dolfinx=0.9.*
1212
- libadios2=2.10.1
13+
- mpich
1314
- petsc4py
1415
- pint
1516
- python-gmsh

benchmarks/linear-elastic-plate-with-hole/generate_config.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,13 @@ def get_configuration(file):
3939
# Reverse mapping for easy lookup by configuration name
4040
configuration_to_parameter_file = {v: str(k) for k, v in configurations.items()}
4141

42-
tools = ["fenics", "kratos"]
4342
benchmark = "linear-elastic-plate-with-hole"
4443
benchmark_uri = "https://portal.mardi4nfdi.de/wiki/Model:6775296"
4544

4645
# Template for workflow config
4746
workflow_config = {
4847
"configuration_to_parameter_file": configuration_to_parameter_file,
4948
"configurations": list(configurations.values()),
50-
"tools": tools,
5149
"benchmark": benchmark,
5250
"benchmark_uri": benchmark_uri
5351
}

0 commit comments

Comments
 (0)