-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #306 from pyiron/dependencies
Add support for dependent tasks
- Loading branch information
Showing
5 changed files
with
242 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from pympipool.scheduler import create_executor | ||
from pympipool.shared.executorbase import ExecutorSteps, execute_tasks_with_dependencies | ||
from pympipool.shared.thread import RaisingThread | ||
|
||
|
||
class ExecutorWithDependencies(ExecutorSteps): | ||
def __init__(self, *args, refresh_rate: float = 0.01, **kwargs): | ||
super().__init__() | ||
executor = create_executor(*args, **kwargs) | ||
self._set_process( | ||
RaisingThread( | ||
target=execute_tasks_with_dependencies, | ||
kwargs={ | ||
# Executor Arguments | ||
"future_queue": self._future_queue, | ||
"executor_queue": executor._future_queue, | ||
"executor": executor, | ||
"refresh_rate": refresh_rate, | ||
}, | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import unittest | ||
from time import sleep | ||
|
||
from pympipool import Executor | ||
from pympipool.shared.executorbase import cloudpickle_register | ||
|
||
|
||
def add_function(parameter_1, parameter_2): | ||
sleep(0.2) | ||
return parameter_1 + parameter_2 | ||
|
||
|
||
class TestExecutorWithDependencies(unittest.TestCase): | ||
def test_executor(self): | ||
with Executor(max_cores=1, backend="mpi", hostname_localhost=True) as exe: | ||
cloudpickle_register(ind=1) | ||
future_1 = exe.submit(add_function, 1, parameter_2=2) | ||
future_2 = exe.submit(add_function, 1, parameter_2=future_1) | ||
self.assertEqual(future_2.result(), 4) |