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

TypeError: deprecated() got an unexpected keyword argument 'deadline' #3855

Closed
hongyi-zhao opened this issue Jun 3, 2024 · 5 comments
Closed
Labels

Comments

@hongyi-zhao
Copy link
Contributor

hongyi-zhao commented Jun 3, 2024

Python version

Python 3.11.1

Pymatgen version

2024.5.31

Operating system version

Ubuntu 22.04.4 LTS

Current behavior

Description: When trying to import MPRester from mp_api.client, I encountered a TypeError related to the deprecated decorator in the pymatgen library. The error message indicates that the deprecated() function received an unexpected keyword argument 'deadline'.

Error Traceback:

TypeError: deprecated() got an unexpected keyword argument 'deadline'

In [3]: from mp_api.client import MPRester
   ...: from pymatgen.io.vasp.sets import MPRelaxSet
   ...: 
   ...: # Replace with your Materials Project API Key
   ...: # api_key = "YOUR_API_KEY"
   ...: 
   ...: # Use MPRester to fetch data
   ...: with MPRester() as mpr:
   ...:     # Search for materials with chemical system "Au" and space group "Fm-3m"
   ...:     results = mpr.materials.search(chemsys="Au", spacegroup_symbol="Fm-3m")
   ...: 
   ...:     # Print results
   ...:     for result in results:
   ...:         material_id = result.material_id
   ...:         print(f"Material ID: {material_id}, Formula: {result.formula_pretty}")
   ...: 
   ...:         # Get material structure
   ...:         structure = mpr.materials.get_structure_by_material_id(material_id)
   ...: 
   ...:         # Generate VASP input files using MPRelaxSet
   ...:         vasp_input_set = MPRelaxSet(structure)
   ...:         incar = vasp_input_set.incar
   ...: 
   ...:         # Print INCAR file content
   ...:         print(incar)
   ...: 
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[3], line 1
----> 1 from mp_api.client import MPRester
      2 from pymatgen.io.vasp.sets import MPRelaxSet
      4 # Replace with your Materials Project API Key
      5 # api_key = "YOUR_API_KEY"
      6 
      7 # Use MPRester to fetch data

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/mp_api/client/__init__.py:7
      4 import os
      5 from importlib.metadata import PackageNotFoundError, version
----> 7 from .core import MPRestError
      8 from .mprester import MPRester
     10 try:

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/mp_api/client/core/__init__.py:3
      1 from __future__ import annotations
----> 3 from .client import BaseRester, MPRestError
      4 from .settings import MAPIClientSettings

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/mp_api/client/core/client.py:24
     21 from urllib.parse import quote, urljoin
     23 import requests
---> 24 from emmet.core.utils import jsanitize
     25 from monty.json import MontyDecoder
     26 from pydantic import BaseModel, create_model

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/emmet/core/utils.py:10
      8 from monty.json import MSONable
      9 from pydantic import BaseModel
---> 10 from pymatgen.analysis.graphs import MoleculeGraph
     11 from pymatgen.analysis.local_env import OpenBabelNN, metal_edge_extender
     12 from pymatgen.analysis.molecule_matcher import MoleculeMatcher

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/analysis/graphs.py:26
     23 from scipy.spatial import KDTree
     24 from scipy.stats import describe
---> 26 from pymatgen.core import Lattice, Molecule, PeriodicSite, Structure
     27 from pymatgen.core.structure import FunctionalGroups
     28 from pymatgen.util.coord import lattice_points_in_supercell

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/core/__init__.py:12
      8 from typing import Any
     10 from ruamel.yaml import YAML
---> 12 from pymatgen.core.composition import Composition
     13 from pymatgen.core.lattice import Lattice
     14 from pymatgen.core.operations import SymmOp

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/core/composition.py:22
     19 from monty.json import MSONable
     20 from monty.serialization import loadfn
---> 22 from pymatgen.core.periodic_table import DummySpecies, Element, ElementType, Species, get_el_sp
     23 from pymatgen.core.units import Mass
     24 from pymatgen.util.string import Stringify, formula_double_format

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/core/periodic_table.py:39
     32     _pt_data = json.load(ptable_json)
     34 _pt_row_sizes = (2, 8, 8, 18, 18, 32, 32)
     37 @functools.total_ordering
     38 @unique
---> 39 class ElementBase(Enum):
     40     """Element class defined without any enum values so it can be subclassed.
     41 
     42     This class is needed to get nested (as|from)_dict to work properly. All emmet classes that had
   (...)
     45     only when they were top level. See https://github.com/materialsproject/pymatgen/issues/2999.
     46     """
     48     def __init__(self, symbol: SpeciesLike) -> None:

File ~/.pyenv/versions/3.11.1/envs/datasci/lib/python3.11/site-packages/pymatgen/core/periodic_table.py:700, in ElementBase()
    696     """True if element is a post-transition or poor metal."""
    697     return self.symbol in ("Al", "Ga", "In", "Tl", "Sn", "Pb", "Bi")
    699 @property
--> 700 @deprecated(
    701     message="Please use is_rare_earth instead, which is corrected to include Y and Sc.", deadline=(2025, 1, 1)
    702 )
    703 def is_rare_earth_metal(self) -> bool:
    704     """True if element is a rare earth metal, Lanthanides (La) series and Actinides (Ac) series.
    705 
    706     This property is Deprecated, and scheduled for removal after 2025-01-01.
    707     """
    708     return self.is_lanthanoid or self.is_actinoid

TypeError: deprecated() got an unexpected keyword argument 'deadline'

Expected Behavior

The code should execute without errors, fetching materials data and generating VASP input files.

Actual Behavior:

The code execution is halted by a TypeError due to an unexpected keyword argument 'deadline' in the deprecated decorator.

Environment:

(datasci) werner@x13dai-t:~$ python --version
Python 3.11.1
(datasci) werner@x13dai-t:~$ pip list | grep mp-api
mp-api                        0.41.2
(datasci) werner@x13dai-t:~$ pip list | grep 'pymatgen[ ]'
pymatgen                      2024.5.31
(datasci) werner@x13dai-t:~$ lsb_release -a
No LSB modules are available.
Distributor ID:	Ubuntu
Description:	Ubuntu 22.04.4 LTS
Release:	22.04
Codename:	jammy

Additional Information:

The issue seems to be related to the deprecated decorator in the pymatgen library, specifically in the ElementBase class in periodic_table.py.

Possible Solution:

Check the implementation of the deprecated decorator and ensure it handles the 'deadline' keyword argument correctly.

This issue affects the usage of both mp-api and pymatgen libraries. Please investigate and provide a fix or workaround.

Minimal example

from mp_api.client import MPRester
from pymatgen.io.vasp.sets import MPRelaxSet

# Replace with your Materials Project API Key
# api_key = "YOUR_API_KEY"

# Use MPRester to fetch data
with MPRester() as mpr:
    # Search for materials with chemical system "Au" and space group "Fm-3m"
    results = mpr.materials.search(chemsys="Au", spacegroup_symbol="Fm-3m")

    # Print results
    for result in results:
        material_id = result.material_id
        print(f"Material ID: {material_id}, Formula: {result.formula_pretty}")

        # Get material structure
        structure = mpr.materials.get_structure_by_material_id(material_id)

        # Generate VASP input files using MPRelaxSet
        vasp_input_set = MPRelaxSet(structure)
        incar = vasp_input_set.incar

        # Print INCAR file content
        print(incar)

Relevant files to reproduce this bug

No response

Regards,
Zhao

@hongyi-zhao hongyi-zhao added the bug label Jun 3, 2024
@DanielYang59
Copy link
Contributor

Yes we already noticed this #3752 (comment), please try to update monty version to latest with pip install -U monty

@hongyi-zhao
Copy link
Contributor Author

hongyi-zhao commented Jun 3, 2024

@DanielYang59 Yes. Your tip does the trick.

But, should the deadline=(2025, 1, 1) in the following line be removed or fixed?

message="Please use is_rare_earth instead, which is corrected to include Y and Sc.", deadline=(2025, 1, 1)

@DanielYang59
Copy link
Contributor

@DanielYang59 Yes. Your tip does the trick.

Great to know. Sorry I forgot to update the monty in setup.py which caused this issue:

"monty>=2024.2.2",

But, should the deadline=(2025, 1, 1) in the following line be removed or fixed?

message="Please use is_rare_earth instead, which is corrected to include Y and Sc.", deadline=(2025, 1, 1)

Sorry I don't quite understand your question, this property is scheduled for removal after 2025-01-01. Is there anything wrong with the decorator?

@hongyi-zhao
Copy link
Contributor Author

Sorry I don't quite understand your question, this property is scheduled for removal after 2025-01-01. Is there anything wrong with the decorator?

I mean, why wait until 2025-01-01, and not remove it immediately?

@DanielYang59
Copy link
Contributor

We decided to schedule it for removal after 2025-01-01 in #3817 to minimize potential impact to other's code base.

If we were to remove it immediately, all code relying on this would be broken without a grace period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants