class_docstr: Default connector piece added by RLlib to the end of any module-to-env pipeline.
  
  If necessary, this connector samples actions, given action dist. inputs and a
  dist. class.
  The connector will only sample from the action distribution, if the
  SampleBatch.ACTIONS key cannot be found in `data`. Otherwise, it'll behave
  as pass through (noop). If SampleBatch.ACTIONS is not present, but
  SampleBatch.ACTION_DIST_INPUTS are, the connector will create a new action
  distribution using the RLModule in the connector context and sample from this
  distribution (deterministically, if we are not exploring, stochastically, if we
  are).
  
  input_type: INPUT_OUTPUT_TYPES.DICT_OF_MODULE_IDS_TO_DATA
      Operates per RLModule as it will have to pull the action distribution from each
      in order to sample actions if necessary. Searches for the ACTIONS and
      ACTION_DIST_INPUTS keys in a module's outputs and - should ACTIONS not be
      found - sample actions from the module's action distribution.
  output_type: INPUT_OUTPUT_TYPES.DICT_OF_MODULE_IDS_TO_DATA (same as input: data in,
      data out, however, data
      out might contain an additional ACTIONS key if it was not previously present
      in the input).
class_docstr_tok: ["Default","connector","piece","added","by","RLlib","to","the","end","of","any","module-to-env","pipeline",".","If","necessary",",","this","connector","samples","actions",",","given","action","dist",".","inputs","and","a","dist",".","class",".","The","connector","will","only","sample","from","the","action","distribution",",","if","the","SampleBatch.ACTIONS","key","can","not","be","found","in","`","data","`",".","Otherwise",",","it","'ll","behave","as","pass","through","(","noop",")",".","If","SampleBatch.ACTIONS","is","not","present",",","but","SampleBatch.ACTION_DIST_INPUTS","are",",","the","connector","will","create","a","new","action","distribution","using","the","RLModule","in","the","connector","context","and","sample","from","this","distribution","(","deterministically",",","if","we","are","not","exploring",",","stochastically",",","if","we","are",")",".","input_type",":","INPUT_OUTPUT_TYPES.DICT_OF_MODULE_IDS_TO_DATA","Operates","per","RLModule","as","it","will","have","to","pull","the","action","distribution","from","each","in","order","to","sample","actions","if","necessary",".","Searches","for","the","ACTIONS","and","ACTION_DIST_INPUTS","keys","in","a","module","'s","outputs","and","-","should","ACTIONS","not","be","found","-","sample","actions","from","the","module","'s","action","distribution",".","output_type",":","INPUT_OUTPUT_TYPES.DICT_OF_MODULE_IDS_TO_DATA","(","same","as","input",":","data","in",",","data","out",",","however",",","data","out","might","contain","an","additional","ACTIONS","key","if","it","was","not","previously","present","in","the","input",")","."]
docstr: Initializes a DefaultModuleToEnv (connector piece) instance.
  
  Args:
      normalize_actions: If True, actions coming from the RLModule's distribution
          (or are directly computed by the RLModule w/o sampling) will
          be assumed 0.0 centered with a small stddev (only affecting Box
          components) and thus be unsquashed (and clipped, just in case) to the
          bounds of the env's action space. For example, if the action space of
          the environment is `Box(-2.0, -0.5, (1,))`, the model outputs
          mean and stddev as 0.1 and exp(0.2), and we sample an action of 0.9
          from the resulting distribution, then this 0.9 will be unsquashed into
          the [-2.0 -0.5] interval. If - after unsquashing - the action still
          breaches the action space, it will simply be clipped.
      clip_actions: If True, actions coming from the RLModule's distribution
          (or are directly computed by the RLModule w/o sampling) will be clipped
          such that they fit into the env's action space's bounds.
          For example, if the action space of the environment is
          `Box(-0.5, 0.5, (1,))`, the model outputs
          mean and stddev as 0.1 and exp(0.2), and we sample an action of 0.9
          from the resulting distribution, then this 0.9 will be clipped to 0.5
          to fit into the [-0.5 0.5] interval.
