Repository navigation
Keep DG state as a PyTree and shard it over spatial cells - #39
Open
rogeriojorge wants to merge 4 commits into
Open
rogeriojorge wants to merge 4 commits into
rogeriojorge wants to merge 4 commits into
Conversation
rogeriojorge
force-pushed
the
agent/dg-pytree-state
branch
from
July 17, 2026 20:19
4fc1c1b to
8fabbfa
Compare
rogeriojorge
changed the base branch from
Discontinuous-Galerkin
to
agent/fix-dg-legendre-quadrature
July 17, 2026 20:19
rogeriojorge
marked this pull request as ready for review
July 17, 2026 20:21
rogeriojorge
force-pushed
the
agent/dg-pytree-state
branch
from
September 26, 2026 21:25
8fabbfa to
87811c7
Compare
rogeriojorge
changed the base branch from
agent/fix-dg-legendre-quadrature
to
Discontinuous-Galerkin
September 26, 2026 21:25
Codecov Report❌ Patch coverage is
🚀 New features to boost your workflow:
|
rogeriojorge
changed the base branch from
Discontinuous-Galerkin
to
agent/dg-autodiff
October 3, 2026 14:33
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.
Stacked on #45: merge #45 first; until then this diff also shows #45's commits.
Problem
The Hermite-DG
simulationflattenedCkandFkinto one vector, so their layouts could not be controlled, and the oldbatchmesh in_simulation.pywas never used. The DG state could not be distributed over devices.Change
(Ck, Fk);Hermite_DG_systemreturns the same structure.simulation(..., shard_axis="x"|"y"|"z")shards both arrays over one spatial cell axis across all JAX devices (shard_map).shift_elementexchanges the one-cell periodic halo withppermuteat device boundaries, and the adaptive controller uses a global RMS norm (psum) so all devices take the same steps.shard_axis=Nonepath is unchanged and still jitted as a whole; the output also carriessolver_result.Effect (office, 16 cores, forced host devices, Nx=4096, Nn=20, Bosh3 adaptive, warm)
2.35x at 16 devices (machine load ~40, so noisy). Results are identical to serial to 1e-15 relative. The serial path runs in 5.5-6.1 s vs 6.4-6.9 s before (same numbers, no slowdown).
Tests
test_spatial_sharding_matches_serialcompares serial and shardedCk/Fk. With 4 forced host devices it fails when the haloppermuteis removed. Full suite: 10 passed with and withoutJAX_ENABLE_X64, plustest_simulation_runs.pywith 4 host devices.Update 2026-10-03 (head 99298f1)
Base changed to
agent/dg-autodiff(#45); #45 is merged in (no rewrite), so the diff is the PyTree/sharding change only.Checked with 2 fake CPU devices (
XLA_FLAGS=--xla_force_host_platform_device_count=2), 2D, 4x4 cells, N_DG=2, H=3, 2 species, t=2:shard_axis="x"and"y": max |dCk| 4.7e-13 (scale 67), max |dFk| 7.1e-15 (scale 1). Halo exchange and the global RMS step-size norm reproduce the serial step sequence.jax.gradthrough the serial path works; through the sharded path it fails (ValueError: Length of device assignment 1 is not equal to the size of the mesh 2), because_placecallsdevice_get/device_puton traced values.max_steps,adjointandprogress_meter(hard-coded1000000, default adjoint,NoProgressMeter,throw=False), andsimulationis no longerjit-decorated.pytest tests18 passed;tests/test_simulation_runs.pywith 2 fake devices 4 passed. Local results.Open: make the sharded path differentiable (or refuse
gradexplicitly), pass the #45 solver keywords through, and measure cost on real devices before merge.