Skip to content

Allow non-word characters in viz_tiptop_run object label regex - #35

Merged
williamshen-nz merged 4 commits into
mainfrom
viz-label-regex-fix
Jul 31, 2026
Merged

Allow non-word characters in viz_tiptop_run object label regex#35
williamshen-nz merged 4 commits into
mainfrom
viz-label-regex-fix

Conversation

@williamshen-nz

@williamshen-nz williamshen-nz commented Jul 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes a crash in viz_tiptop_run when 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 only Rubik, then crashed the object lookup with KeyError.

Changes

  • Match up to the first comma (\w+\(([^,]+),) instead of \w+, and .strip() the result — so apostrophes survive and surrounding whitespace can't leak into the obj_to_current_pose key (the latter per review feedback on the original [^,]+ capture).
  • Pull the parsing into a parse_grasped_object() helper in viz_tiptop_run and cover it in tests/test_plan_labels.py (apostrophe / whitespace / no-space / other operators / unparseable labels). The test imports viz_tiptop_run, so it also smoke-checks that the module imports cleanly.

Verification

pixi run test-unit → 17 passed.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread tiptop/scripts/viz_tiptop_run.py Outdated
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.
@williamshen-nz
williamshen-nz force-pushed the viz-label-regex-fix branch 2 times, most recently from 16066cf to a0044f9 Compare July 30, 2026 23:16
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.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_run at 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 (see tests/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.
@williamshen-nz

Copy link
Copy Markdown
Collaborator Author

Addressed both low-confidence Copilot suggestions in the latest commit: the parse error now uses {label!r} (so whitespace/quotes in a bad label are visible), and the test imports viz_tiptop_run locally inside the test functions, matching the repo's existing convention in tests/test_tiptop_h5.py so collection stays light. The import still runs when the tests execute, so it keeps doubling as a smoke check.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 2 out of 2 changed files in this pull request and generated no new comments.

@williamshen-nz
williamshen-nz merged commit 496d37f into main Jul 31, 2026
1 check passed
@williamshen-nz
williamshen-nz deleted the viz-label-regex-fix branch July 31, 2026 01:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants