MCPcopy Create free account
hub / github.com/google-deepmind/dm_control / set_state

Method set_state

dm_control/mujoco/engine.py:252–285  ·  view source on GitHub ↗

Sets the physics state. Args: physics_state: NumPy array containing the full physics simulation state. sig: Optional integer, if specified then physics_state is passed directly to `mj_setState` with `sig`. Raises: ValueError: If `physics_state` has invalid size.

(self, physics_state, sig=None)

Source from the content-addressed store, hash-verified

250 return retval
251
252 def set_state(self, physics_state, sig=None):
253 """Sets the physics state.
254
255 Args:
256 physics_state: NumPy array containing the full physics simulation state.
257 sig: Optional integer, if specified then physics_state is passed directly
258 to `mj_setState` with `sig`.
259
260 Raises:
261 ValueError: If `physics_state` has invalid size.
262 """
263 if sig is None:
264 state_items = self._physics_state_items()
265
266 expected_shape = (sum(item.size for item in state_items),)
267 if expected_shape != physics_state.shape:
268 raise ValueError(
269 'Input physics state has shape {}. Expected {}.'.format(
270 physics_state.shape, expected_shape
271 )
272 )
273
274 start = 0
275 for state_item in state_items:
276 size = state_item.size
277 np.copyto(state_item, physics_state[start:start + size])
278 start += size
279 else:
280 mujoco.mj_setState(
281 self.model.ptr,
282 self.data.ptr,
283 np.asarray(physics_state, np.float64),
284 sig,
285 )
286
287 def copy(self, share_model=False):
288 """Creates a copy of this `Physics` instance.

Callers 6

_reset_attemptMethod · 0.80
testNstepMethod · 0.80

Calls 1

_physics_state_itemsMethod · 0.95

Tested by 5

testNstepMethod · 0.64