-
Notifications
You must be signed in to change notification settings - Fork 198
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branches 'benc-tmp-sander' and 'benc-3472-recursion' into benc-…
…sander-paper
- Loading branch information
Showing
2 changed files
with
73 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import inspect | ||
from concurrent.futures import Future | ||
from typing import Any, Callable, Dict | ||
|
||
import pytest | ||
|
||
import parsl | ||
from parsl.executors.base import ParslExecutor | ||
|
||
# N is the number of tasks to chain | ||
# With mid-2024 Parsl, N>140 causes Parsl to hang | ||
N = 100 | ||
|
||
# MAX_STACK is the maximum Python stack depth allowed for either | ||
# task submission to an executor or execution of a task. | ||
# With mid-2024 Parsl, 2-3 stack entries will be used per | ||
# recursively launched parsl task. So this should be smaller than | ||
# 2*N, but big enough to allow regular pytest+parsl stuff to | ||
# happen. | ||
MAX_STACK = 50 | ||
|
||
|
||
def local_config(): | ||
return parsl.Config(executors=[ImmediateExecutor()]) | ||
|
||
|
||
class ImmediateExecutor(ParslExecutor): | ||
def start(self): | ||
pass | ||
|
||
def shutdown(self): | ||
pass | ||
|
||
def submit(self, func: Callable, resource_specification: Dict[str, Any], *args: Any, **kwargs: Any) -> Future: | ||
stack_depth = len(inspect.stack()) | ||
assert stack_depth < MAX_STACK, "tasks should not be launched deep in the Python stack" | ||
fut: Future[None] = Future() | ||
res = func(*args, **kwargs) | ||
fut.set_result(res) | ||
return fut | ||
|
||
|
||
@parsl.python_app | ||
def chain(upstream): | ||
stack_depth = len(inspect.stack()) | ||
assert stack_depth < MAX_STACK, "chained dependencies should not be launched deep in the Python stack" | ||
|
||
|
||
@pytest.mark.local | ||
def test_deep_dependency_stack_depth(): | ||
|
||
fut = Future() | ||
here = fut | ||
|
||
for _ in range(N): | ||
here = chain(here) | ||
|
||
fut.set_result(None) | ||
here.result() |