class_docstr: Records spaces (i.e., raw actions and observations) from a single environment step.
  
  Individual items are structured in dictionaries, with keys corresponding to the structured sub-step IDs.
  
  Provides helpers methods for batching, i.e. stacking of multiple spaces records to be processed by a model
  in a single batch.
class_docstr_tok: ["Records","spaces","(","i.e.",",","raw","actions","and","observations",")","from","a","single","environment","step",".","Individual","items","are","structured","in","dictionaries",",","with","keys","corresponding","to","the","structured","sub-step","IDs",".","Provides","helpers","methods","for","batching",",","i.e",".","stacking","of","multiple","spaces","records","to","be","processed","by","a","model","in","a","single","batch","."]
docstr: Convert a state record (containing a Maze state and Maze action) into a spaces record (containing
  raw actions and observations for each sub-step).
  
  Maze states and actions are converted to spaces using the supplied conversion env -- it's action and
  observation interfaces, as well as the wrapper stack determine the format of the converted actions
  and observations.
  
  This is useful e.g. for behavioral cloning, when we have recorded Maze states and actions from teacher runs,
  and now need to convert these into raw actions and observations to be fed to a model.
  
  Note that multi-agent scenarios are not supported yet (the conversion only support a single
  action-observation pair per sub-step key).
  
  :param state_record: State record to convert.
  :param conversion_env: Environment to use for the conversion. Determines the format of the resulting spaces.
  :param first_step_in_episode: Flag whether this is the first step in an episode (to resets stateful wrapper)
  :return: Converted spaces record.
code: def converted_from(
      cls,
      state_record: StateRecord,
      conversion_env: MazeEnv,
      first_step_in_episode: bool,
  ) -> "StructuredSpacesRecord":
      """Convert a state record (containing a Maze state and Maze action) into a spaces record (containing
      raw actions and observations for each sub-step).
  
      Maze states and actions are converted to spaces using the supplied conversion env -- it's action and
      observation interfaces, as well as the wrapper stack determine the format of the converted actions
      and observations.
  
      This is useful e.g. for behavioral cloning, when we have recorded Maze states and actions from teacher runs,
      and now need to convert these into raw actions and observations to be fed to a model.
  
      Note that multi-agent scenarios are not supported yet (the conversion only support a single
      action-observation pair per sub-step key).
  
      :param state_record: State record to convert.
      :param conversion_env: Environment to use for the conversion. Determines the format of the resulting spaces.
      :param first_step_in_episode: Flag whether this is the first step in an episode (to resets stateful wrapper)
      :return: Converted spaces record.
      """
      obs = (
          state_record.maze_state.observation
          if isinstance(state_record.maze_state, RawState)
          else state_record.maze_state
      )
      action = (
          state_record.maze_action.action
          if isinstance(state_record.maze_action, RawMazeAction)
          else state_record.maze_action
      )
  
      obs, action = conversion_env.get_observation_and_action_dicts(
          obs, action, first_step_in_episode
      )
  
      substep_records = [
          SpacesRecord(
              actor_id=ActorID(substep_key, 0),
              observation=obs[substep_key],
              action=action[substep_key],
              reward=None,
              done=None,
          )
          for substep_key in obs.keys()
      ]
  
      substep_records[-1].done = state_record.done
  
      return StructuredSpacesRecord(substep_records=substep_records)
  
imports: from dataclasses import dataclass
  from typing import Optional, List, Union, Dict
  import numpy
  import torch
  from maze.core.env.action_conversion import ActionType, TorchActionType
  from maze.core.env.maze_env import MazeEnv
  from maze.core.env.observation_conversion import ObservationType, TorchObservationType
  from maze.core.env.structured_env import ActorID
  from maze.core.log_events.step_event_log import StepEventLog
  from maze.core.log_stats.log_stats import LogStats
  from maze.core.trajectory_recording.records.raw_maze_state import RawState, RawMazeAction
  from maze.core.trajectory_recording.records.spaces_record import SpacesRecord, PolicyRecordType
  from maze.core.trajectory_recording.records.state_record import StateRecord
label_desc: Use image node_id 5 for calling the StructuredSpacesRecord obj's underlying member method code with example usage: obj.converted_from(cls, state_record, conversion_env, first_step_in_episode) and returns: StructuredSpacesRecord