(self, env, observation_key='step_timing')
Initializes a new mujoco_profiling Wrapper.

    Args:
      env: The environment to wrap.
      observation_key: Optional custom string specifying the profile
        observation's key in the `OrderedDict` of observations. Defaults to
        'step_timing'.

    Raises:
      ValueError: If `env`'s observation spec is not compatible with the
        wrapper. Supported formats are a single array, or a dict of arrays.
      ValueError: If `env`'s observation already contains the specified
        `observation_key`.
Initializes a new mujoco_profiling Wrapper.
Initializes a new mujoco_profiling Wrapper .
def __init__(self, env, observation_key='step_timing'):
    """Initializes a new mujoco_profiling Wrapper.

    Args:
      env: The environment to wrap.
      observation_key: Optional custom string specifying the profile
        observation's key in the `OrderedDict` of observations. Defaults to
        'step_timing'.

    Raises:
      ValueError: If `env`'s observation spec is not compatible with the
        wrapper. Supported formats are a single array, or a dict of arrays.
      ValueError: If `env`'s observation already contains the specified
        `observation_key`.
    """
    wrapped_observation_spec = env.observation_spec()

    if isinstance(wrapped_observation_spec, specs.Array):
      self._observation_is_dict = False
      invalid_keys = set([STATE_KEY])
    elif isinstance(wrapped_observation_spec, collections.abc.MutableMapping):
      self._observation_is_dict = True
      invalid_keys = set(wrapped_observation_spec.keys())
    else:
      raise ValueError('Unsupported observation spec structure.')

    if observation_key in invalid_keys:
      raise ValueError(
          'Duplicate or reserved observation key {!r}.'.format(observation_key))

    if self._observation_is_dict:
      self._observation_spec = wrapped_observation_spec.copy()
    else:
      self._observation_spec = collections.OrderedDict()
      self._observation_spec[STATE_KEY] = wrapped_observation_spec

    env.physics.enable_profiling()

    # Extend observation spec.
    self._observation_spec[observation_key] = specs.Array(
        shape=(2,), dtype=np.double, name=observation_key)

    self._env = env
    self._observation_key = observation_key
def __init__ ( self , env , observation_key = 'step_timing' ) : wrapped_observation_spec = env . observation_spec ( ) if isinstance ( wrapped_observation_spec , specs . Array ) : self . _observation_is_dict = False invalid_keys = set ( [ STATE_KEY ] ) elif isinstance ( wrapped_observation_spec , collections . abc . MutableMapping ) : self . _observation_is_dict = True invalid_keys = set ( wrapped_observation_spec . keys ( ) ) else : raise ValueError ( 'Unsupported observation spec structure.' ) if observation_key in invalid_keys : raise ValueError ( 'Duplicate or reserved observation key {!r}.' . format ( observation_key ) ) if self . _observation_is_dict : self . _observation_spec = wrapped_observation_spec . copy ( ) else : self . _observation_spec = collections . OrderedDict ( ) self . _observation_spec [ STATE_KEY ] = wrapped_observation_spec env . physics . enable_profiling ( ) # Extend observation spec. self . _observation_spec [ observation_key ] = specs . Array ( shape = ( 2 , ) , dtype = np . double , name = observation_key ) self . _env = env self . _observation_key = observation_key