class_docstr: Record of spaces (i.e., raw action, observation, and associated data) from a single sub-step.
class_docstr_tok: ["Record","of","spaces","(","i.e.",",","raw","action",",","observation",",","and","associated","data",")","from","a","single","sub-step","."]
docstr: Stack multiple records into a single spaces record. Useful for processing multiple records in a batch.
  
  All the records should be in numpy and have the same structure of the spaces (i.e. come from the same
  environment etc.).
  
  :param records: Records to stack.
  :return: Single stacked record, containing all the given records, and having the corresponding batch shape.
docstr_tok: ["Stack","multiple","records","into","a","single","spaces","record",".","Useful","for","processing","multiple","records","in","a","batch",".","All","the","records","should","be","in","numpy","and","have","the","same","structure","of","the","spaces","(","i.e",".","come","from","the","same","environment","etc.",")",".",":","param","records",":","Records","to","stack",".",":","return",":","Single","stacked","record",",","containing","all","the","given","records",",","and","having","the","corresponding","batch","shape","."]
code: def stack(cls, records: List["SpacesRecord"]) -> "SpacesRecord":
      """Stack multiple records into a single spaces record. Useful for processing multiple records in a batch.
  
      All the records should be in numpy and have the same structure of the spaces (i.e. come from the same
      environment etc.).
  
      :param records: Records to stack.
      :return: Single stacked record, containing all the given records, and having the corresponding batch shape.
      """
  
      assert (
          len(set([r.substep_key for r in records])) == 1
      ), "Cannot batch records for different sub-step keys."
      assert (
          len(set([r.agent_id for r in records])) == 1
      ), "Cannot batch records for different agent ids."
  
      stacked_record = SpacesRecord(
          actor_id=records[0].actor_id,
          observation=stack_numpy_dict_list(
              [r.observation for r in records]
          ),
          action=stack_numpy_dict_list([r.action for r in records]),
          reward=np.stack([r.reward for r in records]),
          done=np.stack([r.done for r in records]),
      )
  
      if records[0].next_observation:
          stacked_record.next_observation = stack_numpy_dict_list(
              [r.next_observation for r in records]
          )
  
      if records[0].logits:
          stacked_record.logits = stack_torch_dict_list(
              [r.logits for r in records]
          )
  
      if records[0].policy_record:
          raise NotImplementedError(
              "Stacking is not implemented for policy records"
          )
  
      stacked_record.batch_shape = [len(records)]
      if records[0].batch_shape:
          stacked_record.batch_shape += records[0].batch_shape
  
      return stacked_record
  
file_path: maze/maze/core/trajectory_recording/records/spaces_record.py
imports: from dataclasses import dataclass
  from typing import Dict, Union, Optional, List, Any
  import numpy
  import torch
  from maze.core.env.structured_env import ActorID
  from maze.perception.perception_utils import convert_to_numpy, convert_to_torch
  from maze.train.utils.train_utils import stack_numpy_dict_list, stack_torch_dict_list
label_desc: Use image node_id 1 for calling the SpacesRecord obj's underlying member method code with example usage: obj.stack(cls, records) and returns: stacked_record