Repository navigation
Add differentiable simulation example - #36
Closed
rogeriojorge wants to merge 1 commit into
Closed
rogeriojorge wants to merge 1 commit into
rogeriojorge wants to merge 1 commit into
Conversation
rogeriojorge
marked this pull request as ready for review
July 17, 2026 20:26
This was referenced Sep 12, 2026
Member
Author
|
Superseded by #44, which adds the |
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
simulationwith its existing checkpointed discrete adjoint as the defaultThis is stacked on #11 because differentiated and optimized runs should not execute progress-meter host callbacks.
Example
Examples/1D_autodiff.pydifferentiates the final electric-field energy with respect to the counter-streaming drift. It compares:RecursiveCheckpointAdjointForwardModeIt then creates a synthetic electric-energy time trace at drift
1.0and uses reverse-mode gradients to infer that physical drift from a starting value of1.1.Numerical rationale
Diffrax recommends checkpointed reverse mode for scalar objectives with many inputs and
ForwardModefor forward-mode derivatives. Its continuousBacksolveAdjointis approximate and explicitly not recommended. I tested it as requested, but it is also not hashable under SPECTRAX's current outer static JIT, so this PR does not complicate the simulation API to support a discouraged path.Skene and Burns (2025) automate efficient discrete adjoints for sparse spectral PDE solvers by reversing high-level solver control flow and supplying efficient VJPs for structured operators. JAX already supplies FFT VJPs, while Diffrax supplies checkpointed discrete time adjoints; this example follows the same discretize-then-differentiate principle without claiming to reproduce Dedalus's symbolic sparse-solver machinery.
Validation
pytest -q: 3 passed-0.732348217136557-0.7323482171365575-0.73234828515289511.00000636for target1.03.30e-1to2.59e-8in 12 iterations