Note
Go to the end to download the full example code.
Multi-start optimization#
The optimization algorithm multistart
generates starting points using a DOE algorithm
and run a sub-optimization algorithm from each starting point.
from __future__ import annotations
from gemseo import configure_logger
from gemseo import create_design_space
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo import execute_post
from gemseo.algos.opt.multi_start.settings.multi_start_settings import (
MultiStart_Settings,
)
configure_logger()
<RootLogger root (INFO)>
First, we create the disciplines
objective = create_discipline("AnalyticDiscipline", expressions={"obj": "x**3-x+1"})
constraint = create_discipline(
"AnalyticDiscipline", expressions={"cstr": "x**2+obj**2-1.5"}
)
and the design space
design_space = create_design_space()
design_space.add_variable("x", lower_bound=-1.5, upper_bound=1.5, value=1.5)
Then, we define the MDO scenario
scenario = create_scenario(
[objective, constraint],
"obj",
design_space,
formulation_name="DisciplinaryOpt",
)
Note that the formulation settings passed to create_scenario()
can be provided
via a Pydantic model. For more information, see Formulation Settings.
scenario.add_constraint("cstr", constraint_type="ineq")
and execute it with the MultiStart
optimization algorithm
combining the local optimization algorithm SLSQP
and the full-factorial DOE algorithm:
multistart_settings = MultiStart_Settings(
max_iter=100,
opt_algo_name="SLSQP",
doe_algo_name="PYDOE_FULLFACT",
n_start=10,
# Set multistart_file_path to save the history of the local optima.
multistart_file_path="multistart.hdf5",
)
scenario.execute(multistart_settings)
INFO - 08:36:40:
INFO - 08:36:40: *** Start MDOScenario execution ***
INFO - 08:36:40: MDOScenario
INFO - 08:36:40: Disciplines: AnalyticDiscipline AnalyticDiscipline
INFO - 08:36:40: MDO formulation: DisciplinaryOpt
INFO - 08:36:40: Optimization problem:
INFO - 08:36:40: minimize obj(x)
INFO - 08:36:40: with respect to x
INFO - 08:36:40: subject to constraints:
INFO - 08:36:40: cstr(x) <= 0
INFO - 08:36:40: over the design space:
INFO - 08:36:40: +------+-------------+-------+-------------+-------+
INFO - 08:36:40: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:36:40: +------+-------------+-------+-------------+-------+
INFO - 08:36:40: | x | -1.5 | 1.5 | 1.5 | float |
INFO - 08:36:40: +------+-------------+-------+-------------+-------+
INFO - 08:36:40: Solving optimization problem with algorithm MultiStart:
INFO - 08:36:40: 1%| | 1/100 [00:00<00:00, 243.68 it/sec, obj=2.88]
INFO - 08:36:40: 2%|▏ | 2/100 [00:00<00:00, 298.22 it/sec, obj=-0.875]
INFO - 08:36:40: 3%|▎ | 3/100 [00:00<00:00, 290.92 it/sec, obj=-0.267]
INFO - 08:36:40: 4%|▍ | 4/100 [00:00<00:00, 338.18 it/sec, obj=-0.809]
INFO - 08:36:40: 5%|▌ | 5/100 [00:00<00:00, 377.74 it/sec, obj=-0.868]
INFO - 08:36:40: 6%|▌ | 6/100 [00:00<00:00, 410.62 it/sec, obj=-0.872]
INFO - 08:36:40: 7%|▋ | 7/100 [00:00<00:00, 412.19 it/sec, obj=-0.265]
INFO - 08:36:40: 8%|▊ | 8/100 [00:00<00:00, 414.97 it/sec, obj=0.136]
INFO - 08:36:40: 9%|▉ | 9/100 [00:00<00:00, 413.01 it/sec, obj=0.579]
INFO - 08:36:40: 10%|█ | 10/100 [00:00<00:00, 431.87 it/sec, obj=0.289]
INFO - 08:36:40: 11%|█ | 11/100 [00:00<00:00, 431.41 it/sec, obj=1.25]
WARNING - 08:36:40: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:40: 12%|█▏ | 12/100 [00:00<00:00, 413.18 it/sec, obj=0.579]
INFO - 08:36:40: 13%|█▎ | 13/100 [00:00<00:00, 406.77 it/sec, obj=-0.875]
INFO - 08:36:40: 14%|█▍ | 14/100 [00:00<00:00, 409.59 it/sec, obj=-0.267]
INFO - 08:36:40: 15%|█▌ | 15/100 [00:00<00:00, 417.92 it/sec, obj=-0.809]
INFO - 08:36:40: 16%|█▌ | 16/100 [00:00<00:00, 428.81 it/sec, obj=-0.868]
INFO - 08:36:40: 17%|█▋ | 17/100 [00:00<00:00, 439.47 it/sec, obj=-0.874]
INFO - 08:36:41: 18%|█▊ | 18/100 [00:00<00:00, 438.66 it/sec, obj=-0.266]
INFO - 08:36:41: 19%|█▉ | 19/100 [00:00<00:00, 438.56 it/sec, obj=0.135]
INFO - 08:36:41: 20%|██ | 20/100 [00:00<00:00, 434.48 it/sec, obj=0.577]
INFO - 08:36:41: 21%|██ | 21/100 [00:00<00:00, 442.81 it/sec, obj=0.288]
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:41: 22%|██▏ | 22/100 [00:00<00:00, 425.69 it/sec, obj=1.25]
INFO - 08:36:41: 23%|██▎ | 23/100 [00:00<00:00, 420.99 it/sec, obj=-0.875]
INFO - 08:36:41: 24%|██▍ | 24/100 [00:00<00:00, 429.15 it/sec, obj=1.01]
INFO - 08:36:41: 25%|██▌ | 25/100 [00:00<00:00, 429.21 it/sec, obj=-0.875]
INFO - 08:36:41: 26%|██▌ | 26/100 [00:00<00:00, 435.88 it/sec, obj=0.819]
INFO - 08:36:41: 27%|██▋ | 27/100 [00:00<00:00, 435.67 it/sec, obj=-0.875]
INFO - 08:36:41: 28%|██▊ | 28/100 [00:00<00:00, 442.00 it/sec, obj=0.693]
INFO - 08:36:41: 29%|██▉ | 29/100 [00:00<00:00, 438.60 it/sec, obj=0.584]
INFO - 08:36:41: 30%|███ | 30/100 [00:00<00:00, 438.07 it/sec, obj=-0.875]
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:41: 31%|███ | 31/100 [00:00<00:00, 430.88 it/sec, obj=1.38]
INFO - 08:36:41: 32%|███▏ | 32/100 [00:00<00:00, 425.49 it/sec, obj=1.23]
INFO - 08:36:41: 33%|███▎ | 33/100 [00:00<00:00, 425.58 it/sec, obj=2.87]
INFO - 08:36:41: 34%|███▍ | 34/100 [00:00<00:00, 430.80 it/sec, obj=0.848]
INFO - 08:36:41: 35%|███▌ | 35/100 [00:00<00:00, 429.78 it/sec, obj=0.658]
INFO - 08:36:41: 36%|███▌ | 36/100 [00:00<00:00, 425.43 it/sec, obj=0.643]
INFO - 08:36:41: 37%|███▋ | 37/100 [00:00<00:00, 422.29 it/sec, obj=0.616]
INFO - 08:36:41: 38%|███▊ | 38/100 [00:00<00:00, 419.36 it/sec, obj=0.615]
INFO - 08:36:41: 39%|███▉ | 39/100 [00:00<00:00, 416.48 it/sec, obj=0.615]
INFO - 08:36:41: 40%|████ | 40/100 [00:00<00:00, 407.41 it/sec, obj=1.16]
INFO - 08:36:41: 41%|████ | 41/100 [00:00<00:00, 403.58 it/sec, obj=2.87]
INFO - 08:36:41: 42%|████▏ | 42/100 [00:00<00:00, 406.84 it/sec, obj=0.785]
INFO - 08:36:41: 43%|████▎ | 43/100 [00:00<00:00, 401.50 it/sec, obj=0.644]
INFO - 08:36:41: 44%|████▍ | 44/100 [00:00<00:00, 399.37 it/sec, obj=0.624]
INFO - 08:36:41: 45%|████▌ | 45/100 [00:00<00:00, 397.39 it/sec, obj=0.615]
INFO - 08:36:41: 46%|████▌ | 46/100 [00:00<00:00, 395.72 it/sec, obj=0.615]
INFO - 08:36:41: 47%|████▋ | 47/100 [00:00<00:00, 394.21 it/sec, obj=0.615]
INFO - 08:36:41: 48%|████▊ | 48/100 [00:00<00:00, 392.62 it/sec, obj=0.615]
INFO - 08:36:41: 49%|████▉ | 49/100 [00:00<00:00, 386.31 it/sec, obj=0.838]
INFO - 08:36:41: 50%|█████ | 50/100 [00:00<00:00, 383.18 it/sec, obj=0.656]
INFO - 08:36:41: 51%|█████ | 51/100 [00:00<00:00, 381.99 it/sec, obj=0.639]
INFO - 08:36:41: 52%|█████▏ | 52/100 [00:00<00:00, 380.72 it/sec, obj=0.616]
INFO - 08:36:41: 53%|█████▎ | 53/100 [00:00<00:00, 379.81 it/sec, obj=0.615]
INFO - 08:36:41: 54%|█████▍ | 54/100 [00:00<00:00, 378.36 it/sec, obj=0.615]
INFO - 08:36:41: 55%|█████▌ | 55/100 [00:00<00:00, 377.42 it/sec, obj=0.615]
INFO - 08:36:41: 56%|█████▌ | 56/100 [00:00<00:00, 376.56 it/sec, obj=0.615]
INFO - 08:36:41: 57%|█████▋ | 57/100 [00:00<00:00, 375.68 it/sec, obj=0.615]
INFO - 08:36:41: 58%|█████▊ | 58/100 [00:00<00:00, 373.16 it/sec, obj=0.625]
INFO - 08:36:41: 59%|█████▉ | 59/100 [00:00<00:00, 371.62 it/sec, obj=2.87]
INFO - 08:36:41: 60%|██████ | 60/100 [00:00<00:00, 373.93 it/sec, obj=0.616]
INFO - 08:36:41: 61%|██████ | 61/100 [00:00<00:00, 373.24 it/sec, obj=0.615]
INFO - 08:36:41: 62%|██████▏ | 62/100 [00:00<00:00, 372.32 it/sec, obj=0.615]
INFO - 08:36:41: 63%|██████▎ | 63/100 [00:00<00:00, 371.77 it/sec, obj=0.615]
INFO - 08:36:41: 64%|██████▍ | 64/100 [00:00<00:00, 371.01 it/sec, obj=0.615]
INFO - 08:36:41: 65%|██████▌ | 65/100 [00:00<00:00, 370.45 it/sec, obj=0.615]
INFO - 08:36:41: 66%|██████▌ | 66/100 [00:00<00:00, 371.64 it/sec, obj=0.615]
INFO - 08:36:41: 67%|██████▋ | 67/100 [00:00<00:00, 371.87 it/sec, obj=0.745]
INFO - 08:36:41: 68%|██████▊ | 68/100 [00:00<00:00, 370.63 it/sec, obj=-0.875]
INFO - 08:36:41: 69%|██████▉ | 69/100 [00:00<00:00, 370.77 it/sec, obj=-0.267]
INFO - 08:36:41: 70%|███████ | 70/100 [00:00<00:00, 371.88 it/sec, obj=-0.809]
INFO - 08:36:41: 71%|███████ | 71/100 [00:00<00:00, 374.43 it/sec, obj=-0.868]
INFO - 08:36:41: 72%|███████▏ | 72/100 [00:00<00:00, 376.97 it/sec, obj=-0.874]
INFO - 08:36:41: 73%|███████▎ | 73/100 [00:00<00:00, 377.54 it/sec, obj=-0.266]
INFO - 08:36:41: 74%|███████▍ | 74/100 [00:00<00:00, 378.29 it/sec, obj=0.135]
INFO - 08:36:41: 75%|███████▌ | 75/100 [00:00<00:00, 378.95 it/sec, obj=0.577]
INFO - 08:36:41: 76%|███████▌ | 76/100 [00:00<00:00, 381.35 it/sec, obj=0.288]
INFO - 08:36:41: 77%|███████▋ | 77/100 [00:00<00:00, 378.81 it/sec, obj=1.42]
INFO - 08:36:41: 78%|███████▊ | 78/100 [00:00<00:00, 378.24 it/sec, obj=-0.875]
INFO - 08:36:41: 79%|███████▉ | 79/100 [00:00<00:00, 378.90 it/sec, obj=-0.267]
INFO - 08:36:41: 80%|████████ | 80/100 [00:00<00:00, 381.18 it/sec, obj=-0.809]
INFO - 08:36:41: 81%|████████ | 81/100 [00:00<00:00, 383.45 it/sec, obj=-0.868]
INFO - 08:36:41: 82%|████████▏ | 82/100 [00:00<00:00, 385.57 it/sec, obj=-0.874]
INFO - 08:36:41: 83%|████████▎ | 83/100 [00:00<00:00, 386.11 it/sec, obj=-0.266]
INFO - 08:36:41: 84%|████████▍ | 84/100 [00:00<00:00, 386.54 it/sec, obj=0.135]
INFO - 08:36:41: 85%|████████▌ | 85/100 [00:00<00:00, 387.10 it/sec, obj=0.577]
INFO - 08:36:41: 86%|████████▌ | 86/100 [00:00<00:00, 389.11 it/sec, obj=0.288]
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:41: 87%|████████▋ | 87/100 [00:00<00:00, 381.12 it/sec, obj=-0.267]
INFO - 08:36:41: 88%|████████▊ | 88/100 [00:00<00:00, 383.15 it/sec, obj=-0.809]
INFO - 08:36:41: 89%|████████▉ | 89/100 [00:00<00:00, 385.19 it/sec, obj=-0.868]
INFO - 08:36:41: 90%|█████████ | 90/100 [00:00<00:00, 387.14 it/sec, obj=-0.874]
INFO - 08:36:41: 91%|█████████ | 91/100 [00:00<00:00, 387.67 it/sec, obj=-0.266]
INFO - 08:36:41: 92%|█████████▏| 92/100 [00:00<00:00, 388.06 it/sec, obj=0.135]
INFO - 08:36:41: 93%|█████████▎| 93/100 [00:00<00:00, 388.51 it/sec, obj=0.577]
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:41: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:41: Exporting the optimization problem to the file multistart.hdf5 at node
INFO - 08:36:41: Optimization result:
INFO - 08:36:41: Optimizer info:
INFO - 08:36:41: Status: None
INFO - 08:36:41: Message: None
INFO - 08:36:41: Number of calls to the objective function by the optimizer: 1
INFO - 08:36:41: Solution:
INFO - 08:36:41: The solution is feasible.
INFO - 08:36:41: Objective: 0.6150998205402495
INFO - 08:36:41: Standardized constraints:
INFO - 08:36:41: cstr = -0.7883188793606977
INFO - 08:36:41: Design space:
INFO - 08:36:41: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:41: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:36:41: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:41: | x | -1.5 | 0.5773502675245377 | 1.5 | float |
INFO - 08:36:41: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:41: *** End MDOScenario execution (time: 0:00:00.268328) ***
Lastly, we can plot the history of the objective, either by concatenating the 10 sub-optimization histories:
execute_post(
scenario, post_name="BasicHistory", variable_names=["obj"], save=False, show=True
)
<gemseo.post.basic_history.BasicHistory object at 0x7f2514c5d460>
or by filtering the local optima (one per starting point):
execute_post(
"multistart.hdf5",
post_name="BasicHistory",
variable_names=["obj"],
save=False,
show=True,
)
INFO - 08:36:41: Importing the optimization problem from the file multistart.hdf5 at node
<gemseo.post.basic_history.BasicHistory object at 0x7f24f42a99a0>
Total running time of the script: (0 minutes 0.838 seconds)