Allow bounded physics catch-up beyond sensor acquisition overhead
This commit is contained in:
@@ -26,8 +26,8 @@ def main():
|
|||||||
parser.add_argument("--source", type=Path, required=True)
|
parser.add_argument("--source", type=Path, required=True)
|
||||||
parser.add_argument("--stream-address", required=True)
|
parser.add_argument("--stream-address", required=True)
|
||||||
parser.add_argument("--no-stream", action="store_true", help="Qualify sensors without WebRTC")
|
parser.add_argument("--no-stream", action="store_true", help="Qualify sensors without WebRTC")
|
||||||
parser.add_argument('--catch-up-mode', choices=['sensor-period-catchup', 'render-period-catchup'],
|
parser.add_argument('--catch-up-mode', choices=['bounded-wall-catchup', 'sensor-period-catchup', 'render-period-catchup'],
|
||||||
default='sensor-period-catchup', help='Native scheduling qualification')
|
default='bounded-wall-catchup', help='Native scheduling qualification')
|
||||||
args, _ = parser.parse_known_args()
|
args, _ = parser.parse_known_args()
|
||||||
root = Path(__file__).resolve().parents[2]
|
root = Path(__file__).resolve().parents[2]
|
||||||
sys.path.insert(0, str(root / "src"))
|
sys.path.insert(0, str(root / "src"))
|
||||||
|
|||||||
@@ -19,21 +19,21 @@ def _positive(value, name):
|
|||||||
|
|
||||||
|
|
||||||
def build_scheduling_policy(*, continuous, physics_dt, capture_hz, main_loop_hz,
|
def build_scheduling_policy(*, continuous, physics_dt, capture_hz, main_loop_hz,
|
||||||
catch_up_mode="sensor-period-catchup"):
|
catch_up_mode="bounded-wall-catchup"):
|
||||||
"""Bound native catch-up by one sensor acquisition period, not display FPS.
|
"""Allow one acquisition period of scheduling jitter before dropping time.
|
||||||
|
|
||||||
For fractional acquisition/display rates, round only the native setting upward;
|
A clamp of exactly one sensor period assumes the entire synchronous loop
|
||||||
the requested loop and sensor cadences are unchanged. The ceil step bound is a
|
fits that period. RGB/range acquisition also consumes wall time; a loop just
|
||||||
conservative runtime guard, not a promise that every update executes that
|
over 100ms was clamped to six 60Hz steps on every update and could never
|
||||||
many steps. 60Hz physics/10Hz sensing gives a six-step cap. Display-rate catch-up
|
catch up. Two acquisition periods provide bounded headroom while keeping
|
||||||
remains available for qualification against the previous two-step clamp.
|
every native physics step and its fresh-command gate. This does not queue
|
||||||
Explicit legacy-wall-catchup permits a same-build continuous A/B comparison;
|
sensor frames or change physics dt, the sensor cadence, or wall leases.
|
||||||
noncontinuous execution always retains the legacy one-Hz clamp.
|
The earlier clamps remain explicit qualification modes. Noncontinuous
|
||||||
Existing execution-input validation owns the supported capture-rate range.
|
execution retains its original one-Hz clamp.
|
||||||
"""
|
"""
|
||||||
if type(continuous) is not bool:
|
if type(continuous) is not bool:
|
||||||
raise ValueError("Invalid scheduling continuous mode")
|
raise ValueError("Invalid scheduling continuous mode")
|
||||||
if catch_up_mode not in ("sensor-period-catchup", "render-period-catchup", "legacy-wall-catchup"):
|
if catch_up_mode not in ("bounded-wall-catchup", "sensor-period-catchup", "render-period-catchup", "legacy-wall-catchup"):
|
||||||
raise ValueError("Invalid scheduling catch-up mode")
|
raise ValueError("Invalid scheduling catch-up mode")
|
||||||
physics_dt = _positive(physics_dt, "physics dt")
|
physics_dt = _positive(physics_dt, "physics dt")
|
||||||
capture_hz = _positive(capture_hz, "capture rate")
|
capture_hz = _positive(capture_hz, "capture rate")
|
||||||
@@ -42,7 +42,9 @@ def build_scheduling_policy(*, continuous, physics_dt, capture_hz, main_loop_hz,
|
|||||||
effective_mode = catch_up_mode if continuous else "legacy-wall-catchup"
|
effective_mode = catch_up_mode if continuous else "legacy-wall-catchup"
|
||||||
render_period = effective_mode == "render-period-catchup"
|
render_period = effective_mode == "render-period-catchup"
|
||||||
sensor_period = effective_mode == "sensor-period-catchup"
|
sensor_period = effective_mode == "sensor-period-catchup"
|
||||||
minimum = math.ceil(capture_hz) if sensor_period else math.ceil(main_loop_hz) if render_period else 1
|
bounded_wall = effective_mode == "bounded-wall-catchup"
|
||||||
|
minimum = (max(1, math.ceil(capture_hz / 2)) if bounded_wall else
|
||||||
|
math.ceil(capture_hz) if sensor_period else math.ceil(main_loop_hz) if render_period else 1)
|
||||||
maximum_steps = math.ceil(physics_hz / minimum)
|
maximum_steps = math.ceil(physics_hz / minimum)
|
||||||
return dict(
|
return dict(
|
||||||
schema_version=SCHEMA,
|
schema_version=SCHEMA,
|
||||||
@@ -60,8 +62,8 @@ def build_scheduling_policy(*, continuous, physics_dt, capture_hz, main_loop_hz,
|
|||||||
max_physics_steps_per_update=maximum_steps,
|
max_physics_steps_per_update=maximum_steps,
|
||||||
max_requested_physics_interval_seconds=1 / minimum,
|
max_requested_physics_interval_seconds=1 / minimum,
|
||||||
max_integrated_seconds_per_update=maximum_steps * physics_dt,
|
max_integrated_seconds_per_update=maximum_steps * physics_dt,
|
||||||
derivation=("ceil-sensor-rate" if sensor_period else "ceil-main-loop-rate" if render_period else "legacy-one-hz-clamp"),
|
derivation=("two-acquisition-periods" if bounded_wall else "ceil-sensor-rate" if sensor_period else "ceil-main-loop-rate" if render_period else "legacy-one-hz-clamp"),
|
||||||
native_rate_rounding=("up-to-integer" if sensor_period or render_period else "none"),
|
native_rate_rounding=("up-to-integer" if bounded_wall or sensor_period or render_period else "none"),
|
||||||
step_bound_rounding="ceil-conservative-verify-native-counts",
|
step_bound_rounding="ceil-conservative-verify-native-counts",
|
||||||
overload_policy="discard-excess-wall-time-demand-and-report-lower-rtf",
|
overload_policy="discard-excess-wall-time-demand-and-report-lower-rtf",
|
||||||
simulation_clock="sum-completed-physics-dt",
|
simulation_clock="sum-completed-physics-dt",
|
||||||
|
|||||||
@@ -42,3 +42,24 @@ def test_invalid_clocks_and_rates_are_rejected(cadence):
|
|||||||
cadence(10, float("nan"))
|
cadence(10, float("nan"))
|
||||||
with pytest.raises(ValueError):
|
with pytest.raises(ValueError):
|
||||||
cadence(10, 0.).due(float("nan"))
|
cadence(10, 0.).due(float("nan"))
|
||||||
|
|
||||||
|
|
||||||
|
def test_physics_catchup_has_headroom_for_acquisition_without_changing_clocks(monkeypatch):
|
||||||
|
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
|
||||||
|
build = importlib.import_module("scheduling_policy").build_scheduling_policy
|
||||||
|
settings = dict(continuous=True, physics_dt=1/60, capture_hz=10, main_loop_hz=30)
|
||||||
|
candidate = build(**settings)
|
||||||
|
prior = build(**settings, catch_up_mode="sensor-period-catchup")
|
||||||
|
assert candidate["physics_dt_seconds"] == prior["physics_dt_seconds"] == 1/60
|
||||||
|
assert candidate["capture_hz"] == prior["capture_hz"] == 10
|
||||||
|
assert candidate["freshness_clock"] == prior["freshness_clock"]
|
||||||
|
assert candidate["min_simulation_frame_rate_hz"] == 5
|
||||||
|
assert candidate["max_physics_steps_per_update"] == 12
|
||||||
|
assert candidate["max_integrated_seconds_per_update"] == pytest.approx(.2)
|
||||||
|
# A measured ~125ms loop needs 7 or 8 steps. The former six-step
|
||||||
|
# clamp discarded time even though there was room to integrate it.
|
||||||
|
demanded = [7, 8, 7, 8]
|
||||||
|
assert sum(min(n, prior["max_physics_steps_per_update"]) for n in demanded) == 24
|
||||||
|
assert sum(min(n, candidate["max_physics_steps_per_update"]) for n in demanded) == 30
|
||||||
|
legacy = build(**{**settings, "continuous":False})
|
||||||
|
assert legacy["min_simulation_frame_rate_hz"] == 1
|
||||||
|
|||||||
Reference in New Issue
Block a user