From 8f9dc5361f3e3e62c9cae0268cacd1a3cdbdeff4 Mon Sep 17 00:00:00 2001 From: Bill Huang Date: Thu, 12 Oct 2023 10:46:18 +0800 Subject: [PATCH] dev: StdSOMonitor: get_min_fitness -> get_best_fitness --- examples/cmaes_classic_control.py | 4 ++-- examples/pgpe_pong.py | 4 ++-- src/evox/monitors/std_so_monitor.py | 2 +- tests/test_containers.py | 8 ++++---- tests/test_distributed_pipeline.py | 2 +- tests/test_gym.py | 2 +- tests/test_monitors.py | 8 ++++---- tests/test_neuroevolution.py | 4 ++-- tests/test_single_objective_algorithms.py | 2 +- tests/test_uni_workflow.py | 4 ++-- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/examples/cmaes_classic_control.py b/examples/cmaes_classic_control.py index 9b50e9a0e..7cc3a01c7 100644 --- a/examples/cmaes_classic_control.py +++ b/examples/cmaes_classic_control.py @@ -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) diff --git a/examples/pgpe_pong.py b/examples/pgpe_pong.py index 89c90a4e9..875b8719c 100644 --- a/examples/pgpe_pong.py +++ b/examples/pgpe_pong.py @@ -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) diff --git a/src/evox/monitors/std_so_monitor.py b/src/evox/monitors/std_so_monitor.py index a2da6f112..7e3c1b99a 100644 --- a/src/evox/monitors/std_so_monitor.py +++ b/src/evox/monitors/std_so_monitor.py @@ -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 diff --git a/tests/test_containers.py b/tests/test_containers.py index 7d5f88ebe..544b8ec1b 100644 --- a/tests/test_containers.py +++ b/tests/test_containers.py @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/tests/test_distributed_pipeline.py b/tests/test_distributed_pipeline.py index fbef0b568..5a2788986 100644 --- a/tests/test_distributed_pipeline.py +++ b/tests/test_distributed_pipeline.py @@ -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) diff --git a/tests/test_gym.py b/tests/test_gym.py index 62b382cf7..e7b49eb8e 100644 --- a/tests/test_gym.py +++ b/tests/test_gym.py @@ -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 diff --git a/tests/test_monitors.py b/tests/test_monitors.py index e504f57bd..586b5c45a 100644 --- a/tests/test_monitors.py +++ b/tests/test_monitors.py @@ -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() @@ -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() @@ -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() @@ -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() diff --git a/tests/test_neuroevolution.py b/tests/test_neuroevolution.py index dbd35c915..6cf0e0755 100644 --- a/tests/test_neuroevolution.py +++ b/tests/test_neuroevolution.py @@ -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}") @@ -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}") diff --git a/tests/test_single_objective_algorithms.py b/tests/test_single_objective_algorithms.py index b9ecd2de1..07bf46324 100644 --- a/tests/test_single_objective_algorithms.py +++ b/tests/test_single_objective_algorithms.py @@ -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(): diff --git a/tests/test_uni_workflow.py b/tests/test_uni_workflow.py index aa6036468..50fa4ba87 100644 --- a/tests/test_uni_workflow.py +++ b/tests/test_uni_workflow.py @@ -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 @@ -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