ray icon indicating copy to clipboard operation
ray copied to clipboard

Google Research Football simulator serialization

Open yutaizhou opened this issue 6 years ago • 5 comments

Hello,

On the off-chance that someone is using Ray to parallelize google research football (grf), I am getting the following error when I call reset() on the game environment. The goal is to launch multiple game instances and parallelize gameplay, rollouts, etc. I know it has to do with deserialization of state values (in context of reinforcement learning) from the GCS, but I am not sure how to proceed.

I wrote a reset() wrapper task that calls env.reset(), where env is just an instance of grf, but I get cloudpickle errors. The paper states that actors are better suited "to wrap simulators that are hard to serialize", but I don't understand why. Could someone give an idea of why actor is better suited as well as an explanation for the following error? I am not using rllib by the way, only Ray.

Traceback (most recent call last): File "/home/yutaizhou/anaconda3/envs/grf_ray/lib/python3.7/site-packages/ray/serialization.py", line 353, in serialize value, protocol=5, buffer_callback=writer.buffer_callback) File "/home/yutaizhou/anaconda3/envs/grf_ray/lib/python3.7/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 72, in dumps cp.dump(obj) File "/home/yutaizhou/anaconda3/envs/grf_ray/lib/python3.7/site-packages/ray/cloudpickle/cloudpickle_fast.py", line 617, in dump return Pickler.dump(self, obj) RuntimeError: Pickling of "_gameplayfootball.GameConfig" instances is not enabled (http://www.boost.org/libs/python/doc/v2/pickle.html)

yutaizhou avatar Mar 16 '20 16:03 yutaizhou

One trick is to instead of passing the env to a remote task, pass a function that creates it. Then the env can be created remotely without ever needing to be serialized.

ericl avatar Mar 17 '20 19:03 ericl

Thank you, that worked very well! Love the task/actor abstraction!

yutaizhou avatar Mar 25 '20 10:03 yutaizhou

@ericl apologies for the late comment. I'm running into this exact problem. Could you give a quick example on what you mean by passing a function that creates the env to a remote actor? Thanks in advance.

jakeelkins avatar Oct 29 '20 05:10 jakeelkins

e.g.,

@ray.remote
def f(env):
  pass
f.remote(real_env())  # fails

@ray.remote
def f(env_creator):
   env = env_creator()
f.remote(lambda: real_env())  # this will work

ericl avatar Oct 29 '20 06:10 ericl

boom!! that works. thank you so much @ericl that was so simple

jakeelkins avatar Oct 29 '20 06:10 jakeelkins