pymatgen icon indicating copy to clipboard operation
pymatgen copied to clipboard

@cached_class decorator prevents class methods of Compatibility objects from being used in multiprocessing as they can't be pickled

Open CompRhys opened this issue 1 year ago • 2 comments

The use of this decorator leads to the error message:

self = <joblib.parallel.BatchCompletionCallBack object at 0x3376ec590>
    def _return_or_raise(self):
        try:
            if self.status == TASK_ERROR:
>               raise self._result
E               AttributeError: Can't pickle local object 'cached_class.<locals>._decorated'

I'm unsure what problem this decorator is solving in this instance. If there's no reason to keep these decorators I can to submit PR of local edits to use joblib to parallelize applying compatibility settings to large numbers of entries.

https://github.com/materialsproject/pymatgen/blob/fbf8ec0a5a9c0fb649975d66dedb31b17bcc9dfc/pymatgen/entries/compatibility.py#L838-L840

CompRhys avatar Jun 26 '24 20:06 CompRhys