-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
71 lines (50 loc) · 1.23 KB
/
main.py
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
import json
import random
import time
from gxe import GraphExecutionEngine, NodeRegistry
def input(value):
time.sleep(1)
return value
def add(a, b):
time.sleep(1)
return a + b
def subtract(a, b):
time.sleep(1)
return a - b
def multiply(a, b):
time.sleep(1)
return a * b
def divide(a, b):
time.sleep(1)
if b != 0:
return a / b
else:
raise ValueError("Cannot divide by zero.")
class SwapIncrement:
def __init__(self, increment):
self.increment = increment
def __call__(self, a, b):
time.sleep(1)
return {"a": b + self.increment, "b": a + self.increment}
if __name__ == "__main__":
with open("graph.json", "r") as f:
graph = json.load(f)
node_registry = NodeRegistry()
node_registry.register(
[
input,
add,
subtract,
multiply,
divide,
SwapIncrement,
]
)
engine = GraphExecutionEngine(graph, node_registry)
engine.parse_node()
start_time = time.time()
result = engine.execute()
end_time = time.time()
print(f"Execution time: {end_time - start_time:.2f} seconds")
for node in result.values():
print(node)