Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvement of the "Basic Usage" page #54

Open
Arseni1919 opened this issue Dec 18, 2024 · 0 comments
Open

Improvement of the "Basic Usage" page #54

Arseni1919 opened this issue Dec 18, 2024 · 0 comments

Comments

@Arseni1919
Copy link

Many algorithms work in the parallel setting — especially all the algorithms with the CTDE approach (the majority).
Please insert the example of the parallel execution. It was hard to find out how to do it properly.

My suggestion:

# uncomment the required environment
# from magent2.environments.adversarial_pursuit import parallel_env
# from magent2.environments.battle import parallel_env
# from magent2.environments.battlefield import parallel_env
# from magent2.environments.combined_arms import parallel_env
# from magent2.environments.gather import parallel_env, raw_env
from magent2.environments.tiger_deer import parallel_env
import time

# to render or not to render
render_mode='human'
# render_mode=None

env = parallel_env(render_mode=render_mode, max_cycles=200)
observations, infos = env.reset()

i_step = 0
while env.agents:
    # this is where you would insert your policy
    actions = {agent: env.action_space(agent).sample() for agent in env.agents}

    observations, rewards, terminations, truncations, infos = env.step(actions)

    i_step += 1
    print(f'{i_step}')
    # time.sleep(0.1)  # for slower rendering
env.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant