code: def learn_test_plus_evaluate(algo: str, env="CartPole-v1"):
      for fw in framework_iterator(frameworks=("tf", "torch")):
          fw_ = ', \\"framework\\": \\"{}\\"'.format(fw)
  
          tmp_dir = os.popen("mktemp -d").read()[:-1]
          if not os.path.exists(tmp_dir):
              # Last resort: Resolve via underlying tempdir (and cut tmp_.
              tmp_dir = (
                  ray._private.utils.tempfile.gettempdir() + tmp_dir[4:]
              )
              if not os.path.exists(tmp_dir):
                  sys.exit(1)
  
          print("Saving results to {}".format(tmp_dir))
  
          rllib_dir = str(Path(__file__).parent.parent.absolute())
  
          # This is only supported without RLModule API. See AlgorithmConfig for
          # more info. We need to prefetch the default config that will be used when we
          # call rllib train here to see if the RLModule API is enabled.
          algo_cls = get_trainable_cls(algo)
          config = algo_cls.get_default_config()
          if config._enable_new_api_stack:
              eval_ = ', \\"evaluation_config\\": {}'
          else:
              eval_ = (
                  ', \\"evaluation_config\\": {\\"explore\\": false}'
              )
  
          print(
              "RLlib dir = {}\nexists={}".format(
                  rllib_dir, os.path.exists(rllib_dir)
              )
          )
          os.system(
              "TEST_TMPDIR='{}' python {}/train.py --local-dir={} --run={} "
              "--checkpoint-freq=1 --checkpoint-at-end ".format(
                  tmp_dir, rllib_dir, tmp_dir, algo
              )
              + '--config="{\\"num_gpus\\": 0, \\"num_workers\\": 1'
              + eval_
              + fw_
              + '}" '
              + '--stop="{\\"episode_reward_mean\\": 100.0}"'
              + " --env={}".format(env)
          )
  
          # Find last checkpoint and use that for the rollout.
          checkpoint_path = os.popen(
              "ls {}/default/*/checkpoint_*/algorithm_state.pkl".format(
                  tmp_dir
              )
          ).read()[:-1]
          checkpoints = [
              cp
              for cp in checkpoint_path.split("\n")
              if re.match(r"^.+algorithm_state.pkl$", cp)
          ]
          # Sort by number and pick last (which should be the best checkpoint).
          last_checkpoint = sorted(
              checkpoints,
              key=lambda x: int(
                  re.match(r".+checkpoint_(\d+).+", x).group(1)
              ),
          )[-1]
          assert re.match(
              r"^.+checkpoint_\d+/algorithm_state.pkl$", last_checkpoint
          )
          if not os.path.exists(last_checkpoint):
              sys.exit(1)
          print("Best checkpoint={} (exists)".format(last_checkpoint))
  
          # Test rolling out n steps.
          result = os.popen(
              "python {}/evaluate.py --run={} "
              "--steps=400 "
              '--out="{}/rollouts_n_steps.pkl" "{}"'.format(
                  rllib_dir, algo, tmp_dir, last_checkpoint
              )
          ).read()[:-1]
          if not os.path.exists(tmp_dir + "/rollouts_n_steps.pkl"):
              sys.exit(1)
          print("Rollout output exists -> Checking reward ...")
          episodes = result.split("\n")
          mean_reward = 0.0
          num_episodes = 0
          for ep in episodes:
              mo = re.match(r"Episode .+reward: ([\d\.\-]+)", ep)
              if mo:
                  mean_reward += float(mo.group(1))
                  num_episodes += 1
          mean_reward /= num_episodes
          print("Rollout's mean episode reward={}".format(mean_reward))
          assert mean_reward >= 100.0
  
          # Cleanup.
          os.popen('rm -rf "{}"'.format(tmp_dir)).read()
  
imports: import os
  from pathlib import Path
  import re
  import sys
  import unittest
  from unittest import mock
  import ray
  from ray import air, tune
  from ray.rllib.algorithms.algorithm_config import AlgorithmConfig
  from ray.rllib.examples.env.multi_agent import MultiAgentCartPole
  from ray.rllib.utils.test_utils import framework_iterator
  from ray.tune.registry import get_trainable_cls
  from ray.rllib.core.rl_module.rl_module import SingleAgentRLModuleSpec
  from ray.rllib.core.rl_module.marl_module import MultiAgentRLModuleSpec
label_desc: Use image node_id 2 for calling a global function with example usage: learn_test_plus_evaluate(algo, env) without return types