Problem¶
Evaluation runs in a separate process inside a virtual environment. Two attributes control this:
extra_pythonpath(list of directories, default empty): added toPYTHONPATHof the evaluation process. Set it when the problem class is defined in a module outside theiohbladepackage, so the evaluation environment can import it.max_harness_errors(default3): an evaluation that fails before the problem has readsolution.codeis a harness error, a fault in the problem or its environment that the LLM cannot fix. After this many consecutive harness errors the run stops withHarnessError.Nonedisables the check.
- class iohblade.problem.Problem(logger=None, training_instances=None, test_instances=None, name='Problem', eval_timeout=6000, dependencies=None, imports=None)¶
Bases:
ABCAbstract problem class.
- Variables:
minimisation (bool) – Whether lower fitness is better. Subclasses set it in their constructor; the default is maximisation.
show_best_known (bool) – Whether the feedback of an evaluation, which the LLM sees, mentions the best known score of the problem (see
best_known_feedback()). Off by default: the value tells the LLM the target and can identify the benchmark instance. Set it on an instance (problem.show_best_known = True) to enable it.
- best_known_feedback(value, label: str = 'best known') str¶
Feedback text that reports the best known score, if enabled.
- Parameters:
value – The best known score (
Noneif there is none).label – Text shown before the value.
- Returns:
"; <label>: <value>"whenshow_best_knownis True andvalueis not None, otherwise an empty string.- Return type:
str
- cleanup()¶
Delete a private evaluation environment (cached ones are kept).
- enable_hpo(enabled: bool = True) None¶
Enable (or disable) hyperparameter tuning of solutions.
Enabling adds
iohblade.hpo.HPO_DEPENDENCIES(smac and the packages it needs) toself.dependencies; disabling removes the ones enabling added. The dependencies are part of the evaluation environment’s cache key, so the problem then uses an environment with (or without) smac. Call it before the environment is built; if it was built already, it is rebuilt at the next evaluation.- Parameters:
enabled – True to enable tuning, False to disable it.
- Raises:
ValueError – If
enabledis True and the problem does not support tuning (supports_hpois False).
- abstractmethod evaluate(solution: Solution)¶
Evaluates a solution on training instances and updates its fitness and feedback.
- Parameters:
solution (Solution) – Solution object to be evaluated.
- failure_fitness() float¶
Fitness given to a failed evaluation: the worst possible value.
inffor a minimisation problem,-infotherwise, so a timeout or crash can never be mistaken for a good solution.
- abstractmethod get_config() dict[str, Any]¶
The problem’s properties, logged with every run.
- Returns:
A dictionary with the keys
tags(list[str]),name(str),prompt(str),minimisation(bool),evaluator(str) andconfig(dict: extra configuration of the problem, such as HPO settings).- Return type:
dict[str, Any]
- get_prompt()¶
Get the full prompt describing the problem and how to format the answer.
- hpo: bool = False¶
- minimisation: bool = False¶
- set_logger(logger)¶
Sets the logger for this problem.
- show_best_known: bool = False¶
- supports_hpo: bool = False¶
- abstractmethod test(solution: Solution)¶
Performs a complete evaluation on test instances and returns the fitness score.
- Parameters:
solution (Solution) – Solution object to be tested.
- abstractmethod to_dict()¶
Returns a dictionary representation of the problem including all parameters.
- Returns:
Dictionary representation of the problem.
- Return type:
dict
- class iohblade.problem.WrappedProblem(evaluate_fn, *, name='Problem', eval_timeout=6000, training_instances=None, test_instances=None, dependencies=None, imports=None, task_prompt='', example_prompt='', logger=None)¶
Bases:
Problem- evaluate(solution: Solution)¶
Evaluates a solution on training instances and updates its fitness and feedback.
- Parameters:
solution (Solution) – Solution object to be evaluated.
- get_config() dict[str, Any]¶
The problem’s properties, logged with every run.
- Returns:
A dictionary with the keys
tags(list[str]),name(str),prompt(str),minimisation(bool),evaluator(str) andconfig(dict: extra configuration of the problem, such as HPO settings).- Return type:
dict[str, Any]
- test(solution: Solution)¶
Performs a complete evaluation on test instances and returns the fitness score.
- Parameters:
solution (Solution) – Solution object to be tested.
- to_dict()¶
Returns a dictionary representation of the problem including all parameters.
- Returns:
Dictionary representation of the problem.
- Return type:
dict
- iohblade.problem.evaluate_in_subprocess(problem, conn, solution)¶
Evaluate a solution in a dedicated virtual environment.
- iohblade.problem.simplify_subprocess_error(stderr: str, solution=None)¶
Parse a Python traceback string and produce a concise error summary.
The line number and the offending line of
solution.codeare only reported for the last traceback frame that lies in the candidate code (filename"<string>"or the solution’s name). Frames in other files (numpy, the benchmark, …) have line numbers that do not refer to the candidate code, so then only the exception type and message are given.- Parameters:
stderr (str) – Standard error of the evaluation subprocess.
solution (Solution, optional) – The evaluated solution.
- Returns:
The summary.
- Return type:
str
- iohblade.problem.wrap_problem(evaluate_fn, *, name='Problem', eval_timeout=6000, training_instances=None, test_instances=None, dependencies=None, imports=None, task_prompt='', example_prompt='', logger=None)¶