Skip to content

Real-time mode

Wall-clock-synchronized stepping. llmsim.rt.run paces a simulation against time.monotonic() so simulated time tracks real time by a chosen factor; in strict mode it raises RealtimeDriftError when the run cannot keep up. rt is re-exported as a submodule of the top-level llmsim package; RealtimeDriftError is also re-exported at the top level.

run

run(sim, until=None, *, factor=1.0, strict=True)

Advance sim like :meth:~llmsim.core.sim.Sim.run, paced in real time.

Before processing the event at simulated time T, sleeps until start + (T - t0) * factor on the monotonic clock. until accepts exactly what Sim.run accepts (None, a time, or an event whose value is returned), and the offload seam (post-step poll(), drain on every EmptySchedule while a pool is attached) matches Sim.run's loop -- keep the two in lockstep (see core/sim.py).

Parameters:

Name Type Description Default
sim Sim

The simulation to drive; it runs on the calling thread, which must be the Sim's owning thread.

required
until float | Event[Any] | None

Stop condition, as in Sim.run.

None
factor float

Real seconds per simulated time unit (must be positive).

1.0
strict bool

Raise on drift beyond one factor of slack (default), or hurry without sleeping until caught up (strict=False).

True

Raises:

Type Description
ValueError

if factor is not positive, or until is a time at or before sim.now.

RealtimeDriftError

in strict mode, when processing falls behind.

RuntimeError

if until can never trigger because the schedule emptied first (identical to Sim.run).

RealtimeDriftError

RealtimeDriftError(simulated_time, drift)

Bases: SimulationError

The paced run fell behind the wall-clock schedule (strict mode).

Raised by :func:run when the next event's wall deadline has passed by more than one factor unit of slack. Carries the event's simulated time and the measured drift in wall-clock seconds; drift is surfaced, never silently absorbed (docs-honesty rule).

Drift is always measured against the next event's deadline (SimPy 3's rule): an overrun inside the final event's callbacks ends the run late but raises nothing (there is no schedule left to fall behind), and wall time spent draining non-strict offloads after the schedule empties is exempt -- non-strict delivery is wall-clock-driven by its own contract.

Store the slipped event's simulated time and the drift seconds.

simulated_time property

simulated_time

The simulated time of the event that missed its wall deadline.

drift property

drift

How many wall-clock seconds behind schedule processing fell.