From 3d988951dcc663c3039e43d4a345f88fb1cdf48c Mon Sep 17 00:00:00 2001 From: Angel Ferran Pousa Date: Fri, 4 Aug 2023 10:15:52 +0200 Subject: [PATCH] Add test with only final analysis --- tests/test_chain_evaluator.py | 46 +++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/tests/test_chain_evaluator.py b/tests/test_chain_evaluator.py index d6dae4f5..a82aa64c 100644 --- a/tests/test_chain_evaluator.py +++ b/tests/test_chain_evaluator.py @@ -68,5 +68,51 @@ def test_chain_evaluator(): exploration.run() +def test_chain_evaluator_only_final_analysis(): + """Test a ChainEvaluator where only the final TemplateEvaluator has an + analysis function.""" + # Define variables and objectives. + var1 = VaryingParameter('x0', -50., 5.) + var2 = VaryingParameter('x1', -5., 15.) + obj = Objective('f', minimize=False) + + # Define variables and objectives. + gen = RandomSamplingGenerator( + varying_parameters=[var1, var2], + objectives=[obj] + ) + + # Create template evaluator. + ev1 = TemplateEvaluator( + sim_template=os.path.join( + os.path.abspath(os.path.dirname(__file__)), + 'resources', + 'template_simulation_script.py' + ) + ) + ev2 = TemplateEvaluator( + sim_template=os.path.join( + os.path.abspath(os.path.dirname(__file__)), + 'resources', + 'template_simulation_script_2.py' + ), + analysis_func=analysis_func_2 + ) + ev = ChainEvaluator([ev1, ev2]) + + # Create exploration. + exploration = Exploration( + generator=gen, + evaluator=ev, + max_evals=10, + sim_workers=2, + exploration_dir_path='./tests_output/test_chain_evaluator_2' + ) + + # Run exploration. + exploration.run() + + if __name__ == '__main__': test_chain_evaluator() + test_chain_evaluator_only_final_analysis()