docstr_tok: ["Initializes","a","DefaultModuleToEnv","(","connector","piece",")","instance",".","Args",":","normalize_actions",":","If","True",",","actions","coming","from","the","RLModule","'s","distribution","(","or","are","directly","computed","by","the","RLModule","w\/o","sampling",")","will","be","assumed","0.0","centered","with","a","small","stddev","(","only","affecting","Box","components",")","and","thus","be","unsquashed","(","and","clipped",",","just","in","case",")","to","the","bounds","of","the","env","'s","action","space",".","For","example",",","if","the","action","space","of","the","environment","is","`","Box","(","-2.0",",","-0.5",",","(","1",",",")",")","`",",","the","model","outputs","mean","and","stddev","as","0.1","and","exp","(","0.2",")",",","and","we","sample","an","action","of","0.9","from","the","resulting","distribution",",","then","this","0.9","will","be","unsquashed","into","the","[","-2.0","-0.5","]","interval",".","If","-","after","unsquashing","-","the","action","still","breaches","the","action","space",",","it","will","simply","be","clipped",".","clip_actions",":","If","True",",","actions","coming","from","the","RLModule","'s","distribution","(","or","are","directly","computed","by","the","RLModule","w\/o","sampling",")","will","be","clipped","such","that","they","fit","into","the","env","'s","action","space","'s","bounds",".","For","example",",","if","the","action","space","of","the","environment","is","`","Box","(","-0.5",",","0.5",",","(","1",",",")",")","`",",","the","model","outputs","mean","and","stddev","as","0.1","and","exp","(","0.2",")",",","and","we","sample","an","action","of","0.9","from","the","resulting","distribution",",","then","this","0.9","will","be","clipped","to","0.5","to","fit","into","the","[","-0.5","0.5","]","interval","."]
code: def __init__(
      self,
      *,
      normalize_actions: bool,
      clip_actions: bool,
      **kwargs,
  ):
      """Initializes a DefaultModuleToEnv (connector piece) instance.
  
      Args:
          normalize_actions: If True, actions coming from the RLModule's distribution
              (or are directly computed by the RLModule w/o sampling) will
              be assumed 0.0 centered with a small stddev (only affecting Box
              components) and thus be unsquashed (and clipped, just in case) to the
              bounds of the env's action space. For example, if the action space of
              the environment is `Box(-2.0, -0.5, (1,))`, the model outputs
              mean and stddev as 0.1 and exp(0.2), and we sample an action of 0.9
              from the resulting distribution, then this 0.9 will be unsquashed into
              the [-2.0 -0.5] interval. If - after unsquashing - the action still
              breaches the action space, it will simply be clipped.
          clip_actions: If True, actions coming from the RLModule's distribution
              (or are directly computed by the RLModule w/o sampling) will be clipped
              such that they fit into the env's action space's bounds.
              For example, if the action space of the environment is
              `Box(-0.5, 0.5, (1,))`, the model outputs
              mean and stddev as 0.1 and exp(0.2), and we sample an action of 0.9
              from the resulting distribution, then this 0.9 will be clipped to 0.5
              to fit into the [-0.5 0.5] interval.
      """
      super().__init__(**kwargs)
  
      self._action_space_struct = get_base_struct_from_space(
          self.action_space
      )
      self.normalize_actions = normalize_actions
      self.clip_actions = clip_actions
  
file_path: ray/python/ray/rllib/connectors/module_to_env/default_module_to_env.py
imports: from typing import Any, List, Optional
  import numpy
  import tree
  from ray.rllib.connectors.connector_v2 import ConnectorV2
  from ray.rllib.core.models.base import STATE_OUT
  from ray.rllib.core.rl_module.rl_module import RLModule
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.numpy import convert_to_numpy
  from ray.rllib.utils.spaces.space_utils import clip_action, get_base_struct_from_space, unsquash_action
  from ray.rllib.utils.typing import EpisodeType
  from ray.util.annotations import PublicAPI
label_desc: Use image node_id 1 to create a new DefaultModuleToEnv object from inherited base classes: ConnectorV2 with example: obj = DefaultModuleToEnv()