From 921e42d488e3579c460872af1d8c9459e0c6e765 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 13:44:55 -0400 Subject: [PATCH 01/10] Added a github action to run the pre-commit hook --- .github/workflows/pre-commit.yaml | 46 +++++++++++++++++++++++++++++++ README.md | 25 ++++++++++++----- 2 files changed, 64 insertions(+), 7 deletions(-) create mode 100644 .github/workflows/pre-commit.yaml diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..dd6cdc2 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,46 @@ +name: pre-commit + +on: + push: + branches: + - main + pull_request: + types: [opened, reopened, synchronize] + +# Prevent parallel runs +concurrency: + group: "${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}" + cancel-in-progress: true + +jobs: + pre-commit: + runs-on: ubuntu-latest + steps: + - name: Checkout repo + uses: actions/checkout@v4 + + - name: Install uv + uses: astral-sh/setup-uv@v5 + + - name: "Set up Python" + uses: actions/setup-python@v5 + with: + python-version-file: ".python-version" + + - name: Install the project + run: uv pip install ".[dev]" + + # Cache pip for Python hook installs + - name: Cache pip + uses: actions/cache@v3 + with: + path: ~/.cache/pip + key: ${{ runner.os }}-pip-${{ hashFiles('**/requirements.txt') }} + restore-keys: | + ${{ runner.os }}-pip- + + # Run pre-commit in check-only mode (fail on any diffs) + - name: Run pre-commit (check-only) + uses: pre-commit/action@v3.0.1 + with: + args: run --all-files --show-diff-on-failure \ No newline at end of file diff --git a/README.md b/README.md index 728edc9..7dc1a1d 100644 --- a/README.md +++ b/README.md @@ -10,11 +10,11 @@ This library provides a simulation stack for Stretch, built on [MuJoCo](https:// Check out the [highlight reel](https://www.youtube.com/watch?v=SWPJt67IB0Q) for features that have been recently added. - ## Getting Started + Start with Google Colab: - - Getting Started Tutorial [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hello-robot/stretch_mujoco/blob/main/docs/getting_started.ipynb) +- Getting Started Tutorial [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hello-robot/stretch_mujoco/blob/main/docs/getting_started.ipynb) **or** follow these instructions on your computer: @@ -50,6 +50,7 @@ To exit, press `Ctrl+C` in the terminal.

> On MacOS, if `mjpython` fails to locate `libpython3.10.dylib` and `libz.1.dylib`, run these commands: + ```shell # Before proceeding, please reload your terminal and/or IDE window, to make sure the correct UV environment variables are loaded. @@ -103,11 +104,11 @@ Ignore any warnings. Use the [StretchMujocoSimulator](./stretch_mujoco/stretch_mujoco.py) class to: - * start the simulation - * position control the robot's ranged joints - * velocity control the robot's mobile base - * read joint states - * read camera imagery +- start the simulation +- position control the robot's ranged joints +- velocity control the robot's mobile base +- read joint states +- read camera imagery Try the code below using `uv run ipython`. For advanced Mujoco users, the class also exposes the `mjModel` and `mjData`. See the [official Mujoco documentation](https://mujoco.readthedocs.io/en/stable/python.html). @@ -213,6 +214,16 @@ Check out the following documentation resources: All the enhancements/missing features/Bugfixes are tracked by [Issues](https://github.com/hello-robot/stretch_mujoco/issues) filed. Please feel free to file an issue if you would like to report bugs or request a feature addition. +## Contributing + +This repository uses [pre-commit hooks](https://pre-commit.com/) to enforce consistent formatting and style. + +Install pre-commit in the dev optional dependencies: `uv pip install ".[dev]` + +Install the hooks locally: cd to the top-level of this repository and run `pre-commit install`. + +Run pre-commit manually: `pre-commit run --all-files` + ## Acknowledgment The assets in this repository contain significant contributions and efforts from [Kevin Zakka](https://github.com/kevinzakka) and [Google Deepmind](https://github.com/google-deepmind), along with others in Hello Robot Inc. who helped us in modeling Stretch in Mujoco. Thank you for your contributions. From e8084625c8cc95a51a1742ddc17270382a2b96d1 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 13:49:50 -0400 Subject: [PATCH 02/10] codespell now ignores jupyter because it trips it up --- .pre-commit-config.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index e16ccc0..c66e66e 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -56,4 +56,8 @@ repos: - repo: https://github.com/codespell-project/codespell rev: v2.2.4 hooks: - - id: codespell \ No newline at end of file + - id: codespell + description: Checks for common misspellings in text files. + entry: codespell --skip="*ipynb" + language: python + types: [text] \ No newline at end of file From 3be1528a17e4065b2a415882e14c429237148525 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 13:57:32 -0400 Subject: [PATCH 03/10] Changed all the formatters to check and display a diff, instead of auto-fix. --- .pre-commit-config.yaml | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c66e66e..cc821ae 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -3,18 +3,26 @@ repos: rev: v4.6.0 hooks: - id: check-added-large-files + - id: check-case-conflict + - id: check-executables-have-shebangs + - id: check-merge-conflict + - id: check-shebang-scripts-are-executable + - id: check-symlinks + - id: check-xml + - id: check-yaml - repo: https://github.com/psf/black rev: 22.3.0 hooks: - id: black + args: ["--check"] - repo: https://github.com/pycqa/isort rev: 5.11.5 hooks: - id: isort - args: ["--profile", "black", "--filter-files"] + args: ["--profile", "black", "--filter-files", "--check"] - repo: https://github.com/pycqa/flake8 rev: 5.0.4 @@ -45,12 +53,15 @@ repos: rev: v6.2.1 hooks: - id: beautysh + args: ["--check"] # Mdformat formats Markdown files - repo: https://github.com/executablebooks/mdformat rev: 0.7.16 hooks: - id: mdformat + args: ["--check"] + exclude: \.github/.* # Codespell checks the code for common misspellings - repo: https://github.com/codespell-project/codespell From f773374a3ab43d97c47816f18714b2a343540d29 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 14:15:32 -0400 Subject: [PATCH 04/10] Removed mdformat because it doesn't work well --- .pre-commit-config.yaml | 8 -------- 1 file changed, 8 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cc821ae..cf79b8a 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -54,14 +54,6 @@ repos: hooks: - id: beautysh args: ["--check"] - - # Mdformat formats Markdown files - - repo: https://github.com/executablebooks/mdformat - rev: 0.7.16 - hooks: - - id: mdformat - args: ["--check"] - exclude: \.github/.* # Codespell checks the code for common misspellings - repo: https://github.com/codespell-project/codespell From 034c7edb0d4644c550de25d726b16671ea123334 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 14:25:13 -0400 Subject: [PATCH 05/10] Added flake8 exceptions that are not harmful but will take too long to fix in the codebase right now --- .flake8 | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.flake8 b/.flake8 index a2296bd..33c52f7 100644 --- a/.flake8 +++ b/.flake8 @@ -1,4 +1,4 @@ [flake8] max-line-length = 120 -extend-ignore = E203,E701 -exclude = __init__.py \ No newline at end of file +extend-ignore = E203,E701,E501,E722,F541 +exclude = __init__.py,stretch_mujoco/robocasa_gen.py \ No newline at end of file From d6c814682e913a3bedd50d302284fd7b470c72df Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Thu, 12 Jun 2025 14:29:14 -0400 Subject: [PATCH 06/10] Fixed github action failing because no venv is created --- .github/workflows/pre-commit.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml index dd6cdc2..ba1b677 100644 --- a/.github/workflows/pre-commit.yaml +++ b/.github/workflows/pre-commit.yaml @@ -27,6 +27,9 @@ jobs: with: python-version-file: ".python-version" + - name: Create a virtual environment + run: uv venv + - name: Install the project run: uv pip install ".[dev]" From 7bfc8409b1e71fdc5af6dc67ec64da4cd6d2b312 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Fri, 13 Jun 2025 14:26:55 -0400 Subject: [PATCH 07/10] Removed checkers that affect styling --- .pre-commit-config.yaml | 21 --------------------- 1 file changed, 21 deletions(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index cf79b8a..c54a9a5 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,25 +11,12 @@ repos: - id: check-xml - id: check-yaml - - - repo: https://github.com/psf/black - rev: 22.3.0 - hooks: - - id: black - args: ["--check"] - - repo: https://github.com/pycqa/isort rev: 5.11.5 hooks: - id: isort args: ["--profile", "black", "--filter-files", "--check"] - - repo: https://github.com/pycqa/flake8 - rev: 5.0.4 - hooks: - - id: flake8 - args: ["--config=.flake8"] - - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.981 @@ -46,14 +33,6 @@ repos: - --no-strict-optional - --disable-error-code=override - --disable-error-code=attr-defined - - - # Beautysh formats Bash scripts - - repo: https://github.com/lovesegfault/beautysh - rev: v6.2.1 - hooks: - - id: beautysh - args: ["--check"] # Codespell checks the code for common misspellings - repo: https://github.com/codespell-project/codespell From 6ffd5d725284f303e9958e5468c327d83f6e4a2c Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Fri, 13 Jun 2025 14:29:39 -0400 Subject: [PATCH 08/10] Removed flake8 config because it's unused --- .flake8 | 4 ---- 1 file changed, 4 deletions(-) delete mode 100644 .flake8 diff --git a/.flake8 b/.flake8 deleted file mode 100644 index 33c52f7..0000000 --- a/.flake8 +++ /dev/null @@ -1,4 +0,0 @@ -[flake8] -max-line-length = 120 -extend-ignore = E203,E701,E501,E722,F541 -exclude = __init__.py,stretch_mujoco/robocasa_gen.py \ No newline at end of file From b7519c1a61941ce91cc633d56572d302bfa379e1 Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Fri, 13 Jun 2025 16:51:58 -0400 Subject: [PATCH 09/10] Revereted README formatting --- README.md | 29 ++++++++++++++--------------- 1 file changed, 14 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index 7dc1a1d..bd7b412 100644 --- a/README.md +++ b/README.md @@ -4,17 +4,17 @@ [![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit&logoColor=white)](https://github.com/pre-commit/pre-commit) [![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black) - + This library provides a simulation stack for Stretch, built on [MuJoCo](https://github.com/google-deepmind/mujoco). There is position control for the arm, head, and gripper joints, velocity control for mobile base, calibrated camera RGB + depth imagery, 2D spinning lidar scans, and more. There is a visualizer that supports [user interaction](https://youtu.be/2P-Dt-Jfd6U), or a more efficient headless mode. There is a [ROS2 package](https://github.com/hello-robot/stretch_ros2/tree/humble/stretch_simulation), built on this library, that works with Nav2, Web Teleop, and more. There is 100s of permutations of Robocasa-provided kitchen environments that Stretch can spawn into. The MuJoCo API can be used for features like deformables, procedural model generation, SDF collisions, cloth simulation, and more. Check out the [highlight reel](https://www.youtube.com/watch?v=SWPJt67IB0Q) for features that have been recently added. -## Getting Started +## Getting Started Start with Google Colab: -- Getting Started Tutorial [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hello-robot/stretch_mujoco/blob/main/docs/getting_started.ipynb) + - Getting Started Tutorial [![Open In Colab](https://colab.research.google.com/assets/colab-badge.svg)](https://colab.research.google.com/github/hello-robot/stretch_mujoco/blob/main/docs/getting_started.ipynb) **or** follow these instructions on your computer: @@ -45,12 +45,11 @@ uv run launch_sim.py To exit, press `Ctrl+C` in the terminal.

