Skip to content

Commit f62110d

Browse files
authored
Treat python_app input/output default arguments like other magic keywords, and like bash_app (#3489)
In a previous PR (#3485), some fields where the default values of outputs and inputs for AppBase were removed. These fields were not being used in any way. However, like the other parsl reserved parameters, the defaults should have been stored in the AppBase.kwargs dict which is used to ensure that the default values of these special reserved parameters are in invocation_kwargs which is sent to the dataflow kernel and used to resolve the corresponding special behaviors. The correct behavior was only observed in BashApp since it does additional checking to store all default args (even the non-reserved ones) to invocation_kwargs. Now it should be consistent for both types of apps. Changed Behaviour: PythonApp will now correctly resolve default arguments for the inputs and outputs special parameters.
1 parent 04a797b commit f62110d

File tree

3 files changed

+51
-0
lines changed

3 files changed

+51
-0
lines changed

parsl/app/app.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,10 @@ def __init__(self, func: Callable,
6666
self.kwargs['walltime'] = params['walltime'].default
6767
if 'parsl_resource_specification' in params:
6868
self.kwargs['parsl_resource_specification'] = params['parsl_resource_specification'].default
69+
if 'outputs' in params:
70+
self.kwargs['outputs'] = params['outputs'].default
71+
if 'inputs' in params:
72+
self.kwargs['inputs'] = params['inputs'].default
6973

7074
@abstractmethod
7175
def __call__(self, *args: Any, **kwargs: Any) -> AppFuture:
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import pytest
2+
3+
from parsl import AUTO_LOGNAME, Config, bash_app, python_app
4+
from parsl.executors import ThreadPoolExecutor
5+
6+
7+
def local_config():
8+
return Config(executors=[ThreadPoolExecutor()])
9+
10+
11+
@pytest.mark.local
12+
def test_default_inputs():
13+
@python_app
14+
def identity(inp):
15+
return inp
16+
17+
@bash_app
18+
def sum_inputs(inputs=[identity(1), identity(2)], stdout=AUTO_LOGNAME):
19+
calc = sum(inputs)
20+
return f"echo {calc}"
21+
22+
fut = sum_inputs()
23+
fut.result()
24+
with open(fut.stdout, 'r') as f:
25+
assert int(f.read()) == 3
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import pytest
2+
3+
import parsl
4+
from parsl import python_app
5+
from parsl.executors.threads import ThreadPoolExecutor
6+
7+
8+
def local_config():
9+
return parsl.Config(executors=[ThreadPoolExecutor()])
10+
11+
12+
@pytest.mark.local
13+
def test_default_inputs():
14+
@python_app
15+
def identity(inp):
16+
return inp
17+
18+
@python_app
19+
def add_inputs(inputs=[identity(1), identity(2)]):
20+
return sum(inputs)
21+
22+
assert add_inputs().result() == 3

0 commit comments

Comments
 (0)