Optimizer and Evolution Source Code
Evolution classes
optim.evolution.Evolution
Bases: ABC
This class implements an abstract evolution object.
Source code in aero_optim/optim/evolution.py
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 |
|
evolve(*args, **kwargs)
abstractmethod
Defines how to execute the optimization.
Source code in aero_optim/optim/evolution.py
49 50 51 52 53 |
|
set_ea(*args, **kwargs)
abstractmethod
Sets the evolutionary computation algorithm.
Source code in aero_optim/optim/evolution.py
43 44 45 46 47 |
|
set_optimizer(*args, **kwargs)
abstractmethod
Sets the optimizer object.
Source code in aero_optim/optim/evolution.py
34 35 36 37 38 39 40 41 |
|
inspyred Evolution
optim.evolution.InspyredEvolution
Bases: Evolution
This class implements a default inspyred based evolution object.
Source code in aero_optim/optim/evolution.py
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 |
|
evolve()
Executes the default evolution method.
Source code in aero_optim/optim/evolution.py
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 |
|
set_ea()
Instantiates the default algorithm attribute.
Source code in aero_optim/optim/evolution.py
129 130 131 132 133 |
|
set_optimizer(debug: bool = False)
Instantiates the optimizer attribute as custom if any or from default classes.
Source code in aero_optim/optim/evolution.py
117 118 119 120 121 122 123 124 125 126 127 |
|
pymoo Evolution
optim.evolution.PymooEvolution
Bases: Evolution
This class implements a default pymoo based evolution object.
Source code in aero_optim/optim/evolution.py
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 |
|
evolve()
Executes the default evolution method.
Source code in aero_optim/optim/evolution.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
|
set_ea()
Instantiates the default algorithm attribute.
Source code in aero_optim/optim/evolution.py
75 76 77 78 79 80 81 82 83 84 |
|
set_optimizer(debug: bool = False)
Instantiates the optimizer attribute as custom if any or from default classes.
Source code in aero_optim/optim/evolution.py
63 64 65 66 67 68 69 70 71 72 73 |
|
Optimizer classes
optim.optimizer.Optimizer
Bases: ABC
This class implements an abstract optimizer.
Source code in aero_optim/optim/optimizer.py
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 |
|
__init__(config: dict, debug: bool = False)
Instantiates the Optimizer object.
Input
- config (dict): the config file dictionary.
- debug (bool): skip FFD and Mesh objects instantation for debugging purposes.
Inner
- n_design (int): the number of design variables (dimensions of the problem).
- doe_size (int): the size of the initial and subsequent generations.
- max_generations (int): the number of generations before termination.
- dat_file (str): path to input_geometry.dat (baseline geometry).
- outdir (str): highest level optimization output directory.
Note
the result folder tree is structured as follows:
outdir
|__ FFD (contains <geom>_gXX_cYY.dat)
|__ Figs (contains the figures generated during the optimization)
|__ MESH (contains <geom>_gXX_cYY.mesh, .log, .geo_unrolled)
|__ SOLVER
|__ solver_gXX_cYY (contains the results of each simulation)
- study_type (str): use-case/meshing routine.
- ffd_type (str): deformation method.
-
strategy (str): the optimization algorithm amongst inspyred's [ES, PSO] and pymoo's [GA, PSO] see https://pythonhosted.org/inspyred/examples.html#standard-algorithms and https://pymoo.org/algorithms/list.html#nb-algorithms-list
-
maximize (bool): whether to maximize or minimize the objective QoIs.
- budget (int): maximum number of concurrent proc in use.
- nproc_per_sim (int): number of proc per simulation.
- bound (tuple[float]): design variables boundaries.
- custom_doe (str): path to a custom doe.
- sampler_name (str): name of the sampling algorithm used to generate samples. the initial generation.
- seed (int): seed number of the random processes involved in the optimization.
- prng (random.Random): pseudo-random generator passed to inspyred generator.
- ea_kwargs (dict): additional arguments to be passed to the evolution algorithm.
- gen_ctr (int): generation counter.
- generator (Generator): Generator object for the initial generation sampling.
- ffd (FFD_2D): FFD_2D object to generate deformed geometries.
- gmsh_mesh (Mesh): Mesh class to generate deformed geometries meshes.
- simulator (Simulator): Simulator object to perform simulations.
- mean (list[float]): list of populations mean fitness.
- median (list[float]): list of populations median fitness.
- max (list[float]): list of populations max fitness.
- min (list[float]): list of populations min fitness.
- J (list[float | list[float]]): the list of all generated candidates fitnesses.
- inputs (list[list[np.ndarray]]): all input candidates.
- ffd_profiles (list[list[np.ndarray]]): all deformed geometries {gid: {cid: ffd_profile}}.
- QoI (str): the quantity of intereset to minimize/maximize.
- n_plt (int): the number of best candidates results to display after each evaluation.
- cmap (str): the colormaps used for the observer plot see https://matplotlib.org/stable/users/explain/colors/colormaps.html.
Source code in aero_optim/optim/optimizer.py
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 |
|
_evaluate(*args, **kwargs) -> list[float | list[float]] | None
abstractmethod
Computes all candidates outputs and return the optimizer list of QoIs.
Source code in aero_optim/optim/optimizer.py
381 382 383 384 385 |
|
_observe(*args, **kwargs)
Plots generation data after each evaluation.
Source code in aero_optim/optim/optimizer.py
298 299 300 301 302 |
|
compute_statistics(gen_fitness: np.ndarray)
Computes generation statistics.
Note
this method is meant to be called in _observe
.
Source code in aero_optim/optim/optimizer.py
286 287 288 289 290 291 292 293 294 295 296 |
|
deform(Delta: np.ndarray, gid: int, cid: int) -> tuple[str, np.ndarray]
Applies FFD on a given candidate and returns its resulting file.
Source code in aero_optim/optim/optimizer.py
234 235 236 237 238 239 240 241 242 |
|
execute_candidates(candidates: list[Individual] | np.ndarray, gid: int)
Executes all candidates and waits for them to finish.
Note
this method is meant to be called in _evaluate.
Source code in aero_optim/optim/optimizer.py
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 |
|
mesh(ffdfile: str) -> str
Builds mesh for a given candidate and returns its resulting file.
Note
if a mesh file matching the pattern name already exists, it is not rebuilt.
Source code in aero_optim/optim/optimizer.py
244 245 246 247 248 249 250 251 252 253 254 255 256 257 |
|
plot_generation(gid: int, sorted_idx: np.ndarray, gen_fitness: np.ndarray, fig_name: str)
Plots the results of the last evaluated generation. Saves the graph in the output directory.
Note
this method is meant to be called in _observe
.
Source code in aero_optim/optim/optimizer.py
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 |
|
plot_progress(gen_nbr: int, fig_name: str, baseline_value: float | None = None)
Plots and saves the overall progress of the optimization.
Note
this method is meant to be called in final_observe
.
Source code in aero_optim/optim/optimizer.py
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 |
|
process_config()
Makes sure the config file contains the required information.
Source code in aero_optim/optim/optimizer.py
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 |
|
save_results()
Saves candidates and fitnesses to file.
Source code in aero_optim/optim/optimizer.py
361 362 363 364 365 366 367 368 369 370 |
|
set_ffd_class()
Instantiates the deformation class and object as custom if found, as one of the default classes otherwise.
Source code in aero_optim/optim/optimizer.py
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 |
|
set_gmsh_mesh_class()
Instantiates the mesher class as custom if found, as one of the default meshers otherwise.
Source code in aero_optim/optim/optimizer.py
210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 |
|
set_inner()
Sets some use-case specific inner variables:
Source code in aero_optim/optim/optimizer.py
228 229 230 231 232 |
|
set_simulator_class()
abstractmethod
Instantiates the simulator class with CustomSimulator if found.
Source code in aero_optim/optim/optimizer.py
372 373 374 375 376 377 378 379 |
|
optim.optimizer.WolfOptimizer
Bases: Optimizer
, ABC
This class implements a Wolf based Optimizer.
Source code in aero_optim/optim/optimizer.py
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 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 |
|
__init__(config: dict)
Instantiates the WolfOptimizer object.
Input
- config (dict): the config file dictionary.
Source code in aero_optim/optim/optimizer.py
392 393 394 395 396 397 398 399 400 |
|
apply_constraints(*args, **kwargs)
abstractmethod
Looks for constraints violations.
Source code in aero_optim/optim/optimizer.py
503 504 505 506 507 |
|
final_observe(*args, **kwargs)
abstractmethod
Plots convergence progress by plotting the fitness values obtained with the successive generations.
Source code in aero_optim/optim/optimizer.py
509 510 511 512 513 514 |
|
plot_generation(gid: int, sorted_idx: np.ndarray, gen_fitness: np.ndarray, fig_name: str)
Plots the results of the last evaluated generation. Saves the graph in the output directory.
Source code in aero_optim/optim/optimizer.py
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 495 |
|
set_inner()
Sets some use-case specific inner variables:
- baseline_CD (float): the drag coefficient of the baseline geometry.
- baseline_CL (float): the lift coefficient of the baseline geometry.
- baseline_area (float): the baseline area that is used as a structural constraint.
- area_margin (float): area tolerance margin given as a percentage wrt baseline_area i.e. a candidate with an area greater/smaller than +/- area_margin % of the baseline_area will be penalized.
- penalty (list): a [key, value] constraint not to be worsen by the optimization.
- constraint (bool): constraints are applied (True) or not (False)
Source code in aero_optim/optim/optimizer.py
410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 |
|
set_simulator_class()
Sets the simulator class as custom if found, as WolfSimulator otherwise.
Source code in aero_optim/optim/optimizer.py
402 403 404 405 406 407 408 |
|
optim.optimizer.DebugOptimizer
Bases: Optimizer
, ABC
Source code in aero_optim/optim/optimizer.py
517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 |
|
__init__(config: dict)
Dummy init.
Source code in aero_optim/optim/optimizer.py
518 519 520 521 522 |
|
execute_candidates(candidates: list[Individual] | np.ndarray, gid: int)
Executes all candidates and waits for them to finish.
Source code in aero_optim/optim/optimizer.py
535 536 537 538 539 540 541 542 543 544 545 546 |
|
set_simulator_class()
Sets the simulator class as custom if found, as DebugSimulator otherwise.
Source code in aero_optim/optim/optimizer.py
524 525 526 527 528 529 530 |
|
inspyred Optimizers
optim.inspyred_optimizer.InspyredWolfOptimizer
Bases: WolfOptimizer
This class implements a Wolf based Optimizer.
Source code in aero_optim/optim/inspyred_optimizer.py
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 |
|
_evaluate(candidates: list[Individual], args: dict) -> list[float | list[float]]
Executes Wolf simulations, extracts results and returns the list of candidates QoIs.
Note
candidates and args are inspyred mandatory arguments see https://pythonhosted.org/inspyred/tutorial.html#the-evaluator
Source code in aero_optim/optim/inspyred_optimizer.py
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 |
|
_observe(population: list[Individual], num_generations: int, num_evaluations: int, args: dict)
Plots the n_plt best results each time a generation has been evaluated:
the simulations residuals, the simulations CD & CL, the candidates fitness, the baseline and deformed profiles.
Note
num_generations, num_evaluations and args are inspyred mandatory arguments see https://pythonhosted.org/inspyred/examples.html#custom-observer
Source code in aero_optim/optim/inspyred_optimizer.py
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 |
|
apply_constraints(gid: int, cid: int, ffd_profile: np.ndarray, pen_value: float) -> float
Returns a penalty value based on some specific constraints see https://inspyred.readthedocs.io/en/latest/recipes.html#constraint-selection
Source code in aero_optim/optim/inspyred_optimizer.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
|
final_observe(*args, **kwargs)
Plots convergence progress by plotting the fitness values obtained with the successive generations see https://pythonhosted.org/inspyred/reference.html#inspyred.ec.analysis.generation_plot
Source code in aero_optim/optim/inspyred_optimizer.py
119 120 121 122 123 124 125 126 |
|
optim.inspyred_optimizer.InspyredDebugOptimizer
Bases: DebugOptimizer
Source code in aero_optim/optim/inspyred_optimizer.py
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 |
|
_evaluate(candidates: list[Individual], args: dict) -> list[float | list[float]]
Executes dummy simulations, extracts results and returns the list of candidates QoIs.
Source code in aero_optim/optim/inspyred_optimizer.py
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 |
|
_observe(population: list[Individual], num_generations: int, num_evaluations: int, args: dict)
Dummy _observe function.
Source code in aero_optim/optim/inspyred_optimizer.py
146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 |
|
final_observe()
Dummy final_observe function.
Source code in aero_optim/optim/inspyred_optimizer.py
167 168 169 170 171 172 |
|
pymoo Optimizers
optim.pymoo_optimizer.PymooWolfOptimizer
Bases: WolfOptimizer
, Problem
This class implements a Wolf based Optimizer.
Source code in aero_optim/optim/pymoo_optimizer.py
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 |
|
__init__(config: dict)
Instantiates the WolfOptimizer object.
Input
- config (dict): the config file dictionary.
Source code in aero_optim/optim/pymoo_optimizer.py
33 34 35 36 37 38 39 40 41 42 43 44 |
|
_evaluate(X: np.ndarray, out: np.ndarray, *args, **kwargs)
Executes Wolf simulations, extracts results and returns arrays of candidates QoIs and constraints.
Source code in aero_optim/optim/pymoo_optimizer.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|
_observe(pop_fitness: np.ndarray)
Plots the n_plt best results each time a generation has been evaluated:
the simulations residuals, the simulations CD & CL, the candidates fitness, the baseline and deformed profiles.
Source code in aero_optim/optim/pymoo_optimizer.py
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 |
|
apply_constraints(gid: int) -> np.ndarray
Returns a constraint array ensuring negative inequality see https://pymoo.org/constraints/index.html
Source code in aero_optim/optim/pymoo_optimizer.py
66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
|
final_observe(*args, **kwargs)
Plots convergence progress by plotting the fitness values obtained with the successive generations
Source code in aero_optim/optim/pymoo_optimizer.py
109 110 111 112 113 114 115 |
|
optim.pymoo_optimizer.PymooDebugOptimizer
Bases: DebugOptimizer
, Problem
Source code in aero_optim/optim/pymoo_optimizer.py
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 |
|
__init__(config: dict)
Dummy init.
Source code in aero_optim/optim/pymoo_optimizer.py
119 120 121 122 123 124 125 126 |
|
_evaluate(X: np.ndarray, out: np.ndarray, *args, **kwargs)
Executes dummy simulations, extracts results and returns the list of candidates QoIs.
Source code in aero_optim/optim/pymoo_optimizer.py
128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 |
|
_observe(pop_fitness: np.ndarray)
Dummy _observe function.
Source code in aero_optim/optim/pymoo_optimizer.py
145 146 147 148 149 150 151 152 153 154 155 156 |
|
final_observe()
Dummy final_observe function.
Source code in aero_optim/optim/pymoo_optimizer.py
158 159 160 161 162 163 164 |
|
Generator class
optim.generator.Generator
This class defines a custom generator based on scipy.qmc samplers.
Source code in aero_optim/optim/generator.py
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 |
|
__init__(seed: int, ndesign: int, doe_size: int, sampler_name: str, bound: tuple[Any, ...], custom_doe: str = '')
Instantiates the Generator class with some optimization parameters and the sampler name.
Input
- seed (int): seed number of the sampler random number generator.
- ndesign (int): the number of design variables (dimensions of the problem).
- doe_size (int): the size of the initial and subsequent generations.
- sampler_name (str): name of the sampling algorithm used to generate samples.
- bound (tuple[Any, ...]): design variables boundaries.
- custom_doe (str): path to the text file containing a custom doe.
Inner
- initial_doe (list[list[float]]): the initial generation sampled from the generator.
Source code in aero_optim/optim/generator.py
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 |
|
_ins_generator(random: Random, args: dict) -> list[float]
Returns a single sample from the initial generation.
Note
random and args are inspyred mandatory arguments see https://pythonhosted.org/inspyred/tutorial.html#the-generator
Source code in aero_optim/optim/generator.py
71 72 73 74 75 76 77 78 79 80 |
|
_pymoo_generator() -> np.ndarray
Returns all samples from the initial generation.
Source code in aero_optim/optim/generator.py
82 83 84 85 86 87 88 |
|
get_sampler(sampler_name: str) -> Optional[qmc.QMCEngine]
Returns scipy qmc sampler.
Source code in aero_optim/optim/generator.py
48 49 50 51 52 53 54 55 56 57 58 59 60 |
|