feat(safety): native real-time safe-projection via PyO3#7
Merged
Conversation
Port the safe_projection workspace envelope (AABB clamp plus radial sphere push-out) into an allocation-free Rust core, exposed to Python as ghostloop._rt_safety. policies/safe_projection.py now dispatches to the native path for sphere-only workspaces and falls back to the unchanged pure-Python implementation when the module is not built, preserving identical results and the projected_from audit field. Adds tests/test_rt_safety_equivalence.py: native vs Python projection is an exact match (max per-axis error 0.0) across index-seeded cases, and projected points satisfy the workspace envelope. Build the module with maturin; the compiled artifact is gitignored.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Ports ghostloop's safe-projection workspace envelope (AABB clamp plus radial sphere push-out) into an allocation-free Rust core, exposed to Python as
ghostloop._rt_safety.Why
The safety-envelope projection sits on the control hot path. A native, heap-free implementation makes it real-time-grade (deterministic, WCET-bounded) while keeping the pure-Python path as the reference and fallback.
How
native/rt_safety(PyO3):in_envelopeandproject_to_workspace, fixed-capacity stack arrays, no heap on the hot path.policies/safe_projection.pydispatches to the native path for sphere-only workspaces and falls back to the unchanged pure-Python implementation when the module is not built. Return shape and theprojected_fromaudit field are identical.Verification
tests/test_rt_safety_equivalence.py: native vs Python projection is an exact match (max per-axis error 0.0) across index-seeded cases, and projected points satisfy the workspace envelope.Build note
Build the module with maturin (
maturin developinnative/rt_safety). The compiled.sois gitignored; without it, the guarded import simply uses the pure-Python path.