Commit bd812752 by nzy

Fix trace bug

parent 9aeb08e2
from rich.prompt import Confirm, Prompt, IntPrompt from rich.prompt import Confirm, Prompt, IntPrompt
from rich.progress import track from rich.progress import track
from utils import sys_str, system_info, code_input, value_input, print_anpl, print_IOExamples, select_task, set_openai_key, fun_select, print_text_IOExamples, Logger from utils import sys_str, system_info, code_input, value_input, print_anpl, print_IOExamples, select_task, set_openai_key, fun_select, print_text_IOExamples, Logger, print_error
from copy import deepcopy from copy import deepcopy
import time import time
...@@ -8,7 +8,6 @@ from anpl.anpl import IOExample, ANPL ...@@ -8,7 +8,6 @@ from anpl.anpl import IOExample, ANPL
from anpl.parser import ANPLParser from anpl.parser import ANPLParser
from anpl.synthesizer import fun_synthesis, batch_fun_synthesis from anpl.synthesizer import fun_synthesis, batch_fun_synthesis
from anpl.tracer import anpl_check, anpl_trace from anpl.tracer import anpl_check, anpl_trace
import traceback
set_openai_key() set_openai_key()
...@@ -93,11 +92,11 @@ while not is_correct: ...@@ -93,11 +92,11 @@ while not is_correct:
if ioc.crash: if ioc.crash:
logger.log("system", "trace", f"{fun_name}: crash") logger.log("system", "trace", f"{fun_name}: crash")
system_info("[red]ANPL crash in this function.[/red]") system_info("[red]ANPL crash in this function.[/red]")
traceback.print_exception(ioc.exception, limit=-1) print_error(ioc.exception)
elif len(ioc.ios) == 0: elif len(ioc.ios) == 0:
logger.log("user", "trace", f"{fun_name}: crash before this function") logger.log("user", "trace", f"{fun_name}: crash before this function")
system_info("[red]ANPL crash before this function.[/red]") system_info("[red]ANPL crash before this function.[/red]")
traceback.print_exception(ioc.exception, limit=-1) print_error(ioc.exception)
else: else:
logger.log("user", "trace", f"{fun_name}: show io to user") logger.log("user", "trace", f"{fun_name}: show io to user")
system_info("[green]Visual IO[/green]") system_info("[green]Visual IO[/green]")
......
from anpl.synthesizer import raw_query, msg from anpl.synthesizer import raw_query, msg
from utils import sys_str, system_info, multiline_input, select_task, set_openai_key, rich_dumps, Logger from utils import sys_str, system_info, multiline_input, select_task, set_openai_key, rich_dumps, Logger, print_error
from rich.prompt import IntPrompt, Confirm, Prompt from rich.prompt import IntPrompt, Confirm, Prompt
import rich import rich
from anpl.sandbox import import_module_from_string, timeout from anpl.sandbox import import_module_from_string, timeout
import numpy as np import numpy as np
import time import time
import traceback
from copy import deepcopy from copy import deepcopy
history = [] history = []
...@@ -77,10 +76,7 @@ while not is_correct: ...@@ -77,10 +76,7 @@ while not is_correct:
except Exception as e: except Exception as e:
logger.log("system", "check", f"crash: {e}") logger.log("system", "check", f"crash: {e}")
system_info("[red]Crash[/red]") system_info("[red]Crash[/red]")
try: print_error(e)
traceback.print_exception(e, limit=-1)
except Exception:
print(e)
continue continue
if np.array_equal(out, real_out): if np.array_equal(out, real_out):
logger.log("system", "check", f"correct") logger.log("system", "check", f"correct")
......
...@@ -12,6 +12,8 @@ import time ...@@ -12,6 +12,8 @@ import time
import os import os
import pickle import pickle
import prompt_toolkit import prompt_toolkit
import traceback
np.set_printoptions(threshold=np.inf)
colors = ["#000000", "#0000FF", "#FF0000", "#008000", "#FFFF00", colors = ["#000000", "#0000FF", "#FF0000", "#008000", "#FFFF00",
"#808080", "#FFC0CB", "#FFA500", "#008080", "#800000"] "#808080", "#FFC0CB", "#FFA500", "#008080", "#800000"]
...@@ -191,3 +193,8 @@ def select_task(): ...@@ -191,3 +193,8 @@ def select_task():
return task_id, input_grid, output_grid return task_id, input_grid, output_grid
def print_error(e):
try:
traceback.print_exception(e, limit=-1)
except Exception:
print(e)
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment