Importing Parsl appsΒΆ

It may be convenient to define Parsl apps separately from the definition of the DataFlowKernel, or in libraries of apps which are intended to be imported by other modules. For this reason, the DataFlowKernel is an optional argument to the App() decorator. If the DataFlowKernel is not passed to the App() decorator, a configuration must be loaded using parsl.load prior to calling the app.

The configuration can be defined in the Parsl script, or elsewhere before being imported. As an example of the latter, consider a file called config.py which contains the following definition:

local_threads = {
    "sites": [
        {
            "site": "local_threads",
            "auth": {
                "channel": None
            },
            "execution": {
                "executor": "threads",
                "provider": None,
                "maxThreads": 4
            }
        }
    ],
    "globals": {
        "lazyErrors": True
    }
}

In a separate file called library.py, we define:

from parsl import App

@App('python')
def increment(x):
    return x + 1

Putting these together in a third file called run_increment.py, we load the configuration from config.py before calling the increment app:

import parsl
from config import local_threads
from library import increment

parsl.load(local_threads)

for i in range(5):
    print('{} + 1 = {}'.format(i, increment(i).result()))

Which produces the following output:

0 + 1 = 1
1 + 1 = 2
2 + 1 = 3
3 + 1 = 4
4 + 1 = 5