using-jax

yallup's avatarfrom yallup

Applies JAX patterns for scientific Python development. Use when working with JAX, distrax, numpyro, blackjax, or scientific computing. Covers vmap, JIT, RNG handling.

⭐1stars🔀0forks📁View on GitHub🕐Updated Dec 30, 2025

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.
nameusing-jax
descriptionApplies JAX patterns for scientific Python development. Use when working with JAX, distrax, numpyro, blackjax, or scientific computing. Covers vmap, JIT, RNG handling.
version2.0.0

JAX Scientific Computing

Core Rules

  1. Pure functions - No side effects
  2. JIT outer functions - @jax.jit on hot paths
  3. vmap not loops - jax.vmap(fn) instead of list comprehensions
  4. 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()