diff --git a/aeon/synthesis_grammar/synthesizer.py b/aeon/synthesis_grammar/synthesizer.py index d86bca47..549ffa2e 100644 --- a/aeon/synthesis_grammar/synthesizer.py +++ b/aeon/synthesis_grammar/synthesizer.py @@ -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"] diff --git a/tests/synth_fitness_test.py b/tests/synth_fitness_test.py index d55938f6..61a6f32e 100644 --- a/tests/synth_fitness_test.py +++ b/tests/synth_fitness_test.py @@ -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 @@ -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) @@ -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)