hawk.diff.event

hawk.diff.event#

A step kernel’s stop rule as a DIFFERENTIABLE guard.

A kernel finishing its sample on terminated = cond stops on a boolean, whose derivative is zero everywhere it exists. Event refinement needs the smooth function that CHANGES SIGN where the boolean flips: event_guard() reads it out of cond as an ordinary IR node, never a mask, under ONE sign convention — the sample stops where g <= 0:

  • a < b / a <= b -> g = a - b;

  • a > b / a >= b -> g = b - a;

  • c1 or c2 ... -> one guard per comparison (each its own stop rule).

Everything else is refused at the guard’s construction, naming the kernel and the rule: and/not, ==/!=, a bare flag, an integer comparison (a count), and a comparison whose two sides carry no smooth dependence on a floating-point input (a rounding, a sign, a class test or a comparison on the path). The guard is a function of the step’s PRE-step inputs — the same body the step evaluates — so evaluating it at a step size tau is the guard at the end of a partial step.

guard_kernel() packages the guards as a kernel committing one event_g<i> plane each, with every launch-start read of a Mutable turned into a plain read of the same plane: a pure function of the state, so the ordinary jvp()/vjp() differentiate it with respect to the state AND the parameters.

Functions

event_guard(…)

kernel's stop rule as EventGuard (see the module docstring for the sign convention and what is refused).

guard_kernel(…)

A kernel committing each guard of kernel into event_g<i> (rank 0), every launch-start Mutable read turned into a plain read of the same plane, named <name>_guard; same kind as kernel.

state_guard(…)

A kernel committing each guard of kernel into event_g<i> as a function of the state AFTER the step, named <name>_state_guard: every value the step commits is read back from its own plane (the time plane included), so its vjp() is g_x over the extended state — what a graze test measures at a located event.

Classes

EventGuard

A kernel's stop rule as smooth guards: guards[i] <= 0 is stop rule i firing; rules[i] spells the comparison it came from.