(self, physics)
Sets the state of the environment at the start of each episode.

    Args:
      physics: An instance of `Physics`.
Sets the state of the environment at the start of each episode.
Sets the state of the environment at the start of each episode .
def initialize_episode(self, physics):
    """Sets the state of the environment at the start of each episode.

    Args:
      physics: An instance of `Physics`.

    """
    # Get heightfield resolution, assert that it is square.
    res = physics.model.hfield_nrow[_HEIGHTFIELD_ID]
    assert res == physics.model.hfield_ncol[_HEIGHTFIELD_ID]
    # Sinusoidal bowl shape.
    row_grid, col_grid = np.ogrid[-1:1:res*1j, -1:1:res*1j]
    radius = np.clip(np.sqrt(col_grid**2 + row_grid**2), .04, 1)
    bowl_shape = .5 - np.cos(2*np.pi*radius)/2
    # Random smooth bumps.
    terrain_size = 2 * physics.model.hfield_size[_HEIGHTFIELD_ID, 0]
    bump_res = int(terrain_size / _TERRAIN_BUMP_SCALE)
    bumps = self.random.uniform(_TERRAIN_SMOOTHNESS, 1, (bump_res, bump_res))
    smooth_bumps = ndimage.zoom(bumps, res / float(bump_res))
    # Terrain is elementwise product.
    terrain = bowl_shape * smooth_bumps
    start_idx = physics.model.hfield_adr[_HEIGHTFIELD_ID]
    physics.model.hfield_data[start_idx:start_idx+res**2] = terrain.ravel()
    super().initialize_episode(physics)

    # If we have a rendering context, we need to re-upload the modified
    # heightfield data.
    if physics.contexts:
      with physics.contexts.gl.make_current() as ctx:
        ctx.call(mjlib.mjr_uploadHField,
                 physics.model.ptr,
                 physics.contexts.mujoco.ptr,
                 _HEIGHTFIELD_ID)

    # Initial configuration.
    orientation = self.random.randn(4)
    orientation /= np.linalg.norm(orientation)
    _find_non_contacting_height(physics, orientation)
def initialize_episode ( self , physics ) : # Get heightfield resolution, assert that it is square. res = physics . model . hfield_nrow [ _HEIGHTFIELD_ID ] assert res == physics . model . hfield_ncol [ _HEIGHTFIELD_ID ] # Sinusoidal bowl shape. row_grid , col_grid = np . ogrid [ - 1 : 1 : res * 1j , - 1 : 1 : res * 1j ] radius = np . clip ( np . sqrt ( col_grid ** 2 + row_grid ** 2 ) , .04 , 1 ) bowl_shape = .5 - np . cos ( 2 * np . pi * radius ) / 2 # Random smooth bumps. terrain_size = 2 * physics . model . hfield_size [ _HEIGHTFIELD_ID , 0 ] bump_res = int ( terrain_size / _TERRAIN_BUMP_SCALE ) bumps = self . random . uniform ( _TERRAIN_SMOOTHNESS , 1 , ( bump_res , bump_res ) ) smooth_bumps = ndimage . zoom ( bumps , res / float ( bump_res ) ) # Terrain is elementwise product. terrain = bowl_shape * smooth_bumps start_idx = physics . model . hfield_adr [ _HEIGHTFIELD_ID ] physics . model . hfield_data [ start_idx : start_idx + res ** 2 ] = terrain . ravel ( ) super ( ) . initialize_episode ( physics ) # If we have a rendering context, we need to re-upload the modified # heightfield data. if physics . contexts : with physics . contexts . gl . make_current ( ) as ctx : ctx . call ( mjlib . mjr_uploadHField , physics . model . ptr , physics . contexts . mujoco . ptr , _HEIGHTFIELD_ID ) # Initial configuration. orientation = self . random . randn ( 4 ) orientation /= np . linalg . norm ( orientation ) _find_non_contacting_height ( physics , orientation )