Farama-Foundation / Minigrid

Simple and easily configurable grid world environments for reinforcement learning
https://minigrid.farama.org/
Other
2.05k stars 597 forks source link

[Question] How to build custom environment with custom action space #405

Open JustinS6626 opened 9 months ago

JustinS6626 commented 9 months ago

Question

I have written a custom Minigrid environment recently and I am trying to modify the action space to exclude irrelevant actions. The only actions that it needs are left, right, and forward. Within the constructor of the custom environment, I do this by overwriting the action space attribute after the constructor of the base class is called. However, in some instances, such as when I make a make a wrapper for the custom environment, or when I instantiate a stable baselines PPO with the custom environment, the action spaces of the resulting objects seem to revert to the default action space with seven actions. I would really appreciate an example like the one here: https://minigrid.farama.org/content/create_env_tutorial/ with additional information on how to set a custom action space so that it never reverts to the default.

Howuhh commented 8 months ago

@JustinS6626 Actually, you can just mask the irrelevant actions during training, like it usually done in PPO. For example, there is an implementation of Maskable PPO in SB3: https://sb3-contrib.readthedocs.io/en/master/modules/ppo_mask.html