diff --git a/src/k1link/compute/__init__.py b/src/k1link/compute/__init__.py index 22edd2a..7d1454c 100644 --- a/src/k1link/compute/__init__.py +++ b/src/k1link/compute/__init__.py @@ -1,278 +1,282 @@ """Host-owned compute handoff contracts.""" -from .annotation_workspace import ( - ANNOTATION_WORKSPACE_SCHEMA, - AnnotationWorkspace, - AnnotationWorkspaceError, - prepare_annotation_workspace, - validate_annotation_workspace, -) -from .e31_source_qualification import ( - DEFAULT_E31_SOURCE_QUALIFICATION_PROFILE, - E31_BINDING_PROFILE_SCHEMA, - E31_SOURCE_QUALIFICATION_REPORT_SCHEMA, - E31_SOURCE_QUALIFICATION_SCHEMA, - E31SourceQualification, - E31SourceQualificationError, - E31SourceQualificationProfile, - build_e31_source_qualification, -) -from .e32_track_geometry_replay import ( - E32_TRACK_GEOMETRY_RECORD_SCHEMA, - E32_TRACK_GEOMETRY_REPLAY_SCHEMA, - E32_TRACK_GEOMETRY_REPORT_SCHEMA, - E32TrackGeometryReplay, - E32TrackGeometryReplayError, - build_e32_track_geometry_replay, - e32_track_geometry_frame, - read_e32_track_geometry_replay, -) -from .e33_worker_shadow import ( - E33_FRAME_SCHEMA, - E33_OUTCOME_SCHEMA, - E33_PACKAGE_SCHEMA, - E33_PROFILE_SCHEMA, - E33_REPORT_SCHEMA, - E33_RESOURCE_SCHEMA, - E33_RESULT_SCHEMA, - E33WorkerShadowError, - E33WorkerShadowResult, - read_e33_worker_shadow_result, - run_e33_worker_shadow, -) -from .e51_motion_semantic_qualification import ( - E51_FRAME_SCHEMA, - E51_PROFILE_SCHEMA, - E51_REPORT_SCHEMA, - E51_RESULT_SCHEMA, - E51_SIGNAL_SCHEMA, - E51MotionSemanticError, - E51MotionSemanticResult, - build_e51_motion_semantic_qualification, - derive_motion_semantic_signal, - read_e51_motion_semantic_qualification, -) -from .e52_camera_first_restoration import ( - E52_CASE_SCHEMA, - E52_PROFILE_SCHEMA, - E52_REPORT_SCHEMA, - E52_RESULT_SCHEMA, - E52CameraFirstRestoration, - E52CameraFirstRestorationError, - build_e52_camera_first_restoration, - evaluate_camera_first_case, - read_e52_camera_first_restoration, -) -from .evaluation_pack import ( - ANNOTATION_CONTRACT_SCHEMA, - EVALUATION_PACK_SCHEMA, - EvaluationFrameRequest, - EvaluationPackFrame, - RecordedEvaluationPack, - RecordedEvaluationPackError, - prepare_recorded_evaluation_pack, - validate_recorded_evaluation_pack, -) -from .fusion_epoch import ( - RecordedCalibratedFusion, - RecordedCalibratedFusionStore, - RecordedPerceptionOverlayMux, - validate_recorded_calibrated_fusion, -) -from .integrated_perception import ( - IntegratedPerceptionOverlayStore, - IntegratedPerceptionResult, - validate_integrated_perception_result, -) -from .jobs import ( - COMPUTE_JOB_SCHEMA, - CameraComputeJob, - prepare_camera_compute_job, - validate_camera_compute_job, -) -from .lab_instances import ( - PublishedCameraEgoMotionLabInstance, - PublishedIntegratedLabInstance, - PublishedPersistentSupportLabInstance, - PublishedTemporalLabInstance, - PublishedWorldMotionLabInstance, - publish_e21_lab_instance, - publish_e22_lab_instance, - publish_e23_lab_instance, - publish_e24_lab_instance, - publish_e25_lab_instance, - publish_e26_lab_instance, - publish_integrated_lab_instance, -) -from .lidar_contract import ( - K1_LAB_LIDAR_PACK_V1_PROFILE, - K1_LIDAR_PACK_V2_PROFILE, - K1_LIVE_LIDAR_PROFILE, - LIDAR_EVIDENCE_PROFILE_SCHEMA, - LIDAR_READINESS_SCHEMA, - LidarContractError, - LidarCoordinateSpace, - LidarEvidenceProfile, - LidarPipelineStage, - LidarPointField, - LidarPoseStatus, - LidarQualityMonitor, - LidarReadiness, - LidarRepresentation, - LidarStageAssessment, - LidarTimeBasis, - assess_lidar_profile, - lidar_readiness_document, - sensor_frame_xyzi, -) -from .lidar_field_review import ( - E10_LIDAR_PACK_SCHEMA, - FIELD_REVIEW_ARRAYS_NAME, - FIELD_REVIEW_MANIFEST_NAME, - FIELD_REVIEW_REPORT_NAME, - LIDAR_FIELD_REVIEW_REPORT_SCHEMA, - LIDAR_FIELD_REVIEW_SCHEMA, - LIDAR_FIELD_REVIEW_WINDOW_SCHEMA, - MAX_FIELD_REVIEW_WINDOW_POINTS, - RAVNOVES00_CENTRAL_WINDOWS, - E10LidarFieldSource, - FieldReviewWindowSpec, - LidarFieldReviewV1, - build_lidar_field_review, - lidar_field_review_catalog_item, -) -from .lidar_ground import ( - DEFAULT_GROUND_BENCHMARK_PROFILE, - LIDAR_GROUND_ANNOTATION_TEMPLATE_SCHEMA, - LIDAR_GROUND_BENCHMARK_REPORT_SCHEMA, - LIDAR_GROUND_BENCHMARK_SCHEMA, - LIDAR_GROUND_FRAME_SCHEMA, - PATCHWORKPP_SOURCE_COMMIT, - PATCHWORKPP_SOURCE_TAG, - PATCHWORKPP_SOURCE_URL, - GroundBenchmarkProfile, - GroundSegmentation, - LidarGroundBenchmarkV1, - LidarGroundError, - LocalPercentileGroundSegmenter, - PatchworkPPGroundSegmenter, - build_lidar_ground_annotation_template, - build_lidar_ground_benchmark, - lidar_ground_benchmark_catalog_item, - lidar_ground_frame_detail, - score_ground_labels, -) -from .lidar_local_surface import ( - DEFAULT_K1_LOCAL_SURFACE_PROFILE, - K1_LOCAL_SURFACE_FRAME_SCHEMA, - K1_LOCAL_SURFACE_REPORT_SCHEMA, - K1_LOCAL_SURFACE_REVIEW_SCHEMA, - K1_LOCAL_SURFACE_SCHEMA, - K1_LOCAL_SURFACE_TIMELINE_SCHEMA, - K1LocalSurfaceProfile, - K1LocalSurfaceV1, - build_k1_local_surface, - k1_local_surface_catalog_item, -) -from .lidar_local_surface_shadow import ( - K1_LOCAL_SURFACE_BINDER_SCHEMA, - K1_LOCAL_SURFACE_SHADOW_FRAME_SCHEMA, - K1_LOCAL_SURFACE_SHADOW_SCHEMA, - K1LocalSurfaceBoundViews, - K1LocalSurfacePoseBinder, - K1LocalSurfaceShadowCoordinator, - K1LocalSurfaceShadowEstimator, - K1LocalSurfaceShadowInput, - K1LocalSurfaceShadowResult, - K1LocalSurfaceShadowRuntime, -) -from .lidar_replay import ( - LIDAR_EQUIVALENCE_REPORT_SCHEMA, - LIDAR_QUALITY_REPORT_SCHEMA, - LIDAR_REPLAY_PACK_SCHEMA, - LidarReplayError, - LidarReplayPackV2, - LidarReplayPointFrame, - LidarReplayPoseFrame, - build_lidar_replay_pack_v2, - lidar_pack_catalog_item, - lidar_pack_detail, - verify_lidar_replay_equivalence, -) -from .live_perception import ( - LIVE_INGRESS_SCHEMA, - LIVE_INGRESS_WIRE_SCHEMA, - TELEMETRY_SCHEMA, - WORLD_STATE_SCHEMA, - LatestWinsQueue, - LiveIngressEvent, - LivePerceptionIngress, - QueueSnapshot, - WorldStateProjector, - classify_health, -) -from .live_replay_qualification import ( - LiveReplayQualificationResult, - validate_live_replay_qualification_result, -) -from .multirate_perception_qualification import ( - MultiratePerceptionArtifact, - MultiratePerceptionQualificationResult, - validate_multirate_perception_qualification_result, -) -from .perception_epoch import ( - RecordedPerceptionEpochResult, - RecordedPerceptionEpochStore, - RecordedPerceptionVideo, - validate_recorded_perception_epoch_result, -) -from .qualification import ( - DEFAULT_QUALIFICATION_FRAME_COUNT, - QUALIFICATION_POLICY, - QualificationFrame, - RecordedQualificationSlice, - RecordedQualificationSliceError, - prepare_recorded_qualification_slice, - validate_recorded_qualification_slice, -) -from .realtime_tracking_qualification import ( - RealtimeTrackingArtifact, - RealtimeTrackingQualificationResult, - validate_realtime_tracking_qualification_result, -) -from .results import ( - DetectionFrame, - ObjectDetection, - RecordedPerceptionOverlayArtifact, - RecordedPerceptionOverlayError, - RecordedPerceptionOverlayStore, - RecordedPerceptionResult, - validate_recorded_perception_result, -) -from .track_geometry import ( - POINT_SLAB_SCHEMA, - TRACK_GEOMETRY_BINDING_SCHEMA, - TRACK_GEOMETRY_FRAME_SCHEMA, - TRACK_GEOMETRY_SCHEMA, - PointSlab, - TrackGeometry, - TrackGeometryContractError, - TrackGeometryCurrentness, - TrackGeometryEvidenceState, - TrackGeometryFrame, - TrackGeometryMetricBasis, - TrackGeometryOwnerKind, - TrackGeometrySourceBinding, -) -from .tracked_fusion_qualification import ( - TrackedFusionQualificationResult, - validate_tracked_fusion_qualification_result, -) -from .tracking_qualification import ( - TrackingQualificationArtifact, - TrackingQualificationResult, - validate_tracking_qualification_result, -) +from importlib import import_module +from typing import TYPE_CHECKING, Any, Final + +if TYPE_CHECKING: + from .annotation_workspace import ( + ANNOTATION_WORKSPACE_SCHEMA, + AnnotationWorkspace, + AnnotationWorkspaceError, + prepare_annotation_workspace, + validate_annotation_workspace, + ) + from .e31_source_qualification import ( + DEFAULT_E31_SOURCE_QUALIFICATION_PROFILE, + E31_BINDING_PROFILE_SCHEMA, + E31_SOURCE_QUALIFICATION_REPORT_SCHEMA, + E31_SOURCE_QUALIFICATION_SCHEMA, + E31SourceQualification, + E31SourceQualificationError, + E31SourceQualificationProfile, + build_e31_source_qualification, + ) + from .e32_track_geometry_replay import ( + E32_TRACK_GEOMETRY_RECORD_SCHEMA, + E32_TRACK_GEOMETRY_REPLAY_SCHEMA, + E32_TRACK_GEOMETRY_REPORT_SCHEMA, + E32TrackGeometryReplay, + E32TrackGeometryReplayError, + build_e32_track_geometry_replay, + e32_track_geometry_frame, + read_e32_track_geometry_replay, + ) + from .e33_worker_shadow import ( + E33_FRAME_SCHEMA, + E33_OUTCOME_SCHEMA, + E33_PACKAGE_SCHEMA, + E33_PROFILE_SCHEMA, + E33_REPORT_SCHEMA, + E33_RESOURCE_SCHEMA, + E33_RESULT_SCHEMA, + E33WorkerShadowError, + E33WorkerShadowResult, + read_e33_worker_shadow_result, + run_e33_worker_shadow, + ) + from .e51_motion_semantic_qualification import ( + E51_FRAME_SCHEMA, + E51_PROFILE_SCHEMA, + E51_REPORT_SCHEMA, + E51_RESULT_SCHEMA, + E51_SIGNAL_SCHEMA, + E51MotionSemanticError, + E51MotionSemanticResult, + build_e51_motion_semantic_qualification, + derive_motion_semantic_signal, + read_e51_motion_semantic_qualification, + ) + from .e52_camera_first_restoration import ( + E52_CASE_SCHEMA, + E52_PROFILE_SCHEMA, + E52_REPORT_SCHEMA, + E52_RESULT_SCHEMA, + E52CameraFirstRestoration, + E52CameraFirstRestorationError, + build_e52_camera_first_restoration, + evaluate_camera_first_case, + read_e52_camera_first_restoration, + ) + from .evaluation_pack import ( + ANNOTATION_CONTRACT_SCHEMA, + EVALUATION_PACK_SCHEMA, + EvaluationFrameRequest, + EvaluationPackFrame, + RecordedEvaluationPack, + RecordedEvaluationPackError, + prepare_recorded_evaluation_pack, + validate_recorded_evaluation_pack, + ) + from .fusion_epoch import ( + RecordedCalibratedFusion, + RecordedCalibratedFusionStore, + RecordedPerceptionOverlayMux, + validate_recorded_calibrated_fusion, + ) + from .integrated_perception import ( + IntegratedPerceptionOverlayStore, + IntegratedPerceptionResult, + validate_integrated_perception_result, + ) + from .jobs import ( + COMPUTE_JOB_SCHEMA, + CameraComputeJob, + prepare_camera_compute_job, + validate_camera_compute_job, + ) + from .lab_instances import ( + PublishedCameraEgoMotionLabInstance, + PublishedIntegratedLabInstance, + PublishedPersistentSupportLabInstance, + PublishedTemporalLabInstance, + PublishedWorldMotionLabInstance, + publish_e21_lab_instance, + publish_e22_lab_instance, + publish_e23_lab_instance, + publish_e24_lab_instance, + publish_e25_lab_instance, + publish_e26_lab_instance, + publish_integrated_lab_instance, + ) + from .lidar_contract import ( + K1_LAB_LIDAR_PACK_V1_PROFILE, + K1_LIDAR_PACK_V2_PROFILE, + K1_LIVE_LIDAR_PROFILE, + LIDAR_EVIDENCE_PROFILE_SCHEMA, + LIDAR_READINESS_SCHEMA, + LidarContractError, + LidarCoordinateSpace, + LidarEvidenceProfile, + LidarPipelineStage, + LidarPointField, + LidarPoseStatus, + LidarQualityMonitor, + LidarReadiness, + LidarRepresentation, + LidarStageAssessment, + LidarTimeBasis, + assess_lidar_profile, + lidar_readiness_document, + sensor_frame_xyzi, + ) + from .lidar_field_review import ( + E10_LIDAR_PACK_SCHEMA, + FIELD_REVIEW_ARRAYS_NAME, + FIELD_REVIEW_MANIFEST_NAME, + FIELD_REVIEW_REPORT_NAME, + LIDAR_FIELD_REVIEW_REPORT_SCHEMA, + LIDAR_FIELD_REVIEW_SCHEMA, + LIDAR_FIELD_REVIEW_WINDOW_SCHEMA, + MAX_FIELD_REVIEW_WINDOW_POINTS, + RAVNOVES00_CENTRAL_WINDOWS, + E10LidarFieldSource, + FieldReviewWindowSpec, + LidarFieldReviewV1, + build_lidar_field_review, + lidar_field_review_catalog_item, + ) + from .lidar_ground import ( + DEFAULT_GROUND_BENCHMARK_PROFILE, + LIDAR_GROUND_ANNOTATION_TEMPLATE_SCHEMA, + LIDAR_GROUND_BENCHMARK_REPORT_SCHEMA, + LIDAR_GROUND_BENCHMARK_SCHEMA, + LIDAR_GROUND_FRAME_SCHEMA, + PATCHWORKPP_SOURCE_COMMIT, + PATCHWORKPP_SOURCE_TAG, + PATCHWORKPP_SOURCE_URL, + GroundBenchmarkProfile, + GroundSegmentation, + LidarGroundBenchmarkV1, + LidarGroundError, + LocalPercentileGroundSegmenter, + PatchworkPPGroundSegmenter, + build_lidar_ground_annotation_template, + build_lidar_ground_benchmark, + lidar_ground_benchmark_catalog_item, + lidar_ground_frame_detail, + score_ground_labels, + ) + from .lidar_local_surface import ( + DEFAULT_K1_LOCAL_SURFACE_PROFILE, + K1_LOCAL_SURFACE_FRAME_SCHEMA, + K1_LOCAL_SURFACE_REPORT_SCHEMA, + K1_LOCAL_SURFACE_REVIEW_SCHEMA, + K1_LOCAL_SURFACE_SCHEMA, + K1_LOCAL_SURFACE_TIMELINE_SCHEMA, + K1LocalSurfaceProfile, + K1LocalSurfaceV1, + build_k1_local_surface, + k1_local_surface_catalog_item, + ) + from .lidar_local_surface_shadow import ( + K1_LOCAL_SURFACE_BINDER_SCHEMA, + K1_LOCAL_SURFACE_SHADOW_FRAME_SCHEMA, + K1_LOCAL_SURFACE_SHADOW_SCHEMA, + K1LocalSurfaceBoundViews, + K1LocalSurfacePoseBinder, + K1LocalSurfaceShadowCoordinator, + K1LocalSurfaceShadowEstimator, + K1LocalSurfaceShadowInput, + K1LocalSurfaceShadowResult, + K1LocalSurfaceShadowRuntime, + ) + from .lidar_replay import ( + LIDAR_EQUIVALENCE_REPORT_SCHEMA, + LIDAR_QUALITY_REPORT_SCHEMA, + LIDAR_REPLAY_PACK_SCHEMA, + LidarReplayError, + LidarReplayPackV2, + LidarReplayPointFrame, + LidarReplayPoseFrame, + build_lidar_replay_pack_v2, + lidar_pack_catalog_item, + lidar_pack_detail, + verify_lidar_replay_equivalence, + ) + from .live_perception import ( + LIVE_INGRESS_SCHEMA, + LIVE_INGRESS_WIRE_SCHEMA, + TELEMETRY_SCHEMA, + WORLD_STATE_SCHEMA, + LatestWinsQueue, + LiveIngressEvent, + LivePerceptionIngress, + QueueSnapshot, + WorldStateProjector, + classify_health, + ) + from .live_replay_qualification import ( + LiveReplayQualificationResult, + validate_live_replay_qualification_result, + ) + from .multirate_perception_qualification import ( + MultiratePerceptionArtifact, + MultiratePerceptionQualificationResult, + validate_multirate_perception_qualification_result, + ) + from .perception_epoch import ( + RecordedPerceptionEpochResult, + RecordedPerceptionEpochStore, + RecordedPerceptionVideo, + validate_recorded_perception_epoch_result, + ) + from .qualification import ( + DEFAULT_QUALIFICATION_FRAME_COUNT, + QUALIFICATION_POLICY, + QualificationFrame, + RecordedQualificationSlice, + RecordedQualificationSliceError, + prepare_recorded_qualification_slice, + validate_recorded_qualification_slice, + ) + from .realtime_tracking_qualification import ( + RealtimeTrackingArtifact, + RealtimeTrackingQualificationResult, + validate_realtime_tracking_qualification_result, + ) + from .results import ( + DetectionFrame, + ObjectDetection, + RecordedPerceptionOverlayArtifact, + RecordedPerceptionOverlayError, + RecordedPerceptionOverlayStore, + RecordedPerceptionResult, + validate_recorded_perception_result, + ) + from .track_geometry import ( + POINT_SLAB_SCHEMA, + TRACK_GEOMETRY_BINDING_SCHEMA, + TRACK_GEOMETRY_FRAME_SCHEMA, + TRACK_GEOMETRY_SCHEMA, + PointSlab, + TrackGeometry, + TrackGeometryContractError, + TrackGeometryCurrentness, + TrackGeometryEvidenceState, + TrackGeometryFrame, + TrackGeometryMetricBasis, + TrackGeometryOwnerKind, + TrackGeometrySourceBinding, + ) + from .tracked_fusion_qualification import ( + TrackedFusionQualificationResult, + validate_tracked_fusion_qualification_result, + ) + from .tracking_qualification import ( + TrackingQualificationArtifact, + TrackingQualificationResult, + validate_tracking_qualification_result, + ) __all__ = [ "ANNOTATION_CONTRACT_SCHEMA", @@ -495,3 +499,376 @@ __all__ = [ "sensor_frame_xyzi", "verify_lidar_replay_equivalence", ] + +_EXPORTS: Final[dict[str, str]] = { + **dict.fromkeys( + ( + "ANNOTATION_WORKSPACE_SCHEMA", + "AnnotationWorkspace", + "AnnotationWorkspaceError", + "prepare_annotation_workspace", + "validate_annotation_workspace", + ), + ".annotation_workspace", + ), + **dict.fromkeys( + ( + "DEFAULT_E31_SOURCE_QUALIFICATION_PROFILE", + "E31_BINDING_PROFILE_SCHEMA", + "E31_SOURCE_QUALIFICATION_REPORT_SCHEMA", + "E31_SOURCE_QUALIFICATION_SCHEMA", + "E31SourceQualification", + "E31SourceQualificationError", + "E31SourceQualificationProfile", + "build_e31_source_qualification", + ), + ".e31_source_qualification", + ), + **dict.fromkeys( + ( + "E32_TRACK_GEOMETRY_RECORD_SCHEMA", + "E32_TRACK_GEOMETRY_REPLAY_SCHEMA", + "E32_TRACK_GEOMETRY_REPORT_SCHEMA", + "E32TrackGeometryReplay", + "E32TrackGeometryReplayError", + "build_e32_track_geometry_replay", + "e32_track_geometry_frame", + "read_e32_track_geometry_replay", + ), + ".e32_track_geometry_replay", + ), + **dict.fromkeys( + ( + "E33_FRAME_SCHEMA", + "E33_OUTCOME_SCHEMA", + "E33_PACKAGE_SCHEMA", + "E33_PROFILE_SCHEMA", + "E33_REPORT_SCHEMA", + "E33_RESOURCE_SCHEMA", + "E33_RESULT_SCHEMA", + "E33WorkerShadowError", + "E33WorkerShadowResult", + "read_e33_worker_shadow_result", + "run_e33_worker_shadow", + ), + ".e33_worker_shadow", + ), + **dict.fromkeys( + ( + "E51_FRAME_SCHEMA", + "E51_PROFILE_SCHEMA", + "E51_REPORT_SCHEMA", + "E51_RESULT_SCHEMA", + "E51_SIGNAL_SCHEMA", + "E51MotionSemanticError", + "E51MotionSemanticResult", + "build_e51_motion_semantic_qualification", + "derive_motion_semantic_signal", + "read_e51_motion_semantic_qualification", + ), + ".e51_motion_semantic_qualification", + ), + **dict.fromkeys( + ( + "E52_CASE_SCHEMA", + "E52_PROFILE_SCHEMA", + "E52_REPORT_SCHEMA", + "E52_RESULT_SCHEMA", + "E52CameraFirstRestoration", + "E52CameraFirstRestorationError", + "build_e52_camera_first_restoration", + "evaluate_camera_first_case", + "read_e52_camera_first_restoration", + ), + ".e52_camera_first_restoration", + ), + **dict.fromkeys( + ( + "ANNOTATION_CONTRACT_SCHEMA", + "EVALUATION_PACK_SCHEMA", + "EvaluationFrameRequest", + "EvaluationPackFrame", + "RecordedEvaluationPack", + "RecordedEvaluationPackError", + "prepare_recorded_evaluation_pack", + "validate_recorded_evaluation_pack", + ), + ".evaluation_pack", + ), + **dict.fromkeys( + ( + "RecordedCalibratedFusion", + "RecordedCalibratedFusionStore", + "RecordedPerceptionOverlayMux", + "validate_recorded_calibrated_fusion", + ), + ".fusion_epoch", + ), + **dict.fromkeys( + ( + "IntegratedPerceptionOverlayStore", + "IntegratedPerceptionResult", + "validate_integrated_perception_result", + ), + ".integrated_perception", + ), + **dict.fromkeys( + ( + "COMPUTE_JOB_SCHEMA", + "CameraComputeJob", + "prepare_camera_compute_job", + "validate_camera_compute_job", + ), + ".jobs", + ), + **dict.fromkeys( + ( + "PublishedCameraEgoMotionLabInstance", + "PublishedIntegratedLabInstance", + "PublishedPersistentSupportLabInstance", + "PublishedTemporalLabInstance", + "PublishedWorldMotionLabInstance", + "publish_e21_lab_instance", + "publish_e22_lab_instance", + "publish_e23_lab_instance", + "publish_e24_lab_instance", + "publish_e25_lab_instance", + "publish_e26_lab_instance", + "publish_integrated_lab_instance", + ), + ".lab_instances", + ), + **dict.fromkeys( + ( + "K1_LAB_LIDAR_PACK_V1_PROFILE", + "K1_LIDAR_PACK_V2_PROFILE", + "K1_LIVE_LIDAR_PROFILE", + "LIDAR_EVIDENCE_PROFILE_SCHEMA", + "LIDAR_READINESS_SCHEMA", + "LidarContractError", + "LidarCoordinateSpace", + "LidarEvidenceProfile", + "LidarPipelineStage", + "LidarPointField", + "LidarPoseStatus", + "LidarQualityMonitor", + "LidarReadiness", + "LidarRepresentation", + "LidarStageAssessment", + "LidarTimeBasis", + "assess_lidar_profile", + "lidar_readiness_document", + "sensor_frame_xyzi", + ), + ".lidar_contract", + ), + **dict.fromkeys( + ( + "E10_LIDAR_PACK_SCHEMA", + "FIELD_REVIEW_ARRAYS_NAME", + "FIELD_REVIEW_MANIFEST_NAME", + "FIELD_REVIEW_REPORT_NAME", + "LIDAR_FIELD_REVIEW_REPORT_SCHEMA", + "LIDAR_FIELD_REVIEW_SCHEMA", + "LIDAR_FIELD_REVIEW_WINDOW_SCHEMA", + "MAX_FIELD_REVIEW_WINDOW_POINTS", + "RAVNOVES00_CENTRAL_WINDOWS", + "E10LidarFieldSource", + "FieldReviewWindowSpec", + "LidarFieldReviewV1", + "build_lidar_field_review", + "lidar_field_review_catalog_item", + ), + ".lidar_field_review", + ), + **dict.fromkeys( + ( + "DEFAULT_GROUND_BENCHMARK_PROFILE", + "LIDAR_GROUND_ANNOTATION_TEMPLATE_SCHEMA", + "LIDAR_GROUND_BENCHMARK_REPORT_SCHEMA", + "LIDAR_GROUND_BENCHMARK_SCHEMA", + "LIDAR_GROUND_FRAME_SCHEMA", + "PATCHWORKPP_SOURCE_COMMIT", + "PATCHWORKPP_SOURCE_TAG", + "PATCHWORKPP_SOURCE_URL", + "GroundBenchmarkProfile", + "GroundSegmentation", + "LidarGroundBenchmarkV1", + "LidarGroundError", + "LocalPercentileGroundSegmenter", + "PatchworkPPGroundSegmenter", + "build_lidar_ground_annotation_template", + "build_lidar_ground_benchmark", + "lidar_ground_benchmark_catalog_item", + "lidar_ground_frame_detail", + "score_ground_labels", + ), + ".lidar_ground", + ), + **dict.fromkeys( + ( + "DEFAULT_K1_LOCAL_SURFACE_PROFILE", + "K1_LOCAL_SURFACE_FRAME_SCHEMA", + "K1_LOCAL_SURFACE_REPORT_SCHEMA", + "K1_LOCAL_SURFACE_REVIEW_SCHEMA", + "K1_LOCAL_SURFACE_SCHEMA", + "K1_LOCAL_SURFACE_TIMELINE_SCHEMA", + "K1LocalSurfaceProfile", + "K1LocalSurfaceV1", + "build_k1_local_surface", + "k1_local_surface_catalog_item", + ), + ".lidar_local_surface", + ), + **dict.fromkeys( + ( + "K1_LOCAL_SURFACE_BINDER_SCHEMA", + "K1_LOCAL_SURFACE_SHADOW_FRAME_SCHEMA", + "K1_LOCAL_SURFACE_SHADOW_SCHEMA", + "K1LocalSurfaceBoundViews", + "K1LocalSurfacePoseBinder", + "K1LocalSurfaceShadowCoordinator", + "K1LocalSurfaceShadowEstimator", + "K1LocalSurfaceShadowInput", + "K1LocalSurfaceShadowResult", + "K1LocalSurfaceShadowRuntime", + ), + ".lidar_local_surface_shadow", + ), + **dict.fromkeys( + ( + "LIDAR_EQUIVALENCE_REPORT_SCHEMA", + "LIDAR_QUALITY_REPORT_SCHEMA", + "LIDAR_REPLAY_PACK_SCHEMA", + "LidarReplayError", + "LidarReplayPackV2", + "LidarReplayPointFrame", + "LidarReplayPoseFrame", + "build_lidar_replay_pack_v2", + "lidar_pack_catalog_item", + "lidar_pack_detail", + "verify_lidar_replay_equivalence", + ), + ".lidar_replay", + ), + **dict.fromkeys( + ( + "LIVE_INGRESS_SCHEMA", + "LIVE_INGRESS_WIRE_SCHEMA", + "TELEMETRY_SCHEMA", + "WORLD_STATE_SCHEMA", + "LatestWinsQueue", + "LiveIngressEvent", + "LivePerceptionIngress", + "QueueSnapshot", + "WorldStateProjector", + "classify_health", + ), + ".live_perception", + ), + **dict.fromkeys( + ( + "LiveReplayQualificationResult", + "validate_live_replay_qualification_result", + ), + ".live_replay_qualification", + ), + **dict.fromkeys( + ( + "MultiratePerceptionArtifact", + "MultiratePerceptionQualificationResult", + "validate_multirate_perception_qualification_result", + ), + ".multirate_perception_qualification", + ), + **dict.fromkeys( + ( + "RecordedPerceptionEpochResult", + "RecordedPerceptionEpochStore", + "RecordedPerceptionVideo", + "validate_recorded_perception_epoch_result", + ), + ".perception_epoch", + ), + **dict.fromkeys( + ( + "DEFAULT_QUALIFICATION_FRAME_COUNT", + "QUALIFICATION_POLICY", + "QualificationFrame", + "RecordedQualificationSlice", + "RecordedQualificationSliceError", + "prepare_recorded_qualification_slice", + "validate_recorded_qualification_slice", + ), + ".qualification", + ), + **dict.fromkeys( + ( + "RealtimeTrackingArtifact", + "RealtimeTrackingQualificationResult", + "validate_realtime_tracking_qualification_result", + ), + ".realtime_tracking_qualification", + ), + **dict.fromkeys( + ( + "DetectionFrame", + "ObjectDetection", + "RecordedPerceptionOverlayArtifact", + "RecordedPerceptionOverlayError", + "RecordedPerceptionOverlayStore", + "RecordedPerceptionResult", + "validate_recorded_perception_result", + ), + ".results", + ), + **dict.fromkeys( + ( + "POINT_SLAB_SCHEMA", + "TRACK_GEOMETRY_BINDING_SCHEMA", + "TRACK_GEOMETRY_FRAME_SCHEMA", + "TRACK_GEOMETRY_SCHEMA", + "PointSlab", + "TrackGeometry", + "TrackGeometryContractError", + "TrackGeometryCurrentness", + "TrackGeometryEvidenceState", + "TrackGeometryFrame", + "TrackGeometryMetricBasis", + "TrackGeometryOwnerKind", + "TrackGeometrySourceBinding", + ), + ".track_geometry", + ), + **dict.fromkeys( + ( + "TrackedFusionQualificationResult", + "validate_tracked_fusion_qualification_result", + ), + ".tracked_fusion_qualification", + ), + **dict.fromkeys( + ( + "TrackingQualificationArtifact", + "TrackingQualificationResult", + "validate_tracking_qualification_result", + ), + ".tracking_qualification", + ), +} + +if set(_EXPORTS) != set(__all__) or len(_EXPORTS) != len(__all__): + raise RuntimeError("compute lazy export table does not match __all__") + + +def __getattr__(name: str) -> Any: + module_name = _EXPORTS.get(name) + if module_name is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value: Any = getattr(import_module(module_name, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted({*globals(), *__all__}) diff --git a/src/k1link/device_plugins/xgrids_k1/__init__.py b/src/k1link/device_plugins/xgrids_k1/__init__.py index 6c79f1d..9dadd11 100644 --- a/src/k1link/device_plugins/xgrids_k1/__init__.py +++ b/src/k1link/device_plugins/xgrids_k1/__init__.py @@ -1,5 +1,30 @@ """XGRIDS/LixelKity K1 compatibility plugin implementation.""" -from .observation import build_xgrids_k1_observation, xgrids_k1_archive_source +from importlib import import_module +from typing import TYPE_CHECKING, Any, Final + +if TYPE_CHECKING: + from .observation import build_xgrids_k1_observation, xgrids_k1_archive_source __all__ = ["build_xgrids_k1_observation", "xgrids_k1_archive_source"] + +_EXPORTS: Final = { + "build_xgrids_k1_observation": ".observation", + "xgrids_k1_archive_source": ".observation", +} + +if set(_EXPORTS) != set(__all__) or len(_EXPORTS) != len(__all__): + raise RuntimeError("XGRIDS K1 lazy export table does not match __all__") + + +def __getattr__(name: str) -> Any: + module_name = _EXPORTS.get(name) + if module_name is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value: Any = getattr(import_module(module_name, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted({*globals(), *__all__}) diff --git a/src/k1link/device_plugins/xgrids_k1/analyze/__init__.py b/src/k1link/device_plugins/xgrids_k1/analyze/__init__.py index 931431b..7d127bf 100644 --- a/src/k1link/device_plugins/xgrids_k1/analyze/__init__.py +++ b/src/k1link/device_plugins/xgrids_k1/analyze/__init__.py @@ -1,33 +1,37 @@ """Bounded, offline analysis of sensitive K1 evidence artifacts.""" -from k1link.device_plugins.xgrids_k1.analyze.calibrated_overlay import ( - CalibratedOverlayExperiment, - CalibratedOverlayExperimentError, - run_calibrated_overlay_experiment, -) -from k1link.device_plugins.xgrids_k1.analyze.calibrated_projection import ( - CalibratedProjectionError, - Kb4ProjectionProfile, - ProjectedPointCloud, - depth_colors, - map_points_to_lidar, - project_map_points_kb4, - quaternion_xyzw_to_rotation_matrix, - unproject_pixels_kb4, -) -from k1link.device_plugins.xgrids_k1.analyze.stream_summary import ( - DEFAULT_STREAM_SUMMARY_MAX_PAYLOAD_BYTES, - MAX_STREAM_SUMMARY_PAYLOAD_BYTES, - StreamSummary, - summarize_mqtt_streams, -) -from k1link.device_plugins.xgrids_k1.analyze.valid_fov import ( - DEFAULT_EDGE_MARGIN_PIXELS, - K1ValidFovMask, - K1ValidFovMaskError, - prepare_k1_valid_fov_mask, - validate_k1_valid_fov_mask, -) +from importlib import import_module +from typing import TYPE_CHECKING, Any, Final + +if TYPE_CHECKING: + from k1link.device_plugins.xgrids_k1.analyze.calibrated_overlay import ( + CalibratedOverlayExperiment, + CalibratedOverlayExperimentError, + run_calibrated_overlay_experiment, + ) + from k1link.device_plugins.xgrids_k1.analyze.calibrated_projection import ( + CalibratedProjectionError, + Kb4ProjectionProfile, + ProjectedPointCloud, + depth_colors, + map_points_to_lidar, + project_map_points_kb4, + quaternion_xyzw_to_rotation_matrix, + unproject_pixels_kb4, + ) + from k1link.device_plugins.xgrids_k1.analyze.stream_summary import ( + DEFAULT_STREAM_SUMMARY_MAX_PAYLOAD_BYTES, + MAX_STREAM_SUMMARY_PAYLOAD_BYTES, + StreamSummary, + summarize_mqtt_streams, + ) + from k1link.device_plugins.xgrids_k1.analyze.valid_fov import ( + DEFAULT_EDGE_MARGIN_PIXELS, + K1ValidFovMask, + K1ValidFovMaskError, + prepare_k1_valid_fov_mask, + validate_k1_valid_fov_mask, + ) __all__ = [ "CalibratedOverlayExperiment", @@ -51,3 +55,62 @@ __all__ = [ "unproject_pixels_kb4", "validate_k1_valid_fov_mask", ] + +_EXPORTS: Final = { + **dict.fromkeys( + ( + "CalibratedOverlayExperiment", + "CalibratedOverlayExperimentError", + "run_calibrated_overlay_experiment", + ), + ".calibrated_overlay", + ), + **dict.fromkeys( + ( + "CalibratedProjectionError", + "Kb4ProjectionProfile", + "ProjectedPointCloud", + "depth_colors", + "map_points_to_lidar", + "project_map_points_kb4", + "quaternion_xyzw_to_rotation_matrix", + "unproject_pixels_kb4", + ), + ".calibrated_projection", + ), + **dict.fromkeys( + ( + "DEFAULT_STREAM_SUMMARY_MAX_PAYLOAD_BYTES", + "MAX_STREAM_SUMMARY_PAYLOAD_BYTES", + "StreamSummary", + "summarize_mqtt_streams", + ), + ".stream_summary", + ), + **dict.fromkeys( + ( + "DEFAULT_EDGE_MARGIN_PIXELS", + "K1ValidFovMask", + "K1ValidFovMaskError", + "prepare_k1_valid_fov_mask", + "validate_k1_valid_fov_mask", + ), + ".valid_fov", + ), +} + +if set(_EXPORTS) != set(__all__) or len(_EXPORTS) != len(__all__): + raise RuntimeError("XGRIDS K1 analysis lazy export table does not match __all__") + + +def __getattr__(name: str) -> Any: + module_name = _EXPORTS.get(name) + if module_name is None: + raise AttributeError(f"module {__name__!r} has no attribute {name!r}") + value: Any = getattr(import_module(module_name, __name__), name) + globals()[name] = value + return value + + +def __dir__() -> list[str]: + return sorted({*globals(), *__all__}) diff --git a/tests/test_m49_worker_minimal_import.py b/tests/test_m49_worker_minimal_import.py new file mode 100644 index 0000000..5504cf3 --- /dev/null +++ b/tests/test_m49_worker_minimal_import.py @@ -0,0 +1,91 @@ +from __future__ import annotations + +import os +import subprocess +import sys +import textwrap +from pathlib import Path + +REPOSITORY_ROOT = Path(__file__).resolve().parents[1] +SOURCE_ROOT = REPOSITORY_ROOT / "src" + + +def test_m49_container_import_excludes_optional_visualization_dependencies() -> None: + script = textwrap.dedent( + """ + import hashlib + import importlib.abc + import json + import sys + + blocked = frozenset({"PIL", "pyarrow", "rerun"}) + + class OptionalDependencyBlocker(importlib.abc.MetaPathFinder): + def find_spec(self, fullname, path=None, target=None): + if fullname.partition(".")[0] in blocked: + raise ModuleNotFoundError( + f"blocked optional dependency: {fullname}", + name=fullname, + ) + return None + + assert blocked.isdisjoint(sys.modules) + sys.meta_path.insert(0, OptionalDependencyBlocker()) + + import k1link.compute as compute + import k1link.device_plugins.xgrids_k1 as xgrids_k1 + import k1link.device_plugins.xgrids_k1.analyze as analyze + import k1link.observatory.m49_worker_container_main as container_main + from k1link.compute import LidarReplayPackV2 + from k1link.compute.lidar_replay import LidarReplayPackV2 as DirectReplayPack + from k1link.device_plugins.xgrids_k1.analyze import Kb4ProjectionProfile + from k1link.device_plugins.xgrids_k1.analyze.calibrated_projection import ( + Kb4ProjectionProfile as DirectProjectionProfile, + ) + + expected_public_api = { + compute: (219, "a8616ca1402ee26774fb8c8ca2df12b77877305260bde2d64db75acbdc79b598"), + xgrids_k1: (2, "735cce20efdc7b1abd12006073233051c6702b00e8f15d21c2142d671061a79b"), + analyze: (20, "4a3edcb6b9c735338c0392838be0eac89cad2db1178a5ab7833c1231b6ecc4c2"), + } + for package, (length, digest) in expected_public_api.items(): + payload = json.dumps(package.__all__, separators=(",", ":")).encode() + assert len(package.__all__) == length + assert hashlib.sha256(payload).hexdigest() == digest + assert set(package.__all__).issubset(dir(package)) + + assert LidarReplayPackV2 is DirectReplayPack + assert Kb4ProjectionProfile is DirectProjectionProfile + assert container_main.__name__ == "k1link.observatory.m49_worker_container_main" + assert "k1link.compute.fusion_epoch" not in sys.modules + assert "k1link.device_plugins.xgrids_k1.observation" not in sys.modules + assert ( + "k1link.device_plugins.xgrids_k1.analyze.calibrated_overlay" + not in sys.modules + ) + assert "k1link.device_plugins.xgrids_k1.analyze.valid_fov" not in sys.modules + assert all( + module.partition(".")[0] not in blocked + for module in sys.modules + ) + """ + ) + environment = os.environ.copy() + inherited_python_path = environment.get("PYTHONPATH") + python_path = [str(SOURCE_ROOT)] + if inherited_python_path: + python_path.append(inherited_python_path) + environment["PYTHONPATH"] = os.pathsep.join(python_path) + environment["PYTHONNOUSERSITE"] = "1" + + completed = subprocess.run( + [sys.executable, "-c", script], + cwd=REPOSITORY_ROOT, + env=environment, + check=False, + capture_output=True, + text=True, + timeout=30, + ) + + assert completed.returncode == 0, completed.stderr