# SPDX-License-Identifier: Apache-2.0 """Where the tests find data that does not ship in code/: the AutowareFoundation/lidar_centerpoint weights, the research scripts and goldens of the workspace, the git-ignored PandaSet sample staging copy, and the bundle's own small goldens. Missing data skips the test that needs it in the container image and in a Hub clone, which have neither the workspace nor, offline, the weights; inside the workspace (``in_workspace``) it FAILS (``missing``), so that no frozen gate is ever evaluated on less data than it was frozen on (VERIFY_PORT round 2 L4). - weights: ``$CENTERPOINT_WEIGHTS_DIR`` (holds base/ and tiny/), else the workspace download ``assets/centerpoint/hf_lidar_centerpoint`` (sha256-verified, S:centerpoint:74-91), else the local HF cache snapshot at the pinned revision (``local_files_only``: tests never download); - research: ``$CENTERPOINT_RESEARCH_DIR``, else ``research/centerpoint`` of the workspace; - large goldens: ``$CENTERPOINT_GOLDEN_DIR``, else ``research/centerpoint/goldens`` (never shipped); - samples (``sample_path``): the shipped ``samples/`` (``test_pcd.npz``, Apache-2.0), then the git-ignored ``staging_samples_pandaset/`` of the bundle (``pandaset_019_f40.npz`` and its stored references: PandaSet-derived, not shipped until the user approves PandaSet samples, research/DATASETS.md N5; ``code/scripts/make_samples.py`` and ``make_goldens.py`` write it). The frame catalogue at the end names the development frames (``test_e2e_device.py``, ``DEV_FRAMES``) and the held-out frames (``test_heldout_device.py``, ``heldout_frames``, ``HELDOUT_COUNTS``) shared by the tests and ``code/scripts/make_goldens.py``; their counts are pinned. """ from __future__ import annotations import os import sys from pathlib import Path from typing import Optional import pytest PKG_DIR = Path(__file__).resolve().parents[1] SAMPLES = PKG_DIR / "samples" GOLDENS = Path(__file__).resolve().parent / "goldens" WORKSPACE = Path("/home/ubuntu/experiments/tt-models") BUNDLE_DIR = PKG_DIR.parents[1] # PandaSet 019 frames 40 + 39 (CC BY 4.0 + PandaSet Dataset Terms): staged next to code/, not shipped, until the user # approves PandaSet-derived samples (research/DATASETS.md N5). It stays the frame of the frozen ``.sample.*`` gates # of test_e2e_device.py and a development frame; staging_samples_pandaset/README.md has the swap-in steps. PANDASET_STAGING = BUNDLE_DIR / "staging_samples_pandaset" SAMPLE_PANDASET_NAME = "pandaset_019_f40.npz" SAMPLE_TESTPCD = SAMPLES / "test_pcd.npz" # the shipped sample: autoware_universe test.pcd (Apache-2.0) def _first_dir(*candidates: Optional[Path]) -> Optional[Path]: for c in candidates: if c is not None and c.is_dir(): return c return None def in_workspace() -> bool: """True on the machine that holds the port's research data (``research/centerpoint`` with its scripts).""" env = os.environ.get("CENTERPOINT_RESEARCH_DIR") d = _first_dir(Path(env) if env else None, WORKSPACE / "research" / "centerpoint") return d is not None and (d / "scripts" / "centerpoint_ref.py").is_file() def missing(message: str): """Missing test data: FAIL inside the workspace (a gate must never run on less data than it was frozen on), skip elsewhere (a Hub clone or the container image has no workspace data).""" if in_workspace(): pytest.fail(f"{message} [inside the workspace missing test data is an error, not a skip]") pytest.skip(message) def find_sample(name: str) -> Optional[Path]: """A sample file by name (input or stored reference): the shipped ``samples/``, then the PandaSet staging copy.""" for d in (SAMPLES, PANDASET_STAGING): if (d / name).is_file(): return d / name return None def sample_path(name: str) -> Path: """:func:`find_sample`, or :func:`missing` (fail in the workspace, skip elsewhere).""" p = find_sample(name) if p is None: missing(f"sample {name} found neither in {SAMPLES} nor in {PANDASET_STAGING} (code/scripts/make_samples.py; " "the stored references: code/scripts/make_goldens.py)") return p def pandaset_sample() -> Path: """The PandaSet 019 f40 sample (213,007 points, 2 sweeps, 26,730 pillars): ``samples/`` once it ships, until then the staging copy.""" return sample_path(SAMPLE_PANDASET_NAME) def find_weights_dir() -> Optional[Path]: env = os.environ.get("CENTERPOINT_WEIGHTS_DIR") found = _first_dir(Path(env) if env else None, WORKSPACE / "assets" / "centerpoint" / "hf_lidar_centerpoint") if found is not None and (found / "base" / "pts_backbone_neck_head.onnx").is_file(): return found try: from huggingface_hub import snapshot_download from tt_centerpoint.api import CenterPoint snap = Path(snapshot_download(CenterPoint.DEFAULT_REPO, revision=CenterPoint.DEFAULT_REVISION, allow_patterns=list(CenterPoint.ALLOW_PATTERNS), local_files_only=True)) if (snap / "base" / "pts_backbone_neck_head.onnx").is_file(): return snap except Exception: # noqa: BLE001 -- not cached / no huggingface_hub: the caller skips pass return None def weights_dir() -> Path: d = find_weights_dir() if d is None: missing("lidar_centerpoint weights not found (set CENTERPOINT_WEIGHTS_DIR)") return d def research_dir() -> Path: env = os.environ.get("CENTERPOINT_RESEARCH_DIR") d = _first_dir(Path(env) if env else None, WORKSPACE / "research" / "centerpoint") if d is None or not (d / "scripts" / "centerpoint_ref.py").is_file(): pytest.skip("research/centerpoint (the research reference scripts) not found") return d def research_module(name: str): """Import a research script by name (``centerpoint_ref``, ``verify_ort_decode``, ...); their directory is workspace code, not a download.""" scripts = str(research_dir() / "scripts") if scripts not in sys.path: sys.path.insert(0, scripts) import importlib return importlib.import_module(name) def golden_dir() -> Path: env = os.environ.get("CENTERPOINT_GOLDEN_DIR") d = _first_dir(Path(env) if env else None, WORKSPACE / "research" / "centerpoint" / "goldens") if d is None: missing("large goldens (research/centerpoint/goldens) not found (code/scripts/make_goldens.py)") return d def rosbag_frames_dir() -> Path: """Decoded Autoware sample-rosbag frames (license unstated: research only, never shipped; S:centerpoint:417).""" d = WORKSPACE / "assets" / "centerpoint" / "derived_sample_rosbag_frames" if not (d / "frame_0151.npz").is_file(): missing("decoded sample-rosbag frames not found (research/centerpoint/scripts/decode_sample_rosbag.py)") return d # ------------------------------------------------------------------------------------- frame catalogue # The development frames: the e2e gates of tests/test_e2e_device.py and the goldens of ``make_goldens.py --set # core`` (the shipped samples, these public frames, two sample-rosbag pairs). The base precision policy was chosen # on them (PORT_LOG.md M3). PUBLIC_CORE = ("pandaset/ps090_f40", "nuscenes/ns_0103_kf20", "nuscenes/ns_0916_kf20", "av2/av2_280269f9_s080", "av2/av2_51bbdd4d_s080", "av2/av2_e13c06cb_s080") SHIPPED_PUBLIC = "pandaset/ps019_f40" # = samples/pandaset_019_f40.npz ROSBAG_CORE = (("rosbag_0151_0150", "frame_0150.npz", "frame_0151.npz", ""), ("rosbag_0181_0180", "frame_0180.npz", "frame_0181.npz", "stats_tmp_180")) # The held-out frames (tests/test_heldout_device.py, ``make_goldens.py --set heldout``): never used to choose a # policy or to freeze a development gate. Every other public input frame of research/centerpoint/public_data # (PandaSet 019 / 090 f30-49, nuScenes key-frames 0 / 39, AV2 sweep 0) and the PLAN.md 2.3 sample-rosbag frames the # development set does not use: 152 + 151 and the statistics pairs (i + 1) + i (181 + 180 is a development frame). ROSBAG_HELDOUT = (("rosbag_0152_0151", "frame_0151.npz", "frame_0152.npz", ""),) + tuple( (f"rosbag_{i + 1:04d}_{i:04d}", f"frame_{i:04d}.npz", f"frame_{i + 1:04d}.npz", f"stats_tmp_{i}") for i in (0, 30, 60, 90, 120, 210, 240, 270)) ROSBAG_DIR = WORKSPACE / "assets" / "centerpoint" / "derived_sample_rosbag_frames" # Pinned counts (VERIFY_PORT round 2 L4): inside the workspace the device tests fail unless they evaluate exactly these. DEV_FRAMES = ("pandaset_019_f40", "test_pcd") + tuple(Path(r).name for r in PUBLIC_CORE) + tuple( r[0] for r in ROSBAG_CORE) # 10 development frames HELDOUT_COUNTS = {"pandaset": 38, "nuscenes": 4, "av2": 3, "rosbag": 9} # 54 held-out frames class Frame: """One validation frame: ``calls()`` loads it as the API's call kwargs (the last entry is the frame; earlier ones prime the server-side stream cache), ``source`` says where it comes from.""" def __init__(self, name: str, dataset: str, loader, source: dict, license: str, shippable: bool = False): self.name, self.dataset, self._loader = name, dataset, loader self.source, self.license, self.shippable = source, license, shippable def calls(self) -> list: return self._loader() def _npy_frame(path: Path, dataset: str, workspace: Path) -> Frame: import json import numpy as np def load(): from tt_centerpoint.ttaw import io as tio return [{"points": tio.PointCloud(np.load(path, allow_pickle=False), ("x", "y", "z", "time_lag"))}] meta = json.loads(path.with_suffix(".json").read_text()) if path.with_suffix(".json").is_file() else {} try: rel = str(path.relative_to(workspace)) except ValueError: rel = str(path) return Frame(path.stem, dataset, load, {"input": rel, "format": "npy_xyzt"}, meta.get("license", "?"), bool(meta.get("shippable", False))) def rosbag_calls(bag: Path, past: str, cur: str, sub: str, stream_id: str) -> list: """The two API calls of a sample-rosbag pair through the server-side stream path (Autoware's 2-sweep densification with the odometry poses): the past sweep primes a fresh stream, the current one is the frame.""" import numpy as np d = bag / sub if sub else bag calls = [] for f in (past, cur): z = np.load(d / f, allow_pickle=False) calls.append({"points": z["points_xyzirc"][:, :3], "stream": {"id": stream_id, "timestamp_s": float(z["stamp"]), "T_world_from_ego": z["world_T_base"], "reset": f == past}}) return calls def heldout_frames(research: Path, bag: Path = ROSBAG_DIR, workspace: Path = WORKSPACE) -> list: """The held-out frames that exist on this machine, in a fixed order (public by dataset / id, then rosbag).""" core = set(PUBLIC_CORE) | {SHIPPED_PUBLIC} out = [] for path in sorted((research / "public_data" / "inputs").glob("*/*.npy")): if f"{path.parent.name}/{path.stem}" not in core: out.append(_npy_frame(path, path.parent.name, workspace)) for name, past, cur, sub in ROSBAG_HELDOUT: if (bag / sub / cur if sub else bag / cur).is_file(): out.append(Frame(name, "rosbag", lambda p=past, c=cur, s=sub, n=name: rosbag_calls(bag, p, c, s, f"heldout_{n}"), {"rosbag": [f"{sub}/{past}" if sub else past, f"{sub}/{cur}" if sub else cur]}, "Autoware sample-rosbag (license unstated): research only")) return out