Skip to content

Update EXP IC routines for HDF5 output - #229

Merged
The9Cat merged 52 commits into
develfrom
generateHDF5ICs
Dec 1, 2026
Merged

The9Cat merged 52 commits into
develfrom
generateHDF5ICs

Conversation

@The9Cat

@The9Cat The9Cat commented Aug 14, 2026 •

Copy link
Copy Markdown
Member

Summary

  • Add a new helper class to create particle ICs files using the new HDF5 schema
  • Updated gensph, gendisk, gendisk2d, zangics, cubeics, slabics with an -5,--hdf5 option for producing HDF5
  • The helper class makes these changes moderately non-invasive. None of the phase-space generation algorithms are changed by the call to write bodies.

This PR completes the deprecation of default ascii i/o for phase space, although ascii remains available if requested explicitly (e.g. OutAscii and automatic fallback to ascii phase-space input if HDF5 is not detected).

Why

  • HDF5 read/write is much more efficient on network file systems. E.g. ascii read write slows down ceph by more than an order of magnitude in write time.
  • Compressed, float32 saves approximately a factor of 5 in disk space relative to ascii. Float64 is an option but seems unnecessary for ICs.
  • Added compression to EmpCylSL cache files to squeeze out a bit more disk space. Level 5 yields a compression factor of about 1.5.

Tests

  • Added CTest tests to verify that the HDF5 files have the expected metadata and have particles masses that sum to some user-specificed expected value. Default is 1.
  • Tests passed for gensph, slabics and cubeics.
  • Test slabics IC generation
  • Perform a simulation from slabics generated ICs
  • Test gendisk IC generation
  • Perform a simulation from gendisk generated ICs

TBD

  • Set HDF5 output to the default after all tests are successfully completed.
  • Set the default EmpCylSL::H5compress=5. Was set to 0during testing.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds HDF5 output support to EXP initial-condition generators using the runtime particle schema.

Changes:

  • Introduces a shared HDF5 particle writer with MPI gathering, compression, and precision options.
  • Integrates HDF5 output across six IC generators.
  • Centralizes 1D mass models and adds HDF5 smoke tests.

Reviewed changes

Copilot reviewed 14 out of 14 changed files in this pull request and generated 16 comments.

Show a summary per file
File Description
utils/ICs/ZangICs.cc Adds HDF5 output options.
utils/ICs/ParticleHDF5.H Implements the shared writer.
utils/ICs/massmodel1d.H Removes the local model header.
utils/ICs/initial2d.cc Adds gendisk2d HDF5 output.
utils/ICs/initial.cc Adds gendisk HDF5 output.
utils/ICs/gensph.cc Adds distributed HDF5 output.
utils/ICs/genslab.cc Reworks slab generation and output.
utils/ICs/cubeICs.cc Adds cube HDF5 output.
utils/ICs/CMakeLists.txt Uses centralized mass models.
tests/CMakeLists.txt Registers HDF5 smoke tests.
tests/check_hdf5_particles.py Validates particle schemas.
include/massmodel1d.H Centralizes and expands 1D models.
exputil/massmodel1d.cc Implements centralized models.
exputil/CMakeLists.txt Adds models to exputil.
Suppressed comments (3)

