Skip to content

Commit 69546e3

Browse files
authored
Remove external tools from creator (#712)
Users should just import and use these from their home Signed-off-by: liamhuber <liamhuber@greyhavensolutions.com>
1 parent 0a9ace9 commit 69546e3

File tree

7 files changed

+26
-28
lines changed

7 files changed

+26
-28
lines changed

notebooks/deepdive.ipynb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2727,6 +2727,8 @@
27272727
}
27282728
},
27292729
"source": [
2730+
"from concurrent import futures\n",
2731+
"\n",
27302732
"wf = pwf.Workflow(\"test\")\n",
27312733
"wf.a = pwf.std.UserInput(1)\n",
27322734
"wf.b = pwf.std.UserInput(\"two\")\n",
@@ -2740,7 +2742,7 @@
27402742
"wf.starting_nodes = [wf.a]\n",
27412743
"wf.automate_execution = False\n",
27422744
"\n",
2743-
"with pwf.Workflow.create.ProcessPoolExecutor() as exe:\n",
2745+
"with futures.ProcessPoolExecutor() as exe:\n",
27442746
" wf.c_fails.executor = exe\n",
27452747
" wf(raise_run_exceptions=False)\n",
27462748
"\n",

notebooks/quickstart.ipynb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1273,6 +1273,8 @@
12731273
}
12741274
},
12751275
"source": [
1276+
"from concurrent import futures\n",
1277+
"\n",
12761278
"@Workflow.wrap.as_function_node\n",
12771279
"def Report(t1, t2, t3):\n",
12781280
" tmax = max(t1, t2, t3)\n",
@@ -1294,7 +1296,7 @@
12941296
"\n",
12951297
"t0 = time()\n",
12961298
"\n",
1297-
"with Workflow.create.ThreadPoolExecutor(max_workers=3) as exe:\n",
1299+
"with futures.ThreadPoolExecutor(max_workers=3) as exe:\n",
12981300
" for n in wf:\n",
12991301
" if n.label not in [\"t_sleep\", \"midway\", \"finally\"]:\n",
13001302
" n.executor = exe\n",
@@ -1496,7 +1498,7 @@
14961498
"\n",
14971499
"macro_with_for_loops = InternallyIterates()\n",
14981500
"\n",
1499-
"with Workflow.create.ThreadPoolExecutor(max_workers=1) as exe:\n",
1501+
"with futures.ThreadPoolExecutor(max_workers=1) as exe:\n",
15001502
" macro_with_for_loops.iter_add.body_node_executor = exe\n",
15011503
" out = macro_with_for_loops(data=[1, 2, 3])\n",
15021504
"\n",

pyiron_workflow/create.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,6 @@
44

55
from __future__ import annotations
66

7-
from concurrent.futures import ProcessPoolExecutor, ThreadPoolExecutor
8-
9-
import executorlib
107
from pyiron_snippets.dotdict import DotDict
118

129
from pyiron_workflow.executors import CloudpickleProcessPoolExecutor
@@ -23,16 +20,11 @@ class Creator:
2320
"""
2421

2522
def __init__(self):
26-
# Standard lib
27-
self.ProcessPoolExecutor = ProcessPoolExecutor
28-
self.ThreadPoolExecutor = ThreadPoolExecutor
2923
# Local cloudpickler
3024
self.CloudpickleProcessPoolExecutor = CloudpickleProcessPoolExecutor
3125

3226
self.function_node = function_node
3327

34-
executorlib = executorlib
35-
3628
@property
3729
def std(self):
3830
from pyiron_workflow.nodes import standard

tests/integration/test_parallel_speedup.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import unittest
2+
from concurrent import futures
23
from time import perf_counter, sleep
34

45
from pyiron_workflow import Workflow
@@ -42,7 +43,7 @@ def make_workflow(label):
4243
wf.d << (wf.a, wf.b, wf.c)
4344
wf.starting_nodes = [wf.a, wf.b, wf.c]
4445

45-
with wf.create.ProcessPoolExecutor(max_workers=3) as executor:
46+
with futures.ProcessPoolExecutor(max_workers=3) as executor:
4647
wf.a.executor = executor
4748
wf.b.executor = executor
4849
wf.c.executor = executor
@@ -81,7 +82,7 @@ def test_executor_instructions(self):
8182
wf.sleep3 = Workflow.create.std.Sleep(t)
8283
wf.sleep4 = Workflow.create.std.Sleep(t)
8384
for n in wf:
84-
n.executor = (Workflow.create.ThreadPoolExecutor, (), {})
85+
n.executor = (futures.ThreadPoolExecutor, (), {})
8586

8687
wf.save()
8788
reloaded = Workflow("test")

tests/integration/test_workflow.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import unittest
66
from concurrent import futures
77

8+
import executorlib
89
from static import demo_nodes
910

1011
from pyiron_workflow._tests import ensure_tests_in_python_path
@@ -147,7 +148,7 @@ def test_executor_and_creator_interaction(self):
147148
wf = Workflow("depickle")
148149

149150
wf.before_pickling = demo_nodes.OptionallyAdd(1)
150-
wf.before_pickling.executor = wf.create.ProcessPoolExecutor()
151+
wf.before_pickling.executor = futures.ProcessPoolExecutor()
151152
wf()
152153
wf.before_pickling.future.result(timeout=120) # Wait for it to finish
153154
wf.executor_shutdown()
@@ -158,10 +159,10 @@ def test_executor_and_creator_interaction(self):
158159

159160
def test_executors(self):
160161
executors = [
161-
Workflow.create.ProcessPoolExecutor,
162-
Workflow.create.ThreadPoolExecutor,
162+
futures.ProcessPoolExecutor,
163+
futures.ThreadPoolExecutor,
163164
Workflow.create.CloudpickleProcessPoolExecutor,
164-
Workflow.create.executorlib.SingleNodeExecutor,
165+
executorlib.SingleNodeExecutor,
165166
]
166167

167168
wf = Workflow("executed")
@@ -272,7 +273,7 @@ def test_failure(self):
272273

273274
with (
274275
self.subTest("Check completion"),
275-
Workflow.create.ProcessPoolExecutor() as exe,
276+
futures.ProcessPoolExecutor() as exe,
276277
):
277278
wf.c_fails.executor = exe
278279
wf(raise_run_exceptions=False)

tests/unit/nodes/test_macro.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pickle
22
import unittest
3-
from concurrent.futures import Future
3+
from concurrent import futures
44
from time import sleep
55

66
from static import demo_nodes
@@ -217,7 +217,7 @@ def test_with_executor(self):
217217
# at the downstream output, and none of this is happening in a workflow
218218

219219
original_one = macro.one
220-
macro.executor = macro.create.ProcessPoolExecutor()
220+
macro.executor = futures.ProcessPoolExecutor()
221221

222222
self.assertIs(
223223
NOT_DATA,
@@ -227,7 +227,7 @@ def test_with_executor(self):
227227

228228
result = macro.run(one__x=0)
229229
self.assertIsInstance(
230-
result, Future, msg="Should be running as a parallel process"
230+
result, futures.Future, msg="Should be running as a parallel process"
231231
)
232232
self.assertIs(
233233
NOT_DATA,

tests/unit/test_workflow.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import pickle
22
import unittest
3-
from concurrent.futures import Future, ThreadPoolExecutor
3+
from concurrent import futures
44
from time import sleep
55

66
from bidict import ValueDuplicationError
@@ -175,7 +175,7 @@ def test_with_executor(self):
175175
wf.b = wf.create.function_node(plus_one, x=wf.a)
176176

177177
original_a = wf.a
178-
wf.executor = wf.create.ProcessPoolExecutor()
178+
wf.executor = futures.ProcessPoolExecutor()
179179

180180
self.assertIs(
181181
NOT_DATA,
@@ -185,7 +185,7 @@ def test_with_executor(self):
185185

186186
result = wf(a__x=0)
187187
self.assertIsInstance(
188-
result, Future, msg="Should be running as a parallel process"
188+
result, futures.Future, msg="Should be running as a parallel process"
189189
)
190190

191191
_ = result.result(timeout=120) # Wait for the process to finish
@@ -215,7 +215,7 @@ def test_run_in_thread_exceptions(self):
215215
wf = Workflow("wf")
216216
wf.a = wf.create.function_node(plus_one)
217217

218-
wf.executor = (ThreadPoolExecutor, (), {})
218+
wf.executor = (futures.ThreadPoolExecutor, (), {})
219219

220220
with self.assertRaises(
221221
ValueError,
@@ -230,7 +230,7 @@ def test_parallel_execution(self):
230230
wf.fast = five()
231231
wf.sum = sum(a=wf.fast, b=wf.slow)
232232

233-
wf.slow.executor = wf.create.ProcessPoolExecutor()
233+
wf.slow.executor = futures.ProcessPoolExecutor()
234234

235235
wf.slow.run()
236236
wf.fast.run()
@@ -405,15 +405,15 @@ def add_three_macro(self, one__x):
405405
msg="Sanity check, pulling here should work perfectly fine",
406406
)
407407

408-
wf.m.one.executor = wf.create.ProcessPoolExecutor()
408+
wf.m.one.executor = futures.ProcessPoolExecutor()
409409
with self.assertRaises(
410410
ValueError, msg="Should not be able to pull with executor in local scope"
411411
):
412412
wf.m.two.pull()
413413
wf.m.one.executor_shutdown() # Shouldn't get this far, but if so, shutdown
414414
wf.m.one.executor = None
415415

416-
wf.n1.executor = wf.create.ProcessPoolExecutor()
416+
wf.n1.executor = futures.ProcessPoolExecutor()
417417
with self.assertRaises(
418418
ValueError, msg="Should not be able to pull with executor in parent scope"
419419
):

0 commit comments

Comments
 (0)