|
7 | 7 | from optimagic.benchmarking.get_benchmark_problems import get_benchmark_problems |
8 | 8 | from optimagic.optimization.optimize import minimize |
9 | 9 |
|
10 | | -cases = [] |
11 | | -algo_options = { |
12 | | - "random_hull": { |
13 | | - "sampler": "random_hull", |
14 | | - "sphere_subsolver": "gqtpar_fast", |
15 | | - "sample_filter": "keep_all", |
16 | | - "stopping_maxiter": 10, |
17 | | - }, |
18 | | - "optimal_hull": { |
19 | | - "sampler": "optimal_hull", |
20 | | - "sphere_subsolver": "gqtpar_fast", |
21 | | - "sample_filter": "keep_all", |
22 | | - "stopping_maxiter": 10, |
23 | | - }, |
24 | | -} |
25 | | -for problem in ["rosenbrock_good_start", "watson_6_good_start"]: |
26 | | - inputs = get_benchmark_problems("more_wild")[problem]["inputs"] |
27 | | - fun = inputs["fun"] |
28 | | - start_params = inputs["params"] |
29 | | - for algorithm in ["tranquilo", "tranquilo_ls"]: |
30 | | - results = {} |
31 | | - for s, options in algo_options.items(): |
32 | | - results[s] = minimize( |
33 | | - fun=fun, |
34 | | - params=start_params, |
35 | | - algo_options=options, |
36 | | - algorithm=algorithm, |
37 | | - ) |
38 | | - cases.append(results) |
39 | 10 |
|
| 11 | +def benchmark_cases(): |
| 12 | + cases = [] |
| 13 | + algo_options = { |
| 14 | + "random_hull": { |
| 15 | + "sampler": "random_hull", |
| 16 | + "sphere_subsolver": "gqtpar_fast", |
| 17 | + "sample_filter": "keep_all", |
| 18 | + "stopping_maxiter": 10, |
| 19 | + }, |
| 20 | + "optimal_hull": { |
| 21 | + "sampler": "optimal_hull", |
| 22 | + "sphere_subsolver": "gqtpar_fast", |
| 23 | + "sample_filter": "keep_all", |
| 24 | + "stopping_maxiter": 10, |
| 25 | + }, |
| 26 | + } |
| 27 | + for problem in ["rosenbrock_good_start", "watson_6_good_start"]: |
| 28 | + inputs = get_benchmark_problems("more_wild")[problem]["inputs"] |
| 29 | + fun = inputs["fun"] |
| 30 | + start_params = inputs["params"] |
| 31 | + for algorithm in ["tranquilo", "tranquilo_ls"]: |
| 32 | + results = {} |
| 33 | + for s, options in algo_options.items(): |
| 34 | + results[s] = minimize( |
| 35 | + fun=fun, |
| 36 | + params=start_params, |
| 37 | + algo_options=options, |
| 38 | + algorithm=algorithm, |
| 39 | + ) |
| 40 | + cases.append(results) |
| 41 | + return cases |
40 | 42 |
|
41 | | -@pytest.mark.parametrize("results", cases) |
| 43 | + |
| 44 | +@pytest.mark.parametrize("results", benchmark_cases() if IS_OPTIMAGIC_INSTALLED else []) |
42 | 45 | def test_visualize_tranquilo(results): |
43 | 46 | visualize_tranquilo(results, 5) |
44 | 47 | for res in results.values(): |
|
0 commit comments