exputil/massmodel1d.cc:375

  • setDF(..., nint) stores a requested quadrature size, but compute_model ignores it and always uses 400 points. Use the member so the public tuning parameter has an effect.
    exputil/massmodel1d.cc:4
  • This source still constructs std::ifstream at line 26 but no longer includes <fstream>. Compilation now depends on an unrelated transitive include from SLGridMP2.H; include the defining standard header directly.
    include/massmodel1d.H:706
  • The default constructor leaves both epsilon and dist_defined indeterminate, although distf immediately uses epsilon and callers inspect dist_defined. Initialize a deliberate regularization value and mark the completed model as defined, as the other constructors do.
    H = 1.0;
    Omega = std::sqrt(2.0*M_PI/H);
    norm  = std::sqrt(2/Omega)/(M_PI*2.0*H);
    Jmax  = 0.5*Omega*H*H;
    ModelID = "Uniform";

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread utils/ICs/ParticleHDF5.H Resolved
Comment thread utils/ICs/ParticleHDF5.H Resolved
Comment thread utils/ICs/ParticleHDF5.H Resolved
Comment thread utils/ICs/genslab.cc Resolved
Comment thread utils/ICs/genslab.cc Resolved
Comment thread tests/check_hdf5_particles.py Resolved
Comment thread utils/ICs/initial.cc Resolved
Comment thread utils/ICs/initial2d.cc Resolved
Comment thread utils/ICs/ZangICs.cc Resolved
Comment thread utils/ICs/ParticleHDF5.H Resolved
The9Cat and others added 6 commits August 14, 2026 16:36
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: The9Cat <25960766+The9Cat@users.noreply.github.com>
@The9Cat

The9Cat commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@copilot I addressed your review below in a series of recent commits. Please review again.

Copilot AI commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@copilot I addressed your review below in a series of recent commits. Please review again.

I reviewed the updated PR. One remaining medium-severity issue needs correction before merge: the filter IDs for SZIP, SHUFFLE, and FLETCHER32 are mismatched with HDF5’s actual built-in IDs in utils/ICs/ParticleHDF5.H. HDF5 defines SHUFFLE=2, FLETCHER32=3, and SZIP=4, but the CLI mapping labels 2 as SZIP, 3 as shuffle-only, and 4 as Fletcher32; the code then passes those raw IDs and the wrong option arrays to H5Pset_filter. Consequently --filter 2 attempts to configure SHUFFLE with SZIP parameters, and --filter 4 configures SZIP with no SZIP options. These selections can fail during dataset creation. Please map CLI choices to the correct HDF5 filter constants/configuration or relabel/reassign the CLI IDs. I found no other new blocker in the areas previously flagged: rank-zero writing is column-streamed with MPI error propagation, and concurrent independent cache writers are explicitly documented as unsupported. Latest Build and Test runs for this head are still in progress.

@The9Cat

The9Cat commented Nov 30, 2026

Copy link
Copy Markdown
Member Author

@copilot You are correct and it's worse than you said. --filter 4 crashes with a floating point exception, and --filter 2 silently writes uncompressed. The default GZIP and the plugin filters are fine.

In the lastest commits, I switched to HDF5's own numbering, where 2 is shuffle, 3 is Fletcher32 and 4 is SZIP, set through the proper API. The slab test would switch to filter 2, and a new test would check filters 2 to 4. This implies that --filter 3 would change meaning, but the PR hasn't merged yet, so this should not be a concern.

After the updates, --filter 4 no longer crashes. All cube and slab tests pass, and filters 2, 3 and 4 each wrote the right filter. I updated the test script and successfully executed the round-trip tests.

Please review the updates.

Copilot AI commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@copilot You are correct and it's worse than you said. --filter 4 crashes with a floating point exception, and --filter 2 silently writes uncompressed. The default GZIP and the plugin filters are ...

Reviewed the latest changes. The implementation’s HDF5 IDs and APIs now line up: 2 uses shuffle, 3 uses Fletcher32, and 4 uses SZIP; the new round-trip checks exercise these correctly when the filter is available.

One remaining test portability issue: check_filter(4) intentionally falls back to GZIP (or shuffle if GZIP encoding is unavailable) when SZIP cannot encode. But the new test at tests/test_hdf5_ics.py accepts only SZIP or no filter for ID 4, so it fails on HDF5 builds that take the documented fallback. Please condition the expected properties on SZIP encoder availability or accept the fallback configurations. CI for the latest head (f9ade36) is still in progress; no failure is reported yet.

@The9Cat

The9Cat commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@copilot Good point. Without an SZIP encoder, the code falls back to GZIP with shuffle, but the filter 4 test doesn’t accept that. It passes on on my development machine because HDF5 has full SZIP.

