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] cannot import name 'Renderer' from 'magent' #756

Closed
1 task done
hellofinch opened this issue Aug 11, 2022 · 12 comments
Closed
1 task done

[Bug Report] cannot import name 'Renderer' from 'magent' #756

hellofinch opened this issue Aug 11, 2022 · 12 comments
Labels
help wanted Extra attention is needed

Comments

@hellofinch
Copy link

If you are submitting a bug report, please fill in the following details and use the tag [bug].

Describe the bug
I try to change the environment based on this script. The origin script used waterworld which has bug so I change it to magent.battle. The output show below:


Traceback (most recent call last):
  File "rlpe.py", line 4, in <module>
    from pettingzoo.magent import battle_v4
  File "/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/pettingzoo/magent/__init__.py", line 5, in __getattr__
    return deprecated_handler(env_name, __path__, __name__)
  File "/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/pettingzoo/utils/deprecated_module.py", line 52, in deprecated_handler
    spec.loader.exec_module(module)
  File "/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/pettingzoo/magent/battle_v4.py", line 1, in <module>
    from .battle.battle import env, parallel_env, raw_env  # noqa: F401
  File "/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/pettingzoo/magent/battle/battle.py", line 7, in <module>
    from pettingzoo.magent.magent_env import magent_parallel_env, make_env
  File "/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/pettingzoo/magent/magent_env.py", line 4, in <module>
    from magent import Renderer
ImportError: cannot import name 'Renderer' from 'magent' (/anaconda3/envs/PettingZoo/lib/python3.7/site-packages/magent/__init__.py)

Code example

from ray import tune
from ray.tune.registry import register_env
from ray.rllib.env.wrappers.pettingzoo_env import PettingZooEnv
from pettingzoo.magent import battle_v4

# Based on code from github.com/parametersharingmadrl/parametersharingmadrl

if __name__ == "__main__":
    # RDQN - Rainbow DQN
    # ADQN - Apex DQN
    def env_creator(args):
        return PettingZooEnv(battle_v4.env(map_size=45, minimap_mode=False, step_reward=-0.005,
dead_penalty=-0.1, attack_penalty=-0.1, attack_opponent_reward=0.2,
max_cycles=1000, extra_features=False))

    env = env_creator({})
    register_env("battle", env_creator)

    tune.run(
        "APEX_DDPG",
        stop={"episodes_total": 60000},
        checkpoint_freq=10,
        config={
            # Enviroment specific
            "env": "battle",
            # General
            "num_gpus": 1,
            "num_workers": 2,
            # Method specific
            "multiagent": {
                "policies": set(env.agents),
                "policy_mapping_fn": (lambda agent_id, episode, **kwargs: agent_id),
            },
        },
    )

System Info
Describe the characteristic of your environment:
Linux with conda and pip
Python 3.7.9
PettingZoo 1.20.1
supersuit 3.5.0
gym 0.22.0
Additional context
Add any other context about the problem here.

Checklist

  • I have checked that there is no similar issue in the repo (required)
@jjshoots
Copy link
Member

@dsctt could you have a look at this?

@benblack769
Copy link
Contributor

What is the magent package version?

@hellofinch
Copy link
Author

@benblack769 How can I know the version? I try pettingzoo.magent.__version__ but it failed.

@jjshoots
Copy link
Member

@hellofinch magent is a standalone package on pypi, try pip3 show magent in the terminal.

@hellofinch
Copy link
Author

@jjshoots I use 0.1.13

Name: magent
Version: 0.1.13
Summary: Multi-Agent Reinforcement Learning environments with very large numbers of agents
Home-page: https://github.com/PettingZoo-Team/MAgent
Author: PettingZoo Team
Author-email: justinkterry@gmail.com
License: UNKNOWN
Location: /anaconda3/envs/PettingZoo/lib/python3.7/site-packages
Requires: numpy, pygame
Required-by:

@jjshoots jjshoots added the help wanted Extra attention is needed label Aug 19, 2022
@benblack769
Copy link
Contributor

0.1.13 is a very old version of MAgent. You should be able to upgrade your version to the most recent version with pip install magent --upgrade or pip install magent==0.2.3

Also watch out, if you installed the original, unmaintained magent package here https://github.com/geek-ai/MAgent, then you will need to manually uninstall it, which might be tricky.

@hellofinch
Copy link
Author

I upgrade themagent.

Name: magent
Version: 0.2.3
Summary: Multi-Agent Reinforcement Learning environments with very large numbers of agents
Home-page: https://github.com/Farama-Foundation/MAgent
Author: Farama Foundation
Author-email: jkterry@farama.org
License: None
Location: /anaconda3/envs/PettingZoo/lib/python3.7/site-packages
Requires: numpy, pygame
Required-by:

And I try to run the script again and another error comes out.

Traceback (most recent call last):
  File "rlpe.py", line 31, in <module>
    "policies": set(env.agents),
AttributeError: 'PettingZooEnv' object has no attribute 'agents'

@WillDudley
Copy link
Contributor

magent is depreciated

@hellofinch
Copy link
Author

@WillDudley May I know why magent is depreciated? I think it is a good environment that has an invariable observation shape.
If I want to use magent, what can I do?

@jjshoots
Copy link
Member

@hellofinch Magent has not been deprecated, it's just been moved to its own repository because it deserves to have its own management team behind it. View it here :).

@WillDudley
Copy link
Contributor

We should add a warning to notify users of this. I'll add it to the list of things to do.

Thanks for the issue!

@dsctt
Copy link
Contributor

dsctt commented Nov 14, 2022

We should add a warning to notify users of this. I'll add it to the list of things to do.

Thanks for the issue!

#857

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

5 participants