- - + +

> On MacOS, if `mjpython` fails to locate `libpython3.10.dylib` and `libz.1.dylib`, run these commands: - ```shell # Before proceeding, please reload your terminal and/or IDE window, to make sure the correct UV environment variables are loaded. @@ -97,18 +96,18 @@ uv run examples/robocasa_environment.py Ignore any warnings. - - + + ## Writing Code Use the [StretchMujocoSimulator](./stretch_mujoco/stretch_mujoco.py) class to: -- start the simulation -- position control the robot's ranged joints -- velocity control the robot's mobile base -- read joint states -- read camera imagery + * start the simulation + * position control the robot's ranged joints + * velocity control the robot's mobile base + * read joint states + * read camera imagery Try the code below using `uv run ipython`. For advanced Mujoco users, the class also exposes the `mjModel` and `mjData`. See the [official Mujoco documentation](https://mujoco.readthedocs.io/en/stable/python.html). @@ -216,7 +215,7 @@ All the enhancements/missing features/Bugfixes are tracked by [Issues](https://g ## Contributing -This repository uses [pre-commit hooks](https://pre-commit.com/) to enforce consistent formatting and style. +This repository uses [pre-commit hooks](https://pre-commit.com/). Install pre-commit in the dev optional dependencies: `uv pip install ".[dev]` @@ -226,4 +225,4 @@ Run pre-commit manually: `pre-commit run --all-files` ## Acknowledgment -The assets in this repository contain significant contributions and efforts from [Kevin Zakka](https://github.com/kevinzakka) and [Google Deepmind](https://github.com/google-deepmind), along with others in Hello Robot Inc. who helped us in modeling Stretch in Mujoco. Thank you for your contributions. +The assets in this repository contain significant contributions and efforts from [Kevin Zakka](https://github.com/kevinzakka) and [Google Deepmind](https://github.com/google-deepmind), along with others in Hello Robot Inc. who helped us in modeling Stretch in Mujoco. Thank you for your contributions. \ No newline at end of file From e7fc175f89963d7290643e22ef7e1078569a221a Mon Sep 17 00:00:00 2001 From: Shehab Attia Date: Fri, 13 Jun 2025 17:12:00 -0400 Subject: [PATCH 10/10] Removed isort --- .isort.cfg | 6 ------ .pre-commit-config.yaml | 7 ------- stretch_mujoco/mujoco_server_camera_manager.py | 2 +- stretch_mujoco/mujoco_server_passive.py | 2 +- 4 files changed, 2 insertions(+), 15 deletions(-) delete mode 100644 .isort.cfg diff --git a/.isort.cfg b/.isort.cfg deleted file mode 100644 index 8b3801a..0000000 --- a/.isort.cfg +++ /dev/null @@ -1,6 +0,0 @@ -[settings] -py_version=39 -known_first_party=stretch -known_third_party=stretch_body -known_third_party=stretch_urdf -line_length = 100 \ No newline at end of file diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index c54a9a5..827a998 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -11,13 +11,6 @@ repos: - id: check-xml - id: check-yaml - - repo: https://github.com/pycqa/isort - rev: 5.11.5 - hooks: - - id: isort - args: ["--profile", "black", "--filter-files", "--check"] - - - repo: https://github.com/pre-commit/mirrors-mypy rev: v0.981 hooks: diff --git a/stretch_mujoco/mujoco_server_camera_manager.py b/stretch_mujoco/mujoco_server_camera_manager.py index 5720b17..101f9d3 100644 --- a/stretch_mujoco/mujoco_server_camera_manager.py +++ b/stretch_mujoco/mujoco_server_camera_manager.py @@ -96,7 +96,7 @@ def _pull_camera_data(self): def _create_camera_renderer(self, for_camera: StretchCameras): settings = for_camera.initial_camera_settings - # Update mujoco's offscreen gl buffer size to accomodate bigger resolutions: + # Update mujoco's offscreen gl buffer size to accommodate bigger resolutions: offscreen_buffer_width = self.mujoco_server.mjmodel.vis.global_.offwidth offscreen_buffer_height = self.mujoco_server.mjmodel.vis.global_.offheight diff --git a/stretch_mujoco/mujoco_server_passive.py b/stretch_mujoco/mujoco_server_passive.py index e2cb115..ed40241 100644 --- a/stretch_mujoco/mujoco_server_passive.py +++ b/stretch_mujoco/mujoco_server_passive.py @@ -77,7 +77,7 @@ def _run_ui_simulation(self, show_viewer_ui: bool): ) # 1/Hz.Put the UI thread to sleep so that the physics thread can do work, to mitigate `viewer.lock()` locking physics thread. click.secho( - f"Using the Mujoco Passive Viewer. Note: UI thread and camera rendering is capped to {1/UI_FPS_CAP_RATE}Hz to increase performance. You can set this rate using the `camera_rate` arugment.", + f"Using the Mujoco Passive Viewer. Note: UI thread and camera rendering is capped to {1/UI_FPS_CAP_RATE}Hz to increase performance. You can set this rate using the `camera_rate` argument.", fg="green", )