Skip to main content

engine.solvers.realtime

engine.solvers.realtime

Real-time solvers: the timed path between a learned proposer and the drives.

Domain implementations behind mlsysim.solvers (the public import path, derived from engine.solvers.__init__). The equations live in physics.robotics.control (phase lag of a delay, response-time bound, CAN FD and EtherCAT serialization, the lease ceiling) and physics.robotics.stopping; these models compose them for one stated situation (added 2026-10-20).

Classes

Name Description
CanFdBusModel Serialization occupancy of a cyclic CAN FD exchange: frames x t_frame against the cycle.
CommandAuthenticationModel Authentication of a remote command as one more pre-brake delay, and a flood of forgeries.
EtherCatCycleModel One EtherCAT summation frame through a chain of drives (calc_ethercat_cycle_time).
LeaseBudgetModel A chunk lease as a term of the stopping budget, bounded by the lease rule.
PhaseLagBudgetModel Phase a sampled loop spends on delay at its crossover frequency.
ResponseTimeModel Response-time bound of one periodic task, R = C + B + I, against its deadline.
SharedDramReadModel A permission tick’s snapshot read behind FIFO backlogs on a shared DRAM controller.
ThermalThrottleModel A tick on a governed clock: a thermal trip reduces the clock until the junction clears.

CanFdBusModel

engine.solvers.realtime.CanFdBusModel()

Serialization occupancy of a cyclic CAN FD exchange: frames x t_frame against the cycle.

Frame time and bits come from calc_canfd_bus_utilization (ISO 11898-1:2015 frame format, worst-case stuffing by default). Occupancy is a necessary check only; blocking and retransmission need a response-time analysis. axes_capacity is the most axes whose frames fit one cycle.

Methods

Name Description
solve Count CAN FD serialization occupancy within one control cycle.
solve
engine.solvers.realtime.CanFdBusModel.solve(
    num_axes,
    payload_bytes,
    frames_per_axis,
    baud_arbitration,
    baud_data,
    cycle,
)

Count CAN FD serialization occupancy within one control cycle.

Parameters
Name Type Description Default
num_axes int Positive number of axes sharing this bus. required
payload_bytes int Application bytes per frame, from zero through 64; padded to a legal CAN FD data-field size. required
frames_per_axis int Positive number of command/feedback frames per axis per cycle. required
baud_arbitration Quantity Positive nominal-phase bit rate, convertible to bit/s. required
baud_data Quantity Positive data-phase bit rate, convertible to bit/s. required
cycle Quantity Positive cycle duration in time units. required
Returns
Name Type Description
CanFdBusResult Frame bit counts, times in microseconds, utilization fraction, and axes_capacity. fits is a serialization-only occupancy check.
See Also

mlsysim.physics.robotics.control.calc_canfd_bus_utilization : CAN FD frame accounting and serialization.

Notes

Equation: t_frame = bits_nominal/baud_arbitration + bits_data/baud_data; occupancy = num_axes*frames_per_axis*t_frame; axes_capacity = floor(cycle/(frames_per_axis*t_frame)).

Assumptions: Standard identifiers, worst-case dynamic stuffing, and the frame-format accounting of calc_canfd_bus_utilization; all frames have the supplied payload.

Excludes: Competing traffic, nonpreemptive blocking, retransmissions, and a schedulability guarantee.

References

Derivation: serialization time is bit count divided by bit rate, summed across the nominal and data phases. Frame-format assumptions are documented in the linked physics function.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import CanFdBusModel
>>> result = CanFdBusModel().solve(1, 8, 2, Q_(1, "Mbit/s"),
...     Q_(5, "Mbit/s"), Q_(1, "ms"))
>>> bool(result.fits and result.axes_capacity >= 1)
True

CommandAuthenticationModel

engine.solvers.realtime.CommandAuthenticationModel()

Authentication of a remote command as one more pre-brake delay, and a flood of forgeries.

A supplied cycle count divided by the permission processor’s clock gives the time of one signature verification and of a MAC over a frame of mac_blocks cipher blocks. Verification adds to the delay before a remote stop can act, so each millisecond is travel at speed against the finished budget’s spare; a replay at the edge of the freshness window carries the machine v x tau_fresh. Verified serially, n forged signed packets queued ahead of a valid veto finish it at (n + 1) t_verify; the fewest that push it past the deadline is n = floor(T_latest / t_verify), with sustained verifier saturation at ceil(1 / t_verify) packets per second (added 2026-10-20).

Methods

Name Description
solve Charge serial authentication work against a remote-command deadline.
solve
engine.solvers.realtime.CommandAuthenticationModel.solve(
    clock,
    verify_cycles,
    mac_block_cycles,
    mac_blocks,
    speed,
    spare,
    deadline,
    deadline_after_admission,
    freshness_window,
)

Charge serial authentication work against a remote-command deadline.

Parameters
Name Type Description Default
clock Quantity Positive verification-processor clock frequency in Hz. required
verify_cycles float Positive assumed cycle count for one signature verification. required
mac_block_cycles float Positive assumed cycle count for authenticating one cipher block. required
mac_blocks int Positive cipher-block count per authenticated command. required
speed Quantity Nonnegative machine speed held during verification and freshness delays. required
spare Quantity Remaining distance allowance before adding authentication delay. required
deadline Quantity Positive total command-verification deadline. required
deadline_after_admission Quantity Positive verification allowance for a command already admitted. required
freshness_window Quantity Nonnegative maximum age accepted by the command freshness check. required
Returns
Name Type Description
CommandAuthenticationResult Signature time in ms, MAC time in microseconds, travel in mm, and forged-packet counts/rate. Negative remaining spare denotes budget exhaustion.
See Also

mlsysim.physics.quantities.compute_time : Work divided by service rate.

Notes

Equation: t_sig = verify_cycles/clock; t_mac = mac_blocks*mac_block_cycles/clock; travel = speed*time; n = floor(deadline/t_sig) forged commands queued ahead of the veto delay it until (n+1)*t_sig; sustaining a non-draining backlog requires an injection rate at or above the serial service rate ceil(1/t_sig).

Assumptions: Cycle counts are supplied, verification is serial, and each forged signed packet consumes a full verification before rejection.

Excludes: Cryptographic security strength, early rejection, parallel verification, network admission controls, and a deployed-system timing guarantee.

References

Derivation: convert cycles to time at a fixed clock and count serial service slots before the deadline; integrate constant speed over that delay.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import CommandAuthenticationModel
>>> result = CommandAuthenticationModel().solve(Q_(1, "MHz"), 1000, 10, 1,
...     Q_(1, "m/s"), Q_(1, "m"), Q_(10, "ms"), Q_(5, "ms"), Q_(1, "ms"))
>>> bool(result.veto_verified_at > result.deadline)
True

EtherCatCycleModel

engine.solvers.realtime.EtherCatCycleModel()

One EtherCAT summation frame through a chain of drives (calc_ethercat_cycle_time).

The frame carries every axis’s process data; each node forwards it with a fixed hop delay, so occupancy is serialization plus forwarding.

Methods

Name Description
solve Budget one summation frame through an EtherCAT drive chain.
solve
engine.solvers.realtime.EtherCatCycleModel.solve(
    num_axes,
    bytes_per_axis,
    baud_rate,
    header_bytes,
    hop_delay,
    cycle,
)

Budget one summation frame through an EtherCAT drive chain.

Parameters
Name Type Description Default
num_axes int Positive number of nodes traversed by the frame. required
bytes_per_axis int Positive process-data payload bytes contributed by each node. required
baud_rate Quantity Positive link bit rate, convertible to bit/s. required
header_bytes int Nonnegative total framing overhead in bytes, supplied by the caller. required
hop_delay Quantity Nonnegative forwarding time per node. required
cycle Quantity Positive control-cycle duration. required
Returns
Name Type Description
EtherCatCycleResult Serialization, forwarding, occupancy, and margin times; dimensionless utilization and fits comparing total occupancy with cycle.
See Also

mlsysim.physics.robotics.control.calc_ethercat_cycle_time : Summation-frame occupancy.

Notes

Equation: occupancy = 8*(header_bytes + num_axes*bytes_per_axis)/baud_rate + num_axes*hop_delay; utilization = occupancy/cycle.

Assumptions: One frame carries all process data and each node adds a fixed forwarding delay.

Excludes: Cable propagation unless included in hop_delay, multi-frame fragmentation, host jitter, and protocol error recovery.

References

Derivation: transmit all frame bits at the declared line rate, then add the per-node forwarding budgets along the chain.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import EtherCatCycleModel
>>> result = EtherCatCycleModel().solve(2, 32, Q_(100, "Mbit/s"),
...     64, Q_(1, "us"), Q_(1, "ms"))
>>> bool(result.fits and result.unallocated > Q_(0, "us"))
True

LeaseBudgetModel

engine.solvers.realtime.LeaseBudgetModel()

A chunk lease as a term of the stopping budget, bounded by the lease rule.

After the last admission a stalled proposer’s chunk drives on for the lease; the tick that notices expiry and the bus cycle that carries the stop follow, then the brake onset. That interval is travel at speed, added to the braking travel, the localization and margin overhead, and the onset travel (StoppingBudgetModel). The lease rule bounds the lease from both sides:

T_renew + T_jitter  <  T_lease  <=  tau_max - T_tick - T_bus - T_onset - age

where tau_max is the longest pre-brake delay whose stop fits and age is the evidence’s age when the chunk is admitted. The stall timeline puts the stall after the second renewal completes.

Methods

Name Description
solve Bound a command lease using the remaining stopping distance.
solve
engine.solvers.realtime.LeaseBudgetModel.solve(
    speed,
    deceleration,
    clear_distance,
    loc_margin,
    physical_margin,
    brake_onset,
    lease,
    tick,
    bus,
    observation_age,
    admission_age,
    renewal_period,
    renewal_jitter,
    inference_latency,
)

Bound a command lease using the remaining stopping distance.

Parameters
Name Type Description Default
speed Quantity Positive travel speed in length/time units, held constant until braking. required
deceleration Quantity Positive available constant braking deceleration. required
clear_distance Quantity Positive distance available before the protected boundary. required
loc_margin Quantity Nonnegative localization-distance allowance. required
physical_margin Quantity Nonnegative protective distance retained after stopping. required
brake_onset Quantity Nonnegative delay from stop command delivery to braking onset. required
lease Quantity Positive command-validity duration since admission. required
tick Quantity Positive worst-case expiry-detection tick delay. required
bus Quantity Nonnegative stop-command bus delay. required
observation_age Quantity Nonnegative age of evidence for the reported age-adjusted ceiling. required
admission_age Quantity Nonnegative evidence age at admission, used by the fits comparison. required
renewal_period Quantity Positive interval between replacement requests. required
renewal_jitter Quantity Nonnegative additional renewal-lateness allowance. required
inference_latency Quantity Nonnegative inference time used to place the constructed stall timeline. required
Returns
Name Type Description
LeaseBudgetResult Timing budgets in ms and travel in mm. fits checks renewal_period + renewal_jitter < lease <= the admission-age-adjusted ceiling.
See Also

mlsysim.engine.solvers.embodied.StoppingBudgetModel.solve : Distance and delay ceilings.

Notes

Equation: stop distance = speed*(lease + tick + bus + brake_onset) + speed**2/(2*deceleration) + loc_margin + physical_margin. Subtract fixed delays from the distance-derived delay ceiling to obtain the lease ceiling.

Assumptions: Straight-line constant speed before constant-deceleration braking; the constructed stall occurs after the second renewal completes.

Excludes: Jerk ramps, changing obstacles, stochastic delays, and proof that a deployed watchdog or brake meets these budgets.

References

Derivation: integrate constant cruise and braking motion, reserve both distance margins, then isolate the lease term in the stopping-distance inequality.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import LeaseBudgetModel
>>> result = LeaseBudgetModel().solve(Q_(1, "m/s"), Q_(2, "m/s^2"),
...     Q_(2, "m"), Q_(0, "m"), Q_(0, "m"), Q_(10, "ms"),
...     Q_(100, "ms"), Q_(1, "ms"), Q_(1, "ms"), Q_(0, "ms"),
...     Q_(0, "ms"), Q_(50, "ms"), Q_(1, "ms"), Q_(10, "ms"))
>>> bool(result.fits and result.spare > Q_(0, "mm"))
True

