ray.rllib.evaluation.rollout_worker.RolloutWorker.sample_with_count#

RolloutWorker.sample_with_count() Tuple[SampleBatch | MultiAgentBatch, int][source]#

Same as sample() but returns the count as a separate value.

Returns:

A columnar batch of experiences (e.g., tensors) and the

size of the collected batch.

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=PPOTFPolicy)
print(worker.sample_with_count())
(SampleBatch({"obs": [...], "action": [...], ...}), 3)