Skip to content

Particles: Cross-Precision Restart - #5578

Draft
ax3l wants to merge 2 commits into
AMReX-Codes:developmentfrom
ax3l:topic-particle-restart-cross-precision
Draft

Particles: Cross-Precision Restart#5578
ax3l wants to merge 2 commits into
AMReX-Codes:developmentfrom
ax3l:topic-particle-restart-cross-precision

Conversation

@ax3l

@ax3l ax3l commented Jul 23, 2026

Copy link
Copy Markdown
Member

Summary

Allow ParticleContainer::Restart to read files whose particle precision differs from the build's ParticleReal, e.g. single-precision plotfiles/checkpoints in a double-precision build:

  • ReadParticles buffers the real components in ParticleReal (converting each value on insertion) instead of the file's precision RTYPE, 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 (FPC::Native32/64RealDescriptor(), i.e. what the writing code's ParticleRealDescriptor was) instead of this build's - a no-op for matched reads.
  • The amrex::Error precision-mismatch branches in Restart are 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):

ctest --test-dir build -R 'CheckpointRestart' -E 'HDF5|AsyncIO' --output-on-failure

Cross precision, verified manually (candidate for a CI fixture, feedback welcome):

  1. Built Tests/Particles/CheckpointRestartSOA with -DAMReX_PARTICLES_PRECISION=SINGLE and wrote a plotfile (Version_Two_Dot_One_single, 4096 particles, 12 real + 4 int SoA comps at known constants, 8 grids).
  2. Restarted it in a double-precision build with a standalone verifier: particle count matches the header and grid table; positions in range; all non-position real components and all int components reproduced exactly (the constants are float-representable).

Checklist

The proposed changes:

  • fix a bug or incorrect behavior in AMReX
  • add new capabilities to AMReX
  • changes answers in the test suite to more than roundoff level
  • are likely to significantly affect the results of downstream AMReX users
  • include documentation in the code and/or rst files, if appropriate

🤖 Generated with Claude Code

ax3l and others added 2 commits July 22, 2026 17:02
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>
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant