feat: cleanup

This commit is contained in:
Henri Saudubray 2025-04-25 14:25:55 +02:00
parent e07f165494
commit c867859cce
Signed by: hms
GPG key ID: 7065F57ED8856128
3 changed files with 27 additions and 18 deletions

View file

@ -6,6 +6,7 @@ open State
module LazySim (S : SimState) =
struct
(** "Lazy" simulation of a model with an appropriate solver. *)
let run
(HNode model : ('p, 'a, 'b, 'y, 'yder, 'zin, 'zout) hnode)
(DNode solver : ('y, 'yder, 'zin, 'zout) solver)
@ -64,6 +65,8 @@ module LazySim (S : SimState) =
S.update ms ss (S.set_idle s) in
DNode { state; step; reset }
(** Run the model on the given input until the end of the input or until the
model stops answering. *)
let run_on model solver input use =
let DNode sim = run model solver in
let state = match sim.step sim.state (Some input) with
@ -75,6 +78,8 @@ module LazySim (S : SimState) =
| Some o -> use o; loop (DNode { s with state }) in
loop (DNode { sim with state })
(** Run the model autonomously until [length], or until the model stops
answering. *)
let run_until model solver length =
run_on model solver { start = 0.0; length; u = fun _ -> () }