Skip to content

Evaluation & Debugging


Evaluation

After training, use crux.eval() to evaluate any symbolic expression:

# On the training domain
pred = crux.eval(u)    # shape: (B, T, N, out_dim)

# On a different domain (e.g., fine test grid)
test_domain = jno.shape.rect(0, 0, 1, 1, size=0.01).domain()
pred_fine = crux.eval(u, domain=test_domain)

# Prediction on arbitrary point arrays
import numpy as np
points = np.tile(test_domain.points[None, ...], (B, 1, 1))  # (B, N, 2)
pred = crux.predict(points=points, operation=u, context=test_domain.context)

Debugging

Inspect the core — jno.info

One entry for everything about a built object: models, what training does with their parameters (trainable / frozen / LoRA), the equations in mathematical notation, the optimizer, and — with deep=True — every constraint as an expression tree with the shape of each node.

print(jno.info(crux))                        # models, parameters, equations, optimizer
print(jno.info(crux, deep=True))             # + the expression tree with shapes

open("tree.txt", "w").write(str(jno.info(crux, deep=True)))   # to a file

For the Burgers equation the tree reads

  expression tree
      [0] ∂u/∂t + u ∂u/∂x − 0.01/π ∂²u/∂x²         (10000, 1) → mse → ()
          ├─ ∂u/∂t                                 (10000, 1)
          ├─ u ∂u/∂x                               (10000, 1)
          │  └─ ∂u/∂x                              (10000, 1)
          └─ −0.01/π ∂²u/∂x²                       (10000, 1)
             └─ ∂²u/∂x²                            (10000, 1)
      [1] u + sin(π x)                             (50, 1) → mse → ()
          └─ sin(π x)                              (50, 1)
             └─ π x                                (50, 1)
      where u = MLP(x, t)                          (10000, 1), (50, 1)

Nothing is drawn twice. A sum's terms are siblings, each with its sign. A network, its outputs and a field built on it are not nodes of the tree: they appear by name in the labels and are defined once, in the where block, with the shape on every point set they are evaluated on. The shapes come from one abstract evaluation (jax.eval_shape), so nothing is computed; a node evaluated only inside a derivative pass, one point at a time, is marked per point.

Debug Print Inside Expressions

Use JAX's debug print inside expressions for verbose intermediate inspection (expensive — use sparingly):

pde = jno.np.laplacian(u, [x, y]) + 1.0
pde.debug._shape = True   # print shape at this node each step
pde.debug._mean = True    # print mean value

Profiler

Pass profile=True to solve() to capture a JAX performance trace:

history = crux.solve(5000, profile=True)

jNO skips the first outer step (startup JIT compilation) and then records the next 50 steady-state steps. The traces are written to <logger.path>/traces/ in Perfetto format — open them at ui.perfetto.dev to inspect the timeline.

What the trace shows

The Perfetto timeline breaks down each training step into the individual XLA ops that make it up. Typical things to look for:

Symptom Likely cause
A single long "unflatten" span every few steps Python GC pause — jNO disables cyclic GC during training to suppress these
Many short gaps between ops Host–device sync points; consider fusing ops or using jax.block_until_ready less aggressively
One constraint takes 10× longer than others That expression has much higher compute cost — consider finite-difference vs AD trade-off
Compile time dominates the first step Normal for JIT; the skip-first-step logic means this is excluded from the captured trace

Controlling the output directory

The trace path follows the jNO logger, which defaults to the current working directory. Set it explicitly with jno.setup:

import jno
jno.setup("runs/my_experiment")   # traces go to runs/my_experiment/traces/

crux = jno.core([pde.mse])
history = crux.solve(5000, profile=True)

Notes

  • profile=True is a side effect only — it does not change the return value of solve().
  • Profiling adds negligible overhead to the captured steps themselves; the trace serialisation happens asynchronously.
  • For very short runs (fewer than 52 epochs) the capture window is clamped: min(50, epochs - 1) steps are recorded.

Training Statistics

solve() returns a statistics object:

stats = crux.solve(5000)

stats.plot("history.png")            # save loss curves; returns self, so it chains off solve()

# Access raw data
stats.total_loss                     # FINAL scalar total loss (a float, not an array)
stats.total_loss_history             # 1-D array, concatenated across every solve() call
stats.training_logs                  # list of per-solve()-call dicts; each carries the raw
                                     # "epoch", "total_loss", "losses", "timestamps",
                                     # "training_time" and "trainable_params" records
stats.training_logs[-1]["losses"]    # e.g. per-constraint losses from the last call

Note total_loss is the final value — the curve lives in total_loss_history, and everything else (epoch indices, per-constraint losses, wall-clock time, parameter counts) is read from the training_logs dicts rather than from attributes.


Checkpoints

solve() automatically saves a checkpoint (model weights, optimiser state, RNG key) after every call. All checkpoints are accessible via crux.checkpoints:

# Inspect available checkpoints
for i, ckpt in enumerate(crux.checkpoints):
    print(i, ckpt["step"], ckpt["time"])

# Restore a specific checkpoint
crux.models = crux.checkpoints[-1]["models"]