Skip to content

Commit

Permalink
synth fitness test fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
eduardo-imadeira committed Feb 2, 2024
1 parent a077624 commit 984332c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 6 deletions.
2 changes: 1 addition & 1 deletion aeon/synthesis_grammar/synthesizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ def geneticengine_synthesis(
"""Performs a synthesis procedure with GeneticEngine"""
# gp_params = gp_params or parse_config("aeon/synthesis_grammar/gpconfig.gengy", "DEFAULT") # TODO
gp_params = gp_params or gengy_default_config

gp_params = dict(gp_params)
representation_name = gp_params.pop("representation")
config_name = gp_params.pop("config_name")
seed = gp_params["seed"]
Expand Down
27 changes: 22 additions & 5 deletions tests/synth_fitness_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,21 @@

from abc import ABC

from aeon.__main__ import apply_decorators_in_program
from aeon.core.terms import Term
from aeon.core.types import top
from aeon.frontend.anf_converter import ensure_anf
from aeon.logger.logger import setup_logger
from aeon.sugar.desugar import desugar
from aeon.sugar.parser import parse_program
from aeon.synthesis_grammar.grammar import mk_method_core_literal
from aeon.synthesis_grammar.synthesizer import synthesize
from aeon.typechecking.typeinfer import check_type_errors

setup_logger()

def mock_literal_individual(value: int):

def mock_literal_individual(value: int):
class t_Int(ABC):
pass

Expand All @@ -29,10 +32,9 @@ def __init__(self, value: int):


def test_fitness():
code = """
def year : Int = 2023;
def synth : Int = (?hole: Int) * 7;
def __internal__fitness_function_synth : Int = year - synth;
code = """def year : Int = 2023;
def synth (i: Int): Int { (?hole: Int) * i}
def __internal__fitness_function_synth : Int = year - synth(7);
"""
prog = parse_program(code)
p, ctx, ectx = desugar(prog)
Expand All @@ -41,3 +43,18 @@ def __internal__fitness_function_synth : Int = year - synth;
term = synthesize(ctx, ectx, p, [("synth", ["hole"])])

assert isinstance(term, Term)


def test_fitness2():
code = """def year : Int = 2023;
@minimize_int( year - synth(7) )
def synth (i:Int) : Int {(?hole: Int) * i}
"""
prog = parse_program(code)
prog = apply_decorators_in_program(prog)
p, ctx, ectx = desugar(prog)
p = ensure_anf(p)
check_type_errors(ctx, p, top)
term = synthesize(ctx, ectx, p, [("synth", ["hole"])])

assert isinstance(term, Term)

0 comments on commit 984332c

Please sign in to comment.