Skip to content

Commit

Permalink
[gym_jiminy/common] Speed-up env pipeline.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexis Duburcq committed Aug 18, 2023
1 parent 180bf43 commit fc77bf2
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions python/gym_jiminy/common/gym_jiminy/common/envs/env_generic.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

import tree
import numpy as np
from numpy.core.umath import ( # type: ignore[attr-defined]
copyto as _array_copyto)
from gymnasium import spaces
from gymnasium.core import RenderFrame

Expand Down Expand Up @@ -231,7 +233,6 @@ def __init__(self,
"of custom action spaces.")

# Define specialized operators for efficiency
self._copyto_observation = build_copyto(self.observation)
self._copyto_action = build_copyto(self.action)
self._contains_observation = build_contains(
self.observation, self.observation_space)
Expand Down Expand Up @@ -1396,7 +1397,15 @@ def refresh_observation(self, measurement: EngineObsType) -> None:
checking whether the simulation already started. It is not exactly
the same but it does the job regarding preserving efficiency.
"""
self._copyto_observation(measurement)
observation = self.observation
observation["t"][()] = measurement["t"]
_array_copyto(observation['states']['agent']['q'],
measurement['states']['agent']['q'])
_array_copyto(observation['states']['agent']['v'],
measurement['states']['agent']['v'])
sensors_data = observation['measurements']
for key, value in dict.items(measurement['measurements']):
_array_copyto(sensors_data[key], value)

def compute_command(self, action: ActT) -> np.ndarray:
"""Compute the motors efforts to apply on the robot.
Expand Down

0 comments on commit fc77bf2

Please sign in to comment.