class_docstr: Randomly generates observations following the given observation_spec.
  
  If an action_spec is provided it validates that the actions used to step the
  environment fall within the defined spec.
docstr: Initializes the environment.
  
  Args:
    observation_spec: An `ArraySpec`, or a nested dict, list or tuple of
      `ArraySpec`s.
    action_spec: An `ArraySpec`, or a nested dict, list or tuple of
      `ArraySpec`s.
    episode_end_probability: Probability an episode will end when the
      environment is stepped.
    discount: Discount to set in time_steps.
    reward_fn: Callable that takes in step_type, action, an observation(s),
      and returns a numpy array of rewards.
    batch_size: (Optional) Number of observations generated per call. If this
      value is not `None`, then all actions are expected to have an additional
      major axis of size `batch_size`, and all outputs will have an additional
      major axis of size `batch_size`.
    auto_reset: Bool, whether the random environment will auto reset when it
      reaches the end of the episode. By default it will.
    seed: Seed to use for rng used in observation generation.
    render_size: Size of the random render image to return when calling
      render.
    min_duration: Number of steps at the beginning of the episode during which
      the episode can not terminate.
    max_duration: Optional number of steps after which the episode terminates
      regarless of the termination probability.
  
  Raises:
    ValueError: If batch_size argument is not None and does not match the
    shapes of discount or reward.
docstr_tok: ["Initializes","the","environment",".","Args",":","observation_spec",":","An","`","ArraySpec","`",",","or","a","nested","dict",",","list","or","tuple","of","`","ArraySpec","`","s",".","action_spec",":","An","`","ArraySpec","`",",","or","a","nested","dict",",","list","or","tuple","of","`","ArraySpec","`","s",".","episode_end_probability",":","Probability","an","episode","will","end","when","the","environment","is","stepped",".","discount",":","Discount","to","set","in","time_steps",".","reward_fn",":","Callable","that","takes","in","step_type",",","action",",","an","observation","(","s",")",",","and","returns","a","numpy","array","of","rewards",".","batch_size",":","(","Optional",")","Number","of","observations","generated","per","call",".","If","this","value","is","not","`","None","`",",","then","all","actions","are","expected","to","have","an","additional","major","axis","of","size","`","batch_size","`",",","and","all","outputs","will","have","an","additional","major","axis","of","size","`","batch_size","`",".","auto_reset",":","Bool",",","whether","the","random","environment","will","auto","reset","when","it","reaches","the","end","of","the","episode",".","By","default","it","will",".","seed",":","Seed","to","use","for","rng","used","in","observation","generation",".","render_size",":","Size","of","the","random","render","image","to","return","when","calling","render",".","min_duration",":","Number","of","steps","at","the","beginning","of","the","episode","during","which","the","episode","can","not","terminate",".","max_duration",":","Optional","number","of","steps","after","which","the","episode","terminates","regarless","of","the","termination","probability",".","Raises",":","ValueError",":","If","batch_size","argument","is","not","None","and","does","not","match","the","shapes","of","discount","or","reward","."]
code: def __init__(
      self,
      observation_spec: types.NestedArray,
      action_spec: Optional[types.NestedArray] = None,
      episode_end_probability: types.Float = 0.1,
      discount: types.Float = 1.0,
      reward_fn: Optional[RewardFn] = None,
      batch_size: Optional[types.Int] = None,
      auto_reset: bool = True,
      seed: types.Seed = 42,
      render_size: Sequence[int] = (2, 2, 3),
      min_duration: types.Int = 0,
      max_duration: Optional[types.Int] = None,
  ):
      """Initializes the environment.
  
      Args:
        observation_spec: An `ArraySpec`, or a nested dict, list or tuple of
          `ArraySpec`s.
        action_spec: An `ArraySpec`, or a nested dict, list or tuple of
          `ArraySpec`s.
        episode_end_probability: Probability an episode will end when the
          environment is stepped.
        discount: Discount to set in time_steps.
        reward_fn: Callable that takes in step_type, action, an observation(s),
          and returns a numpy array of rewards.
        batch_size: (Optional) Number of observations generated per call. If this
          value is not `None`, then all actions are expected to have an additional
          major axis of size `batch_size`, and all outputs will have an additional
          major axis of size `batch_size`.
        auto_reset: Bool, whether the random environment will auto reset when it
          reaches the end of the episode. By default it will.
        seed: Seed to use for rng used in observation generation.
        render_size: Size of the random render image to return when calling
          render.
        min_duration: Number of steps at the beginning of the episode during which
          the episode can not terminate.
        max_duration: Optional number of steps after which the episode terminates
          regarless of the termination probability.
  
      Raises:
        ValueError: If batch_size argument is not None and does not match the
        shapes of discount or reward.
      """
      self._batch_size = batch_size
      self._observation_spec = observation_spec
      self._time_step_spec = ts.time_step_spec(self._observation_spec)
      self._action_spec = action_spec or []
      self._episode_end_probability = episode_end_probability
      discount = np.asarray(discount, dtype=np.float32)
  
      if self._batch_size:
          if not discount.shape:
              discount = np.tile(discount, self._batch_size)
          if self._batch_size != len(discount):
              raise ValueError(
                  "Size of discounts must equal the batch size."
              )
      self._discount = discount
  
      if reward_fn is None:
          # Return a reward whose size matches the batch size
          if self._batch_size is None:
              self._reward_fn = lambda *_: np.asarray(
                  0.0, dtype=np.float32
              )
          else:
              self._reward_fn = lambda *_: np.zeros(
                  self._batch_size, dtype=np.float32
              )
      else:
          self._reward_fn = reward_fn
  
      self._done = True
      self._num_steps = 0
      self._min_duration = min_duration
      self._max_duration = max_duration
      self._rng = np.random.RandomState(seed)
      self._render_size = render_size
      super(RandomPyEnvironment, self).__init__(
          handle_auto_reset=auto_reset
      )
  
imports: from __future__ import absolute_import
  from __future__ import division
  from __future__ import print_function
  from typing import Callable, Optional, Sequence, Text
  import numpy
  from tf_agents.environments import py_environment
  from tf_agents.specs import array_spec
  from tf_agents.trajectories import time_step
  from tf_agents.typing import types
  from tf_agents.utils import nest_utils
label_desc: Use image node_id 1 to create a new RandomPyEnvironment object from inherited base classes: py_environment with example: obj = RandomPyEnvironment(observation_spec, action_spec, episode_end_probability, discount, reward_fn, batch_size, auto_reset, seed, render_size, min_duration, max_duration)