code: def check_train_results(train_results: ResultDict):
      """Checks proper structure of a Algorithm.train() returned dict.
  
      Args:
          train_results: The train results dict to check.
  
      Raises:
          AssertionError: If `train_results` doesn't have the proper structure or
              data in it.
      """
      # Import these here to avoid circular dependencies.
      from ray.rllib.policy.sample_batch import DEFAULT_POLICY_ID
      from ray.rllib.utils.metrics.learner_info import (
          LEARNER_INFO,
          LEARNER_STATS_KEY,
      )
  
      # Assert that some keys are where we would expect them.
      for key in [
          "agent_timesteps_total",
          "config",
          "custom_metrics",
          "episode_len_mean",
          "episode_reward_max",
          "episode_reward_mean",
          "episode_reward_min",
          "hist_stats",
          "info",
          "iterations_since_restore",
          "num_healthy_workers",
          "perf",
          "policy_reward_max",
          "policy_reward_mean",
          "policy_reward_min",
          "sampler_perf",
          "time_since_restore",
          "time_this_iter_s",
          "timesteps_total",
          "timers",
          "time_total_s",
          "training_iteration",
      ]:
          assert (
              key in train_results
          ), f"'{key}' not found in `train_results` ({train_results})!"
  
      # Make sure, `config` is an actual dict, not an AlgorithmConfig object.
      assert isinstance(
          train_results["config"], dict
      ), "`config` in results not a python dict!"
  
      from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  
      is_multi_agent = (
          AlgorithmConfig()
          .update_from_dict(
              {"policies": train_results["config"]["policies"]}
          )
          .is_multi_agent()
      )
  
      # Check in particular the "info" dict.
      info = train_results["info"]
      assert (
          LEARNER_INFO in info
      ), f"'learner' not in train_results['infos'] ({info})!"
      assert (
          "num_steps_trained" in info or NUM_ENV_STEPS_TRAINED in info
      ), f"'num_(env_)?steps_trained' not in train_results['infos'] ({info})!"
  
      learner_info = info[LEARNER_INFO]
  
      # Make sure we have a default_policy key if we are not in a
      # multi-agent setup.
      if not is_multi_agent:
          # APEX algos sometimes have an empty learner info dict (no metrics
          # collected yet).
          assert (
              len(learner_info) == 0
              or DEFAULT_POLICY_ID in learner_info
          ), (
              f"'{DEFAULT_POLICY_ID}' not found in "
              f"train_results['infos']['learner'] ({learner_info})!"
          )
  
      for pid, policy_stats in learner_info.items():
          if pid == "batch_count":
              continue
  
          # the pid can be __all__ in multi-agent case when the new learner stack is
          # enabled.
          if pid == "__all__":
              continue
  
          # On the new API stack, policy has no LEARNER_STATS_KEY under it anymore.
          if LEARNER_STATS_KEY in policy_stats:
              learner_stats = policy_stats[LEARNER_STATS_KEY]
          else:
              learner_stats = policy_stats
          for key, value in learner_stats.items():
              # Min- and max-stats should be single values.
              if key.startswith("min_") or key.startswith("max_"):
                  assert np.isscalar(
                      value
                  ), f"'key' value not a scalar ({value})!"
  
      return train_results
  
imports: from collections import Counter
  import copy
  import gymnasium
  from gymnasium.spaces import Box, Discrete, MultiDiscrete, MultiBinary
  from gymnasium.spaces import Dict
  from gymnasium.spaces import Tuple
  import inspect
  import logging
  import numpy
  import os
  import pprint
  import random
  import re
  import time
  import tree
  from typing import TYPE_CHECKING, Any, Dict, List, Optional, Sequence, Tuple, Type, Union
  import yaml
  import ray
  from ray import air, tune
  from ray.rllib.env.wrappers.atari_wrappers import is_atari, wrap_deepmind
  from ray.rllib.utils.framework import try_import_jax, try_import_tf, try_import_torch
  from ray.rllib.utils.metrics import DIFF_NUM_GRAD_UPDATES_VS_SAMPLER_POLICY, NUM_ENV_STEPS_SAMPLED, NUM_ENV_STEPS_TRAINED
  from ray.rllib.utils.nested_dict import NestedDict
  from ray.rllib.utils.typing import ResultDict
  from ray.rllib.utils.error import UnsupportedSpaceException
  from ray.tune import CLIReporter, run_experiments
label_desc: Use image node_id 7 for calling a global function with example usage: check_train_results(train_results) and returns: train_results