jax-pde
Advanced sub-skill for JAX focused on solving Partial Differential Equations (PDEs) and Differentiable Physics. Covers Finite Difference Methods (FDM), Neural Operators, and Physics-Informed Neural Networks (PINNs).
What this skill does
# JAX - Differentiable Physics & PDEs
JAX is uniquely suited for physics because it can differentiate through numerical solvers. This guide covers how to implement traditional PDE solvers that are "optimization-friendly" and how to build neural-hybrid physical models.
## When to Use
- Solving Navier-Stokes, Wave, or Heat equations on GPU.
- Implementing Physics-Informed Neural Networks (PINNs).
- Performing Inverse Design (finding material properties from observations).
- Creating differentiable simulations for robotics or climate modeling.
- Sensitivity analysis of physical systems.
## Core Principles
### 1. Differentiation through the Solver
In JAX, if you write an Euler or Runge-Kutta integrator using `jax.numpy`, you can automatically calculate ∂Result/∂InitialCondition or ∂Result/∂Viscosity.
### 2. Staggered Grids & Vmap
Physical fields (velocity, pressure) are often stored on grids. JAX's `vmap` allows you to parallelize solvers across different boundary conditions or parameter sets instantly.
### 3. The Adjoint Method
For very large systems, JAX's reverse-mode autodiff effectively implements the "Adjoint State Method" used in traditional CFD/Geophysics for gradient calculation.
## Implementation Patterns
### 1. PINNs (Physics-Informed Neural Networks)
```python
import jax.numpy as jnp
from jax import grad, vmap
# A simple MLP representing the solution u(x, t)
def model(params, x, t):
# standard neural net logic...
return result
# Residual of the PDE: u_t + u*u_x - nu*u_xx = 0 (Burgers Equation)
def pde_loss(params, x, t, nu):
u = lambda x, t: model(params, x, t)
# Automatic derivatives of the MODEL
u_t = grad(u, argnums=1)(x, t)
u_x = grad(u, argnums=0)(x, t)
u_xx = grad(grad(u, argnums=0), argnums=0)(x, t)
return jnp.mean((u_t + u * u_x - nu * u_xx)**2)
```
### 2. Differentiable Finite Difference Solver
```python
@jit
def update_step(u, dt, dx, nu):
"""One step of a diffusion solver."""
# Vectorized Laplacian using shifts (Zero-copy views)
u_left = jnp.roll(u, -1)
u_right = jnp.roll(u, 1)
laplacian = (u_left + u_right - 2*u) / (dx**2)
return u + dt * nu * laplacian
# We can now differentiate this solver!
def loss(initial_u, target_u):
final_u = integrate_pde(initial_u) # Loop of update_step
return jnp.sum((final_u - target_u)**2)
grad_initial_condition = grad(loss)(initial_u, target_u)
```
## Critical Rules
### ✅ DO
- **Use jax.lax.scan for time loops** - Standard Python for loops create massive XLA graphs. `scan` compiles the loop into a single efficient kernel.
- **Normalize your Grids** - Like ML, PINNs converge faster if x, t are scaled to [0,1] or [-1,1].
- **Combine Data and Physics** - Use PINNs where you have some sensor data + the physical law to "fill the gaps".
- **Use Double Precision for Physics** - Use `jax.config.update("jax_enable_x64", True)` for sensitive numerical solvers.
### ❌ DON'T
- **Don't use PINNs for everything** - Traditional solvers (FDM/FEM) are much faster for "forward" problems. PINNs excel at "inverse" problems.
- **Don't ignore Boundary Conditions (BCs)** - In PINNs, BCs must be added to the loss function: Loss = PDE_loss + BC_loss.
- **Don't forget the 'Ghost Cells'** - When implementing FDM, handle boundaries carefully to avoid artifacts.
## Practical Workflows: Inverse Problem
### Finding Viscosity from a Video of Fluid
```python
def objective(nu_guess):
# 1. Run simulation with nu_guess
final_state = run_simulation(initial_state, nu_guess)
# 2. Compare with experimental data
return jnp.mean((final_state - experimental_frame)**2)
# Gradient descent to find the real physical property
optimal_nu = optimize(grad(objective))
```
JAX PDE transforms physics from a static simulation into a dynamic, optimizable landscape. It allows researchers to ask "What physical parameters produced this result?" and find the answer through the power of gradients.
Related in General
modeling-omnistudio-epc-catalog
IncludedSalesforce Industries CME EPC product-modeling skill for Product2-based catalog creation. Use when creating EPC products, configuring product attributes, building offer bundles with Product Child Items, or reviewing EPC DataPack JSON metadata for product catalog changes. TRIGGER when: user creates or updates Product2 EPC records, AttributeAssignment payloads, AttributeMetadata/AttributeDefaultValues, Offer bundles, or ProductChildItem relationships. DO NOT TRIGGER when: designing OmniScripts/FlexCards/Integration Procedures (use building-omnistudio-omniscript, building-omnistudio-flexcard, or building-omnistudio-integration-procedure), implementing Apex business logic (use generating-apex), or troubleshooting deployment pipelines (use deploying-metadata).
relationship-science-coach
IncludedUse this skill for direct, practical adult relationship coaching: couples conflict, repair, trust, marriage, dating, flirting, attachment patterns, emotional connection, sex, desire differences, eroticism, kink negotiation, affection, love languages, breakups, and long-term passion. Draw on Gottman, EFT and Hold Me Tight, attachment science, modern sex research, Perel, Nagoski, Kerner, Schnarch, Love and Stosny, and flexible love-language tools. Be concrete and low-hedge. Redirect only for imminent danger, abuse, coercive control, minors, non-consent, self-harm, stalking, or medical/legal/psychiatric decisions.
building-sf-integrations
IncludedSalesforce integration architecture and runtime plumbing with 120-point scoring. Use this skill to set up Named Credentials, External Credentials, External Services, REST/SOAP callout patterns, Platform Events, and Change Data Capture. TRIGGER when: user sets up Named Credentials, External Services, REST/SOAP callouts, Platform Events, CDC, or touches .namedCredential-meta.xml files. DO NOT TRIGGER when: Connected App/OAuth config (use configuring-connected-apps), Apex-only logic (use generating-apex), or data import/export (use handling-sf-data).
venue-templates
IncludedAccess comprehensive LaTeX templates, formatting requirements, and submission guidelines for major scientific publication venues (Nature, Science, PLOS, IEEE, ACM), academic conferences (NeurIPS, ICML, CVPR, CHI), research posters, and grant proposals (NSF, NIH, DOE, DARPA). This skill should be used when preparing manuscripts for journal submission, conference papers, research posters, or grant proposals and need venue-specific formatting requirements and templates.
let-fate-decide
IncludedDraws the 12 Houses of the Zodiac Tarot spread to inject entropy into planning when prompts are vague, ambiguous, or casually delegated. Interprets the spread to guide next steps. Use when the user says 'let fate decide', 'YOLO', 'whatever', 'idk', or other nonchalant phrases, makes Yu-Gi-Oh references, or when you are about to arbitrarily pick between multiple reasonable approaches. Prefer over ask-questions-if-underspecified when the user's tone is casual or playful rather than precision-seeking.
net-ops
IncludedCross-platform network troubleshooting (Windows, macOS, Linux) via local or remote shell. Use for: DNS broken, can't resolve hostnames, nslookup/dig works but apps fail, NRPT, WFP, scutil, /etc/resolver, systemd-resolved, /etc/resolv.conf, NetworkManager, VPN DNS leak residue (ProtonVPN/Mullvad/WireGuard/AnyConnect), AV/firewall blocking DNS or DoH, Tailscale DNS interaction, intermittent connectivity, remote diagnostics over SSH.