以下代码摘自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
,所以上面的代码应该按顺序执行操作,即一个接一个地执行操作。如果是这样,那么做上述事情的意义何在?