Datasets:

Modalities:
Tabular
Text
Size:
< 1K
DOI:
License:
shakxy42 commited on
Commit
52dd7a4
·
verified ·
1 Parent(s): 3b8cda6

Update BubbleML_2.py

Browse files
Files changed (1) hide show
  1. BubbleML_2.py +88 -62
BubbleML_2.py CHANGED
@@ -11,7 +11,6 @@ from datasets import (
11
  GeneratorBasedBuilder,
12
  DatasetInfo,
13
  Features,
14
- Array3D,
15
  Sequence,
16
  Value,
17
  Split,
@@ -20,115 +19,142 @@ from datasets import (
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 = os.path.dirname(os.path.abspath(__file__))
89
-
90
- cfg = self.config
91
-
92
- def resolve(files_dict):
93
- paths = []
94
- for subdir, flist in files_dict.items():
95
- subdir_path = os.path.join(base_dir, subdir)
96
- for fname in flist:
97
- full = os.path.join(subdir_path, fname)
98
- if not os.path.isfile(full):
99
- raise FileNotFoundError(f"Could not find {full}")
100
- paths.append(full)
101
- return paths
102
 
103
- train_files = resolve(cfg.train_files_dict)
104
- test_files = resolve(cfg.test_files_dict)
 
 
 
 
 
 
105
 
106
  return [
107
- datasets.SplitGenerator(name=Split.TRAIN, gen_kwargs={"files": train_files}),
108
- datasets.SplitGenerator(name=Split.TEST, gen_kwargs={"files": test_files}),
 
 
 
 
109
  ]
110
 
111
  def _generate_examples(self, files):
 
112
  for idx, path in enumerate(files):
 
113
  with h5py.File(path, "r") as h5f:
114
- inp = np.stack([h5f[k][:5] for k in ["dfun","temperature","velx","vely"]])
115
- out = np.stack([h5f[k][5:10] for k in ["dfun","temperature","velx","vely"]])
116
- # metadata
 
117
  meta_path = path.replace(".hdf5", ".json")
118
- if os.path.exists(meta_path):
119
- with open(meta_path) as jf:
120
  p = json.load(jf)
121
  fluid_params = [
122
- p["inv_reynolds"], p["cpgas"], p["mugas"], p["rhogas"],
123
- p["thcogas"], p["stefan"], p["prandtl"],
124
- p["heater"]["nucWaitTime"], p["heater"]["wallTemp"]
 
 
 
 
 
 
125
  ]
126
  else:
127
  fluid_params = []
128
 
129
  yield idx, {
130
- "input": inp.astype(np.float32),
131
- "output": out.astype(np.float32),
132
  "fluid_params": fluid_params,
133
  "filename": os.path.basename(path),
134
  }
 
11
  GeneratorBasedBuilder,
12
  DatasetInfo,
13
  Features,
 
14
  Sequence,
15
  Value,
16
  Split,
 
19
 
20
  _CITATION = "" # optional
21
  _DESCRIPTION = """
22
+ BubbleML: high-fidelity boiling simulations for 3 Liquids- (FC72 & R515B & LN2)
23
+ and Flow Boiling Regimes.
24
+ Pre-defined train/test splits across all benchmarks.
25
  """
26
 
27
  class BubbleMLConfig(BuilderConfig):
28
  """BuilderConfig for BubbleML_2."""
29
  def __init__(
30
  self,
31
+ *,
32
+ name: str,
33
+ description: str,
34
+ data_files: dict,
35
+ data_dir: str = "",
36
  version: Version = Version("1.0.0"),
37
  **kwargs,
38
  ):
39
+ super().__init__(name=name, version=version, description=description, **kwargs)
40
+ self.data_files = data_files
41
+ self.data_dir = data_dir
 
42
 
43
  class BubbleMLDataset(GeneratorBasedBuilder):
44
  """BubbleML_2: combined single-bubble dataset."""
 
45
  BUILDER_CONFIG_CLASS = BubbleMLConfig
46
+ DEFAULT_CONFIG_NAME = "single-bubble"
47
  BUILDER_CONFIGS = [
48
  BubbleMLConfig(
49
  name="single-bubble",
50
  description="Single-bubble (FC72 & R515B) train/test split",
51
+ data_dir="", # repo root when loading remotely; overridden by --data_dir in CLI
52
+ data_files={
53
+ "train": [
54
+ # FC72 train
55
+ "SingleBubble-Saturated-FC72-2D/Twall_90.hdf5",
56
+ "SingleBubble-Saturated-FC72-2D/Twall_91.hdf5",
57
+ "SingleBubble-Saturated-FC72-2D/Twall_92.hdf5",
58
+ "SingleBubble-Saturated-FC72-2D/Twall_94.hdf5",
59
+ "SingleBubble-Saturated-FC72-2D/Twall_96.hdf5",
60
+ "SingleBubble-Saturated-FC72-2D/Twall_98.hdf5",
61
+ "SingleBubble-Saturated-FC72-2D/Twall_99.hdf5",
62
+ "SingleBubble-Saturated-FC72-2D/Twall_100.hdf5",
63
+ # R515B train
64
+ "SingleBubble-Saturated-R515B-2D/Twall_13.hdf5",
65
+ "SingleBubble-Saturated-R515B-2D/Twall_14.hdf5",
66
+ "SingleBubble-Saturated-R515B-2D/Twall_15.hdf5",
67
+ "SingleBubble-Saturated-R515B-2D/Twall_17.hdf5",
68
+ "SingleBubble-Saturated-R515B-2D/Twall_19.hdf5",
69
+ "SingleBubble-Saturated-R515B-2D/Twall_21.hdf5",
70
+ "SingleBubble-Saturated-R515B-2D/Twall_22.hdf5",
71
+ "SingleBubble-Saturated-R515B-2D/Twall_23.hdf5",
72
  ],
73
+ "test": [
74
+ # FC72 test
75
+ "SingleBubble-Saturated-FC72-2D/Twall_87.hdf5",
76
+ "SingleBubble-Saturated-FC72-2D/Twall_95.hdf5",
77
+ "SingleBubble-Saturated-FC72-2D/Twall_103.hdf5",
78
+ # R515B test
79
+ "SingleBubble-Saturated-R515B-2D/Twall_10.hdf5",
80
+ "SingleBubble-Saturated-R515B-2D/Twall_18.hdf5",
81
+ "SingleBubble-Saturated-R515B-2D/Twall_26.hdf5",
82
  ],
83
  },
 
 
 
 
84
  ),
85
  ]
 
86
 
87
  def _info(self) -> DatasetInfo:
88
+ # Nested Sequence to represent 4D arrays (time, channel, H, W) of floats
89
+ features = Features({
90
+ "input": Sequence(Sequence(Sequence(Sequence(Value("float32"))))),
91
+ "output": Sequence(Sequence(Sequence(Sequence(Value("float32"))))),
92
+ "fluid_params": Sequence(Value("float32")),
93
+ "filename": Value("string"),
94
+ })
95
  return DatasetInfo(
96
  description=_DESCRIPTION,
97
+ features=features,
 
 
 
 
 
98
  supervised_keys=None,
99
  homepage="https://huggingface.co/datasets/hpcforge/BubbleML_2",
100
  citation=_CITATION,
101
  )
102
 
103
  def _split_generators(self, dl_manager: datasets.DownloadManager):
104
+ base_dir = (
105
+ self.config.data_dir
106
+ if self.config.data_dir
107
+ else os.path.dirname(os.path.abspath(__file__))
108
+ )
 
 
 
 
 
 
 
 
 
 
109
 
110
+ def resolve(split_name: str):
111
+ out = []
112
+ for rel in self.config.data_files[split_name]:
113
+ full = os.path.join(base_dir, rel)
114
+ if not os.path.isfile(full):
115
+ raise FileNotFoundError(f"Expected data file at {full}, but not found.")
116
+ out.append(full)
117
+ return out
118
 
119
  return [
120
+ datasets.SplitGenerator(
121
+ name=Split.TRAIN, gen_kwargs={"files": resolve("train")}
122
+ ),
123
+ datasets.SplitGenerator(
124
+ name=Split.TEST, gen_kwargs={"files": resolve("test")}
125
+ ),
126
  ]
127
 
128
  def _generate_examples(self, files):
129
+ """Yield examples as dicts with input, output, fluid_params, filename."""
130
  for idx, path in enumerate(files):
131
+ # Load HDF5 arrays
132
  with h5py.File(path, "r") as h5f:
133
+ inp = np.stack([h5f[k][:5] for k in ["dfun", "temperature", "velx", "vely"]])
134
+ out = np.stack([h5f[k][5:10] for k in ["dfun", "temperature", "velx", "vely"]])
135
+
136
+ # Load metadata JSON
137
  meta_path = path.replace(".hdf5", ".json")
138
+ if os.path.isfile(meta_path):
139
+ with open(meta_path, "r") as jf:
140
  p = json.load(jf)
141
  fluid_params = [
142
+ p["inv_reynolds"],
143
+ p["cpgas"],
144
+ p["mugas"],
145
+ p["rhogas"],
146
+ p["thcogas"],
147
+ p.get("stefan", 0.0),
148
+ p["prandtl"],
149
+ p["heater"]["nucWaitTime"],
150
+ p["heater"].get("wallTemp", 0.0),
151
  ]
152
  else:
153
  fluid_params = []
154
 
155
  yield idx, {
156
+ "input": inp.astype(np.float32).tolist(),
157
+ "output": out.astype(np.float32).tolist(),
158
  "fluid_params": fluid_params,
159
  "filename": os.path.basename(path),
160
  }