PhaseLagBudgetModel

engine.solvers.realtime.PhaseLagBudgetModel()

Phase a sampled loop spends on delay at its crossover frequency.

The hold costs half a sample period, then the compute and transport delays; a pure delay tau removes 360 f_c tau degrees at crossover (calc_phase_lag_total). Against a stated phase allowance the model also gives the largest total delay the allowance absorbs and the highest crossover the delay supports. A budget, not a stability proof.

Methods

Name Description
solve Budget the phase consumed by sampling, computation, and transport.
solve
engine.solvers.realtime.PhaseLagBudgetModel.solve(
    crossover,
    sample_period,
    compute_delay=None,
    transport_delay=None,
    phase_allowance=None,
)

Budget the phase consumed by sampling, computation, and transport.

Parameters
Name Type Description Default
crossover Quantity Positive loop crossover frequency, convertible to Hz. required
sample_period Quantity Positive controller sampling period, convertible to seconds. required
compute_delay Quantity Nonnegative sample-to-output time; None contributes zero delay. None
transport_delay Quantity Nonnegative output-to-actuator time; None contributes zero delay. None
phase_allowance Quantity Positive phase budget in degrees or radians; None omits budget comparisons. None
Returns
Name Type Description
PhaseLagBudgetResult Delays in ms, phases in degrees, and optional crossover ceiling in Hz. The fits flag checks only the stated phase budget.
See Also

mlsysim.physics.robotics.control.calc_phase_lag_total : Delay and phase calculation.

Notes

Equation: tau = sample_period/2 + compute_delay + transport_delay; phase = 360*crossover*tau degrees. The allowance gives tau_max = phase_allowance/(360*crossover).

Assumptions: The zero-order hold is approximated by a half-sample delay well below the sampling frequency; compute and transport are pure delays.

Excludes: Plant poles, controller dynamics, jitter distributions, and a closed-loop stability proof.

References

Derivation: a pure delay has frequency response exp(-j*omega*tau), hence phase loss omega*tau; composing delays adds their phase losses.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import PhaseLagBudgetModel
>>> result = PhaseLagBudgetModel().solve(Q_(10, "Hz"), Q_(1, "ms"),
...     phase_allowance=Q_(30, "degree"))
>>> bool(result.fits and result.total_delay > Q_(0, "ms"))
True

ResponseTimeModel

engine.solvers.realtime.ResponseTimeModel()

Response-time bound of one periodic task, R = C + B + I, against its deadline.

calc_response_time_bound sums the declared WCET, the blocking bound, and the interference bound; the margin and the largest blocking that still meets the deadline follow. With an observed unloaded run, the gap between it and the declared WCET is the claim that timing analysis must justify.

Methods

Name Description
solve Compare a declared response-time bound with a deadline.
solve
engine.solvers.realtime.ResponseTimeModel.solve(
    wcet,
    blocking,
    interference,
    deadline,
    unloaded=None,
)

Compare a declared response-time bound with a deadline.

Parameters
Name Type Description Default
wcet Quantity Nonnegative declared worst-case execution time, convertible to microseconds. required
blocking Quantity Nonnegative declared blocking bound in time units. required
interference Quantity Nonnegative declared higher-priority interference bound in time units. required
deadline Quantity Positive relative deadline in time units. required
unloaded Quantity Observed unloaded execution time; None omits the WCET-minus-observation gap. None
Returns
Name Type Description
ResponseTimeResult Component times and margins in microseconds; meets_deadline is true when the supplied sum is no greater than deadline.
See Also

mlsysim.physics.robotics.control.calc_response_time_bound : Add declared timing bounds.

Notes

Equation: R = wcet + blocking + interference; margin = deadline - R; blocking_limit = deadline - wcet - interference.

Assumptions: The caller supplies independently justified bounds that may be summed for the task under study.

