Newer
Older
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
77
78
79
80
# Summary
[](https://www.python.org/)
[](https://git.jinr.ru/dag-computing/dag-flow/commits/master)
[](https://git.jinr.ru/dag-computing/dag-flow/-/commits/master)
<!--- Uncomment here after adding docs!
[](http://dag-computing.pages.jinr.ru/dag-flow)
-->
DAGFlow is python implementation of dataflow programming with lazy graph evaluation.
Main goals:
* Lazy evaluated directed acyclic graph
* Concise connection syntax
* Plotting with graphviz
* Flexibility. The goal of DAGFlow is not to be efficient, but rather flexible.
Here is an animation, showing the process of the graph evaluation

# Minimal example
An example of small, graph calculating the formula (n1 + n2 + n3) * n4 may be
found in the [example](example/example.py):
```python
#!/usr/bin/env python
from dagflow.node_deco import NodeClass
from dagflow.graph import Graph
from dagflow.graphviz import savegraph
from dagflow.input_extra import MissingInputAddOne
import numpy as N
# Node functions
@NodeClass(output='array')
def Array(node, inputs, output):
"""Creates a note with single data output with predefined array"""
outputs[0].data = N.arange(5, dtype='d')
@NodeClass(missing_input_handler=MissingInputAddOne(output_fmt='result'))
def Adder(node, inputs, output):
"""Adds all the inputs together"""
out = None
for input in inputs:
if out is None:
out=outputs[0].data = input.data.copy()
else:
out+=input.data
@NodeClass(missing_input_handler=MissingInputAddOne(output_fmt='result'))
def Multiplier(node, inputs, output):
"""Multiplies all the inputs together"""
out = None
for input in inputs:
if out is None:
out = outputs[0].data = input.data.copy()
else:
out*=input.data
# The actual code
with Graph() as graph:
(in1, in2, in3, in4) = [Array(name) for name in ['n1', 'n2', 'n3', 'n4']]
s = Adder('add')
m = Multiplier('mul')
(in1, in2, in3) >> s
(in4, s) >> m
print('Result is:', m.outputs["result"].data)
savegraph(graph, 'output/dagflow_example.png')
```
The code produces the following graph:

For `n=[1, 2, 3, 4]` the output is:
```
Result is: [ 0. 3. 12. 27. 48.]
```