Update BubbleML_2.py
Browse files- BubbleML_2.py +95 -61
BubbleML_2.py
CHANGED
|
@@ -1,98 +1,132 @@
|
|
|
|
|
|
|
|
| 1 |
import os
|
| 2 |
-
import h5py
|
| 3 |
import json
|
|
|
|
| 4 |
import numpy as np
|
|
|
|
| 5 |
import datasets
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
-
class BubbleMLConfig(
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
self
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
self.test_files_dict = test_files_dict
|
| 14 |
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
BUILDER_CONFIGS = [
|
| 18 |
BubbleMLConfig(
|
| 19 |
name="single-bubble",
|
| 20 |
-
description="
|
| 21 |
-
subset_dirs=[
|
|
|
|
|
|
|
|
|
|
| 22 |
train_files_dict={
|
| 23 |
"SingleBubble-Saturated-FC72-2D": [
|
| 24 |
-
"Twall_90.hdf5",
|
| 25 |
-
"Twall_96.hdf5",
|
| 26 |
],
|
| 27 |
"SingleBubble-Saturated-R515B-2D": [
|
| 28 |
-
"Twall_13.hdf5",
|
| 29 |
-
"Twall_19.hdf5",
|
| 30 |
],
|
| 31 |
},
|
| 32 |
test_files_dict={
|
| 33 |
-
"SingleBubble-Saturated-FC72-2D": ["Twall_87.hdf5",
|
| 34 |
-
"SingleBubble-Saturated-R515B-2D": ["Twall_10.hdf5",
|
| 35 |
-
}
|
| 36 |
-
)
|
| 37 |
]
|
|
|
|
| 38 |
|
| 39 |
-
def _info(self):
|
| 40 |
-
return
|
| 41 |
-
description=
|
| 42 |
-
features=
|
| 43 |
-
"input":
|
| 44 |
-
"output":
|
| 45 |
-
"fluid_params":
|
|
|
|
| 46 |
}),
|
| 47 |
supervised_keys=None,
|
|
|
|
|
|
|
| 48 |
)
|
| 49 |
|
| 50 |
-
def _split_generators(self, dl_manager):
|
| 51 |
-
|
| 52 |
-
base_dir = dl_manager.
|
|
|
|
| 53 |
|
| 54 |
-
def
|
| 55 |
-
|
| 56 |
-
for
|
| 57 |
-
for
|
| 58 |
-
|
| 59 |
-
return
|
| 60 |
-
|
| 61 |
-
train_files = resolve_paths(config.train_files_dict)
|
| 62 |
-
test_files = resolve_paths(config.test_files_dict)
|
| 63 |
|
| 64 |
return [
|
| 65 |
-
datasets.SplitGenerator(
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 67 |
]
|
| 68 |
|
| 69 |
def _generate_examples(self, files):
|
| 70 |
-
for idx,
|
| 71 |
-
with h5py.File(
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
params = json.load(jf)
|
| 80 |
fluid_params = [
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
params["rhogas"],
|
| 85 |
-
params["thcogas"],
|
| 86 |
-
params["stefan"],
|
| 87 |
-
params["prandtl"],
|
| 88 |
-
params["heater"]["nucWaitTime"],
|
| 89 |
-
params["heater"]["wallTemp"],
|
| 90 |
]
|
| 91 |
else:
|
| 92 |
fluid_params = []
|
| 93 |
|
| 94 |
yield idx, {
|
| 95 |
-
"input":
|
| 96 |
-
"output":
|
| 97 |
-
"fluid_params": fluid_params
|
|
|
|
| 98 |
}
|
|
|
|
| 1 |
+
# BubbleML_2.py
|
| 2 |
+
|
| 3 |
import os
|
|
|
|
| 4 |
import json
|
| 5 |
+
import h5py
|
| 6 |
import numpy as np
|
| 7 |
+
|
| 8 |
import datasets
|
| 9 |
+
from datasets import (
|
| 10 |
+
BuilderConfig,
|
| 11 |
+
GeneratorBasedBuilder,
|
| 12 |
+
DatasetInfo,
|
| 13 |
+
Features,
|
| 14 |
+
Array3D,
|
| 15 |
+
Sequence,
|
| 16 |
+
Value,
|
| 17 |
+
Split,
|
| 18 |
+
Version,
|
| 19 |
+
)
|
| 20 |
|
| 21 |
+
_CITATION = "" # optional
|
| 22 |
+
_DESCRIPTION = """
|
| 23 |
+
BubbleML: high-fidelity single-bubble boiling simulations (FC72 & R515B).
|
| 24 |
+
Pre-defined train/test splits across two directories.
|
| 25 |
+
"""
|
| 26 |
|
| 27 |
+
class BubbleMLConfig(BuilderConfig):
|
| 28 |
+
"""BuilderConfig for BubbleML_2."""
|
| 29 |
+
def __init__(
|
| 30 |
+
self,
|
| 31 |
+
subset_dirs,
|
| 32 |
+
train_files_dict,
|
| 33 |
+
test_files_dict,
|
| 34 |
+
version: Version = Version("1.0.0"),
|
| 35 |
+
**kwargs,
|
| 36 |
+
):
|
| 37 |
+
super().__init__(name=kwargs.pop("name"), version=version, description=kwargs.pop("description"), **kwargs)
|
| 38 |
+
self.subset_dirs = subset_dirs
|
| 39 |
+
self.train_files_dict = train_files_dict
|
| 40 |
self.test_files_dict = test_files_dict
|
| 41 |
|
| 42 |
+
class BubbleMLDataset(GeneratorBasedBuilder):
|
| 43 |
+
"""BubbleML_2: combined single-bubble dataset."""
|
| 44 |
+
|
| 45 |
+
BUILDER_CONFIG_CLASS = BubbleMLConfig
|
| 46 |
BUILDER_CONFIGS = [
|
| 47 |
BubbleMLConfig(
|
| 48 |
name="single-bubble",
|
| 49 |
+
description="Single-bubble (FC72 & R515B) train/test split",
|
| 50 |
+
subset_dirs=[
|
| 51 |
+
"SingleBubble-Saturated-FC72-2D",
|
| 52 |
+
"SingleBubble-Saturated-R515B-2D",
|
| 53 |
+
],
|
| 54 |
train_files_dict={
|
| 55 |
"SingleBubble-Saturated-FC72-2D": [
|
| 56 |
+
"Twall_90.hdf5","Twall_91.hdf5","Twall_92.hdf5","Twall_94.hdf5",
|
| 57 |
+
"Twall_96.hdf5","Twall_98.hdf5","Twall_99.hdf5","Twall_100.hdf5",
|
| 58 |
],
|
| 59 |
"SingleBubble-Saturated-R515B-2D": [
|
| 60 |
+
"Twall_13.hdf5","Twall_14.hdf5","Twall_15.hdf5","Twall_17.hdf5",
|
| 61 |
+
"Twall_19.hdf5","Twall_21.hdf5","Twall_22.hdf5","Twall_23.hdf5",
|
| 62 |
],
|
| 63 |
},
|
| 64 |
test_files_dict={
|
| 65 |
+
"SingleBubble-Saturated-FC72-2D": ["Twall_87.hdf5","Twall_95.hdf5","Twall_103.hdf5"],
|
| 66 |
+
"SingleBubble-Saturated-R515B-2D": ["Twall_10.hdf5","Twall_18.hdf5","Twall_26.hdf5"],
|
| 67 |
+
},
|
| 68 |
+
),
|
| 69 |
]
|
| 70 |
+
DEFAULT_CONFIG_NAME = "single-bubble"
|
| 71 |
|
| 72 |
+
def _info(self) -> DatasetInfo:
|
| 73 |
+
return DatasetInfo(
|
| 74 |
+
description=_DESCRIPTION,
|
| 75 |
+
features=Features({
|
| 76 |
+
"input": Array3D(shape=(5, 4, None, None), dtype="float32"),
|
| 77 |
+
"output": Array3D(shape=(5, 4, None, None), dtype="float32"),
|
| 78 |
+
"fluid_params": Sequence(Value("float32")),
|
| 79 |
+
"filename": Value("string"),
|
| 80 |
}),
|
| 81 |
supervised_keys=None,
|
| 82 |
+
homepage="https://huggingface.co/datasets/hpcforge/BubbleML_2",
|
| 83 |
+
citation=_CITATION,
|
| 84 |
)
|
| 85 |
|
| 86 |
+
def _split_generators(self, dl_manager: datasets.DownloadManager):
|
| 87 |
+
# data already lives in the repo
|
| 88 |
+
base_dir = dl_manager.extract("./")
|
| 89 |
+
cfg = self.config
|
| 90 |
|
| 91 |
+
def _resolve(files_dict):
|
| 92 |
+
paths = []
|
| 93 |
+
for d, files in files_dict.items():
|
| 94 |
+
for fname in files:
|
| 95 |
+
paths.append(os.path.join(base_dir, d, fname))
|
| 96 |
+
return paths
|
|
|
|
|
|
|
|
|
|
| 97 |
|
| 98 |
return [
|
| 99 |
+
datasets.SplitGenerator(
|
| 100 |
+
name=Split.TRAIN,
|
| 101 |
+
gen_kwargs={"files": _resolve(cfg.train_files_dict)},
|
| 102 |
+
),
|
| 103 |
+
datasets.SplitGenerator(
|
| 104 |
+
name=Split.TEST,
|
| 105 |
+
gen_kwargs={"files": _resolve(cfg.test_files_dict)},
|
| 106 |
+
),
|
| 107 |
]
|
| 108 |
|
| 109 |
def _generate_examples(self, files):
|
| 110 |
+
for idx, path in enumerate(files):
|
| 111 |
+
with h5py.File(path, "r") as h5f:
|
| 112 |
+
inp = np.stack([h5f[k][:5] for k in ["dfun","temperature","velx","vely"]])
|
| 113 |
+
out = np.stack([h5f[k][5:10] for k in ["dfun","temperature","velx","vely"]])
|
| 114 |
+
# metadata
|
| 115 |
+
meta_path = path.replace(".hdf5", ".json")
|
| 116 |
+
if os.path.exists(meta_path):
|
| 117 |
+
with open(meta_path) as jf:
|
| 118 |
+
p = json.load(jf)
|
|
|
|
| 119 |
fluid_params = [
|
| 120 |
+
p["inv_reynolds"], p["cpgas"], p["mugas"], p["rhogas"],
|
| 121 |
+
p["thcogas"], p["stefan"], p["prandtl"],
|
| 122 |
+
p["heater"]["nucWaitTime"], p["heater"]["wallTemp"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 123 |
]
|
| 124 |
else:
|
| 125 |
fluid_params = []
|
| 126 |
|
| 127 |
yield idx, {
|
| 128 |
+
"input": inp.astype(np.float32),
|
| 129 |
+
"output": out.astype(np.float32),
|
| 130 |
+
"fluid_params": fluid_params,
|
| 131 |
+
"filename": os.path.basename(path),
|
| 132 |
}
|