-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig.py
494 lines (423 loc) · 16.4 KB
/
config.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
"""This module contains the general configuration of the project.
Below an overview of the non-trivial concepts:
PROBLEM_SETS: This is a dictionary that defines the problems that can be used in
benchmarks. The keys are names, the values are dictionaries with keyword arguments for
`em.get_benchmark_problems`.
COMPETITION: This is a dictionary that defines the optimizer configurations against
which we want to compare tranquilo. The keys are the names of the optimizer
configurations, the values are dictionaries with keyword arguments for the minimization.
PLOT_CONFIG: This is a dictionary that defines which problem-optimizer combinations are
plotted against each other. Only combinations that are used in some plot will actually
run.
"""
import socket
from pathlib import Path
from typing import NamedTuple
# ======================================================================================
# Paths
# ======================================================================================
SRC = Path(__file__).parent.resolve()
ROOT = SRC.joinpath("..", "..").resolve()
BLD = ROOT.joinpath("bld").resolve()
PUBLIC = BLD.joinpath("public").resolve()
# ======================================================================================
# Global Options
# ======================================================================================
class ProjectOptions(NamedTuple):
"""This class contains the global options of the project.
The options are:
- RUN_DETERMINISTIC (bool): Whether to run the deterministic benchmarks.
- RUN_NOISY (bool): Whether to run the noisy benchmarks.
- RUN_PUBLICATION_CASES (bool): Whether to run the benchmarks required for the
publication figures.
- RUN_DEVELOPMENT_CASES (bool): Whether to run the benchmarks required for the
development figures.
- DETERMINISTIC_Y_TOL (float): The tolerance for the deterministic benchmarks.
- NOISY_Y_TOL (float): The tolerance for the noisy benchmarks.
- PLOT_TYPES (tuple): The plot types that are being created. Must be an iterable
with entries from {"profile_plot", "convergence_plot", "deviation_plot"}.
- PROBLEM_SETS (tuple): The problem sets that are being used. Must be an
iterable with entries from {"more_wild", "cartis_roberts"}.
"""
# Do not alter the default values of this class for development purposes. Instead
# set the options in the class instantiation below.
RUN_DETERMINISTIC: bool = True
RUN_NOISY: bool = True
RUN_PUBLICATION_CASES: bool = True
RUN_DEVELOPMENT_CASES: bool = True
DETERMINISTIC_Y_TOL: float = 1e-3
NOISY_Y_TOL: float = 0.01
PLOT_TYPES: tuple[str] = ("profile_plot", "convergence_plot", "deviation_plot")
PROBLEM_SETS: tuple[str] = ("more_wild", "cartis_roberts")
N_CORES_DEFAULT: int = 1
@property
def n_cores(self):
"""Set the number of cores depending on the hostname."""
hostnames_to_requested_cores = {
# Tim's thinkpad
"thinky": 16,
# Janos' thinkpad
"IZA-LAP479": 10,
}
hostname = socket.gethostname()
return hostnames_to_requested_cores.get(hostname, self.N_CORES_DEFAULT)
# Set development options HERE and not in the class above
# ======================================================================================
OPTIONS = ProjectOptions(
PLOT_TYPES=("profile_plot", "deviation_plot"),
PROBLEM_SETS=("more_wild",),
)
def get_max_criterion_evaluations(noisy):
return 5_000 if noisy else 2_000
def get_max_iterations(noisy, functype): # noqa: U100
return 500 if functype == "ls" else 2000
def get_tranquilo_version(functype):
return "tranquilo" if functype == "scalar" else "tranquilo_ls"
TRANQUILO_BASE_OPTIONS = {
"algo_options": {
"disable_convergence": False,
"silence_experimental_warning": True,
},
}
def get_benchmark_problem_info(problem_set):
info = {
"more_wild": {
# Number of additional draws per problem that are used to generate more
# problems. For each problems n_draws new start vectors are drawn in the
# vicinity of the original start vector, each defining a new problem.
"n_additional_draws": 4,
# Random number generator seed used to control the random draws.
"seed": 440219,
},
"cartis_roberts": {
"n_additional_draws": 0,
"seed": None,
},
}
if "mw" in problem_set:
out = info["more_wild"]
elif "cr" in problem_set:
out = info["cartis_roberts"]
return out
# ======================================================================================
# Benchmark sets and configurations
# ======================================================================================
# Exclude the following problems from the cartis_roberts set because their solution
# is undefined. See the cartis_roberts.py module in estimagic for reference.
_exlude_from_cartis_roberts = [
"artif",
"chandheq",
"chemrcta",
"drcavty1",
"flosp2hh",
"flosp2hl",
"flosp2hm",
"flosp2th",
"flosp2tl",
"flosp2tm",
"luksan12",
"luksan17",
"penalty_1",
]
PROBLEM_SETS = {
"mw": {
"name": "more_wild",
"exclude": ["brown_almost_linear_medium"],
},
"mw_noisy": {
"name": "more_wild",
"exclude": ["brown_almost_linear_medium"],
"additive_noise": True,
"additive_noise_options": {"distribution": "normal", "std": 1.2},
"seed": 925408,
},
"cr": {
"name": "cartis_roberts",
"exclude": _exlude_from_cartis_roberts,
},
"cr_noisy": {
"name": "cartis_roberts",
"exclude": _exlude_from_cartis_roberts,
"additive_noise": True,
"additive_noise_options": {"distribution": "normal", "std": 1.2},
"seed": 925408,
},
}
# ======================================================================================
# Define competition. These are the optimizers against which tranquilo is compared.
# ======================================================================================
# Create evaluation functions for DFO-LS noisy cases
def _n_evals_5(*args, **kwargs): # noqa: U100
return 5
def _n_evals_3(*args, **kwargs): # noqa: U100
return 3
def _n_evals_10(*args, **kwargs): # noqa: U100
return 10
COMPETITION = {
"nlopt_bobyqa": {"algorithm": "nlopt_bobyqa"},
"nag_bobyqa": {"algorithm": "nag_pybobyqa"},
"dfols": {"algorithm": "nag_dfols"},
"pounders": {"algorithm": "pounders"},
"tao_pounders": {"algorithm": "tao_pounders"},
"scipy_neldermead": {"algorithm": "scipy_neldermead"},
"nlopt_neldermead": {"algorithm": "nlopt_neldermead"},
"nag_bobyqa_noisy_3": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_3,
},
},
"dfols_noisy_3": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_3,
},
},
"nag_bobyqa_noisy_5": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_5,
},
},
"dfols_noisy_5": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_5,
},
},
"nag_bobyqa_noisy_10": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_10,
},
},
"dfols_noisy_10": {
"algorithm": "nag_dfols",
"algo_options": {
"noise_additive_level": 0.1,
"noise_n_evals_per_point": _n_evals_10,
},
},
}
# ======================================================================================
# Plotting configuration
# --------------------------------------------------------------------------------------
# Note that keys for each plot configuration must adhere to the convention that they
# either start with "publication_" or "development_". Developments plots are stored
# in bld/figures while publication plots are stored in bld/bld_paper. Running
# experiments should be done with development plots.
# ======================================================================================
_deterministic_plots = {
# Development / Experimental cases
# ==================================================================================
"development": {
"scalar_benchmark": {
"scenarios": [
"tranquilo_default",
"tranquilo_experimental",
"nlopt_bobyqa",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
"ls_benchmark": {
"scenarios": [
"tranquilo_ls_default",
"tranquilo_ls_experimental",
"dfols",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
"parallel_benchmark": {
"scenarios": [
"tranquilo_ls_parallel_2",
"tranquilo_ls_parallel_4",
"tranquilo_ls_parallel_8",
"tranquilo_ls_experimental_parallel_2",
"tranquilo_ls_experimental_parallel_4",
"tranquilo_ls_experimental_parallel_8",
"dfols",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
"runtime_measure": "n_batches",
},
"convergence_plot_options": {"n_cols": 6, "runtime_measure": "n_batches"},
"deviation_plot_options": {"runtime_measure": "n_batches"},
},
},
# Publication / Presentation cases
# ==================================================================================
"publication": {
"scalar_benchmark": {
"scenarios": [
"tranquilo_default",
"nag_bobyqa",
"nlopt_bobyqa",
"nlopt_neldermead",
"scipy_neldermead",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
"ls_benchmark": {
"scenarios": [
"tranquilo_ls_default",
"dfols",
"pounders",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
"parallel_benchmark": {
"scenarios": [
"tranquilo_ls_default",
"tranquilo_ls_parallel_2",
"tranquilo_ls_parallel_4",
"tranquilo_ls_parallel_8",
"dfols",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
"runtime_measure": "n_batches",
},
"convergence_plot_options": {"n_cols": 6, "runtime_measure": "n_batches"},
"deviation_plot_options": {"runtime_measure": "n_batches"},
},
"scalar_vs_ls_benchmark": {
"scenarios": [
"dfols",
"tranquilo_default",
"tranquilo_ls_default",
"nlopt_bobyqa",
"nlopt_neldermead",
"pounders",
],
"profile_plot_options": {
"y_precision": OPTIONS.DETERMINISTIC_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
},
}
_noisy_plots = {
# Development / Experimental cases
# ==================================================================================
"development": {
"noisy_benchmark": {
"scenarios": [
"dfols_noisy_3",
"dfols_noisy_5",
"dfols_noisy_10",
"tranquilo_ls_default",
"tranquilo_ls_experimental",
],
"profile_plot_options": {
"y_precision": OPTIONS.NOISY_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
},
# Publication / Presentation cases
# ==================================================================================
"publication": {
"noisy_benchmark": {
"scenarios": [
"dfols_noisy_3",
"dfols_noisy_5",
"dfols_noisy_10",
"tranquilo_ls_default",
],
"profile_plot_options": {
"y_precision": OPTIONS.NOISY_Y_TOL,
"normalize_runtime": True,
},
"convergence_plot_options": {"n_cols": 6},
},
},
}
# ======================================================================================
# Consolidate configuration
# ======================================================================================
def _add_problem_name_to_configs(plot_config, problem_name, development_or_publication):
"""Add id of the problem set to the plot configuration.
New name of a plot configuration would look like:
- "development_scalar_benchmark_mw"
- "publication_ls_benchmark_mw"
- "development_scalar_benchmark_mw_noisy"
- ...
"""
updated = {}
for plot_name, info in plot_config.items():
name = f"{development_or_publication}_{plot_name}_{problem_name}"
updated[name] = {**info, "problem_name": problem_name}
return updated
def _get_problem_name(problem_set, noisy):
mapping = {
"more_wild": "mw",
"cartis_roberts": "cr",
}
name = mapping[problem_set]
return f"{name}_noisy" if noisy else name
# Collect all plots that we actually want to run
# ======================================================================================
PLOT_CONFIG = {}
for problem_set in OPTIONS.PROBLEM_SETS:
if OPTIONS.RUN_DETERMINISTIC:
if OPTIONS.RUN_PUBLICATION_CASES:
_updated_configs = _add_problem_name_to_configs(
_deterministic_plots["publication"],
problem_name=_get_problem_name(problem_set, noisy=False),
development_or_publication="publication",
)
PLOT_CONFIG.update(_updated_configs)
if OPTIONS.RUN_DEVELOPMENT_CASES:
_updated_configs = _add_problem_name_to_configs(
_deterministic_plots["development"],
problem_name=_get_problem_name(problem_set, noisy=False),
development_or_publication="development",
)
PLOT_CONFIG.update(_updated_configs)
if OPTIONS.RUN_NOISY:
if OPTIONS.RUN_PUBLICATION_CASES:
_updated_configs = _add_problem_name_to_configs(
_noisy_plots["publication"],
problem_name=_get_problem_name(problem_set, noisy=True),
development_or_publication="publication",
)
PLOT_CONFIG.update(_updated_configs)
if OPTIONS.RUN_DEVELOPMENT_CASES:
_updated_configs = _add_problem_name_to_configs(
_noisy_plots["development"],
problem_name=_get_problem_name(problem_set, noisy=True),
development_or_publication="development",
)
PLOT_CONFIG.update(_updated_configs)
BENCHMARK_CASES = []
for info in PLOT_CONFIG.values():
for scenario in info["scenarios"]:
BENCHMARK_CASES.append((info["problem_name"], scenario))
COMPETITION_CASES = [case for case in BENCHMARK_CASES if "tranquilo" not in case[1]]
TRANQUILO_CASES = [case for case in BENCHMARK_CASES if "tranquilo" in case[1]]