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 - 02:57:42:
INFO - 02:57:42: *** Start MDOScenario execution ***
INFO - 02:57:42: MDOScenario
INFO - 02:57:42: Disciplines: AnalyticDiscipline AnalyticDiscipline
INFO - 02:57:42: MDO formulation: DisciplinaryOpt
INFO - 02:57:42: Optimization problem:
INFO - 02:57:42: minimize obj(x)
INFO - 02:57:42: with respect to x
INFO - 02:57:42: subject to constraints:
INFO - 02:57:42: cstr(x) <= 0
INFO - 02:57:42: over the design space:
INFO - 02:57:42: +------+-------------+-------+-------------+-------+
INFO - 02:57:42: | Name | Lower bound | Value | Upper bound | Type |
INFO - 02:57:42: +------+-------------+-------+-------------+-------+
INFO - 02:57:42: | x | -1.5 | 1.5 | 1.5 | float |
INFO - 02:57:42: +------+-------------+-------+-------------+-------+
INFO - 02:57:42: Solving optimization problem with algorithm MultiStart:
INFO - 02:57:42: 1%| | 1/100 [00:00<00:00, 304.40 it/sec, obj=2.88]
INFO - 02:57:42: 2%|▏ | 2/100 [00:00<00:00, 401.02 it/sec, obj=-0.875]
INFO - 02:57:42: 3%|▎ | 3/100 [00:00<00:00, 430.63 it/sec, obj=-0.267]
INFO - 02:57:42: 4%|▍ | 4/100 [00:00<00:00, 517.58 it/sec, obj=-0.809]
INFO - 02:57:42: 5%|▌ | 5/100 [00:00<00:00, 589.52 it/sec, obj=-0.868]
INFO - 02:57:42: 6%|▌ | 6/100 [00:00<00:00, 648.04 it/sec, obj=-0.872]
INFO - 02:57:42: 7%|▋ | 7/100 [00:00<00:00, 664.24 it/sec, obj=-0.265]
INFO - 02:57:42: 8%|▊ | 8/100 [00:00<00:00, 674.88 it/sec, obj=0.136]
INFO - 02:57:42: 9%|▉ | 9/100 [00:00<00:00, 682.23 it/sec, obj=0.579]
INFO - 02:57:42: 10%|█ | 10/100 [00:00<00:00, 716.01 it/sec, obj=0.289]
INFO - 02:57:42: 11%|█ | 11/100 [00:00<00:00, 722.40 it/sec, obj=1.25]
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
INFO - 02:57:42: 12%|█▏ | 12/100 [00:00<00:00, 697.85 it/sec, obj=0.579]
INFO - 02:57:42: 13%|█▎ | 13/100 [00:00<00:00, 689.12 it/sec, obj=-0.875]
INFO - 02:57:42: 14%|█▍ | 14/100 [00:00<00:00, 695.22 it/sec, obj=-0.267]
INFO - 02:57:42: 15%|█▌ | 15/100 [00:00<00:00, 710.68 it/sec, obj=-0.809]
INFO - 02:57:42: 16%|█▌ | 16/100 [00:00<00:00, 732.23 it/sec, obj=-0.868]
INFO - 02:57:42: 17%|█▋ | 17/100 [00:00<00:00, 752.81 it/sec, obj=-0.874]
INFO - 02:57:42: 18%|█▊ | 18/100 [00:00<00:00, 753.36 it/sec, obj=-0.266]
INFO - 02:57:42: 19%|█▉ | 19/100 [00:00<00:00, 753.64 it/sec, obj=0.135]
INFO - 02:57:42: 20%|██ | 20/100 [00:00<00:00, 754.91 it/sec, obj=0.577]
INFO - 02:57:42: 21%|██ | 21/100 [00:00<00:00, 770.66 it/sec, obj=0.288]
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
INFO - 02:57:42: 22%|██▏ | 22/100 [00:00<00:00, 740.94 it/sec, obj=1.25]
INFO - 02:57:42: 23%|██▎ | 23/100 [00:00<00:00, 733.74 it/sec, obj=-0.875]
INFO - 02:57:42: 24%|██▍ | 24/100 [00:00<00:00, 748.33 it/sec, obj=1.01]
INFO - 02:57:42: 25%|██▌ | 25/100 [00:00<00:00, 748.69 it/sec, obj=-0.875]
INFO - 02:57:42: 26%|██▌ | 26/100 [00:00<00:00, 760.99 it/sec, obj=0.819]
INFO - 02:57:42: 27%|██▋ | 27/100 [00:00<00:00, 762.11 it/sec, obj=-0.875]
INFO - 02:57:42: 28%|██▊ | 28/100 [00:00<00:00, 773.91 it/sec, obj=0.693]
INFO - 02:57:42: 29%|██▉ | 29/100 [00:00<00:00, 768.51 it/sec, obj=0.584]
INFO - 02:57:42: 30%|███ | 30/100 [00:00<00:00, 768.21 it/sec, obj=-0.875]
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
INFO - 02:57:42: 31%|███ | 31/100 [00:00<00:00, 757.35 it/sec, obj=1.38]
INFO - 02:57:42: 32%|███▏ | 32/100 [00:00<00:00, 748.04 it/sec, obj=1.23]
INFO - 02:57:42: 33%|███▎ | 33/100 [00:00<00:00, 748.52 it/sec, obj=2.87]
INFO - 02:57:42: 34%|███▍ | 34/100 [00:00<00:00, 757.23 it/sec, obj=0.848]
INFO - 02:57:42: 35%|███▌ | 35/100 [00:00<00:00, 756.62 it/sec, obj=0.658]
INFO - 02:57:42: 36%|███▌ | 36/100 [00:00<00:00, 748.83 it/sec, obj=0.643]
INFO - 02:57:42: 37%|███▋ | 37/100 [00:00<00:00, 741.84 it/sec, obj=0.616]
INFO - 02:57:42: 38%|███▊ | 38/100 [00:00<00:00, 735.91 it/sec, obj=0.615]
INFO - 02:57:42: 39%|███▉ | 39/100 [00:00<00:00, 730.06 it/sec, obj=0.615]
INFO - 02:57:42: 40%|████ | 40/100 [00:00<00:00, 713.98 it/sec, obj=1.16]
INFO - 02:57:42: 41%|████ | 41/100 [00:00<00:00, 707.24 it/sec, obj=2.87]
INFO - 02:57:42: 42%|████▏ | 42/100 [00:00<00:00, 712.47 it/sec, obj=0.785]
INFO - 02:57:42: 43%|████▎ | 43/100 [00:00<00:00, 702.04 it/sec, obj=0.644]
INFO - 02:57:42: 44%|████▍ | 44/100 [00:00<00:00, 698.08 it/sec, obj=0.624]
INFO - 02:57:42: 45%|████▌ | 45/100 [00:00<00:00, 693.92 it/sec, obj=0.615]
INFO - 02:57:42: 46%|████▌ | 46/100 [00:00<00:00, 689.52 it/sec, obj=0.615]
INFO - 02:57:42: 47%|████▋ | 47/100 [00:00<00:00, 686.34 it/sec, obj=0.615]
INFO - 02:57:42: 48%|████▊ | 48/100 [00:00<00:00, 683.14 it/sec, obj=0.615]
INFO - 02:57:42: 49%|████▉ | 49/100 [00:00<00:00, 671.40 it/sec, obj=0.838]
INFO - 02:57:42: 50%|█████ | 50/100 [00:00<00:00, 665.85 it/sec, obj=0.656]
INFO - 02:57:42: 51%|█████ | 51/100 [00:00<00:00, 662.73 it/sec, obj=0.639]
INFO - 02:57:42: 52%|█████▏ | 52/100 [00:00<00:00, 660.34 it/sec, obj=0.616]
INFO - 02:57:42: 53%|█████▎ | 53/100 [00:00<00:00, 658.26 it/sec, obj=0.615]
INFO - 02:57:42: 54%|█████▍ | 54/100 [00:00<00:00, 655.86 it/sec, obj=0.615]
INFO - 02:57:42: 55%|█████▌ | 55/100 [00:00<00:00, 654.09 it/sec, obj=0.615]
INFO - 02:57:42: 56%|█████▌ | 56/100 [00:00<00:00, 652.10 it/sec, obj=0.615]
INFO - 02:57:42: 57%|█████▋ | 57/100 [00:00<00:00, 650.34 it/sec, obj=0.615]
INFO - 02:57:42: 58%|█████▊ | 58/100 [00:00<00:00, 645.97 it/sec, obj=0.625]
INFO - 02:57:42: 59%|█████▉ | 59/100 [00:00<00:00, 643.41 it/sec, obj=2.87]
INFO - 02:57:42: 60%|██████ | 60/100 [00:00<00:00, 647.01 it/sec, obj=0.616]
INFO - 02:57:42: 61%|██████ | 61/100 [00:00<00:00, 645.62 it/sec, obj=0.615]
INFO - 02:57:42: 62%|██████▏ | 62/100 [00:00<00:00, 643.81 it/sec, obj=0.615]
INFO - 02:57:42: 63%|██████▎ | 63/100 [00:00<00:00, 642.27 it/sec, obj=0.615]
INFO - 02:57:42: 64%|██████▍ | 64/100 [00:00<00:00, 640.96 it/sec, obj=0.615]
INFO - 02:57:42: 65%|██████▌ | 65/100 [00:00<00:00, 639.57 it/sec, obj=0.615]
INFO - 02:57:42: 66%|██████▌ | 66/100 [00:00<00:00, 641.51 it/sec, obj=0.615]
INFO - 02:57:42: 67%|██████▋ | 67/100 [00:00<00:00, 642.40 it/sec, obj=0.745]
INFO - 02:57:42: 68%|██████▊ | 68/100 [00:00<00:00, 639.81 it/sec, obj=-0.875]
INFO - 02:57:42: 69%|██████▉ | 69/100 [00:00<00:00, 639.92 it/sec, obj=-0.267]
INFO - 02:57:42: 70%|███████ | 70/100 [00:00<00:00, 641.56 it/sec, obj=-0.809]
INFO - 02:57:42: 71%|███████ | 71/100 [00:00<00:00, 646.17 it/sec, obj=-0.868]
INFO - 02:57:42: 72%|███████▏ | 72/100 [00:00<00:00, 650.84 it/sec, obj=-0.874]
INFO - 02:57:42: 73%|███████▎ | 73/100 [00:00<00:00, 652.28 it/sec, obj=-0.266]
INFO - 02:57:42: 74%|███████▍ | 74/100 [00:00<00:00, 653.45 it/sec, obj=0.135]
INFO - 02:57:42: 75%|███████▌ | 75/100 [00:00<00:00, 654.50 it/sec, obj=0.577]
INFO - 02:57:42: 76%|███████▌ | 76/100 [00:00<00:00, 658.82 it/sec, obj=0.288]
INFO - 02:57:42: 77%|███████▋ | 77/100 [00:00<00:00, 655.27 it/sec, obj=1.42]
INFO - 02:57:42: 78%|███████▊ | 78/100 [00:00<00:00, 654.25 it/sec, obj=-0.875]
INFO - 02:57:42: 79%|███████▉ | 79/100 [00:00<00:00, 655.87 it/sec, obj=-0.267]
INFO - 02:57:42: 80%|████████ | 80/100 [00:00<00:00, 659.73 it/sec, obj=-0.809]
INFO - 02:57:42: 81%|████████ | 81/100 [00:00<00:00, 663.98 it/sec, obj=-0.868]
INFO - 02:57:42: 82%|████████▏ | 82/100 [00:00<00:00, 668.11 it/sec, obj=-0.874]
INFO - 02:57:42: 83%|████████▎ | 83/100 [00:00<00:00, 669.24 it/sec, obj=-0.266]
INFO - 02:57:42: 84%|████████▍ | 84/100 [00:00<00:00, 670.27 it/sec, obj=0.135]
INFO - 02:57:42: 85%|████████▌ | 85/100 [00:00<00:00, 671.51 it/sec, obj=0.577]
INFO - 02:57:42: 86%|████████▌ | 86/100 [00:00<00:00, 675.35 it/sec, obj=0.288]
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
INFO - 02:57:42: 87%|████████▋ | 87/100 [00:00<00:00, 661.69 it/sec, obj=-0.267]
INFO - 02:57:42: 88%|████████▊ | 88/100 [00:00<00:00, 665.26 it/sec, obj=-0.809]
INFO - 02:57:42: 89%|████████▉ | 89/100 [00:00<00:00, 668.74 it/sec, obj=-0.868]
INFO - 02:57:42: 90%|█████████ | 90/100 [00:00<00:00, 672.50 it/sec, obj=-0.874]
INFO - 02:57:42: 91%|█████████ | 91/100 [00:00<00:00, 673.63 it/sec, obj=-0.266]
INFO - 02:57:42: 92%|█████████▏| 92/100 [00:00<00:00, 674.69 it/sec, obj=0.135]
INFO - 02:57:42: 93%|█████████▎| 93/100 [00:00<00:00, 675.59 it/sec, obj=0.577]
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 02:57:42: Optimization found no feasible point; the least infeasible point is selected.
INFO - 02:57:42: Exporting the optimization problem to the file multistart.hdf5
INFO - 02:57:42: Optimization result:
INFO - 02:57:42: Optimizer info:
INFO - 02:57:42: Status: None
INFO - 02:57:42: Message: None
INFO - 02:57:42: Number of calls to the objective function by the optimizer: 1
INFO - 02:57:42: Solution:
INFO - 02:57:42: The solution is feasible.
INFO - 02:57:42: Objective: 0.6150998205402495
INFO - 02:57:42: Standardized constraints:
INFO - 02:57:42: cstr = -0.7883188793606977
INFO - 02:57:42: Design space:
INFO - 02:57:42: +------+-------------+--------------------+-------------+-------+
INFO - 02:57:42: | Name | Lower bound | Value | Upper bound | Type |
INFO - 02:57:42: +------+-------------+--------------------+-------------+-------+
INFO - 02:57:42: | x | -1.5 | 0.5773502675245377 | 1.5 | float |
INFO - 02:57:42: +------+-------------+--------------------+-------------+-------+
INFO - 02:57:42: *** End MDOScenario execution (time: 0:00:00.156401) ***
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 0x7f7987030980>
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 - 02:57:42: Importing the optimization problem from the file multistart.hdf5
<gemseo.post.basic_history.BasicHistory object at 0x7f79854ed100>
Total running time of the script: (0 minutes 0.522 seconds)