moju is a physics supervision and audit library for SciML. The core is JAX-native: moju.piratio provides Groups, Models, Laws, and Operators, while moju.monitor provides ResidualEngine, build_loss, audit, and visualize. The moju.torch namespace exposes a PyTorch-facing engine and interop helpers.
pip install moju # residuals, audit, visualize, PDF
pip install "moju[io]" # + state_ref file loaders
pip install "moju[studio]" # Streamlit Moju Studio
pip install "moju[torch,io]" # PyTorch + file loaders
User config and state dictionaries flow through ResidualEngine. Groups
materialize dimensionless quantities into merged state. Laws produce governing residuals.
Constitutive audits compare catalog models against references or implied values. Optional
data/ residuals run in eval mode when state_ref is supplied.
build_loss uses law residuals for optimization; audit
and visualize summarize the full log.
Path A builds state_pred from (model, params, collocation)
using a state_builder. Path B passes state_pred directly,
which is convenient for CFD snapshots, saved neural-operator fields, or already-computed
derivatives.
In the minimal 1D slab cooling example, Path B supplies T,
T_t, T_laplacian, x, t,
L, and material properties directly. No finite-difference inference is
needed. The Fourier conduction law runs from those fields, and the default law-linked
implied audit checks Models.thermal_diffusivity(k, rho, cp) against the
diffusivity implied by the law fields.
law_scale_mode="auto" term-balance scale_k by default; constitutive implied_delta / ref_delta use worst-point r_max for admissibility (logged rms stays RMS for training). Path B: state_units="dimensional" for SI uploads.(model − implied) / (|model| + ε)) and a Constitutive Consistency line plot with spatially varying ±0.1 % / ±0.5 % / ±1 % acceptability bands and tier boundary markers centred on the model prediction.Use monitor_training_vs_eval.md for run-mode details and law_implied_audits.md for the law-linked constitutive audit registry.
Install moju[torch] to use the moju.torch namespace.
It provides TorchResidualEngine, build_loss_torch,
r_eff_scalar_torch, Torch-native nondimensionalization helpers, and
wrap_law_torch for calling JAX laws from Torch tensors through
jax2torch.
See scripts/torch_laws_jax2torch_example.py,
tests/test_torch_engine.py, and tests/test_torch_interop.py
for the current public surface.
examples/slab_cooling_demo.py - full 1D slab cooling demo.examples/cfd_snapshot_cookbook_heat_1d.py - xarray snapshot to eval audit.examples/cookbook_path_b_fd_law_laplace.py - optional Path B finite-difference fill.examples/cookbook_constitutive_divergence.py - constitutive divergence dashboard.scripts/torch_laws_jax2torch_example.py - basic Torch interop.