Physics supervision and audit tools for SciML and Physics AI.
GitHub | PyPI | API overview
Moju turns predicted state fields into governing-law residuals, physics losses,
constitutive consistency checks, and audit reports. It is JAX-native at the core,
with a PyTorch-facing interface through moju.torch.
Models, Groups, and Laws.build_loss for governing-law training losses.audit and visualize for training/eval diagnostics.pip install moju
pip install "moju[io]"
pip install "moju[torch,io]"
Minimal Path B flow: pass state_pred directly. The derivatives are already
provided, so no finite-difference inference is needed.
import jax.numpy as jnp
from moju.monitor import audit, build_loss, build_minimal_residual_engine, visualize
L = 0.02
rho, cp, k = 2700.0, 900.0, 200.0
alpha = k / (rho * cp)
x = jnp.linspace(0.0, L, 64)
t = jnp.ones_like(x) * 10.0
T = 300.0 + 20.0 * (1.0 - x / L) ** 2
T_laplacian = jnp.ones_like(x) * (40.0 / (L**2))
T_t = alpha * T_laplacian
state_pred = {
"x": x,
"t": t,
"T": T,
"T_t": T_t,
"T_laplacian": T_laplacian,
"L": jnp.ones_like(x) * L,
"k": jnp.ones_like(x) * k,
"rho": jnp.ones_like(x) * rho,
"cp": jnp.ones_like(x) * cp,
"alpha": jnp.ones_like(x) * alpha,
}
engine = build_minimal_residual_engine(
law_names=["fourier_conduction"],
coord_dimension=1,
)
residuals = engine.compute_residuals(state_pred, run_mode="training")
loss = build_loss(residuals)
report = audit(engine.log)
fig = visualize(engine.log, engine=engine)
The Fourier law automatically adds the law-linked thermal_diffusivity
implied audit. fig is the Plotly dashboard.
Moju does not define physics for you. It provides a structured way to apply, measure, and audit the physics you already trust.