Skip to content

Commit

Permalink
dev: StdSOMonitor: get_min_fitness -> get_best_fitness
Browse files Browse the repository at this point in the history
  • Loading branch information
BillHuang2001 committed Oct 12, 2023
1 parent dc76d3f commit 8f9dc53
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 20 deletions.
4 changes: 2 additions & 2 deletions examples/cmaes_classic_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,11 @@ def __call__(self, x):
state = workflow.init(workflow_key)
# run the workflow for 100 steps
for i in range(100):
print(monitor.get_min_fitness())
print(monitor.get_best_fitness())
state = workflow.step(state)

sample_pop, state = workflow.sample(state)
# problem._render(state.get_child_state("problem"), adapter.to_tree(sample_pop[0]))

min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(min_fitness)
4 changes: 2 additions & 2 deletions examples/pgpe_pong.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ def __call__(self, img):
state = workflow.init(workflow_key)
# run the workflow for 100 steps
for i in range(10):
print(monitor.get_min_fitness())
print(monitor.get_best_fitness())
state = workflow.step(state)

sample_pop, state = workflow.sample(state)
# problem._render(adapter.to_tree(sample_pop[0]), ale_render_mode="human")
# the result should be close to 0
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(min_fitness)
2 changes: 1 addition & 1 deletion src/evox/monitors/std_so_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def get_topk_fitness(self):
def get_topk_solutions(self):
return self.topk_solutions

def get_min_fitness(self):
def get_best_fitness(self):
if self.topk_fitness is None:
warnings.warn("trying to get info from a monitor with no recorded data")
return None
Expand Down
8 changes: 4 additions & 4 deletions tests/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_clustered_cma_es():
for i in range(200):
state = workflow.step(state)

min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
assert min_fitness < 2


Expand Down Expand Up @@ -91,7 +91,7 @@ def test_vectorized_coevolution(random_subpop):
for i in range(200):
state = workflow.step(state)

min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
assert min_fitness < 1


Expand Down Expand Up @@ -124,7 +124,7 @@ def test_coevolution(random_subpop, num_subpop_iter):
for i in range(4 * 200):
state = workflow.step(state)

min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
assert min_fitness < 2


Expand Down Expand Up @@ -156,6 +156,6 @@ def test_random_mask_cso():
for i in range(10):
state = workflow.step(state)

min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(min_fitness)
assert abs(min_fitness - 19.6) < 0.1
2 changes: 1 addition & 1 deletion tests/test_distributed_pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def test_distributed_cso():
state = workflow.step(state)

# the result should be close to 0
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(min_fitness)
assert min_fitness < 1e-4
workflow.health_check(state)
2 changes: 1 addition & 1 deletion tests/test_gym.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,6 @@ def __call__(self, x):

monitor.close()
# the result should be close to 0
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
# gym is deterministic, so the result should always be the same
assert min_fitness == -16.0
8 changes: 4 additions & 4 deletions tests/test_monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def test_std_so_monitor_top1():
fitness1 = jnp.arange(3)
monitor.record_pop(pop1)
monitor.record_fit(fitness1)
assert monitor.get_min_fitness() == 0
assert monitor.get_best_fitness() == 0
assert monitor.get_topk_fitness() == 0
assert (monitor.get_best_solution() == pop1[0]).all()
assert (monitor.get_topk_solutions() == pop1[0:1]).all()
Expand All @@ -21,7 +21,7 @@ def test_std_so_monitor_top1():
fitness2 = -jnp.arange(3)
monitor.record_pop(pop2)
monitor.record_fit(fitness2)
assert monitor.get_min_fitness() == -2
assert monitor.get_best_fitness() == -2
assert monitor.get_topk_fitness() == -2
assert (monitor.get_best_solution() == pop2[2]).all()
assert (monitor.get_topk_solutions() == pop2[2:3]).all()
Expand All @@ -34,7 +34,7 @@ def test_std_so_monitor_top2():
fitness1 = jnp.arange(3)
monitor.record_pop(pop1)
monitor.record_fit(fitness1)
assert monitor.get_min_fitness() == 0
assert monitor.get_best_fitness() == 0
assert (monitor.get_topk_fitness() == jnp.array([0, 1])).all()
assert (monitor.get_best_solution() == pop1[0]).all()
assert (monitor.get_topk_solutions() == pop1[0:2]).all()
Expand All @@ -43,7 +43,7 @@ def test_std_so_monitor_top2():
fitness2 = -jnp.arange(3)
monitor.record_pop(pop2)
monitor.record_fit(fitness2)
assert monitor.get_min_fitness() == -2
assert monitor.get_best_fitness() == -2
assert (monitor.get_topk_fitness() == jnp.array([-2, -1])).all()
assert (monitor.get_best_solution() == pop2[2]).all()
assert (monitor.get_topk_solutions() == pop2[2:0:-1]).all()
Expand Down
4 changes: 2 additions & 2 deletions tests/test_neuroevolution.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_neuroevolution_treemap():
state = workflow.step(state)

# the result should be close to 0
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(f"Treemap loss: {min_fitness} time: {time.perf_counter() - start}")


Expand Down Expand Up @@ -111,5 +111,5 @@ def test_neuroevolution_adapter():
state = workflow.step(state)

# the result should be close to 0
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
print(f"Adapter loss: {min_fitness} time: {time.perf_counter() - start}")
2 changes: 1 addition & 1 deletion tests/test_single_objective_algorithms.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def run_single_objective_algorithm(
for i in range(num_iter):
state = workflow.step(state)

return monitor.get_min_fitness()
return monitor.get_best_fitness()


def test_cso():
Expand Down
4 changes: 2 additions & 2 deletions tests/test_uni_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def run_uni_workflow_with_jit_problem():
state = workflow.step(state)

monitor.close()
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
return min_fitness


Expand All @@ -52,7 +52,7 @@ def run_uni_workflow_with_non_jit_problem():
state = workflow.step(state)

monitor.close()
min_fitness = monitor.get_min_fitness()
min_fitness = monitor.get_best_fitness()
return min_fitness


Expand Down

0 comments on commit 8f9dc53

Please sign in to comment.