Particles: Cross-Precision Restart - #5578
Draft
ax3l wants to merge 2 commits into
Draft
Conversation
Extract the parsing of the per-level grid table (data file index, particle count and byte offset for each grid) from ParticleContainer::Restart into the shared ParticleHeader, so standalone consumers (e.g. language bindings) can locate each grid's binary particle data without duplicating the format logic. ParticleHeader::read() now returns a fully parsed header including the grid table; ParticleHeader::parse() is unchanged and still consumes exactly the metadata prefix. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Allow ParticleContainer::Restart to read files whose particle precision differs from the build's ParticleReal, e.g. single-precision plotfiles and checkpoints in a double-precision build: - ReadParticles buffers the real components in ParticleReal (converting each value on insertion) instead of the file's precision, so the host-to-device copies are well-typed for any file precision. - The real data is read with the descriptor matching the file's precision (the writing code's native descriptor) instead of this build's ParticleRealDescriptor. - Restart no longer errors on a precision mismatch. Reading double-precision data into a single-precision build narrows the values; the reverse is exact. Verified by writing a checkpoint with AMReX_PARTICLES_PRECISION=SINGLE (Tests/Particles/CheckpointRestartSOA) and restarting it in a double-precision build: particle counts and all real/int components are reproduced exactly. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This was referenced Jul 23, 2026
ax3l
added a commit
to AMReX-Codes/pyamrex
that referenced
this pull request
Aug 3, 2026
Follow-up to #581 (stacked on its branch; the first commits shown here belong to #581). Depends on: - [x] #581 (runtime-SoA particle reading) - [x] AMReX-Codes/amrex#5577 (`ParticleHeader` grid table) - the binding needs an AMReX pin that includes it ## Summary - **Bind the particle grid table**: `amrex.ParticleHeader.grids` exposes AMReX's per-level table locating each grid's binary particle data (`GridEntry`: data file index `which`, particle `count`, byte offset `where`) - same C++ parser as `ParticleContainer::Restart`, no duplicated format logic. Useful for standalone tools, e.g. format converters and parallel readers. - **Species discovery**: `amrex.space3d.list_particle_species(plotfile)` lists the particle sub-directories of a plotfile/checkpoint by their particle `Header` files. - **Compat**: disambiguate `Redistribute` for AMReX development (new `IntVect nGrow` overload). - Docs: both features added to the "Read Back Plotfiles" workflow page. ## Testing Built against AMReX `development` + AMReX-Codes/amrex#5577 + AMReX-Codes/amrex#5578 (`-DpyAMReX_amrex_src=...`): ``` python -m pytest tests/test_readparticles.py tests/test_plotfiledata.py -v ``` 10 passed - including new `test_read_particles_grid_table` (table totals match `num_particles`) and `test_list_particle_species`, and per-level grid-table count assertions in `test_read_particles_multilevel`. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --------- Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Allow
ParticleContainer::Restartto read files whose particle precision differs from the build'sParticleReal, e.g. single-precision plotfiles/checkpoints in a double-precision build:ReadParticlesbuffers the real components inParticleReal(converting each value on insertion) instead of the file's precisionRTYPE, so the host-to-device copies are well-typed for any file precision.FPC::Native32/64RealDescriptor(), i.e. what the writing code'sParticleRealDescriptorwas) instead of this build's - a no-op for matched reads.amrex::Errorprecision-mismatch branches inRestartare removed. Reading double data into a single-precision build narrows the values (documented); the reverse is exact.Stacked on #5577 (includes its commit); will rebase once that merges. Motivation: a general plotfile converter (pyAMReX) must read single-precision particle output with default double-precision Python builds.
Testing
Matched precision (as in #5577, all pass):
Cross precision, verified manually (candidate for a CI fixture, feedback welcome):
Tests/Particles/CheckpointRestartSOAwith-DAMReX_PARTICLES_PRECISION=SINGLEand wrote a plotfile (Version_Two_Dot_One_single, 4096 particles, 12 real + 4 int SoA comps at known constants, 8 grids).Checklist
The proposed changes:
🤖 Generated with Claude Code