From f28893c7c605bfd8d1020a50eabf58824c6cb430 Mon Sep 17 00:00:00 2001 From: lmoresi Date: Fri, 19 Jun 2026 12:19:04 +1000 Subject: [PATCH] cleanup(xdmf/snapshot): silence internal write_checkpoint FutureWarning + drop dead cell_dim read (#252) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Follow-ups from the #218 review: - disk_snapshot._write_disk_snapshot is a legitimate internal user of the user-deprecated write_checkpoint (it depends on the .mesh.00000.h5 / ..00000.h5 filename convention its reload path reads). Wrap the call in warnings.catch_warnings()+ignore FutureWarning so persistent snapshots don't spam the deprecation warning. (Full migration to write_timestep tracked in #252.) - checkpoint_xdmf read topo["cells"].attrs["cell_dim"] into cellDim but never used it (topology_precision now derives from cells.dtype.itemsize). Removed — it was a needless dependency on a PETSc-internal attr that could KeyError. Verified: test_0007/0008 (snapshot) pass with -W error::FutureWarning (26/26); test_0003/0005 (save_load/xdmf) green (39/39 total). Item 3 (unify swarmVar HyperSlab XDMF block with the flattened meshVar form) deferred: cosmetic, ParaView-sensitive, no easy local validation — left in #252. Underworld development team with AI support from Claude Code --- src/underworld3/checkpoint/disk_snapshot.py | 21 +++++++++++++------ .../discretisation/discretisation_mesh.py | 1 - 2 files changed, 15 insertions(+), 7 deletions(-) diff --git a/src/underworld3/checkpoint/disk_snapshot.py b/src/underworld3/checkpoint/disk_snapshot.py index 91716fcea..442e93579 100644 --- a/src/underworld3/checkpoint/disk_snapshot.py +++ b/src/underworld3/checkpoint/disk_snapshot.py @@ -38,6 +38,7 @@ import datetime import json import os +import warnings from typing import Any, Optional import numpy as np @@ -311,12 +312,20 @@ def write_snapshot(model, path: str) -> str: # path: lazy-allocated vars with _gvec == None have no data. mesh_vars = [v for v in mesh_vars if v._gvec is not None] - mesh.write_checkpoint( - mesh_safe, - outputPath=bulk_dir, - meshVars=mesh_vars, - index=0, - ) + # write_checkpoint is user-deprecated in favour of write_timestep, but + # the snapshot backend is a legitimate internal user: it relies on the + # `{base}.mesh.00000.h5` / `{base}.{var}.00000.h5` filename convention + # (consumed by the reload path below). Suppress the FutureWarning for + # this internal call rather than spam every snapshot. (Migrating the + # snapshot to write_timestep is tracked in #252.) + with warnings.catch_warnings(): + warnings.simplefilter("ignore", FutureWarning) + mesh.write_checkpoint( + mesh_safe, + outputPath=bulk_dir, + meshVars=mesh_vars, + index=0, + ) mesh_records.append({ "name": mesh.name, diff --git a/src/underworld3/discretisation/discretisation_mesh.py b/src/underworld3/discretisation/discretisation_mesh.py index db9669098..4c003b07d 100644 --- a/src/underworld3/discretisation/discretisation_mesh.py +++ b/src/underworld3/discretisation/discretisation_mesh.py @@ -6039,7 +6039,6 @@ def checkpoint_xdmf( ) numCells = cells.shape[0] numCorners = cells.shape[1] - cellDim = topo["cells"].attrs["cell_dim"] topology_precision = cells.dtype.itemsize if numCorners <= 1: