ml-agents icon indicating copy to clipboard operation
ml-agents copied to clipboard

Multi-agent gym prototype

Open vincentpierre opened this issue 3 years ago • 0 comments

Proposed change(s)

Trying out a multi agent multi behavior multi observation multi action gym interface

Example of usage :

import gym
import gym_unity

env = gym.make("GridWorld-v0", action_space_seed=42)
print(str(env.active))
_ = env.reset()
print(env.active.behavior)
for i in range(10):
  obs, reward, done, _ = env.step(env.action_space.sample())

env.side_channel["EngineConfigurationChannel"].set_configuration_parameters(width = 5, height=5)
for i in range(100):
  print(env.active.agent)
  obs, reward, done, _ = env.step(env.action_space.sample())

env.side_channel["EngineConfigurationChannel"].set_configuration_parameters(width = 500, height=500)
for i in range(100):
  obs, reward, done, _ = env.step(env.action_space.sample())

env.close()

Note that since there are multiple agents, the user must use env.active.agent to get the id of the agent currently in need of an action. There is no guarantee that the next_obs received after a env.step are from the same agent. Note that step does not actually step the environment but only sets the action of an agent. When all agents selected their action, then the environment is stepped.

vincentpierre avatar Jul 27 '21 17:07 vincentpierre