edbeeching / godot_rl_agents

An Open Source package that allows video game creators, AI researchers and hobbyists the opportunity to learn complex behaviors for their Non Player Characters or agents
MIT License
942 stars 69 forks source link

Adds multiple env support to the SB3 wrapper #123

Closed edbeeching closed 1 year ago

edbeeching commented 1 year ago

Adds an option to interact with parallel Godot executables using the n_parallel argument. This only works in on an export env.

Example usage with 4 parallel envs:

env = StableBaselinesGodotEnv(env_path=args.env_path, n_parallel=4)
Ivan-267 commented 1 year ago

Looks great and worked properly in my quick test.

Regarding the last commit: https://github.com/edbeeching/godot_rl_agents/blob/9c25e76d7d992617c39abdd6aac23b63d262ffca/examples/stable_baselines3_example.py#L28 A small note is that the help tip can be updated as well, e.g. "How many instances of the environment executable to launch - requires --env_path to be set if > 1.".

I'm not sure whether this should be added, it's just here as a note, potentially setting a unique seed for each environment could encourage exploration:

from: https://github.com/edbeeching/godot_rl_agents/blob/9c25e76d7d992617c39abdd6aac23b63d262ffca/godot_rl/wrappers/stable_baselines_wrapper.py#L17

to e.g. (untested):

        self.envs = [GodotEnv(env_path=env_path, convert_action_space=True, port=port+p, seed=p, **kwargs) for p in range(n_parallel)]
edbeeching commented 1 year ago

@Ivan-267 , good point about the seed and help description. Thanks. I also added a check in the StableBaselinesGodotEnv init method to ensure env_path is not None when n_parallel>1