from src.execution.search_strategies.base import SearchStrategy
from src.execution.search_strategies.factory import register_strategy
@register_strategy("my_custom_search")
class MyCustomSearch(SearchStrategy):
def __init__(self, config, workspace_dir=None):
super().__init__(config, workspace_dir)
# Custom initialization
def run(self, context, budget_progress=0.0):
# Generate and run experiments
solution = self.generate_solution(context)
result = self._implement_n_debug(
solution, context,
code_debug_tries=5,
branch_name="experiment_0",
)
self.experiment_history.append(result)
def get_experiment_history(self, best_last=False):
if best_last:
return sorted(self.experiment_history, key=lambda x: x.score)
return self.experiment_history
def get_best_experiment(self):
valid = [e for e in self.experiment_history if not e.had_error]
return max(valid, key=lambda x: x.score) if valid else None
def checkout_to_best_experiment_branch(self):
best = self.get_best_experiment()
if best:
self.workspace.switch_branch(best.branch_name)