Uh oh!
There was an error while loading. Please reload this page.
wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach - #3951
wwinp files: Fix MemoryError in WeightWindowsList.export_to_hdf5 and speed up from_wwinp. Alternative Approach#3951yrrepy wants to merge 44 commits into
Conversation
Float/complex ndarrays are dtype-validated, so the per-element isinstance() scan is redundant. Also construct upper_ww_bounds in WeightWindows.__init__ as an ndarray multiplication (not a list comprehension) so the upper-bounds setter benefits too. ~11x speedup on 172M-element wwinp inputs (397 s -> 35 s).
The XML serialization raised MemoryError on bound arrays >~200M elements -- lxml's intermediate ASCII allocation fails before the text node can be built. Write HDF5 directly via h5py, mirroring the C++ WeightWindows::to_hdf5 writer. Critical details for C++ compatibility: - Bounds are 2D (ne, n_voxels) on disk (4D would segfault the C++ tensor::Tensor<double> reader). - max_lower_bound_ratio is written unconditionally (default 1.0). - Root attrs filetype and version are required by openmc_weight_windows_import. Adds Mesh.to_hdf5 on each structured mesh subclass, mirroring the existing Mesh.to_xml_element pattern. UnstructuredMesh raises NotImplementedError (wwinp cannot produce one).
The dtype-trust fast path returned for any float/complex ndarray of matching depth, even when expected_type was int or another class -- the docstring promised element-type validation but the fast path skipped it. Gate the fast path on expected_type in (Real, float, complex) so it only fires when dtype.kind in 'fc' actually satisfies the contract.
The direct-h5py writer cannot serialize an UnstructuredMesh from pure Python: vertex and connectivity data live in the external .exo/.h5m file and only exist in memory after LibMesh/MOAB loads them via openmc.lib.init. Dispatch on mesh type up front: structured meshes take the new fast path; UnstructuredMesh falls back to the previous TemporarySession + openmc.lib.export_weight_windows route, which also restores honoring of init_kwargs on that path. Removes the dead NotImplementedError branch from _write_mesh_group.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Declaring to_hdf5 as an abstractmethod documents that every mesh type implements it
yrrepy
commented
Jun 3, 2026
I'm swamped with other work right now, so I can't follow up on this right now. Can only pivot back in a week or 10 days unfortunately. |
The very specific combination of using libmesh and not using mpi makes openmc crash when trying to write to hdf5 from c-api. |
Closed#3942
in favor of the alternative approach, (this PR).
Switching to the per-mesh
Mesh.to_hdf5design, each mesh subclass serializes itself, mirroring the existingto_xml_elementsuper-call pattern) instead of a central dispatch helper.This PR:
This enables support for many-GB wwinp files and faster processing of them.
Checklist