.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/optimizers/plot_multistart_example.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_examples_optimizers_plot_multistart_example.py: Multi-start optimization ======================== The optimization algorithm ``multistart`` generates starting points using a DOE algorithm and run a sub-optimization algorithm from each starting point. .. GENERATED FROM PYTHON SOURCE LINES 29-44 .. code-block:: Python 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() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 45-47 First, we create the disciplines .. GENERATED FROM PYTHON SOURCE LINES 47-52 .. code-block:: Python objective = create_discipline("AnalyticDiscipline", expressions={"obj": "x**3-x+1"}) constraint = create_discipline( "AnalyticDiscipline", expressions={"cstr": "x**2+obj**2-1.5"} ) .. GENERATED FROM PYTHON SOURCE LINES 53-54 and the design space .. GENERATED FROM PYTHON SOURCE LINES 54-57 .. code-block:: Python design_space = create_design_space() design_space.add_variable("x", lower_bound=-1.5, upper_bound=1.5, value=1.5) .. GENERATED FROM PYTHON SOURCE LINES 58-60 Then, we define the MDO scenario .. GENERATED FROM PYTHON SOURCE LINES 60-66 .. code-block:: Python scenario = create_scenario( [objective, constraint], "obj", design_space, formulation_name="DisciplinaryOpt", ) .. GENERATED FROM PYTHON SOURCE LINES 67-69 Note that the formulation settings passed to :func:`.create_scenario` can be provided via a Pydantic model. For more information, see :ref:`formulation_settings`. .. GENERATED FROM PYTHON SOURCE LINES 69-72 .. code-block:: Python scenario.add_constraint("cstr", constraint_type="ineq") .. GENERATED FROM PYTHON SOURCE LINES 73-76 and execute it with the ``MultiStart`` optimization algorithm combining the local optimization algorithm SLSQP and the full-factorial DOE algorithm: .. GENERATED FROM PYTHON SOURCE LINES 76-86 .. code-block:: Python 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) .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 20:38:20: *** Start MDOScenario execution *** INFO - 20:38:20: MDOScenario INFO - 20:38:20: Disciplines: AnalyticDiscipline AnalyticDiscipline INFO - 20:38:20: MDO formulation: DisciplinaryOpt INFO - 20:38:20: Optimization problem: INFO - 20:38:20: minimize obj(x) INFO - 20:38:20: with respect to x INFO - 20:38:20: under the inequality constraints INFO - 20:38:20: cstr(x) <= 0 INFO - 20:38:20: over the design space: INFO - 20:38:20: +------+-------------+-------+-------------+-------+ INFO - 20:38:20: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:20: +------+-------------+-------+-------------+-------+ INFO - 20:38:20: | x | -1.5 | 1.5 | 1.5 | float | INFO - 20:38:20: +------+-------------+-------+-------------+-------+ INFO - 20:38:20: Solving optimization problem with algorithm MultiStart: INFO - 20:38:20: 1%| | 1/100 [00:00<00:00, 329.87 it/sec, obj=2.88] INFO - 20:38:20: 2%|▏ | 2/100 [00:00<00:00, 424.95 it/sec, obj=-0.875] INFO - 20:38:20: 3%|▎ | 3/100 [00:00<00:00, 464.59 it/sec, obj=-0.267] INFO - 20:38:20: 4%|▍ | 4/100 [00:00<00:00, 571.63 it/sec, obj=-0.809] INFO - 20:38:20: 5%|▌ | 5/100 [00:00<00:00, 660.50 it/sec, obj=-0.868] INFO - 20:38:20: 6%|▌ | 6/100 [00:00<00:00, 741.46 it/sec, obj=-0.872] INFO - 20:38:20: 7%|▋ | 7/100 [00:00<00:00, 775.37 it/sec, obj=-0.265] INFO - 20:38:20: 8%|▊ | 8/100 [00:00<00:00, 801.68 it/sec, obj=0.136] INFO - 20:38:20: 9%|▉ | 9/100 [00:00<00:00, 824.26 it/sec, obj=0.579] INFO - 20:38:20: 10%|█ | 10/100 [00:00<00:00, 870.53 it/sec, obj=0.289] INFO - 20:38:20: 11%|█ | 11/100 [00:00<00:00, 885.43 it/sec, obj=1.25] WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. INFO - 20:38:20: 12%|█▏ | 12/100 [00:00<00:00, 853.50 it/sec, obj=0.579] INFO - 20:38:20: 13%|█▎ | 13/100 [00:00<00:00, 838.13 it/sec, obj=-0.875] INFO - 20:38:20: 14%|█▍ | 14/100 [00:00<00:00, 850.14 it/sec, obj=-0.267] INFO - 20:38:20: 15%|█▌ | 15/100 [00:00<00:00, 881.54 it/sec, obj=-0.809] INFO - 20:38:20: 16%|█▌ | 16/100 [00:00<00:00, 910.42 it/sec, obj=-0.868] INFO - 20:38:20: 17%|█▋ | 17/100 [00:00<00:00, 939.21 it/sec, obj=-0.874] INFO - 20:38:20: 18%|█▊ | 18/100 [00:00<00:00, 944.32 it/sec, obj=-0.266] INFO - 20:38:20: 19%|█▉ | 19/100 [00:00<00:00, 949.55 it/sec, obj=0.135] INFO - 20:38:20: 20%|██ | 20/100 [00:00<00:00, 953.03 it/sec, obj=0.577] INFO - 20:38:20: 21%|██ | 21/100 [00:00<00:00, 973.90 it/sec, obj=0.288] WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. INFO - 20:38:20: 22%|██▏ | 22/100 [00:00<00:00, 930.92 it/sec, obj=1.25] INFO - 20:38:20: 23%|██▎ | 23/100 [00:00<00:00, 922.20 it/sec, obj=-0.875] INFO - 20:38:20: 24%|██▍ | 24/100 [00:00<00:00, 942.06 it/sec, obj=1.01] INFO - 20:38:20: 25%|██▌ | 25/100 [00:00<00:00, 946.04 it/sec, obj=-0.875] INFO - 20:38:20: 26%|██▌ | 26/100 [00:00<00:00, 964.34 it/sec, obj=0.819] INFO - 20:38:20: 27%|██▋ | 27/100 [00:00<00:00, 968.50 it/sec, obj=-0.875] INFO - 20:38:20: 28%|██▊ | 28/100 [00:00<00:00, 984.87 it/sec, obj=0.693] INFO - 20:38:20: 29%|██▉ | 29/100 [00:00<00:00, 982.28 it/sec, obj=0.584] INFO - 20:38:20: 30%|███ | 30/100 [00:00<00:00, 985.68 it/sec, obj=-0.875] WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. INFO - 20:38:20: 31%|███ | 31/100 [00:00<00:00, 962.53 it/sec, obj=1.38] INFO - 20:38:20: 32%|███▏ | 32/100 [00:00<00:00, 950.65 it/sec, obj=1.23] INFO - 20:38:20: 33%|███▎ | 33/100 [00:00<00:00, 953.00 it/sec, obj=2.87] INFO - 20:38:20: 34%|███▍ | 34/100 [00:00<00:00, 965.97 it/sec, obj=0.848] INFO - 20:38:20: 35%|███▌ | 35/100 [00:00<00:00, 967.58 it/sec, obj=0.658] INFO - 20:38:20: 36%|███▌ | 36/100 [00:00<00:00, 960.08 it/sec, obj=0.643] INFO - 20:38:20: 37%|███▋ | 37/100 [00:00<00:00, 954.73 it/sec, obj=0.616] INFO - 20:38:20: 38%|███▊ | 38/100 [00:00<00:00, 949.42 it/sec, obj=0.615] INFO - 20:38:20: 39%|███▉ | 39/100 [00:00<00:00, 944.43 it/sec, obj=0.615] INFO - 20:38:20: 40%|████ | 40/100 [00:00<00:00, 915.65 it/sec, obj=1.16] INFO - 20:38:20: 41%|████ | 41/100 [00:00<00:00, 902.72 it/sec, obj=2.87] INFO - 20:38:20: 42%|████▏ | 42/100 [00:00<00:00, 909.73 it/sec, obj=0.785] INFO - 20:38:20: 43%|████▎ | 43/100 [00:00<00:00, 898.80 it/sec, obj=0.644] INFO - 20:38:20: 44%|████▍ | 44/100 [00:00<00:00, 894.98 it/sec, obj=0.624] INFO - 20:38:20: 45%|████▌ | 45/100 [00:00<00:00, 891.95 it/sec, obj=0.615] INFO - 20:38:20: 46%|████▌ | 46/100 [00:00<00:00, 889.02 it/sec, obj=0.615] INFO - 20:38:20: 47%|████▋ | 47/100 [00:00<00:00, 886.55 it/sec, obj=0.615] INFO - 20:38:20: 48%|████▊ | 48/100 [00:00<00:00, 884.04 it/sec, obj=0.615] INFO - 20:38:20: 49%|████▉ | 49/100 [00:00<00:00, 863.90 it/sec, obj=0.838] INFO - 20:38:20: 50%|█████ | 50/100 [00:00<00:00, 856.39 it/sec, obj=0.656] INFO - 20:38:20: 51%|█████ | 51/100 [00:00<00:00, 854.35 it/sec, obj=0.639] INFO - 20:38:20: 52%|█████▏ | 52/100 [00:00<00:00, 852.77 it/sec, obj=0.616] INFO - 20:38:20: 53%|█████▎ | 53/100 [00:00<00:00, 851.43 it/sec, obj=0.615] INFO - 20:38:20: 54%|█████▍ | 54/100 [00:00<00:00, 849.88 it/sec, obj=0.615] INFO - 20:38:20: 55%|█████▌ | 55/100 [00:00<00:00, 848.98 it/sec, obj=0.615] INFO - 20:38:20: 56%|█████▌ | 56/100 [00:00<00:00, 847.84 it/sec, obj=0.615] INFO - 20:38:20: 57%|█████▋ | 57/100 [00:00<00:00, 846.54 it/sec, obj=0.615] INFO - 20:38:20: 58%|█████▊ | 58/100 [00:00<00:00, 836.14 it/sec, obj=0.625] INFO - 20:38:20: 59%|█████▉ | 59/100 [00:00<00:00, 831.79 it/sec, obj=2.87] INFO - 20:38:20: 60%|██████ | 60/100 [00:00<00:00, 837.16 it/sec, obj=0.616] INFO - 20:38:20: 61%|██████ | 61/100 [00:00<00:00, 836.19 it/sec, obj=0.615] INFO - 20:38:20: 62%|██████▏ | 62/100 [00:00<00:00, 834.98 it/sec, obj=0.615] INFO - 20:38:20: 63%|██████▎ | 63/100 [00:00<00:00, 834.27 it/sec, obj=0.615] INFO - 20:38:20: 64%|██████▍ | 64/100 [00:00<00:00, 833.93 it/sec, obj=0.615] INFO - 20:38:20: 65%|██████▌ | 65/100 [00:00<00:00, 833.55 it/sec, obj=0.615] INFO - 20:38:20: 66%|██████▌ | 66/100 [00:00<00:00, 836.99 it/sec, obj=0.615] INFO - 20:38:20: 67%|██████▋ | 67/100 [00:00<00:00, 833.20 it/sec, obj=0.745] INFO - 20:38:20: 68%|██████▊ | 68/100 [00:00<00:00, 828.46 it/sec, obj=-0.875] INFO - 20:38:20: 69%|██████▉ | 69/100 [00:00<00:00, 828.98 it/sec, obj=-0.267] INFO - 20:38:20: 70%|███████ | 70/100 [00:00<00:00, 832.19 it/sec, obj=-0.809] INFO - 20:38:20: 71%|███████ | 71/100 [00:00<00:00, 838.33 it/sec, obj=-0.868] INFO - 20:38:20: 72%|███████▏ | 72/100 [00:00<00:00, 844.56 it/sec, obj=-0.874] INFO - 20:38:20: 73%|███████▎ | 73/100 [00:00<00:00, 847.05 it/sec, obj=-0.266] INFO - 20:38:20: 74%|███████▍ | 74/100 [00:00<00:00, 849.91 it/sec, obj=0.135] INFO - 20:38:20: 75%|███████▌ | 75/100 [00:00<00:00, 852.52 it/sec, obj=0.577] INFO - 20:38:20: 76%|███████▌ | 76/100 [00:00<00:00, 858.65 it/sec, obj=0.288] INFO - 20:38:20: 77%|███████▋ | 77/100 [00:00<00:00, 851.01 it/sec, obj=1.42] INFO - 20:38:20: 78%|███████▊ | 78/100 [00:00<00:00, 849.57 it/sec, obj=-0.875] INFO - 20:38:20: 79%|███████▉ | 79/100 [00:00<00:00, 852.05 it/sec, obj=-0.267] INFO - 20:38:20: 80%|████████ | 80/100 [00:00<00:00, 857.58 it/sec, obj=-0.809] INFO - 20:38:20: 81%|████████ | 81/100 [00:00<00:00, 863.48 it/sec, obj=-0.868] INFO - 20:38:20: 82%|████████▏ | 82/100 [00:00<00:00, 869.21 it/sec, obj=-0.874] INFO - 20:38:20: 83%|████████▎ | 83/100 [00:00<00:00, 871.18 it/sec, obj=-0.266] INFO - 20:38:20: 84%|████████▍ | 84/100 [00:00<00:00, 873.38 it/sec, obj=0.135] INFO - 20:38:20: 85%|████████▌ | 85/100 [00:00<00:00, 875.68 it/sec, obj=0.577] INFO - 20:38:20: 86%|████████▌ | 86/100 [00:00<00:00, 880.96 it/sec, obj=0.288] WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. INFO - 20:38:20: 87%|████████▋ | 87/100 [00:00<00:00, 859.96 it/sec, obj=-0.267] INFO - 20:38:20: 88%|████████▊ | 88/100 [00:00<00:00, 864.81 it/sec, obj=-0.809] INFO - 20:38:20: 89%|████████▉ | 89/100 [00:00<00:00, 869.88 it/sec, obj=-0.868] INFO - 20:38:20: 90%|█████████ | 90/100 [00:00<00:00, 875.19 it/sec, obj=-0.874] INFO - 20:38:20: 91%|█████████ | 91/100 [00:00<00:00, 877.03 it/sec, obj=-0.266] INFO - 20:38:20: 92%|█████████▏| 92/100 [00:00<00:00, 878.89 it/sec, obj=0.135] INFO - 20:38:20: 93%|█████████▎| 93/100 [00:00<00:00, 880.61 it/sec, obj=0.577] WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. WARNING - 20:38:20: Optimization found no feasible point; the least infeasible point is selected. INFO - 20:38:20: Exporting the optimization problem to the file multistart.hdf5 INFO - 20:38:20: Optimization result: INFO - 20:38:20: Optimizer info: INFO - 20:38:20: Status: None INFO - 20:38:20: Message: None INFO - 20:38:20: Number of calls to the objective function by the optimizer: 0 INFO - 20:38:20: Solution: INFO - 20:38:20: The solution is feasible. INFO - 20:38:20: Objective: 0.6150998205402495 INFO - 20:38:20: Standardized constraints: INFO - 20:38:20: cstr = -0.7883188793606977 INFO - 20:38:20: Design space: INFO - 20:38:20: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:20: | Name | Lower bound | Value | Upper bound | Type | INFO - 20:38:20: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:20: | x | -1.5 | 0.5773502675245377 | 1.5 | float | INFO - 20:38:20: +------+-------------+--------------------+-------------+-------+ INFO - 20:38:20: *** End MDOScenario execution *** .. GENERATED FROM PYTHON SOURCE LINES 87-90 Lastly, we can plot the history of the objective, either by concatenating the 10 sub-optimization histories: .. GENERATED FROM PYTHON SOURCE LINES 90-94 .. code-block:: Python execute_post( scenario, post_name="BasicHistory", variable_names=["obj"], save=False, show=True ) .. image-sg:: /examples/optimizers/images/sphx_glr_plot_multistart_example_001.png :alt: History plot :srcset: /examples/optimizers/images/sphx_glr_plot_multistart_example_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 95-96 or by filtering the local optima (one per starting point): .. GENERATED FROM PYTHON SOURCE LINES 96-103 .. code-block:: Python execute_post( "multistart.hdf5", post_name="BasicHistory", variable_names=["obj"], save=False, show=True, ) .. image-sg:: /examples/optimizers/images/sphx_glr_plot_multistart_example_002.png :alt: History plot :srcset: /examples/optimizers/images/sphx_glr_plot_multistart_example_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 20:38:20: Importing the optimization problem from the file multistart.hdf5 .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.369 seconds) .. _sphx_glr_download_examples_optimizers_plot_multistart_example.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_multistart_example.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_multistart_example.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_multistart_example.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_