Skip to content

Commit 9682b20

Browse files
author
dtyagi
committed
removed nextflow scripts, template for tool workflow generation in txt format
1 parent c45d1bb commit 9682b20

File tree

11 files changed

+67
-415
lines changed

11 files changed

+67
-415
lines changed

.github/workflows/run-benchmark.yml

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ jobs:
4848
shell: bash -l {0}
4949
run: |
5050
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
51+
python simulation_tool_snakefile_generator.py --benchmark_name linear-elastic-plate-with-hole --tool fenics --simulation_script run_fenics_simulation.py --environment_file environment_simulation.yml
5252
5353
- name: run_linear-elastic-plate-with-hole-benchmarks_snakemake
5454
shell: bash -l {0}
@@ -67,13 +67,6 @@ jobs:
6767
--report-metadata4ing-paramscript ../common/parameter_extractor.py \
6868
--report-metadata4ing-filename snakemake_provenance_kratos
6969
unzip snakemake_provenance_kratos -d snakemake_provenance_kratos
70-
71-
- name: run_linear-elastic-plate-with-hole-benchmarks_nextflow
72-
shell: bash -l {0}
73-
run: |
74-
cd $GITHUB_WORKSPACE/benchmarks/linear-elastic-plate-with-hole/
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]
7770
7871
- name: Archive Linear Elastic plate with a hole benchmark data for snakemake fenics
7972
uses: actions/upload-artifact@v4
@@ -89,13 +82,6 @@ jobs:
8982
path: |
9083
benchmarks/linear-elastic-plate-with-hole/snakemake_provenance_kratos/
9184
92-
- name: Archive Linear Elastic plate with a hole benchmark data for nextflow fenics
93-
uses: actions/upload-artifact@v4
94-
with:
95-
name: nextflow_results_linear-elastic-plate-with-hole
96-
path: |
97-
benchmarks/linear-elastic-plate-with-hole/nextflow_results/
98-
9985
process-artifacts:
10086
runs-on: ubuntu-latest
10187
needs: tests
@@ -107,13 +93,13 @@ jobs:
10793
uses: actions/download-artifact@v4
10894
with:
10995
name: snakemake_fenics_result_linear-elastic-plate-with-hole
110-
path: ./snakemake_provenance
96+
path: ./snakemake_fenics_provenance
11197

11298
- name: Download snakemake kratos artifact
11399
uses: actions/download-artifact@v4
114100
with:
115101
name: snakemake_kratos_result_linear-elastic-plate-with-hole
116-
path: ./snakemake_provenance
102+
path: ./snakemake_kratos_provenance
117103

118104
- name: Setup Mambaforge with postprocessing env
119105
uses: conda-incubator/setup-miniconda@v3
@@ -126,7 +112,7 @@ jobs:
126112
- name: Run plotting script
127113
shell: bash -l {0}
128114
run: |
129-
python benchmarks/linear-elastic-plate-with-hole/plot_metrics.py ./snakemake_provenance
115+
python benchmarks/linear-elastic-plate-with-hole/plot_metrics.py ./snakemake_fenics_provenance ./snakemake_kratos_provenance
130116
131117
- name: Upload PDF plot as artifact
132118
uses: actions/upload-artifact@v4

benchmarks/common/nextflow.config

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

benchmarks/common/simulation_tool_snakefile_generator.py

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
from pathlib import Path
1212

1313

14-
def generate_snakefile(tool_name: str, environment_file: str, simulation_script: str, output_path: str = None):
14+
def generate_snakefile(benchmark_name: str, tool_name: str, environment_file: str, simulation_script: str, output_path: str = None):
1515
"""
1616
Generate a Snakefile for a simulation tool.
1717
@@ -22,40 +22,23 @@ def generate_snakefile(tool_name: str, environment_file: str, simulation_script:
2222
output_path: Optional path where to save the Snakefile. If None, saves to {tool_name}/Snakefile
2323
"""
2424

