Publish fresh front perception before supplementary neural views
This commit is contained in:
@@ -87,3 +87,18 @@ def test_perception_evidence_rejects_preview_resolution(tmp_path):
|
||||
with pytest.raises(ValueError, match="exact 800x600"):
|
||||
archive_perception(tmp_path, result)
|
||||
assert not list(tmp_path.iterdir())
|
||||
|
||||
|
||||
def test_fresh_supplement_archives_its_own_geometry(tmp_path):
|
||||
front, extra = view(10, 10, 0), view(11, 11, 90)
|
||||
extra["observation"].update(captured_at=124., pose=[2, 2, .37, 0, 0, 0, 1],
|
||||
points=np.array([[2., 3., 4.]]), lens_depths=np.ones((2, 4, 4)),
|
||||
range_rays={"origins": np.array([[2., 2., 1.]])})
|
||||
front["supplement"] = extra
|
||||
records = archive_perception(tmp_path, front)
|
||||
assert records[1]["file"] == "00000011.supplement.perception.npz"
|
||||
with np.load(tmp_path / records[1]["file"], allow_pickle=False) as saved:
|
||||
for key, source in (("range_points", "points"), ("lens_depths", "lens_depths")):
|
||||
np.testing.assert_array_equal(saved[key], extra["observation"][source])
|
||||
np.testing.assert_array_equal(saved["range_rays.origins"], [[2., 2., 1.]])
|
||||
assert json.loads(str(saved["metadata_json"]))["captured_at"] == 124.
|
||||
|
||||
@@ -0,0 +1,120 @@
|
||||
"""Fresh front/side captures must remain causal across slow neural passes."""
|
||||
import copy
|
||||
import importlib
|
||||
from pathlib import Path
|
||||
from types import SimpleNamespace
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def modules(monkeypatch):
|
||||
monkeypatch.syspath_prepend(str(Path(__file__).parents[1] / "simulation/ai-polygon"))
|
||||
return (importlib.import_module("continuous_composition"),
|
||||
importlib.import_module("continuous_pipeline"))
|
||||
|
||||
|
||||
def observation(stamp, x):
|
||||
return dict(captured_at=stamp, pose=[x, 0, 0, 0, 0, 0, 1],
|
||||
simulation_time_ns=int(stamp*1e9), lens_depths=[x], calibration={})
|
||||
|
||||
|
||||
def test_front_is_published_before_supplement_with_distinct_capture_identity(modules, monkeypatch):
|
||||
composition, _ = modules
|
||||
model = object.__new__(composition.ContinuousComposition)
|
||||
model.recovery_view_request = dict(key="recovery-1-2-90", yaw_degrees=90, after_seconds=9.)
|
||||
model.supplement_yaw = None
|
||||
model.last_supplement = -100.
|
||||
model.recovery_detection_view = None
|
||||
old, fresh = observation(10., 1.), observation(10.6, 2.)
|
||||
now = [10.]
|
||||
monkeypatch.setattr(composition.time, "monotonic", lambda: now[0])
|
||||
published = []
|
||||
def infer(obs, frame, yaw, **kwargs):
|
||||
if yaw:
|
||||
assert len(published) == 1
|
||||
assert obs is fresh and frame == 106
|
||||
assert "recovery_view" not in published[0]
|
||||
now[0] += .6
|
||||
return dict(observation=obs, frame_id=frame, samples=dict(frame_id=f"{frame}:{yaw}"),
|
||||
values={}, completed_at=now[0])
|
||||
model.perceive_view = infer
|
||||
def publish(front):
|
||||
published.append(front)
|
||||
return True
|
||||
result = model.perceive(old, 100, publish_front=publish, latest_sensor=lambda: (106, fresh))
|
||||
early = published[0]
|
||||
assert len(early["semantic_observations"]) == len(early["detection_views"]) == 1
|
||||
assert "supplement" not in early and "recovery_view" not in early
|
||||
assert result["observation"] is old
|
||||
assert result["supplement"]["observation"] is fresh
|
||||
assert result["recovery_observation"] is fresh
|
||||
assert result["semantic_observations"] == [early["samples"], dict(frame_id="106:90")]
|
||||
assert [v["observation"]["captured_at"] for v in result["detection_views"]] == [10., 10.6]
|
||||
assert result["recovery_view"] == model.recovery_view_request
|
||||
# Publishing completion must not advance either capture timestamp.
|
||||
assert now[0] == pytest.approx(11.2)
|
||||
assert [old["captured_at"], fresh["captured_at"]] == [10., 10.6]
|
||||
|
||||
|
||||
def test_pause_fences_inflight_front_and_does_not_start_side_inference(modules, tmp_path):
|
||||
composition, pipeline_module = modules
|
||||
pipeline = pipeline_module.ContinuousPipeline(None, tmp_path)
|
||||
pipeline.enable(True)
|
||||
epoch = pipeline.epoch
|
||||
obs = observation(10., 1.)
|
||||
pipeline.submit(None, 1, 10., 10_000_000_000, obs)
|
||||
assert pipeline.latest_sensor(epoch) == (1, obs)
|
||||
model = object.__new__(composition.ContinuousComposition)
|
||||
model.recovery_view_request = dict(key="side", yaw_degrees=90)
|
||||
model.supplement_yaw = None
|
||||
model.last_supplement = -100.
|
||||
model.recovery_detection_view = None
|
||||
calls = []
|
||||
def infer(observation, frame, yaw):
|
||||
calls.append(yaw)
|
||||
pipeline.enable(False)
|
||||
return dict(observation=observation, samples={}, values={})
|
||||
model.perceive_view = infer
|
||||
model.perceive(obs, 1, publish_front=lambda value: pipeline.publish_perception(epoch, value),
|
||||
latest_sensor=lambda: pipeline.latest_sensor(epoch))
|
||||
assert calls == [0] and pipeline.perception is None
|
||||
assert pipeline.latest_sensor(epoch) is None
|
||||
pipeline.enable(True)
|
||||
assert not pipeline.publish_perception(epoch, {})
|
||||
assert pipeline.perception is None
|
||||
|
||||
|
||||
def test_recovery_acknowledges_the_side_capture_pose_and_time(modules):
|
||||
composition, _ = modules
|
||||
model = object.__new__(composition.ContinuousComposition)
|
||||
front, side, live = observation(10., 1.), observation(10.6, 2.), observation(11., 3.)
|
||||
calls = []
|
||||
model.mission = SimpleNamespace(recovery=SimpleNamespace(active=False,
|
||||
observe_view=lambda *args: calls.append(args)), orientation_target=lambda: None)
|
||||
model.source = SimpleNamespace(lens_depths=None)
|
||||
model.static_values = {}
|
||||
model.inputs = {}
|
||||
model.goal = None
|
||||
model.observed_goals = SimpleNamespace(evidence={})
|
||||
model.graph = SimpleNamespace(sha256="graph", nodes=[SimpleNamespace(
|
||||
module=SimpleNamespace(module_id="nav", group="motion"))])
|
||||
model.navigation_evidence = {}
|
||||
model.plan_mission = lambda values: {}
|
||||
submitted = []
|
||||
def navigate(values):
|
||||
submitted.append(copy.copy(values))
|
||||
return {"motion.command": {}, "motion.path": []}
|
||||
model.navigate = navigate
|
||||
def view(obs):
|
||||
return dict(observation=obs, values={"detection.boxes": [], "navigation.surface": []})
|
||||
request = dict(key="side", yaw_degrees=90)
|
||||
perception = dict(observation=front, values={}, rgb=None, semantic_observations=[],
|
||||
detection_views=[view(front), view(side)], recovery_view=request,
|
||||
recovery_observation=side, module_ms={}, frame_id=100)
|
||||
live["points"] = []
|
||||
model.navigate_latest(live, perception, "current")
|
||||
assert calls == [(request, side["pose"], 10.6)]
|
||||
assert submitted[0]["source.pose"] == live["pose"]
|
||||
assert submitted[0]["source.camera.lens-depths"] == front["lens_depths"]
|
||||
assert [v["lens_depths"] for v in submitted[0]["source.detection-views"]] == [[1.], [2.]]
|
||||
Reference in New Issue
Block a user