class_docstr: Returns an abstract Garage wrapper class for gym.Env.
  
  In order to provide pickling (serialization) and parameterization
  for :class:`gym.Env` instances, they must be wrapped with :class:`GymEnv`.
  This ensures compatibility with existing samplers and checkpointing when
  the envs are passed internally around garage.
  
  Furthermore, classes inheriting from :class:`GymEnv` should silently
  convert :attribute:`action_space` and :attribute:`observation_space`
  from :class:`gym.Space` to :class:`akro.Space`.
  
  :class:`GymEnv` handles all environments created by :func:`~gym.make`.
  
  It returns a different wrapper class instance if the input environment
  requires special handling.
  Current supported wrapper classes are:
      garage.envs.bullet.BulletEnv for Bullet-based gym environments.
  See __new__() for details.
class_docstr_tok: ["Returns","an","abstract","Garage","wrapper","class","for","gym.Env",".","In","order","to","provide","pickling","(","serialization",")","and","parameterization","for",":","class",":","`","gym.Env","`","instances",",","they","must","be","wrapped","with",":","class",":","`","GymEnv","`",".","This","ensures","compatibility","with","existing","samplers","and","checkpointing","when","the","envs","are","passed","internally","around","garage",".","Furthermore",",","classes","inheriting","from",":","class",":","`","GymEnv","`","should","silently","convert",":","attribute",":","`","action_space","`","and",":","attribute",":","`","observation_space","`","from",":","class",":","`","gym.Space","`","to",":","class",":","`","akro.Space","`",".",":","class",":","`","GymEnv","`","handles","all","environments","created","by",":","func",":","`","~gym.make","`",".","It","returns","a","different","wrapper","class","instance","if","the","input","environment","requires","special","handling",".","Current","supported","wrapper","classes","are",":","garage.envs.bullet.BulletEnv","for","Bullet-based","gym","environments",".","See","__new__","(",")","for","details","."]
docstr: Initializes a GymEnv.
  
  Note that if `env` and `env_name` are passed in at the same time,
  `env` will be wrapped.
  
  Args:
      env (gym.Env or str): An gym.Env Or a name of the gym environment
          to be created.
      is_image (bool): True if observations contain pixel values,
          false otherwise. Setting this to true converts a gym.Spaces.Box
          obs space to an akro.Image and normalizes pixel values.
      max_episode_length (int): The maximum steps allowed for an episode.
  
  Raises:
      ValueError: if `env` neither a gym.Env object nor a string.
      RuntimeError: if the environment is wrapped by a TimeLimit and its
          max_episode_steps is not equal to its spec's time limit value.
docstr_tok: ["Initializes","a","GymEnv",".","Note","that","if","`","env","`","and","`","env_name","`","are","passed","in","at","the","same","time",",","`","env","`","will","be","wrapped",".","Args",":","env","(","gym.Env","or","str",")",":","An","gym.Env","Or","a","name","of","the","gym","environment","to","be","created",".","is_image","(","bool",")",":","True","if","observations","contain","pixel","values",",","false","otherwise",".","Setting","this","to","true","converts","a","gym.Spaces.Box","obs","space","to","an","akro.Image","and","normalizes","pixel","values",".","max_episode_length","(","int",")",":","The","maximum","steps","allowed","for","an","episode",".","Raises",":","ValueError",":","if","`","env","`","neither","a","gym.Env","object","nor","a","string",".","RuntimeError",":","if","the","environment","is","wrapped","by","a","TimeLimit","and","its","max_episode_steps","is","not","equal","to","its","spec","'s","time","limit","value","."]
code: def __init__(self, env, is_image=False, max_episode_length=None):
      """Initializes a GymEnv.
  
      Note that if `env` and `env_name` are passed in at the same time,
      `env` will be wrapped.
  
      Args:
          env (gym.Env or str): An gym.Env Or a name of the gym environment
              to be created.
          is_image (bool): True if observations contain pixel values,
              false otherwise. Setting this to true converts a gym.Spaces.Box
              obs space to an akro.Image and normalizes pixel values.
          max_episode_length (int): The maximum steps allowed for an episode.
  
      Raises:
          ValueError: if `env` neither a gym.Env object nor a string.
          RuntimeError: if the environment is wrapped by a TimeLimit and its
              max_episode_steps is not equal to its spec's time limit value.
      """
      self._env = None
      if isinstance(env, str):
          self._env = gym.make(env)
      elif isinstance(env, gym.Env):
          self._env = env
      else:
          raise ValueError(
              "GymEnv can take env as either a string, "
              "or an Gym environment, but got type {} "
              "instead.".format(type(env))
          )
  
      self._max_episode_length = _get_time_limit(
          self._env, max_episode_length
      )
  
      try:
          self._render_modes = self._env.metadata["render_modes"]
      except KeyError:
          self._render_modes = self._env.metadata["render.modes"]
  
      self._step_cnt = None
      self._visualize = False
  
      self._action_space = akro.from_gym(self._env.action_space)
      self._observation_space = akro.from_gym(
          self._env.observation_space, is_image=is_image
      )
      self._spec = EnvSpec(
          action_space=self.action_space,
          observation_space=self.observation_space,
          max_episode_length=self._max_episode_length,
      )
      # stores env_info keys & value types to ensure subsequent env_infos
      # are consistent
      self._env_info = None
  
imports: import copy
  import warnings
  import akro
  import gym
  import numpy
  from garage import Environment, EnvSpec, EnvStep, StepType
label_desc: Use image node_id 2 to create a new GymEnv object from inherited base classes: Environment with example: obj = GymEnv(env, is_image, max_episode_length)