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

[Bug Report] Checking if the entire environment is done #1244

Open
1 task done
destin-v opened this issue Nov 26, 2024 · 1 comment
Open
1 task done

[Bug Report] Checking if the entire environment is done #1244

destin-v opened this issue Nov 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@destin-v
Copy link

Describe the bug

According to the documentation:

"When an agent is terminated or truncated, it’s removed from agents, so when the environments done agents will be an empty list. This means not env.agents is a simple condition for the environment being done." - PettingZoo Doc

I tested this on connect_four_v3 and it does not work:

The env.agents will still have agents in the list even after all agents have terminated. This can be checked by conditioning a break point on all terminated agents.

Code example

import numpy as np
import pettingzoo
from pettingzoo.classic import connect_four_v3


def test_connect4():
    obs: dict[str, np.ndarray]
    termination: bool
    truncation: bool

    env: pettingzoo.AECEnv = connect_four_v3.env(render_mode="human")
    env.reset(seed=42)

    for agent in env.agent_iter():
        obs, _, termination, truncation, _ = env.last()  # type: ignore

        if termination or truncation:
            if len(env.agents) > 0:
                print(f"env.agents: {env.agents}")
                raise ValueError("env.agents should be empty!")

        mask = obs["action_mask"]
        # this is where you would insert your policy
        action = env.action_space(agent).sample(mask)

        env.step(action)

    env.close()

System info

Running on Intel based Macbook Pro 2019.

Additional context

No response

Checklist

  • I have checked that there is no similar issue in the repo
@destin-v destin-v added the bug Something isn't working label Nov 26, 2024
@CreazeD
Copy link

CreazeD commented Dec 2, 2024

I have the same problem

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants