.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples/constraint_aggregation/plot_constraint_aggregation_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_constraint_aggregation_plot_constraint_aggregation_example.py: Examples for constraint aggregation =================================== .. GENERATED FROM PYTHON SOURCE LINES 20-31 .. code-block:: default from __future__ import annotations from copy import deepcopy from gemseo import configure_logger from gemseo import create_scenario from gemseo.algos.design_space import DesignSpace from gemseo.disciplines.analytic import AnalyticDiscipline from gemseo.disciplines.concatenater import Concatenater configure_logger() .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 32-33 Number of constraints .. GENERATED FROM PYTHON SOURCE LINES 33-35 .. code-block:: default N = 100 .. GENERATED FROM PYTHON SOURCE LINES 36-37 Build the discipline .. GENERATED FROM PYTHON SOURCE LINES 37-47 .. code-block:: default constraint_names = [f"g_{k + 1}" for k in range(N)] function_names = ["o"] + constraint_names function_expressions = ["y"] + [f"{k + 1}*x*exp(1-{k + 1}*x)-y" for k in range(N)] disc = AnalyticDiscipline( name="function", expressions=dict(zip(function_names, function_expressions)), ) # This step is required to put all constraints needed for aggregation in one variable. concat = Concatenater(constraint_names, "g") .. GENERATED FROM PYTHON SOURCE LINES 48-49 Build the design space .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: default ds = DesignSpace() ds.add_variable( "x", l_b=0.0, u_b=1, value=1.0 / N / 2.0, var_type=DesignSpace.DesignVariableType.FLOAT, ) ds.add_variable( "y", l_b=0.0, u_b=1, value=1, var_type=DesignSpace.DesignVariableType.FLOAT ) ds_new = deepcopy(ds) .. GENERATED FROM PYTHON SOURCE LINES 63-64 Build the optimization solver options .. GENERATED FROM PYTHON SOURCE LINES 64-83 .. code-block:: default max_iter = 1000 ineq_tol = 1e-5 convergence_tol = 1e-8 normalize = True algo_options = { "algo": "NLOPT_MMA", "max_iter": max_iter, "algo_options": { "ineq_tolerance": ineq_tol, "eq_tolerance": ineq_tol, "xtol_rel": convergence_tol, "xtol_abs": convergence_tol, "ftol_rel": convergence_tol, "ftol_abs": convergence_tol, "ctol_abs": convergence_tol, "normalize_design_space": normalize, }, } .. GENERATED FROM PYTHON SOURCE LINES 84-85 Build the optimization scenario .. GENERATED FROM PYTHON SOURCE LINES 85-98 .. code-block:: default original_scenario = create_scenario( disciplines=[disc, concat], formulation="DisciplinaryOpt", objective_name="o", design_space=ds, maximize_objective=False, ) original_scenario.add_constraint("g", "ineq") original_scenario.execute(algo_options) # Without constraint aggregation MMA iterations become more expensive, when a # large number of constraints are activated. .. rst-class:: sphx-glr-script-out .. code-block:: none INFO - 13:50:51: INFO - 13:50:51: *** Start MDOScenario execution *** INFO - 13:50:51: MDOScenario INFO - 13:50:51: Disciplines: Concatenater function INFO - 13:50:51: MDO formulation: DisciplinaryOpt INFO - 13:50:51: Optimization problem: INFO - 13:50:51: minimize o(x, y) INFO - 13:50:51: with respect to x, y INFO - 13:50:51: subject to constraints: INFO - 13:50:51: g(x, y) <= 0.0 INFO - 13:50:51: over the design space: INFO - 13:50:51: +------+-------------+-------+-------------+-------+ INFO - 13:50:51: | name | lower_bound | value | upper_bound | type | INFO - 13:50:51: +------+-------------+-------+-------------+-------+ INFO - 13:50:51: | x | 0 | 0.005 | 1 | float | INFO - 13:50:51: | y | 0 | 1 | 1 | float | INFO - 13:50:51: +------+-------------+-------+-------------+-------+ INFO - 13:50:51: Solving optimization problem with algorithm NLOPT_MMA: INFO - 13:50:51: ... 0%| | 0/1000 [00:00` .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_constraint_aggregation_example.ipynb ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_