using-jax
Applies JAX patterns for scientific Python development. Use when working with JAX, distrax, numpyro, blackjax, or scientific computing. Covers vmap, JIT, RNG handling.
When & Why to Use This Skill
This Claude skill provides expert guidance and automated pattern application for JAX-based scientific Python development. It optimizes high-performance computing workflows by enforcing functional programming principles, JIT compilation, and efficient vectorization (vmap). By addressing common pitfalls like side effects and improper RNG handling, it helps developers build scalable, GPU-ready simulations and machine learning models using libraries like Distrax, NumPyro, and BlackJAX.
Use Cases
- Accelerating scientific simulations by converting standard Python loops into efficient JAX vmap and scan operations for GPU/TPU execution.
- Implementing high-performance probabilistic models and Bayesian inference using NumPyro or BlackJAX with correct functional patterns.
- Refactoring existing NumPy or Python code to adhere to JAX's immutable array structures and pure function requirements.
- Ensuring reproducible and parallelizable stochastic research by correctly managing and splitting PRNG keys across distributed computations.
- Optimizing hot paths in machine learning pipelines using @jax.jit to minimize compilation overhead and maximize throughput.
| name | using-jax |
|---|---|
| description | Applies JAX patterns for scientific Python development. Use when working with JAX, distrax, numpyro, blackjax, or scientific computing. Covers vmap, JIT, RNG handling. |
| version | 2.0.0 |
JAX Scientific Computing
Core Rules
- Pure functions - No side effects
- JIT outer functions -
@jax.jiton hot paths - vmap not loops -
jax.vmap(fn)instead of list comprehensions - Split RNG keys - Never reuse keys
Patterns
# RNG: always split
key, k1, k2 = jax.random.split(key, 3)
# Batching: vmap not loops
batched = jax.vmap(fn)(inputs)
# Loops: use scan
_, results = jax.lax.scan(step_fn, init, xs)
Gotchas
- Arrays are immutable
- No Python control flow in JIT - use
jax.lax.cond,jax.lax.scan - Check NaNs:
jnp.isnan(x).any()