Skip to content

Commit 1422718

Browse files
committed
Print statements
1 parent c19ba00 commit 1422718

File tree

1 file changed

+61
-1
lines changed

1 file changed

+61
-1
lines changed

src/axiomatic/pic_helpers.py

Lines changed: 61 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
from ipywidgets import interactive, IntSlider # type: ignore
44
from typing import List, Optional
55

6-
from . import Parameter
6+
from . import Parameter, StatementDictionary
77

88

99
def plot_circuit(component):
@@ -201,3 +201,63 @@ def plot_parameter_history(parameters: List[Parameter], parameter_history: List[
201201
]
202202
)
203203
plt.show()
204+
205+
206+
def print_statements(statements: StatementDictionary):
207+
"""
208+
Print a list of statements in nice readable format.
209+
"""
210+
print("-----------------------------------\n")
211+
for z3_stmt in (statements.cost_functions or []) + (statements.parameter_constraints or []):
212+
print("Type:", z3_stmt.type)
213+
print("Statement:", z3_stmt.text)
214+
print("Formalization:", end=" ")
215+
if z3_stmt.formalization is None:
216+
print("UNFORMALIZED")
217+
else:
218+
code = z3_stmt.formalization.code
219+
if z3_stmt.formalization.mapping is not None:
220+
for var_name, computation in z3_stmt.formalization.mapping.items():
221+
if computation is not None:
222+
args_str = ", ".join(
223+
[
224+
f"{argname}="
225+
+ (f"'{argvalue}'" if isinstance(argvalue, str) else str(argvalue))
226+
for argname, argvalue in computation.arguments.items()
227+
]
228+
)
229+
code = code.replace(var_name, f"{computation.name}({args_str})")
230+
print(code)
231+
if z3_stmt.validation is not None:
232+
if z3_stmt.type == "COST_FUNCTION":
233+
print(f"Satisfiable: {z3_stmt.validation.satisfiable}")
234+
print(z3_stmt.validation.message)
235+
else:
236+
print(f"Satisfiable: {z3_stmt.validation.satisfiable}")
237+
print(f"Holds: {z3_stmt.validation.holds} ({z3_stmt.validation.message})")
238+
print("\n-----------------------------------\n")
239+
for struct_stmt in (statements.structure_constraints or []):
240+
print("Type:", struct_stmt.type)
241+
print("Statement:", struct_stmt.text)
242+
print("Formalization:", end=" ")
243+
if struct_stmt.formalization is None:
244+
print("UNFORMALIZED")
245+
else:
246+
func_constr = struct_stmt.formalization
247+
args_str = ", ".join(
248+
[
249+
f"{argname}=" + (f"'{argvalue}'" if isinstance(argvalue, str) else str(argvalue))
250+
for argname, argvalue in func_constr.arguments.items()
251+
]
252+
)
253+
func_str = f"{func_constr.function_name}({args_str}) == {func_constr.expected_result}"
254+
print(func_str)
255+
if struct_stmt.validation is not None:
256+
print(f"Satisfiable: {struct_stmt.validation.satisfiable}")
257+
print(f"Holds: {struct_stmt.validation.holds}")
258+
print("\n-----------------------------------\n")
259+
for unf_stmt in (statements.unformalizable_statements or []):
260+
print("Type:", unf_stmt.type)
261+
print("Statement:", unf_stmt.text)
262+
print("Formalization: UNFORMALIZABLE")
263+
print("\n-----------------------------------\n")

0 commit comments

Comments
 (0)