evox.workflows.eval_monitor#

Module Contents#

Classes#

EvalMonitor

Evaluation monitor. Used for both single-objective and multi-objective workflow. Hooked around the evaluation process, can monitor the offspring, their corresponding fitness and keep track of the evaluation count. Moreover, it can also record the best solution or the pareto front on-the-fly.

Functions#

unique

Return the unique elements of the input tensor, as well as the unique index.

API#

evox.workflows.eval_monitor.unique(x: torch.Tensor, dim=0)[source]#

Return the unique elements of the input tensor, as well as the unique index.

class evox.workflows.eval_monitor.EvalMonitor(multi_obj: bool = False, full_fit_history: bool = True, full_sol_history: bool = False, full_pop_history: bool = False, topk: int = 1, device: torch.device | None = None)[source]#

Bases: evox.core.Monitor

Evaluation monitor. Used for both single-objective and multi-objective workflow. Hooked around the evaluation process, can monitor the offspring, their corresponding fitness and keep track of the evaluation count. Moreover, it can also record the best solution or the pareto front on-the-fly.

Initialization

Initialize the monitor.

Parameters:
  • multi_obj – Whether the optimization is multi-objective. Defaults to False.

  • full_fit_history – Whether to record the full history of fitness value. Default to True. Setting it to False may reduce memory usage.

  • full_sol_history – Whether to record the full history of solutions. Default to False. Setting it to True may increase memory usage.

  • topk – Only affect Single-objective optimization. The number of elite solutions to record. Default to 1, which will record the best individual.

  • device – The device of the monitor. Defaults to None.

Note:

If any of full_fit_history or full_sol_history is set to True, this monitor will introduce a graph break in torch.compile.

fitness_history: List[torch.Tensor]#

None

solution_history: List[torch.Tensor]#

None

auxiliary: List[Dict[str, torch.Tensor]]#

None

set_config(**config)[source]#
record_auxiliary(aux: Dict[str, torch.Tensor])[source]#
post_ask(candidate_solution: torch.Tensor)[source]#
pre_tell(fitness: torch.Tensor)[source]#
record_history()[source]#
get_latest_fitness() torch.Tensor[source]#

Get the fitness values from the latest iteration.

get_latest_solution() torch.Tensor[source]#

Get the solution from the latest iteration.

get_topk_fitness() torch.Tensor[source]#

Get the topk fitness values so far.

get_topk_solutions() torch.Tensor[source]#

Get the topk solutions so far.

get_best_solution() torch.Tensor[source]#

Get the best solution so far.

get_best_fitness() torch.Tensor[source]#

Get the best fitness value so far.

get_pf_fitness(deduplicate=True) torch.Tensor[source]#

Get the approximate pareto front fitness values of all the solutions evaluated so far. Requires enabling full_fit_history.

get_pf_solutions(deduplicate=True) torch.Tensor[source]#

Get the approximate pareto front solutions of all the solutions evaluated so far. Requires enabling both full_sol_history and full_sol_history. If deduplicate is set to True, the duplicated solutions will be removed.

get_pf(deduplicate=True) Tuple[torch.Tensor, torch.Tensor][source]#

Get the approximate pareto front solutions and fitness values of all the solutions evaluated so far. Requires enabling both full_sol_history and full_sol_history. If deduplicate is set to True, the duplicated solutions will be removed.

get_fitness_history() List[torch.Tensor][source]#

Get the full history of fitness values.

get_solution_history() List[torch.Tensor][source]#

Get the full history of solutions.

plot(problem_pf=None, source='eval', **kwargs)[source]#

Plot the fitness history. If the problem’s Pareto front is provided, it will be plotted as well.

Parameters:
  • problem_pf – The Pareto front of the problem. Default to None.

  • source – The source of the data, either “eval” or “pop”, default to “eval”. When “eval”, the fitness from the problem evaluation side will be plotted, representing what the problem sees. When “pop”, the fitness from the population inside the algorithm will be plotted, representing what the algorithm sees.

  • kwargs – Additional arguments for the plot.