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 __init__(
      self,
      level,
      visualize=False,
      import_modules=None,
      min_value=None,
      max_value=None,
      terminal_reward=0.0,
      reward_threshold=None,
      drop_states_indices=None,
      visualize_directory=None,
      **kwargs,
  ):
      super().__init__()
  
      import gym
      import gym.wrappers
  
      if import_modules is None:
          pass
      elif isinstance(import_modules, str):
          importlib.import_module(name=import_modules)
      elif isinstance(import_modules, (list, tuple)):
          for module in import_modules:
              importlib.import_module(name=module)
  
      self.level = level
      self.visualize = visualize
      self.terminal_reward = terminal_reward
  
      if isinstance(level, gym.Env):
          self.environment = self.level
          self.level = self.level.__class__.__name__
          self._max_episode_timesteps = None
      elif isinstance(level, type) and issubclass(level, gym.Env):
          self.environment = self.level(**kwargs)
          self.level = self.level.__class__.__name__
          self._max_episode_timesteps = None
      else:
          (
              self.environment,
              self._max_episode_timesteps,
          ) = self.__class__.create_level(
              level=self.level,
              max_episode_steps=None,
              reward_threshold=reward_threshold,
              **kwargs,
          )
  
      if visualize_directory is not None:
          self.environment = gym.wrappers.Monitor(
              env=self.environment, directory=visualize_directory
          )
  
      self.min_value = min_value
      self.max_value = max_value
      if min_value is not None:
          if max_value is None:
              raise TensorforceError.required(
                  name="OpenAIGym", argument="max_value"
              )
          self.states_spec = OpenAIGym.specs_from_gym_space(
              space=self.environment.observation_space,
              min_value=min_value,
              max_value=max_value,
          )
      elif max_value is not None:
          raise TensorforceError.required(
              name="OpenAIGym", argument="min_value"
          )
      else:
          self.states_spec = OpenAIGym.specs_from_gym_space(
              space=self.environment.observation_space,
              allow_infinite_box_bounds=True,
          )
  
      if drop_states_indices is None:
          self.drop_states_indices = None
      else:
          assert "shape" in self.states_spec
          self.drop_states_indices = sorted(drop_states_indices)
          assert len(self.states_spec["shape"]) == 1
          num_dropped = len(self.drop_states_indices)
          self.states_spec["shape"] = (
              self.states_spec["shape"][0] - num_dropped,
          )
  
      self.actions_spec = OpenAIGym.specs_from_gym_space(
          space=self.environment.action_space
      )
  
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 3 to create a new OpenAIGym object from inherited base classes: Environment with example: obj = OpenAIGym(level, visualize, import_modules, min_value, max_value, terminal_reward, reward_threshold, drop_states_indices, visualize_directory)