materialsproject / api

New API client for the Materials Project
https://materialsproject.github.io/api/
Other
105 stars 33 forks source link

task mp-2048877 fails pydantic validation #869

Closed bernstei closed 7 months ago

bernstei commented 7 months ago

Problem

The following code snippet

task_id = "mp-2048877"
with MPRester(api_key) as mpr:
    task_result = mpr.materials.tasks.get_data_by_id(task_id).dict()

Fails with the error

/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/mprester.py:230: UserWarning: mpcontribs-client not installed. Install the package to query MPContribs data, or construct pourbaix diagrams: 'pip install mpcontribs-client'
  warnings.warn(
Traceback (most recent call last):
  File "/home/cluster2/bernstei/src/work/MACE/foundations/t.py", line 8, in <module>
    task_result = mpr.materials.tasks.get_data_by_id(task_id).dict()
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 1003, in get_data_by_id
    results = self._query_resource_data(criteria=criteria, fields=fields, suburl=document_id)  # type: ignore
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 960, in _query_resource_data
    return self._query_resource(  # type: ignore
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 411, in _query_resource
    data = self._submit_requests(
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 552, in _submit_requests
    initial_data_tuples = self._multi_thread(
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 766, in _multi_thread
    data, subtotal = future.result()
  File "/usr/lib64/python3.9/concurrent/futures/_base.py", line 439, in result
    return self.__get_result()
  File "/usr/lib64/python3.9/concurrent/futures/_base.py", line 391, in __get_result
    raise self._exception
  File "/usr/lib64/python3.9/concurrent/futures/thread.py", line 58, in run
    result = self.fn(*self.args, **self.kwargs)
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 834, in _submit_request_and_process
    raw_doc_list = [self.document_model.parse_obj(d) for d in data["data"]]  # type: ignore
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/mp_api/client/core/client.py", line 834, in <listcomp>
    raw_doc_list = [self.document_model.parse_obj(d) for d in data["data"]]  # type: ignore
  File "/home/Software/python/system/extra/lib/python3.9/site-packages/typing_extensions.py", line 2360, in wrapper
    return arg(*args, **kwargs)
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/pydantic/main.py", line 1027, in parse_obj
    return cls.model_validate(obj)
  File "/home/cluster2/bernstei/.local/lib/python3.9/site-packages/pydantic/main.py", line 503, in model_validate
    return cls.__pydantic_validator__.validate_python(
pydantic_core._pydantic_core.ValidationError: 1 validation error for TaskDoc
calcs_reversed.0.run_type
  Input should be 'AM05', 'GGA', 'PBE', 'PBESol', 'RevPBE+PADE', 'optB86b', 'optB88', 'optPBE', 'revPBE', 'B3LYP', 'HF', 'HSE03', 'HSE06', 'HFCus', 'PBE0', 'M06L', 'MBJL', 'MS0', 'MS1', 'MS2', 'RTPSS', 'SCAN', 'R2SCAN', 'TPSS', 'R2SCAN-rVV10', 'SCAN-rVV10', 'optB86b-vdW', 'optB88-vdW', 'optPBE-vdW', 'rev-vdW-DF2', 'revPBE-vdW', 'vdW-DF2', 'AM05+U', 'GGA+U', 'PBE+U', 'PBESol+U', 'RevPBE+PADE+U', 'optB86b+U', 'optB88+U', 'optPBE+U', 'revPBE+U', 'B3LYP+U', 'HF+U', 'HSE03+U', 'HSE06+U', 'HFCus+U', 'PBE0+U', 'M06L+U', 'MBJL+U', 'MS0+U', 'MS1+U', 'MS2+U', 'RTPSS+U', 'SCAN+U', 'R2SCAN+U', 'TPSS+U', 'R2SCAN-rVV10+U', 'SCAN-rVV10+U', 'optB86b-vdW+U', 'optB88-vdW+U', 'optPBE-vdW+U', 'rev-vdW-DF2+U', 'revPBE-vdW+U', 'vdW-DF2+U', 'LDA' or 'LDA+U' [type=enum, input_value='PBEsol', input_type=str]

Proposed Solution

I can't tell if this is a problem with the data or the API, but either the missing info needs to be added to the data, or the API should be able to handle the missing info.

Alternatives

No response

bernstei commented 7 months ago

Version: Linux, python 3.9, pydantic 2.5.2, mp-api 0.39.0

munrojm commented 7 months ago

Fixed here. Will release a new client today once emmet-core is out.

bernstei commented 7 months ago

Great, thanks.

bernstei commented 7 months ago

Looks like it's working now that I updated mp-api and emmet-core. Thanks.