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

FIX: Properly jsanitize fireworks Task #544

Merged
merged 2 commits into from
Feb 14, 2024
Merged

Conversation

gpetretto
Copy link
Contributor

I have seen that in some cases the JobFiretask does not properly serialize a Job.
Consider the case of a Maker with a Callable as an attribute.

from fireworks import LaunchPad
from jobflow.managers.fireworks import job_to_firework

from dataclasses import dataclass
from typing import Callable
from jobflow import Maker, job


def print_function():
    print("TEST")


@dataclass
class CallableMaker(Maker):
    f: Callable
    name: str = "CallableMaker"

    @job
    def make(self, *args, **kwargs):
        self.f()

j = CallableMaker(f=print_function).make()

fw = job_to_firework(j)
lpad = LaunchPad.auto_load()
lpad.add_wf(fw)

When running this, in the firework DB you have

{
    "spec": {
        "_tasks": [
            {
                "job": {
                    "@module": "jobflow.core.job",
                    "@class": "Job",
                    "@version": "0.1.14.post122+g6439853",
                    "function": {
                        "@module": "__main__",
                        "@callable": "CallableMaker.make",
                        "@bound": {
                            "@module": "__main__",
                            "@class": "CallableMaker",
                            "@version": null,
                            "f": "<function print_function at 0x16ad82cb0>",
                            "name": "CallableMaker"
                        }
                    },
                   ...

}

Where the function is serialized as a string.

This PR addresses this issue by overriding the JobFiretask.to_dict method and explicitly jsanitizing the Job.

@utf
Copy link
Member

utf commented Feb 14, 2024

Great catch! Thanks @gpetretto

Copy link

codecov bot commented Feb 14, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Comparison is base (c211030) 99.42% compared to head (0debb38) 99.42%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main     #544   +/-   ##
=======================================
  Coverage   99.42%   99.42%           
=======================================
  Files          21       21           
  Lines        1556     1564    +8     
  Branches      422      425    +3     
=======================================
+ Hits         1547     1555    +8     
  Misses          9        9           
Files Coverage Δ
src/jobflow/managers/fireworks.py 100.00% <100.00%> (ø)

@utf
Copy link
Member

utf commented Feb 14, 2024

Is it possible to add a quick test?

@gpetretto
Copy link
Contributor Author

Is it possible to add a quick test?

done

@utf
Copy link
Member

utf commented Feb 14, 2024

Perfect, thanks so much.

@utf utf merged commit eda2a65 into materialsproject:main Feb 14, 2024
9 checks passed
@utf utf changed the title jsanitize fireworks Task FIX: Properly jsanitize fireworks Task Feb 14, 2024
@utf utf added the fix Bug fix label Feb 14, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Bug fix
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants