Skip to content

Commit 3eda5d3

Browse files
committed
generalize use-case for psijworker
1 parent d9bca02 commit 3eda5d3

File tree

3 files changed

+28
-16
lines changed

3 files changed

+28
-16
lines changed

pydra/engine/run_pickled_function.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
def run_pickled():
77
file_path = sys.argv[1]
8-
with open(file_path, 'rb') as file:
8+
with open(file_path, "rb") as file:
99
loaded_function = pickle.load(file)
1010

1111
result = loaded_function(rerun=False)

pydra/engine/run_pickled_function_2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ def run_pickled():
77
file_path_1 = sys.argv[1]
88
file_path_2 = sys.argv[2]
99
file_path_3 = sys.argv[3]
10-
with open(file_path_1, 'rb') as file:
10+
with open(file_path_1, "rb") as file:
1111
loaded_function = pickle.load(file)
12-
with open(file_path_2, 'rb') as file:
12+
with open(file_path_2, "rb") as file:
1313
taskmain = pickle.load(file)
14-
with open(file_path_3, 'rb') as file:
14+
with open(file_path_3, "rb") as file:
1515
ind = pickle.load(file)
1616

1717
result = loaded_function(taskmain, ind, rerun=False)

pydra/engine/workers.py

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -924,28 +924,40 @@ async def exec_psij(self, runnable, rerun=False):
924924
import psij
925925
import pickle
926926
import os
927+
927928
self.psij = psij
928-
jex = psij.JobExecutor.get_instance('slurm')
929-
929+
jex = psij.JobExecutor.get_instance("slurm")
930+
absolute_path = os.path.dirname(__file__)
931+
930932
if isinstance(runnable, TaskBase):
931933
cache_dir = runnable.cache_dir
932-
file_path = os.path.join(cache_dir, 'my_function.pkl')
933-
with open(file_path, 'wb') as file:
934+
file_path = os.path.join(cache_dir, "my_function.pkl")
935+
with open(file_path, "wb") as file:
934936
pickle.dump(runnable._run, file)
935-
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function.py", file_path])
937+
func_path = os.path.join(absolute_path, "run_pickled_function.py")
938+
spec = self.make_spec("python", [func_path, file_path])
936939
else: # it could be tuple that includes pickle files with tasks and inputs
937940
cache_dir = runnable[-1].cache_dir
938-
file_path_1 = os.path.join(cache_dir, 'my_function.pkl')
939-
file_path_2 = os.path.join(cache_dir, 'taskmain.pkl')
940-
file_path_3 = os.path.join(cache_dir, 'ind.pkl')
941+
file_path_1 = os.path.join(cache_dir, "my_function.pkl")
942+
file_path_2 = os.path.join(cache_dir, "taskmain.pkl")
943+
file_path_3 = os.path.join(cache_dir, "ind.pkl")
941944
ind, task_main_pkl, task_orig = runnable
942-
with open(file_path_1, 'wb') as file:
945+
with open(file_path_1, "wb") as file:
943946
pickle.dump(load_and_run, file)
944-
with open(file_path_2, 'wb') as file:
947+
with open(file_path_2, "wb") as file:
945948
pickle.dump(task_main_pkl, file)
946-
with open(file_path_3, 'wb') as file:
949+
with open(file_path_3, "wb") as file:
947950
pickle.dump(ind, file)
948-
spec = self.make_spec("python3.9", ["/pydra/pydra/engine/run_pickled_function_2.py", file_path_1, file_path_2, file_path_3])
951+
func_path = os.path.join(absolute_path, "run_pickled_function_2.py")
952+
spec = self.make_spec(
953+
"python",
954+
[
955+
func_path,
956+
file_path_1,
957+
file_path_2,
958+
file_path_3,
959+
],
960+
)
949961

950962
job = self.make_job(spec, None)
951963
jex.submit(job)

0 commit comments

Comments
 (0)