.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/multi_objective/plot_pareto_front_binhkorn_bilevel.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_multi_objective_plot_pareto_front_binhkorn_bilevel.py: Pareto front on the Binh and Korn problem using a BiLevel formulation ===================================================================== In this example, we illustrate the computation of a Pareto front plot for the Binh and Korn problem. We use a BiLevel formulation in order to only compute the Pareto-optimal points. .. GENERATED FROM PYTHON SOURCE LINES 31-35 Import ------ The first step is to import some high-level functions and to configure the logger. .. GENERATED FROM PYTHON SOURCE LINES 35-49 .. code-block:: Python from __future__ import annotations from logging import WARNING from numpy import array from gemseo import configure_logger from gemseo import create_design_space from gemseo import create_discipline from gemseo import create_scenario configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 50-56 Definition of the disciplines ----------------------------- In this example, we create the Binh and Korn disciplines from scratch by declaring their expressions and using the :class:`.AnalyticDiscipline`. .. GENERATED FROM PYTHON SOURCE LINES 56-64 .. code-block:: Python expr_binh_korn = { "obj1": "4*x1**2 + 4*x2**2", "obj2": "(x1-5.)**2 + (x2-5.)**2", "cstr1": "(x1-5.)**2 + x2**2 - 25.", "cstr2": "-(x1-8.)**2 - (x2+3)**2 + 7.7", } .. GENERATED FROM PYTHON SOURCE LINES 65-67 This constraint will be used to set `obj1` to a target value for the lower-level scenario. .. GENERATED FROM PYTHON SOURCE LINES 67-70 .. code-block:: Python expr_cstr_obj1_target = {"cstr3": "obj1 - obj1_target"} .. GENERATED FROM PYTHON SOURCE LINES 71-75 Instantiation of the disciplines -------------------------------- Here, we create the disciplines from their expressions. .. GENERATED FROM PYTHON SOURCE LINES 75-83 .. code-block:: Python discipline_binh_korn = create_discipline( "AnalyticDiscipline", expressions=expr_binh_korn ) discipline_cstr_obj1 = create_discipline( "AnalyticDiscipline", expressions=expr_cstr_obj1_target ) .. GENERATED FROM PYTHON SOURCE LINES 84-86 Definition of the lower-level design space ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 86-96 .. code-block:: Python design_space = create_design_space() design_space.add_variable("x1", l_b=array([0.0]), u_b=array([5.0]), value=array([2.0])) design_space.add_variable("x2", l_b=array([-5.0]), u_b=array([3.0]), value=array([2.0])) disciplines = [ discipline_binh_korn, discipline_cstr_obj1, ] .. GENERATED FROM PYTHON SOURCE LINES 97-100 Creation of the lower-level scenario ------------------------------------ This scenario aims at finding the `obj2` optimal value for a specific value of `obj1`. .. GENERATED FROM PYTHON SOURCE LINES 100-110 .. code-block:: Python sub_scenario = create_scenario( disciplines, "DisciplinaryOpt", "obj2", design_space, ) sub_scenario.default_inputs = {"algo": "NLOPT_SLSQP", "max_iter": 100} .. GENERATED FROM PYTHON SOURCE LINES 111-112 We add the Binh and Korn problem constraints. .. GENERATED FROM PYTHON SOURCE LINES 112-115 .. code-block:: Python sub_scenario.add_constraint("cstr1", constraint_type="ineq") sub_scenario.add_constraint("cstr2", constraint_type="ineq") .. GENERATED FROM PYTHON SOURCE LINES 116-120 Creation of the design space for the system-level scenario ---------------------------------------------------------- At the system level, we will fix a target for the `obj1` value of the lower-level scenario. .. GENERATED FROM PYTHON SOURCE LINES 120-125 .. code-block:: Python system_design_space = create_design_space() system_design_space.add_variable( "obj1_target", l_b=array([0.1]), u_b=array([100.0]), value=array([1.0]) ) .. GENERATED FROM PYTHON SOURCE LINES 126-133 Creation of the system-level DOE Scenario ----------------------------------------- The system-level scenario will perform a DOE over the `obj1_target` variable. We will use the `BiLevel` formulation to nest the lower-level scenario into the DOE. The log level for the sub scenarios is set to `WARNING` to avoid getting the complete log of each sub scenario, which would be too verbose. Set it to `INFO` if you wish to keep the logs of each sub scenario as well. .. GENERATED FROM PYTHON SOURCE LINES 133-143 .. code-block:: Python system_scenario = create_scenario( sub_scenario, "BiLevel", "obj1", system_design_space, scenario_type="DOE", sub_scenarios_log_level=WARNING, ) .. rst-class:: sphx-glr-script-out .. code-block:: none WARNING - 08:56:07: No strongly coupled disciplines detected, MDA1 is deactivated in the BiLevel formulation .. GENERATED FROM PYTHON SOURCE LINES 144-153 Add the system-level constraint and observables ----------------------------------------------- Here, we add the constraint on the `obj1_target`, this way we make sure that the lower-level scenario will respect the target imposed by the system. The BiLevel formulation will automatically add the constraints from the system-level to the lower-level, if you wish to handle the constraints manually, pass `apply_cstr_tosub_scenarios=False` as an argument to `create_scenario`. Note that `obj2` shall be added as an observable of `scenario_doe`, otherwise it cannot be used by the ParetoFront post-processing. .. GENERATED FROM PYTHON SOURCE LINES 153-156 .. code-block:: Python system_scenario.add_constraint("cstr3") system_scenario.add_observable("obj2") system_scenario.xdsmize() .. raw:: html


.. GENERATED FROM PYTHON SOURCE LINES 157-160 Run the scenario ---------------- Finally, we run a full-factorial DOE using 100 samples and run the post-processing. .. GENERATED FROM PYTHON SOURCE LINES 160-165 .. code-block:: Python run_inputs = {"n_samples": 50, "algo": "fullfact"} system_scenario.execute(run_inputs) system_scenario.post_process( "ParetoFront", objectives=["obj1", "obj2"], save=False, show=True ) .. image-sg:: /examples/multi_objective/images/sphx_glr_plot_pareto_front_binhkorn_bilevel_001.png :alt: Pareto front :srcset: /examples/multi_objective/images/sphx_glr_plot_pareto_front_binhkorn_bilevel_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 08:56:07: INFO - 08:56:07: *** Start DOEScenario execution *** INFO - 08:56:07: DOEScenario INFO - 08:56:07: Disciplines: MDOScenario INFO - 08:56:07: MDO formulation: BiLevel INFO - 08:56:07: Optimization problem: INFO - 08:56:07: minimize obj1(obj1_target) INFO - 08:56:07: with respect to obj1_target INFO - 08:56:07: subject to constraints: INFO - 08:56:07: cstr3(obj1_target) == 0.0 INFO - 08:56:07: over the design space: INFO - 08:56:07: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:07: | Name | Lower bound | Value | Upper bound | Type | INFO - 08:56:07: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:07: | obj1_target | 0.1 | 1 | 100 | float | INFO - 08:56:07: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:07: Solving optimization problem with algorithm fullfact: INFO - 08:56:07: 2%|▏ | 1/50 [00:00<00:06, 7.68 it/sec, obj=0.108] INFO - 08:56:07: 4%|▍ | 2/50 [00:00<00:04, 10.15 it/sec, obj=2.14] INFO - 08:56:07: 6%|▌ | 3/50 [00:00<00:03, 11.96 it/sec, obj=4.18] INFO - 08:56:07: 8%|▊ | 4/50 [00:00<00:03, 13.22 it/sec, obj=6.22] INFO - 08:56:07: 10%|█ | 5/50 [00:00<00:03, 14.12 it/sec, obj=8.26] INFO - 08:56:07: 12%|█▏ | 6/50 [00:00<00:03, 14.48 it/sec, obj=10.3] INFO - 08:56:07: 14%|█▍ | 7/50 [00:00<00:02, 14.69 it/sec, obj=12.3] INFO - 08:56:07: 16%|█▌ | 8/50 [00:00<00:02, 14.82 it/sec, obj=14.4] INFO - 08:56:07: 18%|█▊ | 9/50 [00:00<00:02, 14.97 it/sec, obj=16.4] INFO - 08:56:07: 20%|██ | 10/50 [00:00<00:02, 15.07 it/sec, obj=18.5] INFO - 08:56:07: 22%|██▏ | 11/50 [00:00<00:02, 15.35 it/sec, obj=20.5] INFO - 08:56:07: 24%|██▍ | 12/50 [00:00<00:02, 15.60 it/sec, obj=22.5] INFO - 08:56:07: 26%|██▌ | 13/50 [00:00<00:02, 15.78 it/sec, obj=24.6] INFO - 08:56:08: 28%|██▊ | 14/50 [00:00<00:02, 15.94 it/sec, obj=26.6] INFO - 08:56:08: 30%|███ | 15/50 [00:00<00:02, 16.05 it/sec, obj=28.6] INFO - 08:56:08: 32%|███▏ | 16/50 [00:00<00:02, 16.15 it/sec, obj=30.7] INFO - 08:56:08: 34%|███▍ | 17/50 [00:01<00:02, 16.22 it/sec, obj=32.7] INFO - 08:56:08: 36%|███▌ | 18/50 [00:01<00:01, 16.25 it/sec, obj=34.8] INFO - 08:56:08: 38%|███▊ | 19/50 [00:01<00:01, 16.30 it/sec, obj=36.8] INFO - 08:56:08: 40%|████ | 20/50 [00:01<00:01, 16.01 it/sec, obj=38.8] INFO - 08:56:08: 42%|████▏ | 21/50 [00:01<00:01, 16.04 it/sec, obj=40.9] INFO - 08:56:08: 44%|████▍ | 22/50 [00:01<00:01, 16.06 it/sec, obj=42.9] INFO - 08:56:08: 46%|████▌ | 23/50 [00:01<00:01, 15.98 it/sec, obj=45] INFO - 08:56:08: 48%|████▊ | 24/50 [00:01<00:01, 15.98 it/sec, obj=47] INFO - 08:56:08: 50%|█████ | 25/50 [00:01<00:01, 15.99 it/sec, obj=49] INFO - 08:56:08: 52%|█████▏ | 26/50 [00:01<00:01, 15.90 it/sec, obj=51.1] INFO - 08:56:08: 54%|█████▍ | 27/50 [00:01<00:01, 15.89 it/sec, obj=53.1] INFO - 08:56:08: 56%|█████▌ | 28/50 [00:01<00:01, 15.87 it/sec, obj=55.1] INFO - 08:56:09: 58%|█████▊ | 29/50 [00:01<00:01, 15.85 it/sec, obj=57.2] INFO - 08:56:09: 60%|██████ | 30/50 [00:01<00:01, 15.83 it/sec, obj=59.2] INFO - 08:56:09: 62%|██████▏ | 31/50 [00:01<00:01, 15.79 it/sec, obj=61.3] INFO - 08:56:09: 64%|██████▍ | 32/50 [00:02<00:01, 15.74 it/sec, obj=63.3] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 66%|██████▌ | 33/50 [00:02<00:01, 15.71 it/sec, obj=65.3] INFO - 08:56:09: 68%|██████▊ | 34/50 [00:02<00:01, 15.67 it/sec, obj=67.4] INFO - 08:56:09: 70%|███████ | 35/50 [00:02<00:00, 15.63 it/sec, obj=69.4] INFO - 08:56:09: 72%|███████▏ | 36/50 [00:02<00:00, 15.61 it/sec, obj=71.5] INFO - 08:56:09: 74%|███████▍ | 37/50 [00:02<00:00, 15.63 it/sec, obj=73.5] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 76%|███████▌ | 38/50 [00:02<00:00, 15.65 it/sec, obj=75.5] INFO - 08:56:09: 78%|███████▊ | 39/50 [00:02<00:00, 15.67 it/sec, obj=77.6] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 80%|████████ | 40/50 [00:02<00:00, 15.71 it/sec, obj=79.6] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 82%|████████▏ | 41/50 [00:02<00:00, 15.75 it/sec, obj=81.7] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 84%|████████▍ | 42/50 [00:02<00:00, 15.79 it/sec, obj=83.7] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 86%|████████▌ | 43/50 [00:02<00:00, 15.81 it/sec, obj=85.7] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:09: 88%|████████▊ | 44/50 [00:02<00:00, 15.84 it/sec, obj=87.8] ERROR - 08:56:09: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:10: 90%|█████████ | 45/50 [00:02<00:00, 15.87 it/sec, obj=89.8] ERROR - 08:56:10: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:10: 92%|█████████▏| 46/50 [00:02<00:00, 15.89 it/sec, obj=91.8] INFO - 08:56:10: 94%|█████████▍| 47/50 [00:02<00:00, 15.89 it/sec, obj=93.9] ERROR - 08:56:10: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:10: 96%|█████████▌| 48/50 [00:03<00:00, 15.91 it/sec, obj=95.9] ERROR - 08:56:10: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:10: 98%|█████████▊| 49/50 [00:03<00:00, 15.92 it/sec, obj=98] ERROR - 08:56:10: NLopt run failed: NLopt roundoff-limited, RoundoffLimited Traceback (most recent call last): File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/gemseo/algos/opt/lib_nlopt.py", line 498, in _run nlopt_problem.optimize(x_0.real) File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/develop/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize return _nlopt.opt_optimize(self, *args) nlopt.RoundoffLimited: NLopt roundoff-limited INFO - 08:56:10: 100%|██████████| 50/50 [00:03<00:00, 15.09 it/sec, obj=100] INFO - 08:56:10: Optimization result: INFO - 08:56:10: Optimizer info: INFO - 08:56:10: Status: None INFO - 08:56:10: Message: None INFO - 08:56:10: Number of calls to the objective function by the optimizer: 50 INFO - 08:56:10: Solution: INFO - 08:56:10: The solution is feasible. INFO - 08:56:10: Objective: 0.10832777706440924 INFO - 08:56:10: Standardized constraints: INFO - 08:56:10: cstr3 = 0.008327777064409236 INFO - 08:56:10: Design space: INFO - 08:56:10: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:10: | Name | Lower bound | Value | Upper bound | Type | INFO - 08:56:10: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:10: | obj1_target | 0.1 | 0.1 | 100 | float | INFO - 08:56:10: +-------------+-------------+-------+-------------+-------+ INFO - 08:56:10: *** End DOEScenario execution (time: 0:00:03.327132) *** .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 3.587 seconds) .. _sphx_glr_download_examples_multi_objective_plot_pareto_front_binhkorn_bilevel.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_pareto_front_binhkorn_bilevel.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_pareto_front_binhkorn_bilevel.py ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_