ray.rllib.evaluation.rollout_worker.RolloutWorker.sample#

RolloutWorker.sample(**kwargs) SampleBatch | MultiAgentBatch[source]#

Returns a batch of experience sampled from this worker.

This method must be implemented by subclasses.

Returns:

A columnar batch of experiences (e.g., tensors) or a MultiAgentBatch.

import gymnasium as gym
from ray.rllib.evaluation.rollout_worker import RolloutWorker
from ray.rllib.algorithms.ppo.ppo_tf_policy import PPOTF1Policy
worker = RolloutWorker(
  env_creator=lambda _: gym.make("CartPole-v1"),
  default_policy_class=PPOTF1Policy,
  config=AlgorithmConfig(),
)
print(worker.sample())
SampleBatch({"obs": [...], "action": [...], ...})