Make op_system callable JAX-native for diffrax/NUTS workflows#75
Open
jc-macdonald wants to merge 6 commits intomainfrom
Open
Make op_system callable JAX-native for diffrax/NUTS workflows#75jc-macdonald wants to merge 6 commits intomainfrom
jc-macdonald wants to merge 6 commits intomainfrom
Conversation
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.
Closes #74
Summary
Adds a backend-aware compile path so
compile_rhs(andcompile_spec) can return RHS callables that are fully traceable by JAX — no forced NumPy concretization.Changes
Core (
op_system)compile_rhs(..., xp=np)/compile_spec(..., xp=None)— new optionalxpparameter; defaults tonumpy(no behaviour change for existing callers)_is_numpy_backend(xp)guard routes array ops throughxp.sum(xp.stack(...))/xp.asarray()for JAX compatibility_BackendNamespace/_Indexableinternal protocols replaceAnyin all public callable signatureseval_fnskips forcedfloat64cast in JAX mode (avoidsx64config requirement)Adapter (
flepimop2-op_system)backend: Literal["numpy", "jax"]field on the stepper model_get_backend_namespace()lazy-importsjax.numpyviaimportlib(optional dep, no import-time cost)Tests
test_compile_rhs_with_jax_backend_is_jittable— verifiesjax.jitwrapping round-tripstest_compile_rhs_with_diffrax_solve— ODE solve through diffraxODETermtest_compile_rhs_traces_through_blackjax_nuts— NUTS gradient tracing smoke testtest_jax_backend_stepper_jittable(adapter) — stepper survivesjax.jitpytest.importorskipand are skipped when JAX/diffrax/blackjax are absentPackaging
jaxandjax-inferenceoptional dependency groups added topyproject.toml