Excludes: Derivation of WCET, priority assignment, interference fixed-point iteration, and certification from an unloaded observation.

References

Derivation: partition response time into execution, blocking, and interference; rearrange R <= deadline to solve each remaining budget.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import ResponseTimeModel
>>> result = ResponseTimeModel().solve(Q_(20, "us"), Q_(5, "us"),
...     Q_(5, "us"), Q_(40, "us"))
>>> bool(result.meets_deadline and result.response + result.margin == Q_(40, "us"))
True

SharedDramReadModel

engine.solvers.realtime.SharedDramReadModel()

A permission tick’s snapshot read behind FIFO backlogs on a shared DRAM controller.

One backlog (a weight tile, a camera transfer, and a telemetry record, at AXI transaction granularity) waits bytes / bandwidth plus its row conflicts (calc_axi_fifo_contention); the tick’s snapshot read follows. Against the sense allowance, the declared WCET, and the execution ceiling (deadline less blocking and interference), each less the compute after sensing, the model counts the most whole backlogs that still fit and the tick’s end time at each count. A FIFO controller is optimistic: a row-hit-first controller can keep passing the read.

Methods

Name Description
solve Budget a snapshot read behind a constructed FIFO memory backlog.
solve
engine.solvers.realtime.SharedDramReadModel.solve(
    tile_bytes,
    camera_bytes,
    telemetry_bytes,
    snapshot_bytes,
    transaction_bytes,
    bandwidth,
    bank_switches,
    bank_switch_time,
    sense,
    compute_after_sense,
    wcet,
    execution_ceiling,
)

Budget a snapshot read behind a constructed FIFO memory backlog.

Parameters
Name Type Description Default
tile_bytes int Positive weight-tile byte count, aligned to transaction_bytes. required
camera_bytes int Positive camera-transfer byte count, aligned to transaction_bytes. required
telemetry_bytes int Positive telemetry-transfer byte count, aligned to transaction_bytes. required
snapshot_bytes int Positive snapshot-read byte count, aligned to transaction_bytes. required
transaction_bytes int Positive transfer granularity in bytes. required
bandwidth Quantity Positive effective transfer rate, convertible to byte/s; a peak rate yields a floor. required
bank_switches int Nonnegative number of bank/row-switch penalties in one backlog. required
bank_switch_time Quantity Nonnegative time charged for each bank switch. required
sense Quantity Nonnegative sensing-time allowance, before post-sense computation. required
compute_after_sense Quantity Nonnegative computation time following the snapshot read. required
wcet Quantity Declared execution-time budget including sensing and computation. required
execution_ceiling Quantity Deadline-derived execution budget after blocking and interference are removed. required
Returns
Name Type Description
SharedDramReadResult Read and completion times in microseconds, transaction counts, and whole-backlog counts. A negative count indicates that even the own-read allowance does not fit.
See Also

mlsysim.physics.robotics.control.calc_axi_fifo_contention : FIFO and bypass transfer accounting.

Notes

Equation: wait = (tile_bytes + camera_bytes + telemetry_bytes)/bandwidth + bank_switches*bank_switch_time; own = snapshot_bytes/bandwidth; unloaded = sense + compute_after_sense; headroom_wcet = wcet - unloaded; headroom_dead = execution_ceiling - unloaded; n = floor((room-own)/wait); end(n) = unloaded + own + n*wait.

Assumptions: The isolated tick sub-costs (sense + compute_after_sense) remain unchanged; moving the snapshot read onto shared DRAM adds own + n*wait on top of the unloaded tick. All declared backlog transfers queue before the snapshot; FIFO prevents new arrivals from overtaking it. Priority bypass waits for one transaction only.

Excludes: Refresh, arbitration inefficiency, row-hit-first starvation, cache behavior, and an AXI service-time guarantee.

References

