Allow non-word characters in viz_tiptop_run object label regex - #35
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes a label-parsing bug in the viz_tiptop_run visualization script so object names containing punctuation (e.g. apostrophes) are correctly extracted from cuTAMP-style action labels, avoiding downstream lookup failures during plan playback.
Changes:
- Update the gripper-close label regex to capture the first argument up to the next comma (instead of
\w+), preserving non-word characters in object names. - Expand inline comments to document the failure mode and rationale.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
The gripper "close" action's label parser used \w+, which excludes apostrophes, so a label like "Pick(Rubik's_cube, grasp1, q1)" captured only "Rubik" and crashed the object lookup with KeyError. Capture up to the next comma instead, which is the actual end of the first argument. Split out from #28.
Address review feedback: the [^,]+ capture would otherwise include any whitespace inside the parens (e.g. "Pick( Rubik's_cube , ...)"), and grasped_obj is used as a key into obj_to_current_pose, so unstripped whitespace could reintroduce a KeyError. Require the comma delimiter and strip the captured name.
16066cf to
a0044f9
Compare
Move the "Pick(obj, ...)" parsing into a parse_grasped_object() helper in viz_tiptop_run and cover it in tests/test_plan_labels.py (apostrophe and whitespace cases plus unparseable labels). The test imports viz_tiptop_run, which also serves as a smoke check that the module imports cleanly.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.
Comments suppressed due to low confidence (2)
tiptop/scripts/viz_tiptop_run.py:38
- The ValueError message interpolates the raw label, which can hide leading/trailing whitespace (the exact thing this parser is guarding against) and can be hard to read if the label contains quotes or escapes. Using {!r} makes debugging and log output unambiguous.
match = re.match(r"\w+\(([^,]+),", label)
if match is None:
raise ValueError(f"Could not parse object name from label: {label}")
return match.group(1).strip()
tests/test_plan_labels.py:25
- This test imports
tiptop.scripts.viz_tiptop_runat module import time, which pulls in heavy transitive deps (cv2/open3d/rerun/torch/cutamp) during pytest collection. Other tests in this repo intentionally use local imports to avoid slow transitive imports affecting unrelated tests (seetests/test_tiptop_h5.py:27). Consider switching to local imports inside the test functions so collection stays lightweight.
import pytest
from tiptop.scripts.viz_tiptop_run import parse_grasped_object
- Use {label!r} in the parse error so whitespace/quotes in a bad label
are visible in the message.
- Import viz_tiptop_run inside the test functions rather than at module
top, matching the repo convention (tests/test_tiptop_h5.py) so the
heavy transitive import doesn't run during collection of other tests.
|
Addressed both low-confidence Copilot suggestions in the latest commit: the parse error now uses |
Summary
Fixes a crash in
viz_tiptop_runwhen a plan label contains punctuation, with a unit test. Unrelated to RecGen; split out of #28.The bug
The gripper "close" action parses the object name from a label like
Pick(crackers_in_wrapper, grasp1, q1)using\w+, which excludes apostrophes.Pick(Rubik's_cube, grasp1, q1)captured onlyRubik, then crashed the object lookup withKeyError.Changes
\w+\(([^,]+),) instead of\w+, and.strip()the result — so apostrophes survive and surrounding whitespace can't leak into theobj_to_current_posekey (the latter per review feedback on the original[^,]+capture).parse_grasped_object()helper inviz_tiptop_runand cover it intests/test_plan_labels.py(apostrophe / whitespace / no-space / other operators / unparseable labels). The test importsviz_tiptop_run, so it also smoke-checks that the module imports cleanly.Verification
pixi run test-unit→ 17 passed.