materialsproject / api

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

[Feature Request]: pickleable GGA pymatgen.entries.computed_entries.ComputedStructureEntry #921

Open kalvdans opened 2 months ago

kalvdans commented 2 months ago

Problem

I would like to cache the results of API calls, as documented as point 4 in https://docs.materialsproject.org/downloading-data/using-the-api/tips-for-large-downloads

When I try the call mpr.get_entries(["Si-O"], additional_criteria=dict(energy_above_hull=(None, 0.001)), compatible_only=True) I get a list of 5 pymatgen.entries.computed_entries.ComputedStructureEntry entries. However, when I try to pickle.dump(ret, f) them, I get the error:

AttributeError: Can't pickle local object 'cached_class.<locals>._decorated'

It is the 3rd element that is causing the issue, when printed it gives:

mp-546794-GGA ComputedStructureEntry - Si2 O4       (SiO2)
Energy (Uncorrected)     = -47.4976  eV (-7.9163  eV/atom)
Correction               = -2.7480   eV (-0.4580  eV/atom)
Energy (Final)           = -50.2456  eV (-8.3743  eV/atom)
Energy Adjustments:
  MP2020 anion correction (oxide): -2.7480   eV (-0.4580  eV/atom)
Parameters:
  potcar_spec            = [{'titel': 'PAW_PBE Si 05Jan2001', 'hash': 'b2b0ea6feb62e7cde209616683b8f7f5'}, {'titel': 'PAW_PBE O 08Apr2002', 'hash': '7a25bc5b9a5393f46600a4939d357982'}]
  is_hubbard             = False
  hubbards               = {}
  run_type               = GGA
Data:
  oxide_type             = oxide
  aspherical             = True
  last_updated           = 2022-06-07 19:44:16.964000
  task_id                = mp-2287344
  material_id            = mp-546794
  oxidation_states       = {'Si': 4.0, 'O': -2.0}
  run_type               = GGA

Proposed Solution

I suggest that we make all API call results pickleable, as they were in the legacy API, and add unit tests to not accidentally make them unpickleable in the future.

Alternatives

No response

munrojm commented 1 month ago

PR is welcome on this.