code: def flat_structured_space(
      structured_space_dict: Dict[Union[int, str], spaces.Dict]
  ) -> spaces.Dict:
      """Compiles a flat gym.spaces.Dict space from a structured environment space.
      :param: The structured dictionary spaces.
      :return: The flattened dictionary space.
      """
      flat_dict = dict()
      for sub_step_key, sub_step_space in structured_space_dict.items():
          assert isinstance(sub_step_space, spaces.Dict)
  
          for key, space in sub_step_space.spaces.items():
              # check if the heads match
              if key in flat_dict:
                  assert (
                      flat_dict[key] == space
                  ), f"Key '{key}' already contained in flat space dictionary!"
  
              flat_dict[key] = space
      return spaces.Dict(spaces=flat_dict)
  
imports: from typing import Dict, Union, Sequence
  from gym import spaces
  from maze.core.env.structured_env import StepKeyType
label_desc: Use image node_id 1 for calling a global function with example usage: flat_structured_space(structured_space_dict) and returns: spaces