|
|
@ -53,6 +53,7 @@ def cost_noperf( |
|
|
|
class OptimizationParameters: |
|
|
|
max_size: int |
|
|
|
beta: float = DEFAULT_ANNEALING_CONSTANT |
|
|
|
synthesize: bool = True |
|
|
|
synthesis_iters: int = DEFAULT_SYNTHESIS_ITERS |
|
|
|
optimize_iters: int = DEFAULT_OPTIMIZE_ITERS |
|
|
|
num_candidates: int = DEFAULT_NUM_CANDIDATES |
|
|
@ -118,21 +119,25 @@ def optimize( |
|
|
|
outputs: List[Output], |
|
|
|
params: OptimizationParameters, |
|
|
|
) -> Program: |
|
|
|
print("Synthesizing candidates...") |
|
|
|
candidates = [ |
|
|
|
_optimize( |
|
|
|
target_prgm, |
|
|
|
test_cases, |
|
|
|
outputs, |
|
|
|
replace(params, cost_fn=cost_noperf), |
|
|
|
num_iters=params.synthesis_iters, |
|
|
|
init_prgm=create_random_program(params.max_size), |
|
|
|
best_candidate = target_prgm |
|
|
|
|
|
|
|
if params.synthesize: |
|
|
|
print("Synthesizing candidates...") |
|
|
|
candidates = [ |
|
|
|
_optimize( |
|
|
|
target_prgm, |
|
|
|
test_cases, |
|
|
|
outputs, |
|
|
|
replace(params, cost_fn=cost_noperf), |
|
|
|
num_iters=params.synthesis_iters, |
|
|
|
init_prgm=create_random_program(params.max_size), |
|
|
|
) |
|
|
|
for _ in range(params.num_candidates) |
|
|
|
] |
|
|
|
best_candidate = min( |
|
|
|
candidates, key=lambda p: cost(target_prgm, test_cases, outputs, p)[0] |
|
|
|
) |
|
|
|
for _ in range(params.num_candidates) |
|
|
|
] |
|
|
|
best_candidate = min( |
|
|
|
candidates, key=lambda p: cost(target_prgm, test_cases, outputs, p)[0] |
|
|
|
) |
|
|
|
|
|
|
|
print("Optimizing...") |
|
|
|
return _optimize( |
|
|
|
target_prgm, |
|
|
|