Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ MUJOCO_LOG.TXT
## -------------------

benchmark/mujoco_menagerie/
benchmark/myo_sim


## Created directories
Expand Down
12 changes: 12 additions & 0 deletions benchmark/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,17 @@ class Humanoid(benchmark.BenchmarkSuite):
njmax = 64


class MyoArm(benchmark.BenchmarkSuite):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does this break running asv run main^! ?

Does the user have to manually run python get_myosim.py for the command above to work correctly?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, probably need to run the script first

"""MyoArm."""

path = "myo_sim/arm/myoarm.xml"
params = benchmark.BenchmarkSuite.params + ("step.euler",)
batch_size = 8192
nconmax = 16
njmax = 48
overrides = {"opt.ccd_iterations": 50} # default 35 is too low


class ThreeHumanoids(benchmark.BenchmarkSuite):
"""Three MuJoCo humanoids on an infinite plane.

Expand All @@ -130,4 +141,5 @@ class ThreeHumanoids(benchmark.BenchmarkSuite):
Cloth.setup_cache = lambda s: benchmark.BenchmarkSuite.setup_cache(s)
FrankaEmikaPanda.setup_cache = lambda s: benchmark.BenchmarkSuite.setup_cache(s)
Humanoid.setup_cache = lambda s: benchmark.BenchmarkSuite.setup_cache(s)
MyoArm.setup_cache = lambda s: benchmark.BenchmarkSuite.setup_cache(s)
ThreeHumanoids.setup_cache = lambda s: benchmark.BenchmarkSuite.setup_cache(s)
12 changes: 12 additions & 0 deletions benchmark/myosim/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Benchmark musculoskeletal environment from MyoSim

[MyoSim](https://github.com/MyoHub/myo_sim)

- [MyoArm](https://github.com/MyoHub/myo_sim/tree/main/arm)


## Get MyoSim from GitHub

```bash
python get_myosim.py
```
68 changes: 68 additions & 0 deletions benchmark/myosim/get_myosim.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# Copyright 2025 The Newton Developers
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================

"""Get MyoSim from GitHub."""

import subprocess
import sys
from typing import Sequence

from absl import app
from etils import epath

_MYOSIM_PATH = epath.Path(__file__).parent.parent / "myo_sim"

_MYOSIM_COMMIT_SHA = "33f3ded946f55adbdcf963c99999587aadaf975f"


# TODO(team): shared utility with benchmark/kitchen/populate_scene._clone?
Copy link
Collaborator

Choose a reason for hiding this comment

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

yes, in fact we should probably consider doing something like what playground does:

https://github.com/google-deepmind/mujoco_playground/blob/1bd244fa9c51fa7074c7a449934f556d898f7a15/mujoco_playground/_src/mjx_env.py#L92-L109

Perhaps it's time to support something like this so that we can keep these resources all outside of this repo.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

created an issue #1001 for 'resource loader'

def _clone(repo_url: str, target_path: str, commit_sha: str) -> None:
"""Clone a git repo with progress bar."""
process = subprocess.Popen(
["git", "clone", "--progress", repo_url, target_path],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
universal_newlines=True,
)

while True:
# Read output line by line.
if not process.stderr.readline() and process.poll() is not None:
break

if process.returncode != 0:
raise subprocess.CalledProcessError(process.returncode, ["git", "clone"])

# checkout specific commit
print(f"Checking out commit {commit_sha}")
subprocess.run(["git", "-C", target_path, "checkout", commit_sha], check=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)


def main(argv: Sequence[str]):
"""Ensure MyoSim exists, downloading it if necessary."""
print(f"myosim path: {_MYOSIM_PATH}")
if not _MYOSIM_PATH.exists():
print("MyoSim not found. Downloading...")

try:
_clone("https://github.com/MyoHub/myo_sim.git", str(_MYOSIM_PATH), _MYOSIM_COMMIT_SHA)
print("Successfully downloaded MyoSim")
except subprocess.CalledProcessError as e:
print(f"Error downloading MyoSim: {e}", file=sys.stderr)
raise


if __name__ == "__main__":
app.run(main)
2 changes: 2 additions & 0 deletions mujoco_warp/_src/benchmark.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ class BenchmarkSuite:
sample_time = 0
repeat = 1
replay = ""
overrides = {}

def setup_cache(self):
module = importlib.import_module(self.__module__)
Expand Down Expand Up @@ -237,6 +238,7 @@ def setup_cache(self):

free_before = wp.get_device().free_memory
m = io.put_model(mjm)
io.override_model(m, self.overrides)
d = io.put_data(mjm, mjd, self.batch_size, self.nconmax, self.njmax)
free_after = wp.get_device().free_memory

Expand Down
Loading