Skip to content

Commit 2d9cd85

Browse files
committed
fix bug for file patterns
1 parent 8c217b8 commit 2d9cd85

File tree

1 file changed

+13
-4
lines changed
  • benchmarks/linear-elastic-plate-with-hole/FEniCS

1 file changed

+13
-4
lines changed

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from pathlib import Path
22

3-
files = list(Path(".").rglob("parameters_*.json"))
3+
files = list(Path(".").glob("parameters_*.json"))
44

55
# extract the configuration from the parameter files
66
# by reading in the json files and extracting the "configuration" value
@@ -25,6 +25,8 @@ def get_configuration(file):
2525
# configurations: {Path("parameters_1.json"): "1", ...}
2626
# Reverse mapping for easy lookup by configuration name
2727
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])
2830
configuration_to_parameter_file = {v: str(k) for k, v in configurations.items()}
2931

3032
rule all:
@@ -75,17 +77,24 @@ rule summary:
7577
from pathlib import Path
7678

7779
all_summaries = []
78-
80+
print("configurations:", configurations.values())
7981
with h5py.File(output.summary_h5, "w") as h5f:
8082
for idx, config in enumerate(configurations.values()):
83+
print(f"loop over config: {config}")
8184
mesh_path = input.mesh[idx]
8285
mesh_dataset_name = Path(mesh_path).name
8386
with open(mesh_path, "rb") as mesh_file:
8487
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)
8692
with h5py.File(input.solution_field_data[idx], "r") as src_h5f:
8793
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[()])
8998
for idx, config in enumerate(configurations.values()):
9099
summary = {}
91100
summary["benchmark"] = "linear-elastic-plate-with-hole"

0 commit comments

Comments
 (0)