sail-sg / envpool

C++-based high-performance parallel environment execution engine (vectorized env) for general RL environments.
https://envpool.readthedocs.io
Apache License 2.0
1.09k stars 100 forks source link

[BUG] "TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases" when building envpool from sources #170

Closed christianmerkwirth closed 2 years ago

christianmerkwirth commented 2 years ago

Importing envpool fails since about two days with the error message: "TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases"

It did not do this before July 13th (date is not very precise).

I verified that the problem occurs after building and pip installing envpool from the freshly generated wheel on:

The issue did not occur before on both platforms!

Code to reproduce the issue:

import envpool

Detailed error message:

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
[<ipython-input-15-a0a27c8e85d7>](https://localhost:8080/#) in <module>()
----> 1 import envpool as envpool
      2 import numpy as np
      3 
      4 # make gym env
      5 env = envpool.make("Pong-v5", env_type="gym", num_envs=100)

5 frames
[/usr/local/lib/python3.7/dist-packages/envpool/__init__.py](https://localhost:8080/#) in <module>()
     14 """EnvPool package for efficient RL environment simulation."""
     15 
---> 16 import envpool.entry  # noqa: F401
     17 from envpool.registration import (
     18   list_all_envs,

[/usr/local/lib/python3.7/dist-packages/envpool/entry.py](https://localhost:8080/#) in <module>()
     14 """Entry point for all envs' registration."""
     15 
---> 16 import envpool.atari.registration  # noqa: F401
     17 import envpool.box2d.registration  # noqa: F401
     18 import envpool.classic_control.registration  # noqa: F401

[/usr/local/lib/python3.7/dist-packages/envpool/atari/__init__.py](https://localhost:8080/#) in <module>()
     20 
     21 AtariEnvSpec, AtariDMEnvPool, AtariGymEnvPool = py_env(
---> 22   _AtariEnvSpec, _AtariEnvPool
     23 )
     24 

[/content/envpool/envpool/python/api.py](https://localhost:8080/#) in py_env(envspec, envpool)
     32     EnvSpecMeta(spec_name, (envspec,), {}),  # type: ignore[return-value]
     33     DMEnvPoolMeta(pool_name.replace("EnvPool", "DMEnvPool"), (envpool,), {}),
---> 34     GymEnvPoolMeta(pool_name.replace("EnvPool", "GymEnvPool"), (envpool,), {}),
     35   )

[/content/envpool/envpool/python/gym_envpool.py](https://localhost:8080/#) in __new__(cls, name, parents, attrs)
     84 
     85     attrs["_to"] = _to_gym
---> 86     subcls = super().__new__(cls, name, parents, attrs)
     87 
     88     @no_type_check

[/usr/lib/python3.7/abc.py](https://localhost:8080/#) in __new__(mcls, name, bases, namespace, **kwargs)
    124         """
    125         def __new__(mcls, name, bases, namespace, **kwargs):
--> 126             cls = super().__new__(mcls, name, bases, namespace, **kwargs)
    127             _abc_init(cls)
    128             return cls

TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
christianmerkwirth commented 2 years ago

It does not seem to be dependent on the Python package versions of the other dependencies (numpy, gym). The package from pip. does not exhibit the problem. I checked the version I compiled from source against the official pip release in envpool==0.6.2.post2. envpool==0.6.2.post2 does not exhibit the problem, while the version I compiled from source does. My working assumption is that the problem is related on the C++ side, either compiler version or somewhere inside pybind11.

Trinkle23897 commented 2 years ago

Duplicated as #166. It has been fixed in #167. Please rebase your code to the updated main version.