Skip to content

Add reusable demo utilities and DemoBase lifecycle class - #354

Open
yuecideng wants to merge 19 commits into
mainfrom
feature/demo-base-class
Open

Add reusable demo utilities and DemoBase lifecycle class#354
yuecideng wants to merge 19 commits into
mainfrom
feature/demo-base-class

Conversation

@yuecideng

Copy link
Copy Markdown
Contributor

Description

This PR introduces a shared demo utility layer for simulation scripts and refactors the six scripts/tutorials/atomic_action/ tutorials to use it.

New components:

  • embodichain.lab.sim.utility.demo_utils: argument parsing, default simulation setup, recording context manager, trajectory replay, and window/user helpers.
  • embodichain.lab.sim.demo_base.DemoBase: optional lifecycle base class for demos.

The existing scripts/tutorials/atomic_action/tutorial_utils.py now re-exports generic helpers while keeping UR5-specific configuration functions. All six atomic-action tutorials were migrated to DemoBase and the shared helpers; behavior is preserved.

Dependencies: None

Type of change

  • Bug fix (non-breaking change which fixes an issue)
  • Enhancement (non-breaking change which improves an existing functionality)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (existing functionality will not work without user modification)
  • Documentation update

Checklist

  • I have run the black . command to format the code base.
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • Dependencies have been updated, if applicable.

yuecideng and others added 14 commits July 3, 2026 16:01
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
@yuecideng yuecideng added enhancement New feature or request refactor atomic action atomic action related functionality robot Module related to robot visualization Features or functions for visualization with the simulation labels Jul 4, 2026
yuecideng and others added 4 commits July 28, 2026 15:27
Multi-environment demos (e.g. examples/sim/demo) need to forward num_envs
to SimulationManagerCfg. Add a num_envs parameter to create_default_sim and
unit-test it alongside maybe_init_gpu_physics and the default-light path.

Co-Authored-By: Claude <noreply@anthropic.com>
Migrate press_softbody, pick_up_cloth, grasp_cup_to_caffe and scoop_ice to
the DemoBase lifecycle and shared demo_utils helpers (add_demo_args,
create_default_sim, maybe_open_window, maybe_init_gpu_physics,
maybe_wait_for_user). This completes the demo utility rollout called for in
the demo-base design spec.

Behavior is preserved (robot/object configs, IK seeds, trajectory
interpolation and sim.update step counts are unchanged) with three
intentional improvements:
- Guaranteed sim.destroy() via DemoBase.main() try/finally, fixing the
  exit-time segfault (exit 139) that violated the sim-shutdown contract.
- Respect --headless consistently (no hardcoded headless=True) and open the
  window via maybe_open_window.
- --auto_play skips interactive prompts and the keep-alive loop so demos
  terminate for headless integration runs.

press_softbody and pick_up_cloth run end-to-end headless --auto_play with a
clean exit (exit 0).

Co-Authored-By: Claude <noreply@anthropic.com>
Add a 'Writing Demo Scripts' tutorial covering add_demo_args,
create_default_sim, DemoRecording, replay_trajectory and the DemoBase
lifecycle, and register it in the tutorial toctree. Expose demo_utils and
demo_base in the API reference (autosummary + automodule sections) so the
tutorial cross-references resolve.

Co-Authored-By: Claude <noreply@anthropic.com>
Sync the demo-base feature with the latest main (44 commits), which
refactored atomic actions in parallel:
- #346 refactor atomic actions into a primitives package
- #349 env-batched parallel motion generation (AtomicActionEngine.run now
  returns a (B,) success tensor; compute_ik returns a batched success tensor)
- #371 simplify atomic action tutorials (extract helpers into
  tutorial_utils.py, flat style)

Conflict resolution (7 files: 6 atomic_action tutorials + tutorial_utils.py):
- tutorial_utils.py: take main's version. It is a strict superset of the
  PR's (keeps create_ur5_gripper_robot_cfg, make_ur5_solver_cfg,
  draw_axis_marker, start/stop_auto_play_recording and adds
  create_tutorial_simulation, add_ur5_gripper_robot,
  create_toppra_motion_generator, prepare_tutorial_scene, env-batched
  replay_trajectory, broadcast_pose_batch, etc.).
- 6 tutorials: keep the PR's DemoBase migration and adapt to main's
  env-batched API. engine.run success changed from a scalar is_success to a
  (B,) tensor, so the guard is now 'if not success.all():' (compute_ik
  already used torch.all). Target constructor params
  (qpos/name/xpos/semantics/object_target_pose) match main's core.py. This
  also restores the sim.destroy() cleanup that main's flat tutorials lack
  (DemoBase.main try/finally), avoiding the exit-time segfault.

Verified: 19 unit tests pass; move_joints and pickup run headless
--auto_play end-to-end with a clean exit (exit 0).

Co-Authored-By: Claude <noreply@anthropic.com>
@yuecideng
yuecideng marked this pull request as ready for review July 28, 2026 15:50
Copilot AI review requested due to automatic review settings July 28, 2026 15:50

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Copilot AI review requested due to automatic review settings July 29, 2026 02:30

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.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

atomic action atomic action related functionality enhancement New feature or request refactor robot Module related to robot visualization Features or functions for visualization with the simulation

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants