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

Method initialize_episode

dm_control/suite/quadruped.py:362–399  ·  view source on GitHub ↗

Sets the state of the environment at the start of each episode. Args: physics: An instance of `Physics`.

(self, physics)

Source from the content-addressed store, hash-verified

360 """A quadruped task solved by escaping a bowl-shaped terrain."""
361
362 def initialize_episode(self, physics):
363 """Sets the state of the environment at the start of each episode.
364
365 Args:
366 physics: An instance of `Physics`.
367
368 """
369 # Get heightfield resolution, assert that it is square.
370 res = physics.model.hfield_nrow[_HEIGHTFIELD_ID]
371 assert res == physics.model.hfield_ncol[_HEIGHTFIELD_ID]
372 # Sinusoidal bowl shape.
373 row_grid, col_grid = np.ogrid[-1:1:res*1j, -1:1:res*1j]
374 radius = np.clip(np.sqrt(col_grid**2 + row_grid**2), .04, 1)
375 bowl_shape = .5 - np.cos(2*np.pi*radius)/2
376 # Random smooth bumps.
377 terrain_size = 2 * physics.model.hfield_size[_HEIGHTFIELD_ID, 0]
378 bump_res = int(terrain_size / _TERRAIN_BUMP_SCALE)
379 bumps = self.random.uniform(_TERRAIN_SMOOTHNESS, 1, (bump_res, bump_res))
380 smooth_bumps = ndimage.zoom(bumps, res / float(bump_res))
381 # Terrain is elementwise product.
382 terrain = bowl_shape * smooth_bumps
383 start_idx = physics.model.hfield_adr[_HEIGHTFIELD_ID]
384 physics.model.hfield_data[start_idx:start_idx+res**2] = terrain.ravel()
385 super().initialize_episode(physics)
386
387 # If we have a rendering context, we need to re-upload the modified
388 # heightfield data.
389 if physics.contexts:
390 with physics.contexts.gl.make_current() as ctx:
391 ctx.call(mjlib.mjr_uploadHField,
392 physics.model.ptr,
393 physics.contexts.mujoco.ptr,
394 _HEIGHTFIELD_ID)
395
396 # Initial configuration.
397 orientation = self.random.randn(4)
398 orientation /= np.linalg.norm(orientation)
399 _find_non_contacting_height(physics, orientation)
400
401 def get_observation(self, physics):
402 """Returns an observation to the agent."""

Callers

nothing calls this directly

Calls 6

sqrtMethod · 0.80
zoomMethod · 0.80
make_currentMethod · 0.80
initialize_episodeMethod · 0.45
callMethod · 0.45

Tested by

no test coverage detected