code: def rollout(
      policy: Policy,
      env: gym.Env,
      timestep_limit: Optional[int] = None,
      add_noise: bool = False,
      offset: float = 0.0,
  ):
      """Do a rollout.
  
      If add_noise is True, the rollout will take noisy actions with
      noise drawn from that stream. Otherwise, no action noise will be added.
  
      Args:
          policy: RLlib Policy from which to draw actions.
          env: Environment from which to draw rewards, done, and
              next state.
          timestep_limit: Steps after which to end the rollout.
              If None, use `env.spec.max_episode_steps` or 999999.
          add_noise: Indicates whether exploratory action noise should be
              added.
          offset: Value to subtract from the reward (e.g. survival bonus
              from humanoid).
      """
      max_timestep_limit = 999999
      env_timestep_limit = (
          env.spec.max_episode_steps
          if (
              hasattr(env, "spec")
              and hasattr(env.spec, "max_episode_steps")
          )
          else max_timestep_limit
      )
      timestep_limit = (
          env_timestep_limit
          if timestep_limit is None
          else min(timestep_limit, env_timestep_limit)
      )
      rewards = []
      t = 0
      observation, _ = env.reset()
      for _ in range(timestep_limit or max_timestep_limit):
          ac, _, _ = policy.compute_actions(
              [observation], add_noise=add_noise, update=True
          )
          ac = ac[0]
          observation, r, terminated, truncated, _ = env.step(ac)
          if offset != 0.0:
              r -= np.abs(offset)
          rewards.append(r)
          t += 1
          if terminated or truncated:
              break
      rewards = np.array(rewards, dtype=np.float32)
      return rewards, t
  
imports: from typing import Optional
  import gymnasium
  import numpy
  import tree
  import ray
  import ray.experimental.tf_utils
  from ray.rllib.models import ModelCatalog
  from ray.rllib.policy.policy import Policy
  from ray.rllib.policy.sample_batch import SampleBatch
  from ray.rllib.utils import deprecation_warning
  from ray.rllib.utils.annotations import override
  from ray.rllib.utils.filter import get_filter
  from ray.rllib.utils.framework import try_import_tf
  from ray.rllib.utils.spaces.space_utils import get_base_struct_from_space, unbatch
label_desc: Use image node_id 1 for calling a global function with example usage: rollout(policy, env, timestep_limit, add_noise, offset) and returns: rewards,  t