-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.py
51 lines (40 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
import json
import nextmv
from nextpipe import FlowSpec, app, log, needs, repeat, step
# Define the options for the workflow
parameters = [
nextmv.Parameter("instance", str, "latest", "App instance to use. Default is devint.", False),
]
options = nextmv.Options(*parameters)
# >>> Workflow definition
class Flow(FlowSpec):
@app(
app_id="routing-nextroute",
instance_id=options.instance,
parameters={"model.constraints.enable.cluster": True},
)
@repeat(repetitions=3)
@step
def run_nextroute():
"""Runs the model."""
pass
@needs(predecessors=[run_nextroute])
@step
def pick_best(results: list[dict]):
"""Aggregates the results."""
log(f"Values: {[result['statistics']['result']['value'] for result in results]}")
best_solution_idx = min(
range(len(results)),
key=lambda i: results[i]["statistics"]["result"]["value"],
)
return results[best_solution_idx]
def main():
# Load input data
input = nextmv.load_local()
# Run workflow
flow = Flow("DecisionFlow", input.data)
flow.run()
result = flow.get_result(flow.pick_best)
print(json.dumps(result))
if __name__ == "__main__":
main()