Skip to content

Commit

Permalink
fix: get_best behavior under vmap transforms
Browse files Browse the repository at this point in the history
  • Loading branch information
BillHuang2001 committed Sep 9, 2024
1 parent ce5e6cd commit 7e2476b
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/evox/monitors/eval_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def post_ask(self, state, _workflow_state, candidate):
def post_eval(self, state, _workflow_state, fitness):
if fitness.ndim == 1:
# single-objective
self.multi_obj = False
if state.first_step:
topk_solutions = state.latest_solution
topk_fitness = fitness
Expand All @@ -107,6 +108,7 @@ def post_eval(self, state, _workflow_state, fitness):
)
else:
# multi-objective
self.multi_obj = True
state = state.replace(latest_fitness=fitness)

if self.full_fit_history or self.full_sol_history:
Expand Down Expand Up @@ -139,10 +141,12 @@ def get_topk_solutions(self, state):
return state.topk_solutions, state

def get_best_solution(self, state):
return state.topk_solutions[0], state
return state.topk_solutions[..., 0, :], state

def get_best_fitness(self, state):
return self.opt_direction * state.topk_fitness[0], state
if self.multi_obj:
raise ValueError("Multi-objective optimization does not have a single best fitness.")
return self.opt_direction * state.topk_fitness[..., 0], state

def get_fitness_history(self, state):
return [self.opt_direction * fit for fit in self.fitness_history], state
Expand Down

0 comments on commit 7e2476b

Please sign in to comment.