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

RolloutWorker.sample(**kwargs) SampleBatch | MultiAgentBatch | Dict[str, Any][源代码]#

返回从此工作线程中采样的一批经验。

此方法必须由子类实现。

返回:

一批经验(例如,张量)或一个 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": [...], ...})