下面的代码摘自https://bair.berkeley.edu/blog/2018/01/09/ray/。
import gym
@ray.remote
class Simulator(object):
def __init__(self):
self.env = gym.make("Pong-v0")
self.env.reset()
def step(self, action):
return self.env.step(action)
# Create a simulator, this will start a remote process that will run
# all methods for this actor.
simulator = Simulator.remote()
observations = []
for _ in range(4):
# Take action 0 in the simulator. This call does not block and
# it returns a future.
observations.append(simulator.step.remote(0))
当我阅读这段代码时,我感到非常困惑。这段代码真的并行运行吗?根据我的理解,只有一个env
,所以上面的代码应该按顺序执行操作,即逐个执行操作。如果是这样,那么上面的代码有什么意义呢?