class_docstr: Records actions, observations, rewards and dones in structured spaces records.
  
  Dumps one trajectory record file per episode.
  
  :param output_dir: Where to dump the serialized trajectory data. Files for individual episodes
                     will be named after the episode ID, with ".pkl" suffix.
docstr: Serializes the episode record, if available.
docstr_tok: ["Serializes","the","episode","record",",","if","available","."]
code: def write_episode_record(self) -> None:
      """Serializes the episode record, if available."""
      if (
          self.episode_record
          and len(self.episode_record.step_records) > 0
      ):
          output_path = (
              self.output_dir / f"{self.episode_record.id}.pkl"
          )
          self.output_dir.mkdir(parents=True, exist_ok=True)
          with open(output_path, "wb") as out_f:
              pickle.dump(self.episode_record, out_f)
  
imports: import pickle
  from pathlib import Path
  from typing import Union, Any, Tuple, Dict, Optional
  import gym
  from maze.core.annotations import override
  from maze.core.env.action_conversion import ActionType
  from maze.core.env.base_env import BaseEnv
  from maze.core.env.maze_action import MazeActionType
  from maze.core.env.maze_env import MazeEnv
  from maze.core.env.maze_state import MazeStateType
  from maze.core.env.observation_conversion import ObservationType
  from maze.core.trajectory_recording.records.spaces_record import SpacesRecord
  from maze.core.trajectory_recording.records.structured_spaces_record import StructuredSpacesRecord
  from maze.core.trajectory_recording.records.trajectory_record import SpacesTrajectoryRecord
  from maze.core.wrappers.wrapper import Wrapper
label_desc: Use image node_id 4 for calling the SpacesRecordingWrapper obj's underlying member method code with example usage: obj.write_episode_record() without return types