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:15:
INFO - 08:36:15: *** Start MDOScenario execution ***
INFO - 08:36:15: MDOScenario
INFO - 08:36:15: Disciplines: AnalyticDiscipline AnalyticDiscipline
INFO - 08:36:15: MDO formulation: DisciplinaryOpt
INFO - 08:36:15: Optimization problem:
INFO - 08:36:15: minimize obj(x)
INFO - 08:36:15: with respect to x
INFO - 08:36:15: subject to constraints:
INFO - 08:36:15: cstr(x) <= 0
INFO - 08:36:15: over the design space:
INFO - 08:36:15: +------+-------------+-------+-------------+-------+
INFO - 08:36:15: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:36:15: +------+-------------+-------+-------------+-------+
INFO - 08:36:15: | x | -1.5 | 1.5 | 1.5 | float |
INFO - 08:36:15: +------+-------------+-------+-------------+-------+
INFO - 08:36:15: Solving optimization problem with algorithm MultiStart:
INFO - 08:36:15: 1%| | 1/100 [00:00<00:00, 273.73 it/sec, obj=2.88]
INFO - 08:36:15: 2%|▏ | 2/100 [00:00<00:00, 342.52 it/sec, obj=-0.875]
INFO - 08:36:15: 3%|▎ | 3/100 [00:00<00:00, 343.83 it/sec, obj=-0.267]
INFO - 08:36:15: 4%|▍ | 4/100 [00:00<00:00, 406.12 it/sec, obj=-0.809]
INFO - 08:36:15: 5%|▌ | 5/100 [00:00<00:00, 453.20 it/sec, obj=-0.868]
INFO - 08:36:15: 6%|▌ | 6/100 [00:00<00:00, 488.70 it/sec, obj=-0.872]
INFO - 08:36:15: 7%|▋ | 7/100 [00:00<00:00, 491.81 it/sec, obj=-0.265]
INFO - 08:36:15: 8%|▊ | 8/100 [00:00<00:00, 493.56 it/sec, obj=0.136]
INFO - 08:36:15: 9%|▉ | 9/100 [00:00<00:00, 492.19 it/sec, obj=0.579]
INFO - 08:36:15: 10%|█ | 10/100 [00:00<00:00, 512.56 it/sec, obj=0.289]
INFO - 08:36:15: 11%|█ | 11/100 [00:00<00:00, 512.38 it/sec, obj=1.25]
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:15: 12%|█▏ | 12/100 [00:00<00:00, 497.06 it/sec, obj=0.579]
INFO - 08:36:15: 13%|█▎ | 13/100 [00:00<00:00, 490.15 it/sec, obj=-0.875]
INFO - 08:36:15: 14%|█▍ | 14/100 [00:00<00:00, 493.35 it/sec, obj=-0.267]
INFO - 08:36:15: 15%|█▌ | 15/100 [00:00<00:00, 507.38 it/sec, obj=-0.809]
INFO - 08:36:15: 16%|█▌ | 16/100 [00:00<00:00, 520.65 it/sec, obj=-0.868]
INFO - 08:36:15: 17%|█▋ | 17/100 [00:00<00:00, 532.10 it/sec, obj=-0.874]
INFO - 08:36:15: 18%|█▊ | 18/100 [00:00<00:00, 531.45 it/sec, obj=-0.266]
INFO - 08:36:15: 19%|█▉ | 19/100 [00:00<00:00, 530.22 it/sec, obj=0.135]
INFO - 08:36:15: 20%|██ | 20/100 [00:00<00:00, 529.30 it/sec, obj=0.577]
INFO - 08:36:15: 21%|██ | 21/100 [00:00<00:00, 538.89 it/sec, obj=0.288]
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:15: 22%|██▏ | 22/100 [00:00<00:00, 519.35 it/sec, obj=1.25]
INFO - 08:36:15: 23%|██▎ | 23/100 [00:00<00:00, 513.76 it/sec, obj=-0.875]
INFO - 08:36:15: 24%|██▍ | 24/100 [00:00<00:00, 523.45 it/sec, obj=1.01]
INFO - 08:36:15: 25%|██▌ | 25/100 [00:00<00:00, 523.14 it/sec, obj=-0.875]
INFO - 08:36:15: 26%|██▌ | 26/100 [00:00<00:00, 530.24 it/sec, obj=0.819]
INFO - 08:36:15: 27%|██▋ | 27/100 [00:00<00:00, 529.11 it/sec, obj=-0.875]
INFO - 08:36:15: 28%|██▊ | 28/100 [00:00<00:00, 535.76 it/sec, obj=0.693]
INFO - 08:36:15: 29%|██▉ | 29/100 [00:00<00:00, 531.42 it/sec, obj=0.584]
INFO - 08:36:15: 30%|███ | 30/100 [00:00<00:00, 530.66 it/sec, obj=-0.875]
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:15: 31%|███ | 31/100 [00:00<00:00, 523.63 it/sec, obj=1.38]
INFO - 08:36:15: 32%|███▏ | 32/100 [00:00<00:00, 517.23 it/sec, obj=1.23]
INFO - 08:36:15: 33%|███▎ | 33/100 [00:00<00:00, 517.20 it/sec, obj=2.87]
INFO - 08:36:15: 34%|███▍ | 34/100 [00:00<00:00, 523.12 it/sec, obj=0.848]
INFO - 08:36:15: 35%|███▌ | 35/100 [00:00<00:00, 522.07 it/sec, obj=0.658]
INFO - 08:36:15: 36%|███▌ | 36/100 [00:00<00:00, 516.50 it/sec, obj=0.643]
INFO - 08:36:15: 37%|███▋ | 37/100 [00:00<00:00, 512.24 it/sec, obj=0.616]
INFO - 08:36:15: 38%|███▊ | 38/100 [00:00<00:00, 508.40 it/sec, obj=0.615]
INFO - 08:36:15: 39%|███▉ | 39/100 [00:00<00:00, 504.62 it/sec, obj=0.615]
INFO - 08:36:15: 40%|████ | 40/100 [00:00<00:00, 494.47 it/sec, obj=1.16]
INFO - 08:36:15: 41%|████ | 41/100 [00:00<00:00, 490.31 it/sec, obj=2.87]
INFO - 08:36:15: 42%|████▏ | 42/100 [00:00<00:00, 493.96 it/sec, obj=0.785]
INFO - 08:36:15: 43%|████▎ | 43/100 [00:00<00:00, 487.19 it/sec, obj=0.644]
INFO - 08:36:15: 44%|████▍ | 44/100 [00:00<00:00, 484.57 it/sec, obj=0.624]
INFO - 08:36:15: 45%|████▌ | 45/100 [00:00<00:00, 480.05 it/sec, obj=0.615]
INFO - 08:36:15: 46%|████▌ | 46/100 [00:00<00:00, 477.77 it/sec, obj=0.615]
INFO - 08:36:15: 47%|████▋ | 47/100 [00:00<00:00, 474.41 it/sec, obj=0.615]
INFO - 08:36:15: 48%|████▊ | 48/100 [00:00<00:00, 472.38 it/sec, obj=0.615]
INFO - 08:36:15: 49%|████▉ | 49/100 [00:00<00:00, 464.73 it/sec, obj=0.838]
INFO - 08:36:15: 50%|█████ | 50/100 [00:00<00:00, 461.25 it/sec, obj=0.656]
INFO - 08:36:15: 51%|█████ | 51/100 [00:00<00:00, 459.85 it/sec, obj=0.639]
INFO - 08:36:15: 52%|█████▏ | 52/100 [00:00<00:00, 457.23 it/sec, obj=0.616]
INFO - 08:36:15: 53%|█████▎ | 53/100 [00:00<00:00, 455.85 it/sec, obj=0.615]
INFO - 08:36:15: 54%|█████▍ | 54/100 [00:00<00:00, 454.22 it/sec, obj=0.615]
INFO - 08:36:15: 55%|█████▌ | 55/100 [00:00<00:00, 451.98 it/sec, obj=0.615]
INFO - 08:36:15: 56%|█████▌ | 56/100 [00:00<00:00, 450.57 it/sec, obj=0.615]
INFO - 08:36:15: 57%|█████▋ | 57/100 [00:00<00:00, 449.39 it/sec, obj=0.615]
INFO - 08:36:15: 58%|█████▊ | 58/100 [00:00<00:00, 447.15 it/sec, obj=0.625]
INFO - 08:36:15: 59%|█████▉ | 59/100 [00:00<00:00, 445.51 it/sec, obj=2.87]
INFO - 08:36:15: 60%|██████ | 60/100 [00:00<00:00, 448.41 it/sec, obj=0.616]
INFO - 08:36:15: 61%|██████ | 61/100 [00:00<00:00, 447.42 it/sec, obj=0.615]
INFO - 08:36:15: 62%|██████▏ | 62/100 [00:00<00:00, 446.35 it/sec, obj=0.615]
INFO - 08:36:15: 63%|██████▎ | 63/100 [00:00<00:00, 445.35 it/sec, obj=0.615]
INFO - 08:36:15: 64%|██████▍ | 64/100 [00:00<00:00, 444.50 it/sec, obj=0.615]
INFO - 08:36:15: 65%|██████▌ | 65/100 [00:00<00:00, 443.72 it/sec, obj=0.615]
INFO - 08:36:15: 66%|██████▌ | 66/100 [00:00<00:00, 445.12 it/sec, obj=0.615]
INFO - 08:36:15: 67%|██████▋ | 67/100 [00:00<00:00, 446.09 it/sec, obj=0.745]
INFO - 08:36:15: 68%|██████▊ | 68/100 [00:00<00:00, 444.60 it/sec, obj=-0.875]
INFO - 08:36:15: 69%|██████▉ | 69/100 [00:00<00:00, 444.93 it/sec, obj=-0.267]
INFO - 08:36:15: 70%|███████ | 70/100 [00:00<00:00, 446.02 it/sec, obj=-0.809]
INFO - 08:36:15: 71%|███████ | 71/100 [00:00<00:00, 448.62 it/sec, obj=-0.868]
INFO - 08:36:15: 72%|███████▏ | 72/100 [00:00<00:00, 451.44 it/sec, obj=-0.874]
INFO - 08:36:15: 73%|███████▎ | 73/100 [00:00<00:00, 452.16 it/sec, obj=-0.266]
INFO - 08:36:15: 74%|███████▍ | 74/100 [00:00<00:00, 452.90 it/sec, obj=0.135]
INFO - 08:36:15: 75%|███████▌ | 75/100 [00:00<00:00, 453.64 it/sec, obj=0.577]
INFO - 08:36:15: 76%|███████▌ | 76/100 [00:00<00:00, 456.45 it/sec, obj=0.288]
INFO - 08:36:15: 77%|███████▋ | 77/100 [00:00<00:00, 454.10 it/sec, obj=1.42]
INFO - 08:36:15: 78%|███████▊ | 78/100 [00:00<00:00, 453.59 it/sec, obj=-0.875]
INFO - 08:36:15: 79%|███████▉ | 79/100 [00:00<00:00, 454.56 it/sec, obj=-0.267]
INFO - 08:36:15: 80%|████████ | 80/100 [00:00<00:00, 457.21 it/sec, obj=-0.809]
INFO - 08:36:15: 81%|████████ | 81/100 [00:00<00:00, 459.82 it/sec, obj=-0.868]
INFO - 08:36:15: 82%|████████▏ | 82/100 [00:00<00:00, 462.28 it/sec, obj=-0.874]
INFO - 08:36:15: 83%|████████▎ | 83/100 [00:00<00:00, 462.88 it/sec, obj=-0.266]
INFO - 08:36:15: 84%|████████▍ | 84/100 [00:00<00:00, 463.35 it/sec, obj=0.135]
INFO - 08:36:15: 85%|████████▌ | 85/100 [00:00<00:00, 463.97 it/sec, obj=0.577]
INFO - 08:36:15: 86%|████████▌ | 86/100 [00:00<00:00, 466.36 it/sec, obj=0.288]
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:15: 87%|████████▋ | 87/100 [00:00<00:00, 457.39 it/sec, obj=-0.267]
INFO - 08:36:15: 88%|████████▊ | 88/100 [00:00<00:00, 459.74 it/sec, obj=-0.809]
INFO - 08:36:15: 89%|████████▉ | 89/100 [00:00<00:00, 462.12 it/sec, obj=-0.868]
INFO - 08:36:15: 90%|█████████ | 90/100 [00:00<00:00, 464.45 it/sec, obj=-0.874]
INFO - 08:36:15: 91%|█████████ | 91/100 [00:00<00:00, 464.91 it/sec, obj=-0.266]
INFO - 08:36:15: 92%|█████████▏| 92/100 [00:00<00:00, 465.45 it/sec, obj=0.135]
INFO - 08:36:15: 93%|█████████▎| 93/100 [00:00<00:00, 465.89 it/sec, obj=0.577]
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 08:36:15: Optimization found no feasible point; the least infeasible point is selected.
INFO - 08:36:15: Exporting the optimization problem to the file multistart.hdf5 at node
INFO - 08:36:15: Optimization result:
INFO - 08:36:15: Optimizer info:
INFO - 08:36:15: Status: None
INFO - 08:36:15: Message: None
INFO - 08:36:15: Number of calls to the objective function by the optimizer: 1
INFO - 08:36:15: Solution:
INFO - 08:36:15: The solution is feasible.
INFO - 08:36:15: Objective: 0.6150998205402495
INFO - 08:36:15: Standardized constraints:
INFO - 08:36:15: cstr = -0.7883188793606977
INFO - 08:36:15: Design space:
INFO - 08:36:15: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:15: | Name | Lower bound | Value | Upper bound | Type |
INFO - 08:36:15: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:15: | x | -1.5 | 0.5773502675245377 | 1.5 | float |
INFO - 08:36:15: +------+-------------+--------------------+-------------+-------+
INFO - 08:36:15: *** End MDOScenario execution (time: 0:00:00.223764) ***
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 0x7f6e05be9790>
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:16: Importing the optimization problem from the file multistart.hdf5 at node
<gemseo.post.basic_history.BasicHistory object at 0x7f6df8298ee0>
Total running time of the script: (0 minutes 0.732 seconds)