Repository navigation
Commit 6d237d7
feat: adopt #652 multi-datastore schema + ForecastBatch return shape
Pre-emptively land the public API shape proposed in #652
on top of the boundary-datastore work in #635, so the model-side
adapter (Joel's follow-up) doesn't have to break the schema again
later.
Config schema (neural_lam/config.py):
- Replace `datastore` + `datastore_boundary` top-level keys with a
single `datastores: Dict[str, DatastoreSelection]` mapping. The dict
key becomes the canonical source name used throughout the pipeline
(ForecastBatch field keys, weight / clamping disambiguation, etc).
- DatastoreSelection grows optional `inputs:` and `outputs:` per-
category variable include-lists, with `None` per-category values
meaning "all variables in that category". `outputs:` declares which
datastore is the interior (prognostic source); omitted means input-
only.
- Validate at config load: raise InvalidConfigError when two
datastores declare the same variable as an output, pointing the
user at mdp's `dim_mapping.name_format` (new builds) or
`xr.Dataset.assign_coords` on the existing zarr's small
`{category}_feature` coord (milliseconds regardless of zarr size).
- `load_config_and_datastore` returns `(config, Dict[str, BaseDatastore])`
- the full multi-source mapping - rather than the legacy
`(config, interior, boundary)` triple. No transitional adapter.
Dataset return shape (neural_lam/weather_dataset.py):
- New `ForecastBatch` NamedTuple with per-source dict fields
(`init_states`, `target_states`, `forcing`) plus a global
`target_times` tensor. PyTorch's default_collate recurses through
the NamedTuple and the dicts, stacking per-source tensors along a
new batch axis - no custom collate_fn required.
- `WeatherDataset.__init__` takes `(datastores, selections, ...)`
dicts directly. Internally it still resolves the single interior +
optional boundary pair for its slicing/windowing logic - that
internal multi-source rewrite is part of #652's model-side
follow-up. The PUBLIC return type is already shaped for the
multi-source case so the future change is additive on the producer
side.
- `WeatherDataModule` signature updated to match.
- `create_dataarray_from_tensor` refactored to expose a
`build_dataarray_from_tensor` staticmethod for callers (e.g.
`ForecasterModule._create_dataarray_from_tensor`) that have a
datastore but not a full dataset.
Production call site (neural_lam/train_model.py):
- Unpacks the new `(config, datastores)` return shape.
- Uses `_resolve_datastore_roles` to pick out the interior +
boundary for the legacy ForecasterModule constructor (which keeps
its single-datastore + boundary shape pending Joel's adapter).
- WeatherDataModule receives the full multi-source dicts.
Example YAMLs (tests/datastore_examples/):
- Single-source danra: top-level `datastores: {danra: ...}` wrapping.
- danra + era5 boundary: `datastores: {interior: ..., boundary: ...}`
with explicit `outputs: {state: }` on interior so the resolver
knows which one is the prognostic source.
Intentionally NOT in this PR (per #652 follow-up scope):
- Model-side adapter. `ForecasterModule.training_step` and friends
still unpack the legacy 5-tuple `(init_states, target_states,
forcing, boundary, target_times)`, which will fail at runtime when
Lightning hands them a `ForecastBatch`. Joel's follow-up replaces
those positional unpacks with `batch.init_states["interior"]`-style
per-source dict access.
- Test updates. Every test that builds a `WeatherDataset` or
`NeuralLAMConfig` with the old keyword signature will fail. They
need mechanical updates to the new dict shape (and the model-
exercising ones should stay skipped until the model adapter
lands).
- Variable include-lists honoured at runtime. The schema parses
`inputs:` / `outputs:` but `WeatherDataset` still fetches all
variables per category from each datastore. Filtering by the
declared subsets is a small follow-up that depends on whether
Joel's adapter wants to do it at dataset level or model level.
- Diagnostic outputs. The schema accepts `outputs.diagnostic: [...]`
but nothing concatenates them into the target tensor yet; same
story (small follow-up after the model adapter decides on the
prognostic/diagnostic split semantic).
Refs #635, refs #652.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>1 parent 78a4d52 commit 6d237d7
6 files changed
Lines changed: 399 additions & 171 deletions
File tree
- neural_lam
- models
- tests/datastore_examples/mdp
- danra_100m_winds
- era5_1000hPa_danra_100m_winds
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
| 4 | + | |
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
21 | | - | |
| 21 | + | |
| 22 | + | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
27 | 28 | | |
28 | 29 | | |
29 | | - | |
30 | | - | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
31 | 51 | | |
32 | 52 | | |
33 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
34 | 57 | | |
35 | 58 | | |
36 | 59 | | |
37 | 60 | | |
38 | 61 | | |
39 | | - | |
40 | | - | |
41 | 62 | | |
42 | 63 | | |
43 | 64 | | |
| |||
89 | 110 | | |
90 | 111 | | |
91 | 112 | | |
92 | | - | |
| 113 | + | |
93 | 114 | | |
94 | | - | |
95 | | - | |
| 115 | + | |
| 116 | + | |
96 | 117 | | |
97 | 118 | | |
98 | 119 | | |
| |||
112 | 133 | | |
113 | 134 | | |
114 | 135 | | |
115 | | - | |
116 | | - | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
117 | 142 | | |
118 | 143 | | |
119 | 144 | | |
120 | 145 | | |
121 | | - | |
122 | | - | |
| 146 | + | |
123 | 147 | | |
124 | 148 | | |
125 | 149 | | |
126 | 150 | | |
127 | 151 | | |
128 | 152 | | |
129 | | - | |
130 | | - | |
131 | | - | |
132 | | - | |
133 | | - | |
134 | | - | |
135 | | - | |
136 | | - | |
137 | | - | |
138 | | - | |
139 | | - | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
140 | 165 | | |
141 | 166 | | |
142 | 167 | | |
| |||
145 | 170 | | |
146 | 171 | | |
147 | 172 | | |
148 | | - | |
149 | | - | |
| 173 | + | |
| 174 | + | |
150 | 175 | | |
151 | 176 | | |
152 | 177 | | |
153 | 178 | | |
154 | 179 | | |
155 | 180 | | |
156 | 181 | | |
| 182 | + | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
157 | 219 | | |
158 | 220 | | |
159 | 221 | | |
160 | 222 | | |
161 | | - | |
162 | | - | |
| 223 | + | |
163 | 224 | | |
164 | | - | |
165 | | - | |
166 | | - | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
167 | 229 | | |
168 | 230 | | |
169 | 231 | | |
| |||
172 | 234 | | |
173 | 235 | | |
174 | 236 | | |
175 | | - | |
176 | | - | |
177 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
178 | 242 | | |
179 | 243 | | |
180 | 244 | | |
| |||
183 | 247 | | |
184 | 248 | | |
185 | 249 | | |
186 | | - | |
187 | | - | |
188 | | - | |
189 | | - | |
190 | | - | |
191 | | - | |
192 | | - | |
193 | 250 | | |
194 | | - | |
195 | | - | |
196 | | - | |
197 | | - | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
198 | 255 | | |
199 | | - | |
200 | | - | |
201 | | - | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
202 | 264 | | |
203 | 265 | | |
204 | | - | |
| 266 | + | |
| 267 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
243 | 243 | | |
244 | 244 | | |
245 | 245 | | |
246 | | - | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
247 | 251 | | |
248 | | - | |
249 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
250 | 257 | | |
251 | 258 | | |
252 | 259 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
391 | 391 | | |
392 | 392 | | |
393 | 393 | | |
394 | | - | |
395 | | - | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
396 | 406 | | |
397 | 407 | | |
398 | 408 | | |
| |||
408 | 418 | | |
409 | 419 | | |
410 | 420 | | |
411 | | - | |
| 421 | + | |
412 | 422 | | |
413 | | - | |
| 423 | + | |
| 424 | + | |
414 | 425 | | |
415 | 426 | | |
416 | 427 | | |
417 | 428 | | |
418 | 429 | | |
419 | 430 | | |
420 | | - | |
421 | 431 | | |
422 | 432 | | |
423 | 433 | | |
| |||
0 commit comments