class_docstr: [OpenAI Gym](https://gym.openai.com/) environment adapter (specification key: `gym`,
  `openai_gym`).
  
  May require:
  ```bash
  pip3 install gym
  pip3 install gym[all]
  ```
  
  Args:
      level (string | gym.Env): Gym id or instance
          (<span style="color:#C00000"><b>required</b></span>).
      visualize (bool): Whether to visualize interaction
          (<span style="color:#00C000"><b>default</b></span>: false).
      min_value (float): Lower bound clipping for otherwise unbounded state values
          (<span style="color:#00C000"><b>default</b></span>: no clipping).
      max_value (float): Upper bound clipping for otherwise unbounded state values
          (<span style="color:#00C000"><b>default</b></span>: no clipping).
      terminal_reward (float): Additional reward for early termination, if otherwise
          indistinguishable from termination due to maximum number of timesteps
          (<span style="color:#00C000"><b>default</b></span>: Gym default).
      reward_threshold (float): Gym environment argument, the reward threshold before the task is
          considered solved
          (<span style="color:#00C000"><b>default</b></span>: Gym default).
      drop_states_indices (list[int]): Drop states indices
          (<span style="color:#00C000"><b>default</b></span>: none).
      visualize_directory (string): Visualization output directory
          (<span style="color:#00C000"><b>default</b></span>: none).
      kwargs: Additional Gym environment arguments.
class_docstr_tok: ["[","OpenAI","Gym","]","(","https",":","\/\/gym.openai.com\/",")","environment","adapter","(","specification","key",":","`","gym","`",",","`","openai_gym","`",")",".","May","require",":","``","`","bash","pip3","install","gym","pip3","install","gym","[","all","]","``","`","Args",":","level","(","string","|","gym.Env",")",":","Gym","id","or","instance","(","<","span","style=","''","color",":","#","C00000","''",">","<","b",">","required","<","\/b",">","<","\/span",">",")",".","visualize","(","bool",")",":","Whether","to","visualize","interaction","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","false",")",".","min_value","(","float",")",":","Lower","bound","clipping","for","otherwise","unbounded","state","values","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","no","clipping",")",".","max_value","(","float",")",":","Upper","bound","clipping","for","otherwise","unbounded","state","values","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","no","clipping",")",".","terminal_reward","(","float",")",":","Additional","reward","for","early","termination",",","if","otherwise","indistinguishable","from","termination","due","to","maximum","number","of","timesteps","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","Gym","default",")",".","reward_threshold","(","float",")",":","Gym","environment","argument",",","the","reward","threshold","before","the","task","is","considered","solved","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","Gym","default",")",".","drop_states_indices","(","list","[","int","]",")",":","Drop","states","indices","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","none",")",".","visualize_directory","(","string",")",":","Visualization","output","directory","(","<","span","style=","''","color",":","#","00C000","''",">","<","b",">","default","<","\/b",">","<","\/span",">",":","none",")",".","kwargs",":","Additional","Gym","environment","arguments","."]
code: def unflatten_action(action):
      if not isinstance(action, dict):
          if np.isinf(action).any() or np.isnan(action).any():
              raise TensorforceError("Action contains inf or nan.")
  
          return action
  
      elif (
          all(name.startswith("gymmdc") for name in action)
          or all(name.startswith("gymbox") for name in action)
          or all(name.startswith("gymtpl") for name in action)
      ):
          space_type = next(iter(action))[:6]
          actions = list()
          n = 0
          while True:
              if any(
                  name.startswith(space_type + str(n) + "_")
                  for name in action
              ):
                  inner_action = [
                      value
                      for name, value in action.items()
                      if name.startswith(space_type + str(n))
                  ]
                  assert len(inner_action) == 1
                  actions.append(
                      OpenAIGym.unflatten_action(action=inner_action[0])
                  )
              elif any(name == space_type + str(n) for name in action):
                  actions.append(
                      OpenAIGym.unflatten_action(
                          action=action[space_type + str(n)]
                      )
                  )
              else:
                  break
              n += 1
          if all(name.startswith("gymmdc") for name in action) or all(
              name.startswith("gymbox") for name in action
          ):
              name = next(iter(action))
              shape = tuple(
                  int(x) for x in name[name.index("_") + 1 :].split("_")
              )
              return np.array(actions).reshape(shape)
          else:
              return tuple(actions)
  
      else:
          actions = dict()
          for name, action in action.items():
              if "_" in name:
                  name, inner_name = name.split("_", 1)
                  if name not in actions:
                      actions[name] = dict()
                  actions[name][inner_name] = action
              else:
                  actions[name] = action
          for name, action in actions.items():
              if isinstance(action, dict):
                  actions[name] = OpenAIGym.unflatten_action(
                      action=action
                  )
          return actions
  
file_path: tensorforce/tensorforce/environments/openai_gym.py
imports: import importlib
  import numpy
  from tensorforce import TensorforceError, util
  from tensorforce.environments import Environment
label_desc: Use image node_id 13 for calling the OpenAIGym obj's underlying member method code with example usage: obj.unflatten_action(action) and returns: action, actions, np, tuple