Commit bb0b0d3
committed
feat(snapshot v1.1, phase 2): mesh + meshvar bulk via #146 + bit-exact roundtrip
Builds on phase 1's metadata wrapper to actually carry mesh + mesh-
variable state to disk and read it back. Delegates the heavy lifting
to #146's `Mesh.write_checkpoint` / `MeshVariable.read_checkpoint`
PETSc-DMPlex primitives — phase 2's job is layout, dispatch, and
tying the wrapper to the bulk data via a simple convention.
Layout (final v1.1 shape):
/path/to/run.snap.h5 wrapper (h5py-inspectable)
/path/to/run.snap.bulk/ companion directory (one per snap)
{mesh_safe}.mesh.00000.h5
{mesh_safe}.{var_clean}.00000.h5
Wrapper carries /meshes/{mesh_safe}/ with @name, @mesh_file, and
/meshes/{mesh_safe}/variables/{var_safe}/ with @name, @components,
@degree, @continuous, @external_file. The bulk-dir path is derived
from the wrapper path by convention (`.h5` → `.bulk`), so no
external_file attr is needed for the standard placement. Move them
together; a clear FileNotFoundError fires if bulk is missing on read.
Phase 1 layout refactor folded in:
- /mesh (singular) → /meshes (plural) — supports multi-mesh natively.
- /variables removed from the top level — now nests under each mesh
as /meshes/{name}/variables/{var}, matching the in-memory
snapshot's mesh→vars structure.
New API:
- `write_snapshot(model, path)` — writes wrapper + bulk; covers
every registered mesh and every allocated meshvar on each mesh.
Lazy-allocated vars (_gvec is None) are skipped — same rule as the
in-memory path.
- `read_snapshot(model, path)` — loads var DOFs back into already-
registered meshes by name. Mesh / variable mismatch raises a
clear ValueError (mesh-rebuild on read is v1.2 scope).
- `write_snapshot_skeleton` / `read_snapshot_metadata` /
`inspect_snapshot` stay as phase-1 metadata-only entry points.
Branch hygiene: merged origin/development (which now has #146) into
this branch so the new code can actually call read_checkpoint. The
merge was clean — #146 and the snapshot toolkit only overlap at
different methods in `discretisation_mesh.py`, as the earlier
analysis predicted. PR target will be development once #195/#196
land; the diff stays clean because the merged dev commits are
already there.
Tests (12 total, 5 new in phase 2, tier_a level_1):
- write produces wrapper + bulk-dir with the expected file pattern
- wrapper populated with the per-mesh + per-var metadata that makes
inspectability self-sufficient
- bit-exact write→scribble→read roundtrip on a 2D mesh with one
scalar + one vector variable (np.array_equal, zero tolerance)
- missing bulk-dir → clear FileNotFoundError
- mismatched mesh on read → clear ValueError (not an obscure h5py
trace)
Regression: 64 tests pass (24 snapshot + 9 tracker + 12 disk-format
+ 19 core/regression).
Phase 3 next: swarms (with the @external_file freedom kept open for
bulky swarms) + /python_state for DDt + ModelTracker via dataclass-
to-HDF5-attrs serialisation.
Underworld development team with AI support from Claude Code
(https://claude.com/claude-code)1 parent 66a2d74 commit bb0b0d3
3 files changed
Lines changed: 347 additions & 8 deletions
File tree
- src/underworld3/checkpoint
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
30 | 30 | | |
31 | 31 | | |
32 | 32 | | |
| 33 | + | |
33 | 34 | | |
| 35 | + | |
34 | 36 | | |
35 | 37 | | |
36 | 38 | | |
| |||
48 | 50 | | |
49 | 51 | | |
50 | 52 | | |
| 53 | + | |
51 | 54 | | |
| 55 | + | |
52 | 56 | | |
53 | 57 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
36 | 36 | | |
37 | 37 | | |
38 | 38 | | |
| 39 | + | |
39 | 40 | | |
40 | 41 | | |
41 | 42 | | |
| |||
46 | 47 | | |
47 | 48 | | |
48 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
49 | 53 | | |
50 | | - | |
51 | | - | |
| 54 | + | |
52 | 55 | | |
53 | 56 | | |
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
57 | | - | |
58 | | - | |
| 60 | + | |
59 | 61 | | |
60 | 62 | | |
61 | 63 | | |
| |||
180 | 182 | | |
181 | 183 | | |
182 | 184 | | |
183 | | - | |
184 | | - | |
| 185 | + | |
185 | 186 | | |
186 | 187 | | |
187 | 188 | | |
| |||
237 | 238 | | |
238 | 239 | | |
239 | 240 | | |
| 241 | + | |
| 242 | + | |
| 243 | + | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
| 249 | + | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
| 260 | + | |
| 261 | + | |
| 262 | + | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
| 274 | + | |
| 275 | + | |
| 276 | + | |
| 277 | + | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
| 332 | + | |
| 333 | + | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
| 342 | + | |
| 343 | + | |
| 344 | + | |
| 345 | + | |
| 346 | + | |
| 347 | + | |
| 348 | + | |
| 349 | + | |
| 350 | + | |
| 351 | + | |
| 352 | + | |
| 353 | + | |
| 354 | + | |
| 355 | + | |
| 356 | + | |
| 357 | + | |
| 358 | + | |
| 359 | + | |
| 360 | + | |
| 361 | + | |
| 362 | + | |
| 363 | + | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
| 368 | + | |
| 369 | + | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
| 374 | + | |
| 375 | + | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
| 392 | + | |
| 393 | + | |
| 394 | + | |
| 395 | + | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
| 401 | + | |
| 402 | + | |
| 403 | + | |
| 404 | + | |
| 405 | + | |
| 406 | + | |
| 407 | + | |
| 408 | + | |
| 409 | + | |
| 410 | + | |
| 411 | + | |
| 412 | + | |
| 413 | + | |
| 414 | + | |
| 415 | + | |
| 416 | + | |
| 417 | + | |
| 418 | + | |
| 419 | + | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
240 | 423 | | |
241 | 424 | | |
242 | 425 | | |
| |||
0 commit comments