Skip to content

Experimental: indexed/flat particle backends#73

Open
rogeriojorge wants to merge 3 commits intouwplasma:mainfrom
rogeriojorge:codex/cpu-5x-indexed
Open

Experimental: indexed/flat particle backends#73
rogeriojorge wants to merge 3 commits intouwplasma:mainfrom
rogeriojorge:codex/cpu-5x-indexed

Conversation

@rogeriojorge
Copy link
Member

@rogeriojorge rogeriojorge commented Mar 14, 2026

Summary

This PR adds physics-preserving, opt-in experimental particle backends that reduce CPU overhead via data layout changes:

  • fast_backend = "indexed": stores per-particle cell indices + fractional offsets to avoid repeated position->index conversions.
  • fast_backend = "flat": flattens all species into one container (uniform shape & periodic BCs) to reduce per-species overhead.

Core physics-kernel changes are limited to:

  • PyPIC3D/boris.py (indexed interpolation/push)
  • PyPIC3D/J.py (indexed current deposition + 1D/2D multi-species accumulation fix)
  • PyPIC3D/evolve.py (indexed time loop)

All other touched files are routing/metadata only:

  • PyPIC3D/indexed_particles.py (new container + periodic index normalization)
  • PyPIC3D/flat_particles.py (new container)
  • PyPIC3D/initialization.py (fast_backend routing + compatibility checks)
  • PyPIC3D/utils.py (dump metadata for flat backend)

Usage

[simulation_parameters]
fast_backend = "indexed"  # or "flat"

Restrictions:

  • Electrodynamic solver only (no electrostatic / vector potential)
  • Periodic particle BCs required
  • flat backend requires uniform particle shape + update flags across species

Benchmarks (CPU)

Configs: demos/two_stream/two_stream.toml, demos/weibel/weibel.toml, plotting disabled.

Variant two_stream (s/step) Speedup weibel (s/step) Speedup
baseline (origin/main) 5.55e-3 1.00x 2.15e-3 1.00x
default 2.29e-3 2.42x 1.16e-3 1.85x
fast_backend=indexed 2.66e-3 2.09x 1.22e-3 1.76x
fast_backend=flat 2.09e-3 2.66x 9.16e-4 2.35x
fast_mode=aggressive 1.94e-3 2.86x 9.68e-4 2.22x
fast_mode=extreme 1.83e-3 3.04x 9.04e-4 2.38x

Plots (artifacts branch)

Artifacts (plots + raw numbers) live in codex/cpu-5x-indexed-artifacts and are not intended to merge into main.

Runtime & speedup

Runtime per step

Speedup

Two-stream

Two-stream electric energy

Two-stream energy error

Weibel

Weibel electric energy

Weibel energy error

Raw numbers (artifacts branch)

@rogeriojorge
Copy link
Member Author

As of now, it seems to be completely wrong, but the tests still pass. Perhaps we should harden the tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant