Spaces:
Sleeping
Sleeping
Commit
·
76e5d05
1
Parent(s):
3a2cd91
Update live demo
Browse files
app.py
CHANGED
|
@@ -30,30 +30,35 @@ Here, we implement the non-ML subset of BUSTLE, the algorithm proposed by [Odena
|
|
| 30 |
st.subheader("Input-Output Examples")
|
| 31 |
|
| 32 |
st.markdown('''
|
| 33 |
-
Select input-output examples as defined in `examples.py`, or define your own custom examples. The examples are used to synthesize a program
|
| 34 |
''')
|
| 35 |
|
| 36 |
# define variables
|
| 37 |
-
domain = "arithmetic"
|
| 38 |
-
examples_key = "addition"
|
| 39 |
-
max_weight = 3
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
# retrieve selected input-output examples
|
| 42 |
examples = example_set[examples_key]
|
| 43 |
|
| 44 |
# extract constants from examples
|
|
|
|
| 45 |
program_bank = extract_constants(examples)
|
| 46 |
program_bank_str = [p.str() for p in program_bank]
|
| 47 |
print("\nSynthesis Log:")
|
| 48 |
print(f"- Extracted {len(program_bank)} constants from examples.")
|
|
|
|
| 49 |
|
| 50 |
# define operators
|
| 51 |
if domain == "arithmetic":
|
| 52 |
operators = arithmetic_operators
|
| 53 |
elif domain == "strings":
|
| 54 |
operators = string_operators
|
| 55 |
-
else:
|
| 56 |
-
|
| 57 |
|
| 58 |
# define final program
|
| 59 |
final_program = None
|
|
@@ -64,6 +69,7 @@ for weight in range(2, max_weight):
|
|
| 64 |
|
| 65 |
# print message
|
| 66 |
print(f"- Searching level {weight} with {len(program_bank)} primitives.")
|
|
|
|
| 67 |
|
| 68 |
# iterate over each operator
|
| 69 |
for op in operators:
|
|
@@ -111,12 +117,19 @@ elapsed_time = round(end_time - start_time, 4)
|
|
| 111 |
print("\nSynthesis Results:")
|
| 112 |
if final_program is None:
|
| 113 |
print(f"- Max weight of {max_weight} reached, no program found in {elapsed_time}s.")
|
|
|
|
|
|
|
| 114 |
else:
|
| 115 |
print(f"- Program found in {elapsed_time}s.")
|
| 116 |
print(f"- Program: {final_program.str()}")
|
| 117 |
print(f"- Program weight: {final_program.weight}")
|
| 118 |
print(f"- Program return type: {final_program.type.__name__}")
|
| 119 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 120 |
st.header("🔎 Algorithm Details")
|
| 121 |
|
| 122 |
st.markdown('''
|
|
|
|
| 30 |
st.subheader("Input-Output Examples")
|
| 31 |
|
| 32 |
st.markdown('''
|
| 33 |
+
Select input-output examples as defined in `examples.py`, or define your own custom examples. The examples are used to synthesize a satisfying program.
|
| 34 |
''')
|
| 35 |
|
| 36 |
# define variables
|
| 37 |
+
# domain = "arithmetic"
|
| 38 |
+
# examples_key = "addition"
|
| 39 |
+
# max_weight = 3
|
| 40 |
+
domain = st.selectbox("Domain", ["arithmetic", "strings"])
|
| 41 |
+
examples_key = st.selectbox("Examples", example_set.keys())
|
| 42 |
+
max_weight = st.slider("Max Weight", 2, 10, 3)
|
| 43 |
|
| 44 |
# retrieve selected input-output examples
|
| 45 |
examples = example_set[examples_key]
|
| 46 |
|
| 47 |
# extract constants from examples
|
| 48 |
+
st.subheader("Synthesis Demonstration")
|
| 49 |
program_bank = extract_constants(examples)
|
| 50 |
program_bank_str = [p.str() for p in program_bank]
|
| 51 |
print("\nSynthesis Log:")
|
| 52 |
print(f"- Extracted {len(program_bank)} constants from examples.")
|
| 53 |
+
st.write(f"Extracted {len(program_bank)} constants from examples.")
|
| 54 |
|
| 55 |
# define operators
|
| 56 |
if domain == "arithmetic":
|
| 57 |
operators = arithmetic_operators
|
| 58 |
elif domain == "strings":
|
| 59 |
operators = string_operators
|
| 60 |
+
# else:
|
| 61 |
+
# raise Exception('Domain not recognized. Must be either "arithmetic" or "string".')
|
| 62 |
|
| 63 |
# define final program
|
| 64 |
final_program = None
|
|
|
|
| 69 |
|
| 70 |
# print message
|
| 71 |
print(f"- Searching level {weight} with {len(program_bank)} primitives.")
|
| 72 |
+
st.write(f"Searching level {weight} with {len(program_bank)} primitives.")
|
| 73 |
|
| 74 |
# iterate over each operator
|
| 75 |
for op in operators:
|
|
|
|
| 117 |
print("\nSynthesis Results:")
|
| 118 |
if final_program is None:
|
| 119 |
print(f"- Max weight of {max_weight} reached, no program found in {elapsed_time}s.")
|
| 120 |
+
|
| 121 |
+
st.write(f":x: Max weight of {max_weight} reached, no program found in {elapsed_time}s.")
|
| 122 |
else:
|
| 123 |
print(f"- Program found in {elapsed_time}s.")
|
| 124 |
print(f"- Program: {final_program.str()}")
|
| 125 |
print(f"- Program weight: {final_program.weight}")
|
| 126 |
print(f"- Program return type: {final_program.type.__name__}")
|
| 127 |
|
| 128 |
+
st.write(f":white_check_mark: Program found in {elapsed_time}s.")
|
| 129 |
+
st.write(f"Program: {final_program.str()}")
|
| 130 |
+
st.write(f"Weight: {final_program.weight}")
|
| 131 |
+
st.write(f"Return Type: {final_program.type.__name__}")
|
| 132 |
+
|
| 133 |
st.header("🔎 Algorithm Details")
|
| 134 |
|
| 135 |
st.markdown('''
|