The following code is excerpted from 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))
I feel very confused when I'm reading this code. Is this code really run on parallel? Based on my understanding, there is only one env
, so the above code should take actions on a sequential order, i.e. actions are taken one by one. If that's the case, what's the point of doing something like the above?