Skip to content

Commit

Permalink
added definition to Result attributes that need to be cloudpickled
Browse files Browse the repository at this point in the history
  • Loading branch information
tclose committed Feb 6, 2025
1 parent 92cf378 commit 6a72657
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
5 changes: 3 additions & 2 deletions new-docs/source/tutorial/3-troubleshooting.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,9 @@
"# This workflow will fail because we are trying to divide by 0\n",
"wf = UnsafeDivisionWorkflow(a=10, b=5).split(denominator=[3, 2 ,0])\n",
"\n",
"with Submitter(worker=\"cf\") as sub:\n",
" result = sub(wf)\n",
"if __name__ == \"__main__\":\n",
" with Submitter(worker=\"cf\") as sub:\n",
" result = sub(wf)\n",
" \n",
"if result.errored:\n",
" print(\"Workflow failed with errors:\\n\" + str(result.errors))\n",
Expand Down
12 changes: 8 additions & 4 deletions pydra/engine/specs.py
Original file line number Diff line number Diff line change
Expand Up @@ -531,15 +531,19 @@ class Result(ty.Generic[OutputsType]):
errored: bool = False
definition: TaskDef[OutputsType] | None = None

CLOUD_PICKLE_ATTRS = ("outputs", "definition")

def __getstate__(self):
state = attrs_values(self)
if state["outputs"] is not None:
state["outputs"] = cp.dumps(state["outputs"])
for attr in self.CLOUD_PICKLE_ATTRS:
if state[attr] is not None:
state[attr] = cp.dumps(state[attr])
return state

def __setstate__(self, state):
if state["outputs"] is not None:
state["outputs"] = cp.loads(state["outputs"])
for attr in self.CLOUD_PICKLE_ATTRS:
if state[attr] is not None:
state[attr] = cp.loads(state[attr])
for name, val in state.items():
setattr(self, name, val)

Expand Down

0 comments on commit 6a72657

Please sign in to comment.