-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_interface.py
More file actions
37 lines (30 loc) · 1.13 KB
/
Copy pathtest_interface.py
File metadata and controls
37 lines (30 loc) · 1.13 KB
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
import json, stitch_py as sp
from stitch_py import StitchHandle
args = (
'--file "C:\\Users\\mesom\\OneDrive\\backup\\Documents\\UROP\\synthestitch\\data\\origami\\bigram_test.json" '
'--domain simple '
'--model uniform '
'--bigrams-path "C:\\Users\\mesom\\OneDrive\\backup\\Documents\\UROP\\synthestitch\\data\\origami\\sample_probabilities.json" '
'--verbose-eval '
'--threads 1'
)
def sum_list_py(args):
(vec,) = args # one arg: list[int]
return sum(vec)
def mul_py(args):
x, y = args
return x * y
def add_py(args):
x, y = args
return x + y
# Create a handle (this builds the native Simple DSL inside)
handle = StitchHandle()
# Register Python-backed primitives (early-capture into THIS handle’s DSL)
handle.register("sum_py", "list int -> int", sum_list_py)
handle.register("mul_py", "int -> int -> int", mul_py)
handle.register("add_py", "int -> int -> int", add_py)
handle.register("py_const_0", "int", 0)
handle.register("py_const_1", "int", 1)
handle.register("py_const_2", "int", 2)
# IMPORTANT: run using the handle’s DSL (so your registrations are visible)
print(handle.run_cli(args))