ACEsuit / mace

MACE - Fast and accurate machine learning interatomic potentials with higher order equivariant message passing.
Other
550 stars 205 forks source link

Python 3.7 (and 3.8?) not supported #699

Open MicPellegrino opened 1 week ago

MicPellegrino commented 1 week ago

Describe the bug I cannot load the mace_mp calculator by running from mace.calculators import mace_mp. I'm getting:

Python 3.7.4 (default, Jun 18 2023, 14:26:56) 
[GCC 10.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import mace
>>> from mace.calculators import mace_mp
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.7/site-packages/mace/calculators/__init__.py", line 1, in <module>
    from .foundations_models import mace_anicc, mace_mp, mace_off
  File "/usr/local/lib/python3.7/site-packages/mace/calculators/foundations_models.py", line 10, in <module>
    from .mace import MACECalculator
  File "/usr/local/lib/python3.7/site-packages/mace/calculators/mace.py", line 35, in <module>
    class MACECalculator(Calculator):
  File "/usr/local/lib/python3.7/site-packages/mace/calculators/mace.py", line 62, in MACECalculator
    fullgraph=True,
TypeError: 'type' object is not subscriptable
>>>

To Reproduce Run from mace.calculators import mace_mp in Python3.7 (which should be compatible according to https://pypi.org/project/mace-torch/)

Desktop (please complete the following information):

ilyes319 commented 1 week ago

update to 3.8 or later, we are going to drop 3.7 support probably, I ll update the setup

MicPellegrino commented 4 days ago

I see, thank you.

MicPellegrino commented 4 days ago

Hi, I don't think it's python version problem: I tried building a virtual environment with Python 3.8 and I still get the error. On Jupyter:

!python --version

Python 3.8.0
from mace.calculators import mace_mp

TypeError                                 Traceback (most recent call last)
Cell In[2], line 1
----> 1 from mace.calculators import mace_mp

File ~/mambaforge/envs/workflow-hea/lib/python3.8/site-packages/mace/calculators/__init__.py:1
----> 1 from .foundations_models import mace_anicc, mace_mp, mace_off
      2 from .lammps_mace import LAMMPS_MACE
      3 from .mace import MACECalculator

File ~/mambaforge/envs/workflow-hea/lib/python3.8/site-packages/mace/calculators/foundations_models.py:10
      7 from ase import units
      8 from ase.calculators.mixing import SumCalculator
---> 10 from .mace import MACECalculator
     12 module_dir = os.path.dirname(__file__)
     13 local_model_path = os.path.join(
     14     module_dir, "foundations_models/2023-12-03-mace-mp.model"
     15 )

File ~/mambaforge/envs/workflow-hea/lib/python3.8/site-packages/mace/calculators/mace.py:35
     31         return "float32"
     32     raise ValueError(f"Unknown dtype {mode_dtype}")
---> 35 class MACECalculator(Calculator):
     36     """MACE ASE Calculator
     37     args:
     38         model_paths: str, path to model or models if a committee is produced
   (...)
     48     Dipoles are returned in units of Debye
     49     """
     51     def __init__(
     52         self,
     53         model_paths: Union[list, str, None] = None,
   (...)
     63         **kwargs,
     64     ):

File ~/mambaforge/envs/workflow-hea/lib/python3.8/site-packages/mace/calculators/mace.py:54, in MACECalculator()
     35 class MACECalculator(Calculator):
     36     """MACE ASE Calculator
     37     args:
     38         model_paths: str, path to model or models if a committee is produced
   (...)
     48     Dipoles are returned in units of Debye
     49     """
     51     def __init__(
     52         self,
     53         model_paths: Union[list, str, None] = None,
---> 54         models: Union[list[torch.nn.Module], torch.nn.Module, None] = None,
     55         device: str = "cpu",
     56         energy_units_to_eV: float = 1.0,
     57         length_units_to_A: float = 1.0,
     58         default_dtype="",
     59         charges_key="Qs",
     60         model_type="MACE",
     61         compile_mode=None,
     62         fullgraph=True,
     63         **kwargs,
     64     ):
     65         Calculator.__init__(self, **kwargs)
     67         if "model_path" in kwargs:

TypeError: 'type' object is not subscriptable
ilyes319 commented 4 days ago

try 3.10?

MicPellegrino commented 4 days ago

Could it be that some pytorch requirement is missing instead?

ilyes319 commented 4 days ago

no I don't think so, I know the bug, it is the use of list instead of the typing List... I know that this works for 3.10 and later, not sure if it works for 3.9.

MicPellegrino commented 4 days ago

Ok, it worked by specifying python>=3.10 in the environment .yml file (got Python 3.12.7).

CompRhys commented 1 day ago

https://github.com/ACEsuit/mace/pull/537#issuecomment-2269588751 the list List issue can be resolved with this future import (which in the ruff PR linked was added as an automatic fix).