materialsproject / fireworks

The Fireworks Workflow Management Repo.
https://materialsproject.github.io/fireworks
Other
362 stars 185 forks source link

AttributeError: "safe_load()" has been removed #531

Open fraricci opened 6 months ago

fraricci commented 6 months ago

Have you already seen this error?

I have a recent ruamel.yaml v.0.18.6 and got this error when trying to load the launchpad: lpad = LaunchPad.auto_load() or lpad = LaunchPad.from_file()

The full error stack is the following:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Cell In[50], line 1
----> 1 LaunchPad.auto_load()

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/core/launchpad.py:313, in LaunchPad.auto_load(cls)
    310 @classmethod
    311 def auto_load(cls):
    312     if LAUNCHPAD_LOC:
--> 313         return LaunchPad.from_file(LAUNCHPAD_LOC)
    314     return LaunchPad()

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py:291, in FWSerializable.from_file(cls, filename, f_format)
    289     f_format = filename.split(".")[-1]
    290 with open(filename, "r", **ENCODING_PARAMS) as f:
--> 291     return cls.from_format(f.read(), f_format=f_format)

File ~/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py:256, in FWSerializable.from_format(cls, f_str, f_format)
    254     dct = json.loads(f_str)
    255 elif f_format == "yaml":
--> 256     dct = yaml.safe_load(f_str)
    257 else:
    258     raise ValueError(f"Unsupported format {f_format}")

File ~/python-venvs/devel/lib64/python3.11/site-packages/ruamel/yaml/main.py:1105, in safe_load(stream, version)
   1099 def safe_load(stream: StreamTextType, version: Optional[VersionType] = None) -> Any:
   1100     """
   1101     Parse the first YAML document in a stream
   1102     and produce the corresponding Python object.
   1103     Resolve only basic YAML tags.
   1104     """
-> 1105     error_deprecation('safe_load', 'load', arg="typ='safe', pure=True")

File ~/python-venvs/devel/lib64/python3.11/site-packages/ruamel/yaml/main.py:1039, in error_deprecation(fun, method, arg, comment)
   1037     raise AttributeError(s)
   1038 else:
-> 1039     raise AttributeError(s, name=None)

AttributeError: 
"safe_load()" has been removed, use

  yaml = YAML(typ='safe', pure=True)
  yaml.load(...)

instead of file "/home/fraricci/python-venvs/devel/lib64/python3.11/site-packages/fireworks/utilities/fw_serializers.py", line 256

            dct = yaml.safe_load(f_str)

Applying the suggested way of loading a file it works:

from ruamel.yaml import YAML
from pathlib import Path

yaml = YAML(typ='safe', pure=True)
yaml = yaml.load(Path("my_launchpad.yaml").read_text())
lpad = LaunchPad.from_dict(yaml)

If someone can confirm this, I can send a pull request with this fix.

Thanks

ikondov commented 6 months ago

@fraricci Have you used the most recent release or the main branch? The issue has been already solved in the main branch since this PR https://github.com/materialsproject/fireworks/pull/517 but is has not been released yet. So you do not have to provide a PR. For the time being, I would suggest that you pull and install from the main branch.

This issue is duplicate of https://github.com/materialsproject/fireworks/issues/516.

ikondov commented 6 months ago

Another workaround is to downgrade ruamel.yaml <0.18.0 if new installation/upgrade from fireworks main branch is not convenient. This is what I had done until PR https://github.com/materialsproject/fireworks/pull/517 was merged.

fraricci commented 6 months ago

Thank for you reply! I actually searched the issues, but not the pull requests, so I did not see that you had already mentioned and solved the issue. I have the fireworks version that comes with pip. Indeed I installed the last 0.17 version of ruamel.yaml to temporary solve the issue.

Given that relevance of your PR, I believe a new version of Fireworks should be released. @janosh @computron

Thanks!

janosh commented 6 months ago

i'm not a manager of fireworks pypi package and there's no release CI in place. so a new release has to be done by @computron

mattmcdermott commented 5 months ago

Both my coworker and I ran into this same issue and it took us a while to figure out (downgrading ruamel.yaml was the easy fix).

+1 for doing a new release! @computron