Farama-Foundation / PettingZoo

An API standard for multi-agent reinforcement learning environments, with popular reference environments and related utilities
https://pettingzoo.farama.org
Other
2.45k stars 400 forks source link

[Question] Material about converting an existing Gymnasium env to MARL #1108

Closed labanca closed 9 months ago

labanca commented 9 months ago

Question

I'm trying to convert the gymnasium environment PyFlyt to multi-agent using pettingzoo and SuperSuit.

Where can I find material to learn how to do it and where to start? I tried following the Multi-Agent Deep Reinforcement Learning in 13 Lines of Code Using PettingZoo but I get stuck on many errors such as:

assert aec_env.metadata.get("is_parallelizable", False), (
AssertionError: Converting from an AEC environment to a Parallel environment with the to_parallel wrapper is not generally safe (the AEC environment should only update once at the end of each cycle). If you have confirmed that your AEC environment can be converted in this way, then please set the `is_parallelizable` key in your metadata to True

And after adding the metada is_parallelizable to True, the following:

for pipe, proc in zip(self.pipes, self.procs):
AttributeError: 'ProcConcatVec' object has no attribute 'pipes'

I have just started using petting zoo and any help would be greatly appreciated.

Thanks in advance!

elliottower commented 9 months ago

That library is made by one of PettingZoo’s maintainers actually, @jjshoots, so he can probably answer better. The only real way is to modify the underlying environment to make it conform to the API. I imagine jet had some plans or specific details but if you want to do it yourself, I would recommend just changing the base class to ParallelEnv, and making each of the values such as action, observation, reward, termination, truncation, info be dicts indexed by AgentID (from pettingzoo.utils.env import AgentID, just a type that can be used for type hinting to make it more readable). You would then need to change internals about how the step function works to accommodate it, but in concept at least the most straightforward conversation is gymnasium to parallel because they use the same api essentially (returning on step, whereas with AEC envs you have to call env.last() and have an env.observe() method).

In general I’d recommend making an issue on any repo like this which you are trying to modify, as the creators of it will have better knowledge and be able to help you better. Going to close this as this isn’t strictly relevant to pettingzoo as a library. Feel free to reach out and create a question onour discord or continue to use this when it’s closed. Just have to do house keeping to make sure open issues are real issues we need to internally solve.

Also I definitely wouldn’t recommend that tutorial as it is very old, we have more recent ones on our site. https://pettingzoo.farama.org/

jjshoots commented 9 months ago

@labanca if you can move the issue into the issues section for PyFlyt, I can probably help you better there, let's not clutter PZ with a non-PZ issue. :)

labanca commented 9 months ago

@jjshoots I can't move this issue from here to there, the option to move the issue is not available to me.

So, I'm going to open a new issue on PyFlyt and you can delete this one if you prefer.

Sorry for opening the issue in the wrong place and thanks for the help!