File: execute_io.rst

package info (click to toggle)
python-ewokscore 2.0.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky
  • size: 880 kB
  • sloc: python: 10,679; makefile: 5
file content (76 lines) | stat: -rw-r--r-- 2,624 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
Workflow inputs and outputs
===========================

Workflow inputs and outputs can be provided when executing a workflow

.. code:: python

    from ewokscore import execute_graph

    results = execute_graph(
        "/path/to/file.json",
        inputs=[{...}, {...}, ...],   # list of dictionaries
        outputs=[{...}, {...}, ...]   # list of dictionaries
    )

The dictionary keys for inputs are

* name: input variable name
* value: input variable value
* id (optional): node id
* label (optional): used when `id` is missing
* task_identifier (optional): used when `id` is missing (the node's task identifier must end with this string)
* all (optional): used when `id`, `label` and `task_identifier` are missing (`True`: all nodes, `False`: start nodes)

An example to provide the following input arguments to the workflow nodes

* node with id `task1` receive `a=10`
* node with label `My Node` receive `b=20`
* all start nodes receive `collectionId=1234`
* all `mypackage.mymodule.IntegrationTask` tasks receive `nbpts_azi=1024`

.. code:: python

    from ewokscore import execute_graph

    results = execute_graph(
        "/path/to/file.json",
        inputs=[{"id": "task1", "name":"a", "value": 10},
                {"label": "My Node", "name":"b", "value": 20},
                {"name":"collectionId", "value": 1234},
                {"task_identifier": "IntegrationTask", "name":"nbpts_azi", "value": 1024}]
    )

The dictionary keys for outputs are

* name (optional): output variable name (all outputs when missing)
* new_name (optional): optional renaming when `name` is defined (can be used avoid naming collisions)
* id (optional): node id
* label (optional): used when `id` is missing
* task_identifier (optional): used when `id` is missing (the node's task identifier must end with this string)
* all (optional): used when `id`, `label` and `task_identifier` are missing (`True`: all nodes, `False`: end nodes)

When no outputs are provided, the output variables of all *end nodes* are returned

.. code:: python

    from ewokscore import execute_graph

    results = execute_graph(
        "/path/to/file.json",
        outputs=[{"all": False}]
    )

An example where we use the return value of two tasks as the workflow output

.. code:: python

    from ewokscore import execute_graph

    results = execute_graph(
        "/path/to/file.json",
        inputs=[{"id": "task1", "name": "return_value", "new_name": "return_value1"},
                {"id": "task2", "name": "return_value", "new_name": "return_value2"}]
    )

    assert set(results) == {"return_value1", "return_value2"}