Derivation: sum serialized byte-transfer and row-switch times, then solve unloaded + own + n*wait <= bound for the largest integer n.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import SharedDramReadModel
>>> result = SharedDramReadModel().solve(tile_bytes=64, camera_bytes=64,
...     telemetry_bytes=64, snapshot_bytes=64, transaction_bytes=64,
...     bandwidth=Q_(1, "GB/s"), bank_switches=0,
...     bank_switch_time=Q_(0, "us"), sense=Q_(10, "us"),
...     compute_after_sense=Q_(1, "us"), wcet=Q_(20, "us"),
...     execution_ceiling=Q_(30, "us"))
>>> bool(result.loaded_read > result.snapshot_read)
True

ThermalThrottleModel

engine.solvers.realtime.ThermalThrottleModel()

A tick on a governed clock: a thermal trip reduces the clock until the junction clears.

The tick is sized to its declared WCET at the nominal clock; the throttled clock stretches the same cycles. The junction is a first-order lumped model, T(t) = T_inf - (T_inf - T_0) exp(-t / tau) with steady state T_amb + P theta; the clock returns only at the clear threshold, so the hysteresis lasts tau ln((T_trip - T_quiet) / (T_clear - T_quiet)) after the load stops (calc_first_order_time_to_temperature).

Methods

Name Description
solve Translate a thermal clock reduction into task response and recovery time.
solve
engine.solvers.realtime.ThermalThrottleModel.solve(
    wcet,
    blocking_and_interference,
    deadline,
    tick,
    nominal_clock,
    throttled_clock,
    time_constant,
    ambient,
    theta,
    quiet_power,
    loaded_power,
    trip,
    clear,
)

Translate a thermal clock reduction into task response and recovery time.

Parameters
Name Type Description Default
wcet Quantity Positive execution time at nominal_clock, excluding blocking and interference. required
blocking_and_interference Quantity Nonnegative combined blocking and interference time. required
deadline Quantity Positive task deadline. required
tick Quantity Positive period used to count complete ticks exposed during recovery. required
nominal_clock Quantity Positive normal clock frequency, convertible to Hz. required
throttled_clock Quantity Positive reduced clock frequency, convertible to Hz. required
time_constant Quantity Positive first-order thermal time constant. required
ambient Quantity Ambient absolute temperature, convertible to kelvin. required
theta Quantity Positive junction-to-ambient thermal resistance in K/W. required
quiet_power Quantity Nonnegative quiet-state dissipation in watts. required
loaded_power Quantity Loaded dissipation in watts, greater than quiet_power. required
trip Quantity Trip temperature above clear and below the loaded equilibrium. required
clear Quantity Recovery temperature above the quiet equilibrium and below trip. required
Returns
Name Type Description
ThermalThrottleResult Execution and response times in microseconds, junction temperatures in degrees Celsius, thermal durations, and whole exposed-tick counts. Overrun may be negative when slack remains.
See Also

mlsysim.physics.motors.calc_first_order_time_to_temperature : First-order thermal threshold crossing.

Notes

Equation: cycles = wcet*nominal_clock; throttled execution = cycles/throttled_clock. T_inf = ambient + power*theta and t = tau*ln((T_inf-T_start)/(T_inf-T_target)).

Assumptions: Fixed instruction-cycle demand, a single lumped thermal pole, step changes in power, and reachable trip/clear thresholds.

Excludes: Memory-bound execution, temperature-dependent leakage, spatial thermal gradients, and governor transition overhead.

References

Derivation: conserve execution cycles across the frequency change; solve the first-order exponential thermal response for each threshold crossing.

Examples
>>> from mlsysim import Q_
>>> from mlsysim.solvers import ThermalThrottleModel
>>> result = ThermalThrottleModel().solve(wcet=Q_(10, "us"),
...     blocking_and_interference=Q_(1, "us"), deadline=Q_(30, "us"),
...     tick=Q_(1, "ms"), nominal_clock=Q_(1, "GHz"),
...     throttled_clock=Q_(0.5, "GHz"), time_constant=Q_(10, "s"),
...     ambient=Q_(300, "K"), theta=Q_(1, "K/W"),
...     quiet_power=Q_(10, "W"), loaded_power=Q_(100, "W"),
...     trip=Q_(350, "K"), clear=Q_(330, "K"))
>>> bool(result.execution_throttled > result.execution and result.recovery > Q_(0, "s"))
True
Back to top