1
1
from pathlib import Path
2
+ from os .path import join
2
3
3
4
files = list (Path ("." ).glob ("parameters_*.json" ))
4
5
@@ -25,7 +26,7 @@ def get_configuration(file):
25
26
# configurations: {Path("parameters_1.json"): "1", ...}
26
27
configurations = {file : get_configuration (file ) for file in files if file .is_file ()}
27
28
28
- # Check for duplicate configuration values
29
+ # Check for duplicate configuration values (the configurations should be unique)
29
30
config_values = list (configurations .values ())
30
31
duplicates = set ([x for x in config_values if config_values .count (x ) > 1 ])
31
32
if duplicates :
@@ -35,21 +36,20 @@ if duplicates:
35
36
configuration_to_parameter_file = {v : str (k ) for k , v in configurations .items ()}
36
37
37
38
tools = ["fenics" ]
38
-
39
- result_dir = "snakemake_results/linear-elastic-plate-with-hole"
39
+ benchmark = "linear-elastic-plate-with-hole"
40
+ # results are stored in snakemake_results/linear-elastic-plate-with-hole/fenics
41
+ result_dir = join ("snakemake_results" , benchmark )
40
42
41
43
rule all :
42
44
input :
43
45
expand (f"{ result_dir } /{{tool}}/summary.json" , tool = tools ),
44
46
45
-
46
-
47
-
48
47
rule create_mesh :
49
48
input :
50
49
script = "create_mesh.py" ,
51
50
# the parameters file for the current configuration, this has to be a lambda function since
52
- # it the wildcard (configuration) has to be evaluated
51
+ # the wildcard (configuration) has to be evaluated (the dictionary)
52
+ # otherwise, you could just write configuration_to_parameter_file(configuration)
53
53
parameters = lambda wildcards : configuration_to_parameter_file [wildcards .configuration ],
54
54
output :
55
55
mesh = f"{ result_dir } /mesh/mesh_{{configuration}}.msh" ,
@@ -76,6 +76,8 @@ rule run_simulation:
76
76
77
77
rule summary :
78
78
input :
79
+ # the summary is performed for all configurations saved into a single file
80
+ # (snakemake_results/linear-elastic-plate-with-hole/fenics/summary.json)
79
81
parameters = expand ("{param}" , param = [configuration_to_parameter_file [c ] for c in configurations .values ()]),
80
82
mesh = expand (f"{ result_dir } /mesh/mesh_{{configuration}}.msh" , configuration = configurations .values ()),
81
83
metrics = lambda wildcards : expand (
@@ -96,7 +98,7 @@ rule summary:
96
98
all_summaries = []
97
99
for idx , config in enumerate (configurations .values ()):
98
100
summary = {}
99
- summary ["benchmark" ] = "linear-elastic-plate-with-hole"
101
+ summary ["benchmark" ] = benchmark
100
102
with open (input .parameters [idx ], "r" ) as param_file :
101
103
summary ["parameters" ] = json .load (param_file )
102
104
summary ["mesh" ] = f"{ config } /mesh"
0 commit comments