-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #65 from alcides/metahandlers
Metahandlers
- Loading branch information
Showing
32 changed files
with
1,243 additions
and
649 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import abc | ||
from typing import Any | ||
|
||
from aeon.backend.evaluator import EvaluationContext | ||
from aeon.core.terms import Term | ||
from aeon.core.types import Type | ||
from aeon.typechecking.context import TypingContext | ||
|
||
|
||
class SynthesisUI(abc.ABC): | ||
|
||
def start( | ||
self, | ||
typing_ctx: TypingContext, | ||
evaluation_ctx: EvaluationContext, | ||
target_name: str, | ||
target_type: Type, | ||
budget: Any, | ||
): | ||
... | ||
|
||
def register(self, solution: Term, quality: Any, elapsed_time: float, | ||
is_best: bool): | ||
... | ||
|
||
def end(self, solution: Term, quality: Any): | ||
... | ||
|
||
def wrapper(self, f): | ||
"""This wrapper is necessary for the NCurses version of the API""" | ||
return f() | ||
|
||
def display_results(self, program: Term, terms: dict[str, Term]): | ||
print("Synthesized holes:") | ||
for name in terms: | ||
print(f"?{name}: {terms[name]}") | ||
# print() | ||
# pretty_print_term(ensure_anf(synthesis_result, 200)) | ||
|
||
|
||
class SilentSynthesisUI(SynthesisUI): | ||
|
||
def start( | ||
self, | ||
typing_ctx: TypingContext, | ||
evaluation_ctx: EvaluationContext, | ||
target_name: str, | ||
target_type: Type, | ||
budget: Any, | ||
): | ||
pass | ||
|
||
def register(self, solution: Term, quality: Any, elapsed_time: float, | ||
is_best: bool): | ||
pass | ||
|
||
def end(self, solution: Term, quality: Any): | ||
pass |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
from typing import Any | ||
from aeon.backend.evaluator import EvaluationContext | ||
from aeon.core.terms import Term | ||
from aeon.core.types import Type | ||
from aeon.synthesis.uis.api import SynthesisUI | ||
from aeon.typechecking.context import TypingContext | ||
|
||
import curses | ||
|
||
|
||
class NCursesUI(SynthesisUI): | ||
|
||
def start( | ||
self, | ||
typing_ctx: TypingContext, | ||
evaluation_ctx: EvaluationContext, | ||
target_name: str, | ||
target_type: Type, | ||
budget: Any, | ||
): | ||
self.stdscr = curses.initscr() | ||
self.target_name = target_name | ||
self.target_type = target_type | ||
self.budget = budget | ||
|
||
def register(self, solution: Term, quality: Any, elapsed_time: float, | ||
is_best: bool): | ||
if is_best: | ||
self.best_solution = solution | ||
self.best_quality = quality | ||
|
||
self.stdscr.clear() | ||
self.stdscr.addstr(0, 0, f"Synthesizing ?{self.target_name}") | ||
self.stdscr.addstr(1, 0, "====================================") | ||
self.stdscr.addstr(3, 0, f"Fitness: {quality}") | ||
self.stdscr.addstr(4, 0, f"Program: {solution}") | ||
self.stdscr.addstr(6, 0, f"Best: {self.best_solution}") | ||
self.stdscr.addstr(7, 0, f"Best Fitness: {self.best_quality}") | ||
self.stdscr.addstr(9, 0, "====================================") | ||
self.stdscr.addstr(10, 0, | ||
f"""{elapsed_time:.1f} / {self.budget:.1f}s""") | ||
|
||
self.stdscr.refresh() | ||
|
||
def end(self, solution: Term, quality: Any): | ||
curses.endwin() | ||
|
||
def wrapper(self, f): | ||
return curses.wrapper(f) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
from typing import Any | ||
from aeon.backend.evaluator import EvaluationContext | ||
from aeon.core.terms import Term | ||
from aeon.core.types import Type | ||
from aeon.synthesis.uis.api import SynthesisUI | ||
from aeon.typechecking.context import TypingContext | ||
|
||
|
||
class TerminalUI(SynthesisUI): | ||
|
||
def start( | ||
self, | ||
typing_ctx: TypingContext, | ||
evaluation_ctx: EvaluationContext, | ||
target_name: str, | ||
target_type: Type, | ||
budget: Any, | ||
): | ||
self.target_name = target_name | ||
self.target_type = target_type | ||
self.budget = budget | ||
|
||
def register(self, solution: Term, quality: Any, elapsed_time: float, | ||
is_best: bool): | ||
if is_best: | ||
self.best_solution = solution | ||
self.best_quality = quality | ||
|
||
print( | ||
f"Target: {self.target_name} ({elapsed_time:.1f} / {self.budget:.1f}s) " | ||
+ f"| Best: {self.best_solution} ({self.best_quality}) " + | ||
f"| Current: {solution} ({quality})") | ||
|
||
def end(self, solution: Term, quality: Any): | ||
pass |
Oops, something went wrong.