From 85f9571c60329bfec25dff5783d580601dc86e78 Mon Sep 17 00:00:00 2001 From: JeanElsner Date: Sat, 27 Apr 2024 00:39:41 +0200 Subject: [PATCH 1/4] chore: support up to Python 3.12 --- .github/workflows/main.yml | 2 +- .github/workflows/pull_request.yml | 2 +- pyproject.toml | 4 +++- 3 files changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 08f3402..8b1b317 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -15,7 +15,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index 6cdd148..ddde425 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -9,7 +9,7 @@ jobs: runs-on: ubuntu-latest strategy: matrix: - python-version: ["3.8", "3.9", "3.10"] + python-version: ["3.8", "3.9", "3.10", "3.11", "3.12"] steps: - uses: actions/checkout@v3 - name: Set up Python ${{ matrix.python-version }} diff --git a/pyproject.toml b/pyproject.toml index dc43594..26e8f18 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -14,7 +14,7 @@ include = [ name = "dm-robotics-panda" description = "Panda model for dm_robotics." version = "0.4.7" -requires-python = ">=3.8,<3.11" +requires-python = ">=3.8,<3.13" authors = [ { name = "Jean Elsner", email = "jean.elsner@tum.de" }, ] @@ -40,6 +40,8 @@ classifiers = [ "Programming Language :: Python :: 3.8", "Programming Language :: Python :: 3.9", "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", ] [project.optional-dependencies] From bcf2ac5fbf2700f49bded042c880ceb2a4d52a79 Mon Sep 17 00:00:00 2001 From: JeanElsner Date: Fri, 21 Jun 2024 02:30:03 +0200 Subject: [PATCH 2/4] fix: replace mutable default with factory --- src/dm_robotics/panda/parameters.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/dm_robotics/panda/parameters.py b/src/dm_robotics/panda/parameters.py index cfc1be9..5aa3744 100644 --- a/src/dm_robotics/panda/parameters.py +++ b/src/dm_robotics/panda/parameters.py @@ -64,5 +64,6 @@ class RobotParams: robot_ip: Optional[str] = None joint_stiffness: Sequence[float] = (600, 600, 600, 600, 250, 150, 50) joint_damping: Sequence[float] = (50, 50, 50, 20, 20, 20, 10) - collision_behavior: CollisionBehavior = CollisionBehavior() + collision_behavior: CollisionBehavior = dataclasses.field( + default_factory=lambda: CollisionBehavior()) enforce_realtime: bool = False From 4ad77d1ffc0ab19310eb290892189048247f9471 Mon Sep 17 00:00:00 2001 From: JeanElsner Date: Fri, 21 Jun 2024 02:35:59 +0200 Subject: [PATCH 3/4] feat: extend reward plot for multiple signals --- src/dm_robotics/panda/utils.py | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/dm_robotics/panda/utils.py b/src/dm_robotics/panda/utils.py index 7d54143..13f3d91 100644 --- a/src/dm_robotics/panda/utils.py +++ b/src/dm_robotics/panda/utils.py @@ -256,19 +256,25 @@ def __init__(self, maxlen: int = 500) -> None: super().__init__(runtime, maxlen) self.fig.title = 'Reward' - self.maxlines = 1 - self.y.append(deque(maxlen=self.maxlen)) + self.maxlines = None + + def _init_buffer(self): + self.maxlines = self._rt._time_step.reward.shape[0] + for _1 in range(self.maxlines): + self.y.append(deque(maxlen=self.maxlen)) self.reset_data() def render(self, context, viewport): - if self._rt._time_step is None: + if self._rt._time_step is None or self._rt._time_step.reward is None: return - r = self._rt._time_step.reward - self.fig.linepnt[0] = self.maxlen - self.y[0].append(r) - self.fig.linedata[0][:self.maxlen * 2] = np.array([self.x, - self.y[0]]).T.reshape( - (-1,)) + if self.maxlines is None: + self._init_buffer() + for i, r in enumerate(self._rt._time_step.reward): + self.fig.linepnt[i] = self.maxlen + self.y[i].append(r) + self.fig.linedata[i][:self.maxlen * 2] = np.array([self.x, + self.y[i]]).T.reshape( + (-1,)) pos = mujoco.MjrRect(2 * 300 + 5, viewport.height - 200 - 5, 300, 200) mujoco.mjr_figure(pos, self.fig, context.ptr) From 27710fd6c8614e9f5ab341a15dff55d9abac324c Mon Sep 17 00:00:00 2001 From: JeanElsner Date: Fri, 21 Jun 2024 02:51:25 +0200 Subject: [PATCH 4/4] fix: differentiate between scalar and array reward in plot utility --- src/dm_robotics/panda/utils.py | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/dm_robotics/panda/utils.py b/src/dm_robotics/panda/utils.py index 13f3d91..aadb2dd 100644 --- a/src/dm_robotics/panda/utils.py +++ b/src/dm_robotics/panda/utils.py @@ -259,7 +259,10 @@ def __init__(self, self.maxlines = None def _init_buffer(self): - self.maxlines = self._rt._time_step.reward.shape[0] + if isinstance(self._rt._time_step.reward, np.ndarray): + self.maxlines = self._rt._time_step.reward.shape[0] + else: + self.maxlines = 1 for _1 in range(self.maxlines): self.y.append(deque(maxlen=self.maxlen)) self.reset_data() @@ -269,12 +272,19 @@ def render(self, context, viewport): return if self.maxlines is None: self._init_buffer() - for i, r in enumerate(self._rt._time_step.reward): - self.fig.linepnt[i] = self.maxlen - self.y[i].append(r) - self.fig.linedata[i][:self.maxlen * 2] = np.array([self.x, - self.y[i]]).T.reshape( - (-1,)) + if self.maxlines > 1: + for i, r in enumerate(self._rt._time_step.reward): + self.fig.linepnt[i] = self.maxlen + self.y[i].append(r) + self.fig.linedata[i][:self.maxlen * 2] = np.array([self.x, self.y[i] + ]).T.reshape((-1,)) + else: + r = self._rt._time_step.reward + self.fig.linepnt[0] = self.maxlen + self.y[0].append(r) + self.fig.linedata[0][:self.maxlen * 2] = np.array([self.x, + self.y[0]]).T.reshape( + (-1,)) pos = mujoco.MjrRect(2 * 300 + 5, viewport.height - 200 - 5, 300, 200) mujoco.mjr_figure(pos, self.fig, context.ptr)