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 - 11:44:05: *** Start MDOScenario execution ***
   INFO - 11:44:05: MDOScenario
   INFO - 11:44:05:    Disciplines: AnalyticDiscipline AnalyticDiscipline
   INFO - 11:44:05:    MDO formulation: DisciplinaryOpt
   INFO - 11:44:05: Optimization problem:
   INFO - 11:44:05:    minimize obj(x)
   INFO - 11:44:05:    with respect to x
   INFO - 11:44:05:    subject to constraints:
   INFO - 11:44:05:       cstr(x) <= 0
   INFO - 11:44:05:    over the design space:
   INFO - 11:44:05:       +------+-------------+-------+-------------+-------+
   INFO - 11:44:05:       | Name | Lower bound | Value | Upper bound | Type  |
   INFO - 11:44:05:       +------+-------------+-------+-------------+-------+
   INFO - 11:44:05:       | x    |     -1.5    |  1.5  |     1.5     | float |
   INFO - 11:44:05:       +------+-------------+-------+-------------+-------+
   INFO - 11:44:05: Solving optimization problem with algorithm MultiStart:
   INFO - 11:44:05:      1%|          | 1/100 [00:00<00:00, 280.54 it/sec, obj=2.88]
   INFO - 11:44:05:      2%|▏         | 2/100 [00:00<00:00, 364.93 it/sec, obj=-0.875]
   INFO - 11:44:05:      3%|▎         | 3/100 [00:00<00:00, 389.64 it/sec, obj=-0.267]
   INFO - 11:44:05:      4%|▍         | 4/100 [00:00<00:00, 470.66 it/sec, obj=-0.809]
   INFO - 11:44:05:      5%|▌         | 5/100 [00:00<00:00, 537.13 it/sec, obj=-0.868]
   INFO - 11:44:05:      6%|▌         | 6/100 [00:00<00:00, 594.30 it/sec, obj=-0.872]
   INFO - 11:44:05:      7%|▋         | 7/100 [00:00<00:00, 606.34 it/sec, obj=-0.265]
   INFO - 11:44:05:      8%|▊         | 8/100 [00:00<00:00, 617.90 it/sec, obj=0.136]
   INFO - 11:44:05:      9%|▉         | 9/100 [00:00<00:00, 626.66 it/sec, obj=0.579]
   INFO - 11:44:05:     10%|█         | 10/100 [00:00<00:00, 658.67 it/sec, obj=0.289]
   INFO - 11:44:05:     11%|█         | 11/100 [00:00<00:00, 662.30 it/sec, obj=1.25]
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 11:44:05:     12%|█▏        | 12/100 [00:00<00:00, 641.72 it/sec, obj=0.579]
   INFO - 11:44:05:     13%|█▎        | 13/100 [00:00<00:00, 633.51 it/sec, obj=-0.875]
   INFO - 11:44:05:     14%|█▍        | 14/100 [00:00<00:00, 640.19 it/sec, obj=-0.267]
   INFO - 11:44:05:     15%|█▌        | 15/100 [00:00<00:00, 660.48 it/sec, obj=-0.809]
   INFO - 11:44:05:     16%|█▌        | 16/100 [00:00<00:00, 680.38 it/sec, obj=-0.868]
   INFO - 11:44:05:     17%|█▋        | 17/100 [00:00<00:00, 697.61 it/sec, obj=-0.874]
   INFO - 11:44:05:     18%|█▊        | 18/100 [00:00<00:00, 696.59 it/sec, obj=-0.266]
   INFO - 11:44:05:     19%|█▉        | 19/100 [00:00<00:00, 693.22 it/sec, obj=0.135]
   INFO - 11:44:05:     20%|██        | 20/100 [00:00<00:00, 693.28 it/sec, obj=0.577]
   INFO - 11:44:05:     21%|██        | 21/100 [00:00<00:00, 707.23 it/sec, obj=0.288]
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 11:44:05:     22%|██▏       | 22/100 [00:00<00:00, 679.18 it/sec, obj=1.25]
   INFO - 11:44:05:     23%|██▎       | 23/100 [00:00<00:00, 673.09 it/sec, obj=-0.875]
   INFO - 11:44:05:     24%|██▍       | 24/100 [00:00<00:00, 687.03 it/sec, obj=1.01]
   INFO - 11:44:05:     25%|██▌       | 25/100 [00:00<00:00, 687.17 it/sec, obj=-0.875]
   INFO - 11:44:05:     26%|██▌       | 26/100 [00:00<00:00, 699.24 it/sec, obj=0.819]
   INFO - 11:44:05:     27%|██▋       | 27/100 [00:00<00:00, 699.90 it/sec, obj=-0.875]
   INFO - 11:44:05:     28%|██▊       | 28/100 [00:00<00:00, 710.55 it/sec, obj=0.693]
   INFO - 11:44:05:     29%|██▉       | 29/100 [00:00<00:00, 706.19 it/sec, obj=0.584]
   INFO - 11:44:05:     30%|███       | 30/100 [00:00<00:00, 705.97 it/sec, obj=-0.875]
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 11:44:05:     31%|███       | 31/100 [00:00<00:00, 696.67 it/sec, obj=1.38]
   INFO - 11:44:05:     32%|███▏      | 32/100 [00:00<00:00, 688.12 it/sec, obj=1.23]
   INFO - 11:44:05:     33%|███▎      | 33/100 [00:00<00:00, 688.83 it/sec, obj=2.87]
   INFO - 11:44:05:     34%|███▍      | 34/100 [00:00<00:00, 697.39 it/sec, obj=0.848]
   INFO - 11:44:05:     35%|███▌      | 35/100 [00:00<00:00, 696.63 it/sec, obj=0.658]
   INFO - 11:44:05:     36%|███▌      | 36/100 [00:00<00:00, 689.96 it/sec, obj=0.643]
   INFO - 11:44:05:     37%|███▋      | 37/100 [00:00<00:00, 684.12 it/sec, obj=0.616]
   INFO - 11:44:05:     38%|███▊      | 38/100 [00:00<00:00, 678.30 it/sec, obj=0.615]
   INFO - 11:44:05:     39%|███▉      | 39/100 [00:00<00:00, 672.84 it/sec, obj=0.615]
   INFO - 11:44:05:     40%|████      | 40/100 [00:00<00:00, 658.10 it/sec, obj=1.16]
   INFO - 11:44:05:     41%|████      | 41/100 [00:00<00:00, 652.69 it/sec, obj=2.87]
   INFO - 11:44:05:     42%|████▏     | 42/100 [00:00<00:00, 657.85 it/sec, obj=0.785]
   INFO - 11:44:05:     43%|████▎     | 43/100 [00:00<00:00, 648.45 it/sec, obj=0.644]
   INFO - 11:44:05:     44%|████▍     | 44/100 [00:00<00:00, 644.99 it/sec, obj=0.624]
   INFO - 11:44:05:     45%|████▌     | 45/100 [00:00<00:00, 641.31 it/sec, obj=0.615]
   INFO - 11:44:05:     46%|████▌     | 46/100 [00:00<00:00, 638.20 it/sec, obj=0.615]
   INFO - 11:44:05:     47%|████▋     | 47/100 [00:00<00:00, 635.25 it/sec, obj=0.615]
   INFO - 11:44:05:     48%|████▊     | 48/100 [00:00<00:00, 631.24 it/sec, obj=0.615]
   INFO - 11:44:05:     49%|████▉     | 49/100 [00:00<00:00, 620.54 it/sec, obj=0.838]
   INFO - 11:44:05:     50%|█████     | 50/100 [00:00<00:00, 615.70 it/sec, obj=0.656]
   INFO - 11:44:05:     51%|█████     | 51/100 [00:00<00:00, 613.08 it/sec, obj=0.639]
   INFO - 11:44:05:     52%|█████▏    | 52/100 [00:00<00:00, 610.65 it/sec, obj=0.616]
   INFO - 11:44:05:     53%|█████▎    | 53/100 [00:00<00:00, 608.31 it/sec, obj=0.615]
   INFO - 11:44:05:     54%|█████▍    | 54/100 [00:00<00:00, 606.45 it/sec, obj=0.615]
   INFO - 11:44:05:     55%|█████▌    | 55/100 [00:00<00:00, 604.78 it/sec, obj=0.615]
   INFO - 11:44:05:     56%|█████▌    | 56/100 [00:00<00:00, 603.31 it/sec, obj=0.615]
   INFO - 11:44:05:     57%|█████▋    | 57/100 [00:00<00:00, 601.62 it/sec, obj=0.615]
   INFO - 11:44:05:     58%|█████▊    | 58/100 [00:00<00:00, 597.28 it/sec, obj=0.625]
   INFO - 11:44:05:     59%|█████▉    | 59/100 [00:00<00:00, 594.85 it/sec, obj=2.87]
   INFO - 11:44:05:     60%|██████    | 60/100 [00:00<00:00, 598.26 it/sec, obj=0.616]
   INFO - 11:44:05:     61%|██████    | 61/100 [00:00<00:00, 596.80 it/sec, obj=0.615]
   INFO - 11:44:05:     62%|██████▏   | 62/100 [00:00<00:00, 595.19 it/sec, obj=0.615]
   INFO - 11:44:05:     63%|██████▎   | 63/100 [00:00<00:00, 593.62 it/sec, obj=0.615]
   INFO - 11:44:05:     64%|██████▍   | 64/100 [00:00<00:00, 592.61 it/sec, obj=0.615]
   INFO - 11:44:05:     65%|██████▌   | 65/100 [00:00<00:00, 591.39 it/sec, obj=0.615]
   INFO - 11:44:05:     66%|██████▌   | 66/100 [00:00<00:00, 593.44 it/sec, obj=0.615]
   INFO - 11:44:05:     67%|██████▋   | 67/100 [00:00<00:00, 593.31 it/sec, obj=0.745]
   INFO - 11:44:05:     68%|██████▊   | 68/100 [00:00<00:00, 591.06 it/sec, obj=-0.875]
   INFO - 11:44:05:     69%|██████▉   | 69/100 [00:00<00:00, 591.03 it/sec, obj=-0.267]
   INFO - 11:44:05:     70%|███████   | 70/100 [00:00<00:00, 592.70 it/sec, obj=-0.809]
   INFO - 11:44:05:     71%|███████   | 71/100 [00:00<00:00, 596.97 it/sec, obj=-0.868]
   INFO - 11:44:05:     72%|███████▏  | 72/100 [00:00<00:00, 601.31 it/sec, obj=-0.874]
   INFO - 11:44:05:     73%|███████▎  | 73/100 [00:00<00:00, 602.49 it/sec, obj=-0.266]
   INFO - 11:44:05:     74%|███████▍  | 74/100 [00:00<00:00, 603.72 it/sec, obj=0.135]
   INFO - 11:44:05:     75%|███████▌  | 75/100 [00:00<00:00, 604.61 it/sec, obj=0.577]
   INFO - 11:44:05:     76%|███████▌  | 76/100 [00:00<00:00, 608.61 it/sec, obj=0.288]
   INFO - 11:44:05:     77%|███████▋  | 77/100 [00:00<00:00, 604.57 it/sec, obj=1.42]
   INFO - 11:44:05:     78%|███████▊  | 78/100 [00:00<00:00, 603.89 it/sec, obj=-0.875]
   INFO - 11:44:05:     79%|███████▉  | 79/100 [00:00<00:00, 605.37 it/sec, obj=-0.267]
   INFO - 11:44:05:     80%|████████  | 80/100 [00:00<00:00, 609.18 it/sec, obj=-0.809]
   INFO - 11:44:05:     81%|████████  | 81/100 [00:00<00:00, 613.20 it/sec, obj=-0.868]
   INFO - 11:44:05:     82%|████████▏ | 82/100 [00:00<00:00, 616.92 it/sec, obj=-0.874]
   INFO - 11:44:05:     83%|████████▎ | 83/100 [00:00<00:00, 617.93 it/sec, obj=-0.266]
   INFO - 11:44:05:     84%|████████▍ | 84/100 [00:00<00:00, 618.96 it/sec, obj=0.135]
   INFO - 11:44:05:     85%|████████▌ | 85/100 [00:00<00:00, 620.18 it/sec, obj=0.577]
   INFO - 11:44:05:     86%|████████▌ | 86/100 [00:00<00:00, 623.69 it/sec, obj=0.288]
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 11:44:05:     87%|████████▋ | 87/100 [00:00<00:00, 610.26 it/sec, obj=-0.267]
   INFO - 11:44:05:     88%|████████▊ | 88/100 [00:00<00:00, 613.68 it/sec, obj=-0.809]
   INFO - 11:44:05:     89%|████████▉ | 89/100 [00:00<00:00, 617.23 it/sec, obj=-0.868]
   INFO - 11:44:05:     90%|█████████ | 90/100 [00:00<00:00, 620.66 it/sec, obj=-0.874]
   INFO - 11:44:05:     91%|█████████ | 91/100 [00:00<00:00, 621.50 it/sec, obj=-0.266]
   INFO - 11:44:05:     92%|█████████▏| 92/100 [00:00<00:00, 622.58 it/sec, obj=0.135]
   INFO - 11:44:05:     93%|█████████▎| 93/100 [00:00<00:00, 623.61 it/sec, obj=0.577]
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:44:05: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 11:44:05: Exporting the optimization problem to the file multistart.hdf5
   INFO - 11:44:05: Optimization result:
   INFO - 11:44:05:    Optimizer info:
   INFO - 11:44:05:       Status: None
   INFO - 11:44:05:       Message: None
   INFO - 11:44:05:       Number of calls to the objective function by the optimizer: 1
   INFO - 11:44:05:    Solution:
   INFO - 11:44:05:       The solution is feasible.
   INFO - 11:44:05:       Objective: 0.6150998205402495
   INFO - 11:44:05:       Standardized constraints:
   INFO - 11:44:05:          cstr = -0.7883188793606977
   INFO - 11:44:05:       Design space:
   INFO - 11:44:05:          +------+-------------+--------------------+-------------+-------+
   INFO - 11:44:05:          | Name | Lower bound |       Value        | Upper bound | Type  |
   INFO - 11:44:05:          +------+-------------+--------------------+-------------+-------+
   INFO - 11:44:05:          | x    |     -1.5    | 0.5773502675245377 |     1.5     | float |
   INFO - 11:44:05:          +------+-------------+--------------------+-------------+-------+
   INFO - 11:44:05: *** End MDOScenario execution (time: 0:00:00.169368) ***

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
)
History plot
<gemseo.post.basic_history.BasicHistory object at 0x70492a4384a0>

or by filtering the local optima (one per starting point):

execute_post(
    "multistart.hdf5",
    post_name="BasicHistory",
    variable_names=["obj"],
    save=False,
    show=True,
)
History plot
    INFO - 11:44:05: Importing the optimization problem from the file multistart.hdf5

<gemseo.post.basic_history.BasicHistory object at 0x704947481cd0>

Total running time of the script: (0 minutes 0.550 seconds)

Gallery generated by Sphinx-Gallery