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 - 15:35:43: *** Start MDOScenario execution ***
   INFO - 15:35:43: MDOScenario
   INFO - 15:35:43:    Disciplines: AnalyticDiscipline AnalyticDiscipline
   INFO - 15:35:43:    MDO formulation: DisciplinaryOpt
   INFO - 15:35:43: Optimization problem:
   INFO - 15:35:43:    minimize obj(x)
   INFO - 15:35:43:    with respect to x
   INFO - 15:35:43:    subject to constraints:
   INFO - 15:35:43:       cstr(x) <= 0
   INFO - 15:35:43:    over the design space:
   INFO - 15:35:43:       +------+-------------+-------+-------------+-------+
   INFO - 15:35:43:       | Name | Lower bound | Value | Upper bound | Type  |
   INFO - 15:35:43:       +------+-------------+-------+-------------+-------+
   INFO - 15:35:43:       | x    |     -1.5    |  1.5  |     1.5     | float |
   INFO - 15:35:43:       +------+-------------+-------+-------------+-------+
   INFO - 15:35:43: Solving optimization problem with algorithm MultiStart:
   INFO - 15:35:43:      1%|          | 1/100 [00:00<00:00, 286.91 it/sec, obj=2.88]
   INFO - 15:35:43:      2%|▏         | 2/100 [00:00<00:00, 375.36 it/sec, obj=-0.875]
   INFO - 15:35:43:      3%|▎         | 3/100 [00:00<00:00, 402.09 it/sec, obj=-0.267]
   INFO - 15:35:43:      4%|▍         | 4/100 [00:00<00:00, 485.52 it/sec, obj=-0.809]
   INFO - 15:35:43:      5%|▌         | 5/100 [00:00<00:00, 553.08 it/sec, obj=-0.868]
   INFO - 15:35:43:      6%|▌         | 6/100 [00:00<00:00, 612.90 it/sec, obj=-0.872]
   INFO - 15:35:43:      7%|▋         | 7/100 [00:00<00:00, 625.90 it/sec, obj=-0.265]
   INFO - 15:35:43:      8%|▊         | 8/100 [00:00<00:00, 636.19 it/sec, obj=0.136]
   INFO - 15:35:43:      9%|▉         | 9/100 [00:00<00:00, 644.98 it/sec, obj=0.579]
   INFO - 15:35:43:     10%|█         | 10/100 [00:00<00:00, 678.19 it/sec, obj=0.289]
   INFO - 15:35:43:     11%|█         | 11/100 [00:00<00:00, 680.78 it/sec, obj=1.25]
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 15:35:43:     12%|█▏        | 12/100 [00:00<00:00, 659.89 it/sec, obj=0.579]
   INFO - 15:35:43:     13%|█▎        | 13/100 [00:00<00:00, 650.51 it/sec, obj=-0.875]
   INFO - 15:35:43:     14%|█▍        | 14/100 [00:00<00:00, 656.79 it/sec, obj=-0.267]
   INFO - 15:35:43:     15%|█▌        | 15/100 [00:00<00:00, 671.79 it/sec, obj=-0.809]
   INFO - 15:35:43:     16%|█▌        | 16/100 [00:00<00:00, 688.12 it/sec, obj=-0.868]
   INFO - 15:35:43:     17%|█▋        | 17/100 [00:00<00:00, 707.06 it/sec, obj=-0.874]
   INFO - 15:35:43:     18%|█▊        | 18/100 [00:00<00:00, 708.56 it/sec, obj=-0.266]
   INFO - 15:35:43:     19%|█▉        | 19/100 [00:00<00:00, 705.87 it/sec, obj=0.135]
   INFO - 15:35:43:     20%|██        | 20/100 [00:00<00:00, 706.00 it/sec, obj=0.577]
   INFO - 15:35:43:     21%|██        | 21/100 [00:00<00:00, 720.91 it/sec, obj=0.288]
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 15:35:43:     22%|██▏       | 22/100 [00:00<00:00, 693.21 it/sec, obj=1.25]
   INFO - 15:35:43:     23%|██▎       | 23/100 [00:00<00:00, 685.66 it/sec, obj=-0.875]
   INFO - 15:35:43:     24%|██▍       | 24/100 [00:00<00:00, 699.88 it/sec, obj=1.01]
   INFO - 15:35:43:     25%|██▌       | 25/100 [00:00<00:00, 700.49 it/sec, obj=-0.875]
   INFO - 15:35:43:     26%|██▌       | 26/100 [00:00<00:00, 712.17 it/sec, obj=0.819]
   INFO - 15:35:43:     27%|██▋       | 27/100 [00:00<00:00, 713.71 it/sec, obj=-0.875]
   INFO - 15:35:43:     28%|██▊       | 28/100 [00:00<00:00, 725.12 it/sec, obj=0.693]
   INFO - 15:35:43:     29%|██▉       | 29/100 [00:00<00:00, 720.21 it/sec, obj=0.584]
   INFO - 15:35:43:     30%|███       | 30/100 [00:00<00:00, 720.77 it/sec, obj=-0.875]
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 15:35:43:     31%|███       | 31/100 [00:00<00:00, 710.90 it/sec, obj=1.38]
   INFO - 15:35:43:     32%|███▏      | 32/100 [00:00<00:00, 702.46 it/sec, obj=1.23]
   INFO - 15:35:43:     33%|███▎      | 33/100 [00:00<00:00, 702.86 it/sec, obj=2.87]
   INFO - 15:35:43:     34%|███▍      | 34/100 [00:00<00:00, 712.28 it/sec, obj=0.848]
   INFO - 15:35:43:     35%|███▌      | 35/100 [00:00<00:00, 711.60 it/sec, obj=0.658]
   INFO - 15:35:43:     36%|███▌      | 36/100 [00:00<00:00, 704.71 it/sec, obj=0.643]
   INFO - 15:35:43:     37%|███▋      | 37/100 [00:00<00:00, 698.65 it/sec, obj=0.616]
   INFO - 15:35:43:     38%|███▊      | 38/100 [00:00<00:00, 693.27 it/sec, obj=0.615]
   INFO - 15:35:43:     39%|███▉      | 39/100 [00:00<00:00, 688.52 it/sec, obj=0.615]
   INFO - 15:35:43:     40%|████      | 40/100 [00:00<00:00, 673.10 it/sec, obj=1.16]
   INFO - 15:35:43:     41%|████      | 41/100 [00:00<00:00, 667.65 it/sec, obj=2.87]
   INFO - 15:35:43:     42%|████▏     | 42/100 [00:00<00:00, 672.78 it/sec, obj=0.785]
   INFO - 15:35:43:     43%|████▎     | 43/100 [00:00<00:00, 663.69 it/sec, obj=0.644]
   INFO - 15:35:43:     44%|████▍     | 44/100 [00:00<00:00, 659.73 it/sec, obj=0.624]
   INFO - 15:35:43:     45%|████▌     | 45/100 [00:00<00:00, 656.18 it/sec, obj=0.615]
   INFO - 15:35:43:     46%|████▌     | 46/100 [00:00<00:00, 650.20 it/sec, obj=0.615]
   INFO - 15:35:43:     47%|████▋     | 47/100 [00:00<00:00, 646.70 it/sec, obj=0.615]
   INFO - 15:35:43:     48%|████▊     | 48/100 [00:00<00:00, 642.93 it/sec, obj=0.615]
   INFO - 15:35:43:     49%|████▉     | 49/100 [00:00<00:00, 631.90 it/sec, obj=0.838]
   INFO - 15:35:43:     50%|█████     | 50/100 [00:00<00:00, 624.87 it/sec, obj=0.656]
   INFO - 15:35:43:     51%|█████     | 51/100 [00:00<00:00, 622.95 it/sec, obj=0.639]
   INFO - 15:35:43:     52%|█████▏    | 52/100 [00:00<00:00, 620.49 it/sec, obj=0.616]
   INFO - 15:35:43:     53%|█████▎    | 53/100 [00:00<00:00, 618.62 it/sec, obj=0.615]
   INFO - 15:35:43:     54%|█████▍    | 54/100 [00:00<00:00, 616.66 it/sec, obj=0.615]
   INFO - 15:35:43:     55%|█████▌    | 55/100 [00:00<00:00, 615.01 it/sec, obj=0.615]
   INFO - 15:35:43:     56%|█████▌    | 56/100 [00:00<00:00, 613.34 it/sec, obj=0.615]
   INFO - 15:35:43:     57%|█████▋    | 57/100 [00:00<00:00, 611.79 it/sec, obj=0.615]
   INFO - 15:35:43:     58%|█████▊    | 58/100 [00:00<00:00, 607.70 it/sec, obj=0.625]
   INFO - 15:35:43:     59%|█████▉    | 59/100 [00:00<00:00, 605.45 it/sec, obj=2.87]
   INFO - 15:35:43:     60%|██████    | 60/100 [00:00<00:00, 609.47 it/sec, obj=0.616]
   INFO - 15:35:43:     61%|██████    | 61/100 [00:00<00:00, 607.91 it/sec, obj=0.615]
   INFO - 15:35:43:     62%|██████▏   | 62/100 [00:00<00:00, 606.24 it/sec, obj=0.615]
   INFO - 15:35:43:     63%|██████▎   | 63/100 [00:00<00:00, 604.88 it/sec, obj=0.615]
   INFO - 15:35:43:     64%|██████▍   | 64/100 [00:00<00:00, 603.88 it/sec, obj=0.615]
   INFO - 15:35:43:     65%|██████▌   | 65/100 [00:00<00:00, 602.84 it/sec, obj=0.615]
   INFO - 15:35:43:     66%|██████▌   | 66/100 [00:00<00:00, 604.85 it/sec, obj=0.615]
   INFO - 15:35:43:     67%|██████▋   | 67/100 [00:00<00:00, 605.59 it/sec, obj=0.745]
   INFO - 15:35:43:     68%|██████▊   | 68/100 [00:00<00:00, 603.25 it/sec, obj=-0.875]
   INFO - 15:35:43:     69%|██████▉   | 69/100 [00:00<00:00, 603.43 it/sec, obj=-0.267]
   INFO - 15:35:43:     70%|███████   | 70/100 [00:00<00:00, 605.15 it/sec, obj=-0.809]
   INFO - 15:35:43:     71%|███████   | 71/100 [00:00<00:00, 609.56 it/sec, obj=-0.868]
   INFO - 15:35:43:     72%|███████▏  | 72/100 [00:00<00:00, 613.95 it/sec, obj=-0.874]
   INFO - 15:35:43:     73%|███████▎  | 73/100 [00:00<00:00, 615.46 it/sec, obj=-0.266]
   INFO - 15:35:43:     74%|███████▍  | 74/100 [00:00<00:00, 616.84 it/sec, obj=0.135]
   INFO - 15:35:43:     75%|███████▌  | 75/100 [00:00<00:00, 617.62 it/sec, obj=0.577]
   INFO - 15:35:43:     76%|███████▌  | 76/100 [00:00<00:00, 621.67 it/sec, obj=0.288]
   INFO - 15:35:43:     77%|███████▋  | 77/100 [00:00<00:00, 618.35 it/sec, obj=1.42]
   INFO - 15:35:43:     78%|███████▊  | 78/100 [00:00<00:00, 617.74 it/sec, obj=-0.875]
   INFO - 15:35:43:     79%|███████▉  | 79/100 [00:00<00:00, 619.36 it/sec, obj=-0.267]
   INFO - 15:35:43:     80%|████████  | 80/100 [00:00<00:00, 623.11 it/sec, obj=-0.809]
   INFO - 15:35:43:     81%|████████  | 81/100 [00:00<00:00, 627.11 it/sec, obj=-0.868]
   INFO - 15:35:43:     82%|████████▏ | 82/100 [00:00<00:00, 630.98 it/sec, obj=-0.874]
   INFO - 15:35:43:     83%|████████▎ | 83/100 [00:00<00:00, 632.14 it/sec, obj=-0.266]
   INFO - 15:35:43:     84%|████████▍ | 84/100 [00:00<00:00, 633.15 it/sec, obj=0.135]
   INFO - 15:35:43:     85%|████████▌ | 85/100 [00:00<00:00, 634.28 it/sec, obj=0.577]
   INFO - 15:35:43:     86%|████████▌ | 86/100 [00:00<00:00, 638.07 it/sec, obj=0.288]
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 15:35:43:     87%|████████▋ | 87/100 [00:00<00:00, 625.35 it/sec, obj=-0.267]
   INFO - 15:35:43:     88%|████████▊ | 88/100 [00:00<00:00, 628.73 it/sec, obj=-0.809]
   INFO - 15:35:43:     89%|████████▉ | 89/100 [00:00<00:00, 632.42 it/sec, obj=-0.868]
   INFO - 15:35:43:     90%|█████████ | 90/100 [00:00<00:00, 635.98 it/sec, obj=-0.874]
   INFO - 15:35:43:     91%|█████████ | 91/100 [00:00<00:00, 636.95 it/sec, obj=-0.266]
   INFO - 15:35:43:     92%|█████████▏| 92/100 [00:00<00:00, 637.87 it/sec, obj=0.135]
   INFO - 15:35:43:     93%|█████████▎| 93/100 [00:00<00:00, 638.82 it/sec, obj=0.577]
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 15:35:43: Optimization found no feasible point; the least infeasible point is selected.
   INFO - 15:35:43: Exporting the optimization problem to the file multistart.hdf5
   INFO - 15:35:43: Optimization result:
   INFO - 15:35:43:    Optimizer info:
   INFO - 15:35:43:       Status: None
   INFO - 15:35:43:       Message: None
   INFO - 15:35:43:       Number of calls to the objective function by the optimizer: 1
   INFO - 15:35:43:    Solution:
   INFO - 15:35:43:       The solution is feasible.
   INFO - 15:35:43:       Objective: 0.6150998205402495
   INFO - 15:35:43:       Standardized constraints:
   INFO - 15:35:43:          cstr = -0.7883188793606977
   INFO - 15:35:43:       Design space:
   INFO - 15:35:43:          +------+-------------+--------------------+-------------+-------+
   INFO - 15:35:43:          | Name | Lower bound |       Value        | Upper bound | Type  |
   INFO - 15:35:43:          +------+-------------+--------------------+-------------+-------+
   INFO - 15:35:43:          | x    |     -1.5    | 0.5773502675245377 |     1.5     | float |
   INFO - 15:35:43:          +------+-------------+--------------------+-------------+-------+
   INFO - 15:35:43: *** End MDOScenario execution (time: 0:00:00.165387) ***

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 0x7f52266ca930>

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 - 15:35:43: Importing the optimization problem from the file multistart.hdf5

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

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

Gallery generated by Sphinx-Gallery