The new commit makes the following changes:

  • --filter uses HDF5's registered filter IDs. All IC generators take --filter (-Z for zangics): cubeics, slabics, gensph, gendisk, gendisk2d, zangics.
    • 1 = GZIP/DEFLATE, level 5, with byte shuffle (default)
    • 2 = byte SHUFFLE only (no compression)
    • 3 = FLETCHER32 checksum only (no compression)
    • 4 = SZIP (nearest-neighbour coding, 16 pixels per block)
    • 307 = BZIP2, 32001 = BLOSC, 32004 = LZ4 (these need the HDF5 filter plugins on HDF5_PLUGIN_PATH)
  • Byte shuffle is added with GZIP, BZIP2 and LZ4. It is not added with FLETCHER32, SZIP or BLOSC (BLOSC shuffles internally).
  • Unusable filters fall back to GZIP with a warning. This covers an unknown ID, or a filter this HDF5 build can't use for writing. If GZIP is also unavailable, output falls back to shuffle only. The usual case is SZIP on HDF5 builds without libaec/libsz encoding.
  • Small and empty outputs: SZIP needs at least 16 particles per dataset, so smaller SZIP outputs are written uncompressed. Empty outputs (0 particles) are written unchunked and unfiltered.
  • Input checking: cubeics exits with an error and writes nothing when asked for fewer than one particle.

Please check the updated script.

Copilot AI commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@copilot Good point. Without an SZIP encoder, the code falls back to GZIP with shuffle, but the filter 4 test doesn’t accept that. It passes on on my development machine because HDF5 has full SZIP....

The SZIP fallback assertion is now handled correctly, including the no-GZIP fallback to shuffle-only for the filter-specific cases. One remaining portability gap: the test script still assumes default GZIP in read_hdf5 (starting with the ordinary cubeics check at line 96, and similarly for the other default-output cases). If GZIP encoding is unavailable, check_filter(1) intentionally falls back to shuffle-only, so those checks fail before—or independently of—the new filter-4 fallback checks. Please derive the expected default filter properties from the generator warning or apply a shared helper for the fallback behavior. The newest CI run for f6b84b8 is still in progress.

… successfully tested the script one more time...
@The9Cat

The9Cat commented Dec 1, 2026

Copy link
Copy Markdown
Member Author

@copilot You are right in principle, but this a rare edge case I'd treat as very low priority. It only matters on an HDF5 built without zlib. That's very rare, since zlib is a standard HDF5 dependency and is on in every distro, conda and PyPI build that I checked.

Since GZIP is standard, every default-output case uses that default (cube at line 96, sphere, zang, slab and the disks). Without GZIP, check_filter(1) falls back to shuffle-only, so all of those would fail together. Moreover, the gendisk basis-cache check would fail on such a build too. It requires gzip, and the cache uses a GZIP filter that can't be skipped, so without zlib the cache simply isn't written.

Anyway, to address this rare case, I added a helper function in the latest commit that looks for the fallback warning in a run's log. It returns GZIP level 5 with shuffle when there's no warning, and shuffle-only otherwise. The filter-4 check would use it too, so there's one rule in one place.

Please check the latest commit to make sure I didn't miss something.

Copilot AI commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

@copilot You are right in principle, but this a rare edge case I'd treat as very low priority. It only matters on an HDF5 built without zlib. That's very rare, since zlib is a standard HDF5 dependency...

I checked the latest helper in commit 3e514a7. It reads the warning’s selected filter ID and uses a shared mapping for the expected h5py compression properties, and that expectation is now passed to the default-output checks for slab, cube, sphere, Zang, disk/gas, and evolved-disk outputs. The filter-specific SZIP cases also use the helper, including the small-dataset unfiltered case. I found no remaining issue in the updated script. The previous f6b84b8 branch CI runs passed; CI for 3e514a7 is still in progress.

@The9Cat
The9Cat merged commit 15b813a into devel Dec 1, 2026
9 checks passed
@The9Cat
The9Cat deleted the generateHDF5ICs branch December 1, 2026 01:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants