1
1
from pathlib import Path
2
2
3
- files = list (Path ("." ).rglob ("parameters_*.json" ))
3
+ files = list (Path ("." ).glob ("parameters_*.json" ))
4
4
5
5
# extract the configuration from the parameter files
6
6
# by reading in the json files and extracting the "configuration" value
@@ -25,6 +25,8 @@ def get_configuration(file):
25
25
# configurations: {Path("parameters_1.json"): "1", ...}
26
26
# Reverse mapping for easy lookup by configuration name
27
27
configurations = {file : get_configuration (file ) for file in files if file .is_file ()}
28
+ # for testing only use the first two entries
29
+ # configurations = dict(list(configurations.items())[:2])
28
30
configuration_to_parameter_file = {v : str (k ) for k , v in configurations .items ()}
29
31
30
32
rule all :
@@ -75,17 +77,24 @@ rule summary:
75
77
from pathlib import Path
76
78
77
79
all_summaries = []
78
-
80
+ print ( "configurations:" , configurations . values ())
79
81
with h5py .File (output .summary_h5 , "w" ) as h5f :
80
82
for idx , config in enumerate (configurations .values ()):
83
+ print (f"loop over config: { config } " )
81
84
mesh_path = input .mesh [idx ]
82
85
mesh_dataset_name = Path (mesh_path ).name
83
86
with open (mesh_path , "rb" ) as mesh_file :
84
87
mesh_data = mesh_file .read ()
85
- h5f .create_dataset (f"{ config } /mesh" , data = mesh_data )
88
+ mesh_ds_name = f"{ config } /mesh"
89
+ if mesh_ds_name in h5f :
90
+ raise RuntimeError (f"Dataset already exists: { mesh_ds_name } " )
91
+ h5f .create_dataset (mesh_ds_name , data = mesh_data )
86
92
with h5py .File (input .solution_field_data [idx ], "r" ) as src_h5f :
87
93
for name , dataset in src_h5f .items ():
88
- h5f .create_dataset (f"{ config } /{ name } " , data = dataset [()])
94
+ ds_name = f"{ config } /{ name } "
95
+ if ds_name in h5f :
96
+ raise RuntimeError (f"Dataset already exists: { ds_name } " )
97
+ h5f .create_dataset (ds_name , data = dataset [()])
89
98
for idx , config in enumerate (configurations .values ()):
90
99
summary = {}
91
100
summary ["benchmark" ] = "linear-elastic-plate-with-hole"
0 commit comments