Skip to content

Commit 8f1b031

Browse files
committed
added getstate and setsate for sge and slurm workers
1 parent 82b4962 commit 8f1b031

File tree

3 files changed

+38
-3
lines changed

3 files changed

+38
-3
lines changed

docs/source/reference/api.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ API
44
Python tasks
55
------------
66

7-
.. automodule:: pydra.design.python
7+
.. automodule:: pydra.compose.python
88
:members:
99
:undoc-members:
1010
:show-inheritance:
1111

1212
Shell tasks
1313
-----------
1414

15-
.. automodule:: pydra.design.shell
15+
.. automodule:: pydra.compose.shell
1616
:members:
1717
:undoc-members:
1818
:show-inheritance:
1919

2020
Workflows
2121
---------
2222

23-
.. automodule:: pydra.design.workflow
23+
.. automodule:: pydra.compose.workflow
2424
:members:
2525
:undoc-members:
2626
:show-inheritance:

pydra/workers/sge.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,30 @@ class Worker(base.Worker):
7878
result_files_by_jobid: dict[str, ty.Any] = attrs.field(factory=dict, init=False)
7979
job_pkls_rerun: dict[str, ty.Any] = attrs.field(factory=dict, init=False)
8080

81+
_INTERNAL_DICT_ATTRS = [
82+
"error",
83+
"tasks_to_run_by_threads_requested",
84+
"output_by_jobid",
85+
"jobid_by_task_uid",
86+
"threads_used",
87+
"job_completed_by_jobid",
88+
"result_files_by_jobid",
89+
"job_pkls_rerun",
90+
]
91+
92+
def __getstate__(self) -> dict[str, ty.Any]:
93+
"""Return state for pickling."""
94+
state = super().__getstate__()
95+
for atr in self._INTERNAL_DICT_ATTRS:
96+
del state[atr]
97+
return state
98+
99+
def __setstate__(self, state: dict[str, ty.Any]):
100+
"""Set state for unpickling."""
101+
super().__setstate__(state)
102+
for atr in self._INTERNAL_DICT_ATTRS:
103+
setattr(self, atr, {})
104+
81105
def _prepare_runscripts(self, job, interpreter="/bin/sh", rerun=False):
82106
if isinstance(job, Job):
83107
cache_dir = job.cache_dir

pydra/workers/slurm.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,17 @@ class Worker(base.Worker):
3131
sbatch_args: str = ""
3232
error: dict[str, ty.Any] = attrs.field(factory=dict)
3333

34+
def __getstate__(self) -> dict[str, ty.Any]:
35+
"""Return state for pickling."""
36+
state = super().__getstate__()
37+
del state["error"]
38+
return state
39+
40+
def __setstate__(self, state: dict[str, ty.Any]):
41+
"""Set state for unpickling."""
42+
state["error"] = {}
43+
super().__setstate__(state)
44+
3445
def _prepare_runscripts(self, job, interpreter="/bin/sh", rerun=False):
3546
if isinstance(job, Job):
3647
cache_dir = job.cache_dir

0 commit comments

Comments
 (0)