class_docstr: A connector piece that stacks the previous n observations into one.
docstr: Initializes a _FrameStackingConnector instance.
  
  Args:
      num_frames: The number of observation frames to stack up (into a single
          observation) for the RLModule's forward pass.
      as_preprocessor: Whether this connector should simply postprocess the
          received observations from the env and store these directly in the
          episode object. In this mode, the connector can only be used in
          an `EnvToModulePipeline` and it will act as a classic
          RLlib framestacking postprocessor.
      as_learner_connector: Whether this connector is part of a Learner connector
          pipeline, as opposed to an env-to-module pipeline.
docstr_tok: ["Initializes","a","_FrameStackingConnector","instance",".","Args",":","num_frames",":","The","number","of","observation","frames","to","stack","up","(","into","a","single","observation",")","for","the","RLModule","'s","forward","pass",".","as_preprocessor",":","Whether","this","connector","should","simply","postprocess","the","received","observations","from","the","env","and","store","these","directly","in","the","episode","object",".","In","this","mode",",","the","connector","can","only","be","used","in","an","`","EnvToModulePipeline","`","and","it","will","act","as","a","classic","RLlib","framestacking","postprocessor",".","as_learner_connector",":","Whether","this","connector","is","part","of","a","Learner","connector","pipeline",",","as","opposed","to","an","env-to-module","pipeline","."]
code: def __init__(
      self,
      *,
      # Base class constructor args.
      input_observation_space: gym.Space,
      input_action_space: gym.Space,
      # Specific framestacking args.
      num_frames: int = 1,
      as_learner_connector: bool = False,
      **kwargs,
  ):
      """Initializes a _FrameStackingConnector instance.
  
      Args:
          num_frames: The number of observation frames to stack up (into a single
              observation) for the RLModule's forward pass.
          as_preprocessor: Whether this connector should simply postprocess the
              received observations from the env and store these directly in the
              episode object. In this mode, the connector can only be used in
              an `EnvToModulePipeline` and it will act as a classic
              RLlib framestacking postprocessor.
          as_learner_connector: Whether this connector is part of a Learner connector
              pipeline, as opposed to an env-to-module pipeline.
      """
      super().__init__(
          input_observation_space=input_observation_space,
          input_action_space=input_action_space,
          **kwargs,
      )
  
      self.num_frames = num_frames
      self.as_learner_connector = as_learner_connector
  
      # Some assumptions: Space is box AND last dim (the stacking one) is 1.
      assert isinstance(self.observation_space, gym.spaces.Box)
      assert self.observation_space.shape[-1] == 1
  
      # Change our observation space according to the given stacking settings.
      self.observation_space = gym.spaces.Box(
          low=np.repeat(
              self.observation_space.low,
              repeats=self.num_frames,
              axis=-1,
          ),
          high=np.repeat(
              self.observation_space.high,
              repeats=self.num_frames,
              axis=-1,
          ),
          shape=list(self.observation_space.shape)[:-1]
          + [self.num_frames],
          dtype=self.observation_space.dtype,
      )
  
file_path: ray/python/ray/rllib/connectors/common/frame_stacking.py
imports: import numpy
  from typing import Any, List, Optional
  import gymnasium
  import tree
  from ray.rllib.connectors.connector_v2 import ConnectorV2
  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.spaces.space_utils import batch
  from ray.rllib.utils.typing import EpisodeType
label_desc: Use image node_id 1 to create a new _FrameStackingConnector object from inherited base classes: ConnectorV2 with example: obj = _FrameStackingConnector()