25-
# Template for the Snakefile
25+
# Load template from external file
26+
template_path = Path(__file__).parent / "snakefile_template.txt"
27+
with open(template_path, 'r') as f:
28+
snakefile_template = f.read()
2629

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-
'''
30+
# Replace placeholders with actual values
31+
snakefile_content = snakefile_template.replace("{TOOL_NAME}", tool_name) \
32+
.replace("{SIMULATION_SCRIPT}", simulation_script) \
33+
.replace("{ENVIRONMENT_FILE}", environment_file)
5134

5235
# Determine output path
5336
if output_path is None:
54-
output_path = f"../linear-elastic-plate-with-hole/{tool_name}/Snakefile"
37+
output_path = f"../{benchmark_name}/{tool_name}/Snakefile"
5538

5639
# Write the Snakefile
5740
with open(output_path, 'w') as f:
58-
f.write(snakefile_template)
41+
f.write(snakefile_content)
5942

6043
print(f"Snakefile generated successfully: {output_path}")
6144

@@ -78,7 +61,13 @@ def main():
7861
7962
"""
8063
)
81-
64+
parser.add_argument(
65+
'--benchmark_name',
66+
type=str,
67+
required=True,
68+
help='Name of the benchmark (same as the benchmark directory name)'
69+
)
70+
8271
parser.add_argument(
8372
'--tool',
8473
type=str,
@@ -103,6 +92,7 @@ def main():
10392
args = parser.parse_args()
10493

10594
generate_snakefile(
95+
benchmark_name=args.benchmark_name,
10696
tool_name=args.tool,
10797
environment_file=args.environment_file,
10898
simulation_script=args.simulation_script
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import json
2+
import os
3+
4+
tool = "{TOOL_NAME}"
5+
result_dir = "snakemake_results/" + config["benchmark"]
6+
configuration_to_parameter_file = config["configuration_to_parameter_file"]
7+
configurations = config["configurations"]
8+
9+
10+
rule run_{TOOL_NAME}_simulation:
11+
input:
12+
script = f"{tool}/{SIMULATION_SCRIPT}",
13+
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
14+
mesh = f"{result_dir}/{tool}/mesh/mesh_{{configuration}}.msh",
15+
output:
16+
zip = f"{result_dir}/{tool}/solution_field_data_{{configuration}}.zip",
17+
metrics = f"{result_dir}/{tool}/solution_metrics_{{configuration}}.json",
18+
conda:
19+
"{ENVIRONMENT_FILE}",
20+
shell:
21+
"""
22+
python3 {input.script} --input_parameter_file {input.parameters} --input_mesh_file {input.mesh} --output_solution_file_zip {output.zip} --output_metrics_file {output.metrics}
23+
"""

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ benchmark_uri = config["benchmark_uri"]
1111

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

1616
rule create_mesh:
1717
input:
@@ -21,20 +21,18 @@ rule create_mesh:
2121
# otherwise, you could just write configuration_to_parameter_file(configuration)
2222
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
2323
output:
24-
mesh = f"{result_dir}/mesh/mesh_{{configuration}}.msh",
24+
mesh = f"{result_dir}/{tool}/mesh/mesh_{{configuration}}.msh",
2525
conda: "environment_mesh.yml"
2626
shell:
2727
"""
2828
python3 {input.script} --input_parameter_file {input.parameters} --output_mesh_file {output.mesh}
2929
"""
3030

3131
# Include tool-specific rules
32-
# The should have at least the mesh file and the parameters as input
32+
# They should have at least the mesh file and the parameters as input
3333
# and output for each configuration a
3434
# solution_metrics_{configuration}.json and
35-
# and solution_field_data_{configuration}.zip whee all the visualization files are stored
36-
# (e.g. vtk)
37-
#for tool in tools:
35+
# and solution_field_data_{configuration}.zip where all the visualization files are stored (e.g. vtk)
3836
include: f"{tool}/Snakefile"
3937

4038

@@ -44,7 +42,7 @@ rule summary:
4442
# (snakemake_results/linear-elastic-plate-with-hole/fenics/summary.json)
4543
script = "../common/summarize_results.py",
4644
parameters = expand("{param}", param=[configuration_to_parameter_file[c] for c in configurations]),
47-
mesh = expand(f"{result_dir}/mesh/mesh_{{configuration}}.msh", configuration=configurations),
45+
mesh = expand(f"{result_dir}/{tool}/mesh/mesh_{{configuration}}.msh", configuration=configurations),
4846
metrics = lambda wildcards: expand(
4947
f"{result_dir}/{{tool}}/solution_metrics_{{configuration}}.json",
5048
tool=[wildcards.tool], configuration=configurations

benchmarks/linear-elastic-plate-with-hole/fenics/fenics.nf

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

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ kratos_material_template = f"{tool}/StructuralMaterials_template.json"
1212
rule mesh_to_mdpa:
1313
input:
1414
parameters = lambda wildcards: configuration_to_parameter_file[wildcards.configuration],
15-
mesh = f"{result_dir}/mesh/mesh_{{configuration}}.msh",
15+
mesh = f"{result_dir}/{tool}/mesh/mesh_{{configuration}}.msh",
1616
script = f"{tool}/msh_to_mdpa.py",
1717
output:
1818
mdpa = f"{result_dir}/{tool}/mesh_{{configuration}}.mdpa",

0 commit comments

Comments
 (0)