code: def run_rollout(checkpoint, algo, render, steps, episodes):
      config_dir = os.path.dirname(checkpoint)
      config_path = os.path.join(config_dir, "params.pkl")
      config = None
  
      # Try parent directory.
      if not os.path.exists(config_path):
          config_path = os.path.join(config_dir, "../params.pkl")
  
      # Load the config from pickled.
      if os.path.exists(config_path):
          with open(config_path, "rb") as f:
              config = cloudpickle.load(f)
      # If no pkl file found, require command line `--config`.
      else:
          raise ValueError(
              "Could not find params.pkl in either the checkpoint dir or its parent directory"
          )
  
      # Make sure worker 0 has an Env.
      config["create_env_on_driver"] = True
  
      # Merge with `evaluation_config` (first try from command line, then from
      # pkl file).
      evaluation_config = copy.deepcopy(
          config.get("evaluation_config", {})
      )
      config = merge_dicts(config, evaluation_config)
      env = config.get("env")
  
      # Make sure we have evaluation workers.
      if not config.get("evaluation_num_workers"):
          config["evaluation_num_workers"] = config.get(
              "num_workers", 0
          )
      if not config.get("evaluation_duration"):
          config["evaluation_duration"] = 1
  
      # Hard-override this as it raises a warning by Algorithm otherwise.
      # Makes no sense anyways, to have it set to None as we don't call
      # `Algorithm.train()` here.
      config["evaluation_interval"] = 1
  
      # Rendering settings.
      config["render_env"] = render
  
      # Create the Algorithm from config.
      cls = get_trainable_cls(algo)
      algorithm = cls(env=env, config=config)
  
      # Load state from checkpoint, if provided.
      if checkpoint:
          algorithm.restore(checkpoint)
  
      # Do the actual rollout.
      with RolloutSaver(
          outfile=None,
          use_shelve=False,
          write_update_file=False,
          target_steps=steps,
          target_episodes=episodes,
          save_info=False,
      ) as saver:
          rollout(algorithm, env, steps, episodes, saver, not render)
      algorithm.stop()
  
file_path: MachineLearningNotebooks/how-to-use-azureml/reinforcement-learning/cartpole-on-compute-instance/files/cartpole_rollout.py
imports: import os
  import sys
  import argparse
  from ray.rllib.evaluate import RolloutSaver, rollout
  from ray_on_aml.core import Ray_On_AML
  import ray.cloudpickle
  from ray.tune.utils import merge_dicts
  from ray.tune.registry import get_trainable_cls, _global_registry, ENV_CREATOR
  from azureml.core import Run
  from utils import callbacks
  import collections
  import copy
  import gymnasium
  import json
  from pathlib import Path
label_desc: Use image node_id 1 for calling a global function with example usage: run_rollout(checkpoint, algo, render, steps, episodes) without return types