# Parametric scalable MDO problem - MDF¶

We define a ScalableProblem with a shared design variable of size 1 and 2 strongly coupled disciplines. The first one has a local design variable of size 1 and a coupling variable of size 2 while the second one has a local design variable of size 3 and a coupling variable of size 4.

We would like to solve this MDO problem by means of an MDF formulation.

from __future__ import annotations

from gemseo import configure_logger
from gemseo import execute_algo
from gemseo import execute_post
from gemseo import generate_n2_plot
from gemseo.problems.scalable.parametric.core.scalable_discipline_settings import (
ScalableDisciplineSettings,
)
from gemseo.problems.scalable.parametric.scalable_problem import ScalableProblem

configure_logger()

<RootLogger root (INFO)>


## Instantiation of the scalable problem¶

problem = ScalableProblem(
[ScalableDisciplineSettings(1, 2), ScalableDisciplineSettings(3, 4)], 1
)


## Display the coupling structure¶

generate_n2_plot(problem.disciplines, save=False, show=True)


## Solve the MDO using an MDF formulation¶

scenario = problem.create_scenario()
scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100})

    INFO - 16:25:34:
INFO - 16:25:34: *** Start MDOScenario execution ***
INFO - 16:25:34: MDOScenario
INFO - 16:25:34:    Disciplines: MainDiscipline ScalableDiscipline[1] ScalableDiscipline[2]
INFO - 16:25:34:    MDO formulation: MDF
INFO - 16:25:34: Optimization problem:
INFO - 16:25:34:    minimize f(x_0, x_1, x_2)
INFO - 16:25:34:    with respect to x_0, x_1, x_2
INFO - 16:25:34:    subject to constraints:
INFO - 16:25:34:       c_1(x_0, x_1, x_2) <= 0.0
INFO - 16:25:34:       c_2(x_0, x_1, x_2) <= 0.0
INFO - 16:25:34:    over the design space:
INFO - 16:25:34:    |                             Parameter space                             |
INFO - 16:25:34:    +------+-------------+-------+-------------+-------+----------------------+
INFO - 16:25:34:    | name | lower_bound | value | upper_bound | type  | Initial distribution |
INFO - 16:25:34:    +------+-------------+-------+-------------+-------+----------------------+
INFO - 16:25:34:    | x_0  |      0      |  0.5  |      1      | float |                      |
INFO - 16:25:34:    | x_1  |      0      |  0.5  |      1      | float |                      |
INFO - 16:25:34:    | x_2  |      0      |  0.5  |      1      | float |                      |
INFO - 16:25:34:    | x_2  |      0      |  0.5  |      1      | float |                      |
INFO - 16:25:34:    | x_2  |      0      |  0.5  |      1      | float |                      |
INFO - 16:25:34:    +------+-------------+-------+-------------+-------+----------------------+
INFO - 16:25:34: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 16:25:34: ...   0%|          | 0/100 [00:00<?, ?it]
INFO - 16:25:34: ...   1%|          | 1/100 [00:00<00:04, 20.73 it/sec, obj=1]
INFO - 16:25:34: ...   2%|▏         | 2/100 [00:00<00:09, 10.16 it/sec, obj=0.921]
INFO - 16:25:34: ...   3%|▎         | 3/100 [00:00<00:06, 15.19 it/sec, obj=0.513]
INFO - 16:25:34: ...   4%|▍         | 4/100 [00:00<00:09, 10.31 it/sec, obj=0.438]
INFO - 16:25:34: ...   5%|▌         | 5/100 [00:00<00:08, 10.95 it/sec, obj=0.418]
INFO - 16:25:34: ...   6%|▌         | 6/100 [00:00<00:08, 11.37 it/sec, obj=0.416]
INFO - 16:25:34: ...   7%|▋         | 7/100 [00:00<00:07, 11.68 it/sec, obj=0.415]
INFO - 16:25:35: ...   8%|▊         | 8/100 [00:00<00:07, 11.90 it/sec, obj=0.415]
INFO - 16:25:35: ...   9%|▉         | 9/100 [00:00<00:07, 12.09 it/sec, obj=0.415]
INFO - 16:25:35: ...  10%|█         | 10/100 [00:00<00:07, 12.23 it/sec, obj=0.415]
INFO - 16:25:35: ...  11%|█         | 11/100 [00:00<00:07, 12.36 it/sec, obj=0.415]
INFO - 16:25:35: ...  12%|█▏        | 12/100 [00:00<00:07, 12.47 it/sec, obj=0.415]
INFO - 16:25:35: ...  13%|█▎        | 13/100 [00:01<00:06, 12.55 it/sec, obj=0.415]
INFO - 16:25:35: ...  14%|█▍        | 14/100 [00:01<00:06, 13.50 it/sec, obj=Not evaluated]
INFO - 16:25:35: Optimization result:
INFO - 16:25:35:    Optimizer info:
INFO - 16:25:35:       Status: None
INFO - 16:25:35:       Message: Successive iterates of the design variables are closer than xtol_rel or xtol_abs. GEMSEO Stopped the driver
INFO - 16:25:35:       Number of calls to the objective function by the optimizer: 15
INFO - 16:25:35:    Solution:
INFO - 16:25:35:       The solution is feasible.
INFO - 16:25:35:       Objective: 0.4147214934939104
INFO - 16:25:35:       Standardized constraints:
INFO - 16:25:35:          c_1 = [-0.32430624 -0.43254418]
INFO - 16:25:35:          c_2 = [-1.11022302e-16 -2.51297019e-01 -2.35380057e-01 -4.99967998e-01]
INFO - 16:25:35:       +---------------------------------------------------------------------------------------+
INFO - 16:25:35:       |                                    Parameter space                                    |
INFO - 16:25:35:       +------+-------------+---------------------+-------------+-------+----------------------+
INFO - 16:25:35:       | name | lower_bound |        value        | upper_bound | type  | Initial distribution |
INFO - 16:25:35:       +------+-------------+---------------------+-------------+-------+----------------------+
INFO - 16:25:35:       | x_0  |      0      |  0.4836327085400906 |      1      | float |                      |
INFO - 16:25:35:       | x_1  |      0      |  0.9999999999999998 |      1      | float |                      |
INFO - 16:25:35:       | x_2  |      0      | 0.08671672721432457 |      1      | float |                      |
INFO - 16:25:35:       | x_2  |      0      |  0.9085358010297667 |      1      | float |                      |
INFO - 16:25:35:       | x_2  |      0      |  0.2480176715968743 |      1      | float |                      |
INFO - 16:25:35:       +------+-------------+---------------------+-------------+-------+----------------------+
INFO - 16:25:35: *** End MDOScenario execution (time: 0:00:01.056727) ***

{'max_iter': 100, 'algo': 'NLOPT_SLSQP'}


## Post-process the results¶

scenario.post_process("OptHistoryView", save=False, show=True)

/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.0.0/lib/python3.9/site-packages/genson/schema/strategies/base.py:42: UserWarning: Schema incompatible. Keyword 'description' has conflicting values ('The width and height of the figure in inches, e.g. (w, h).\nIf None, use the :attr:.OptPostProcessor.DEFAULT_FIG_SIZE\nof the post-processor.' vs. 'The width and height of the figure in inches, e.g. (w, h).\nIf None, use the :attr:.OptPostProcessor.DEFAULT_FIG_SIZE\nof the post-processor.'). Using 'The width and height of the figure in inches, e.g. (w, h).\nIf None, use the :attr:.OptPostProcessor.DEFAULT_FIG_SIZE\nof the post-processor.'
warn(('Schema incompatible. Keyword {0!r} has conflicting '

<gemseo.post.opt_history_view.OptHistoryView object at 0x7fea489c2760>


## Solve the associated quadratic programming problem¶

problem = problem.create_quadratic_programming_problem()
execute_algo(problem, algo_name="NLOPT_SLSQP", max_iter=100)

    INFO - 16:25:36: Optimization problem:
INFO - 16:25:36:    minimize f = 0.5x'Qx + c'x + d
INFO - 16:25:36:    with respect to x
INFO - 16:25:36:    subject to constraints:
INFO - 16:25:36:       g: Ax-b <= 0 <= 0.0
INFO - 16:25:36:    over the design space:
INFO - 16:25:36:    +------+-------------+-------+-------------+-------+
INFO - 16:25:36:    | name | lower_bound | value | upper_bound | type  |
INFO - 16:25:36:    +------+-------------+-------+-------------+-------+
INFO - 16:25:36:    | x[0] |      0      |  0.5  |      1      | float |
INFO - 16:25:36:    | x[1] |      0      |  0.5  |      1      | float |
INFO - 16:25:36:    | x[2] |      0      |  0.5  |      1      | float |
INFO - 16:25:36:    | x[3] |      0      |  0.5  |      1      | float |
INFO - 16:25:36:    | x[4] |      0      |  0.5  |      1      | float |
INFO - 16:25:36:    +------+-------------+-------+-------------+-------+
INFO - 16:25:36: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 16:25:36: ...   0%|          | 0/100 [00:00<?, ?it]
INFO - 16:25:36: ...   1%|          | 1/100 [00:00<00:00, 2056.03 it/sec, obj=1]
INFO - 16:25:36: ...   2%|▏         | 2/100 [00:00<00:00, 522.13 it/sec, obj=0.921]
INFO - 16:25:36: ...   3%|▎         | 3/100 [00:00<00:00, 732.93 it/sec, obj=0.513]
INFO - 16:25:36: ...   4%|▍         | 4/100 [00:00<00:00, 509.34 it/sec, obj=0.438]
INFO - 16:25:36: ...   5%|▌         | 5/100 [00:00<00:00, 520.82 it/sec, obj=0.418]
INFO - 16:25:36: ...   6%|▌         | 6/100 [00:00<00:00, 526.42 it/sec, obj=0.416]
INFO - 16:25:36: ...   7%|▋         | 7/100 [00:00<00:00, 533.06 it/sec, obj=0.415]
INFO - 16:25:36: ...   8%|▊         | 8/100 [00:00<00:00, 538.75 it/sec, obj=0.415]
INFO - 16:25:36: ...   9%|▉         | 9/100 [00:00<00:00, 541.53 it/sec, obj=0.415]
INFO - 16:25:36: ...  10%|█         | 10/100 [00:00<00:00, 545.80 it/sec, obj=0.415]
INFO - 16:25:36: ...  11%|█         | 11/100 [00:00<00:00, 548.18 it/sec, obj=0.415]
INFO - 16:25:36: ...  12%|█▏        | 12/100 [00:00<00:00, 549.95 it/sec, obj=0.415]
INFO - 16:25:36: ...  13%|█▎        | 13/100 [00:00<00:00, 589.06 it/sec, obj=0.415]
INFO - 16:25:36: Optimization result:
INFO - 16:25:36:    Optimizer info:
INFO - 16:25:36:       Status: None
INFO - 16:25:36:       Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 16:25:36:       Number of calls to the objective function by the optimizer: 15
INFO - 16:25:36:    Solution:
INFO - 16:25:36:       The solution is feasible.
INFO - 16:25:36:       Objective: 0.414721553468123
INFO - 16:25:36:       Standardized constraints:
INFO - 16:25:36:          g = [-3.24306238e-01 -4.32544172e-01 -4.44089210e-16 -2.51297007e-01
INFO - 16:25:36:  -2.35380057e-01 -4.99968031e-01]
INFO - 16:25:36:       Design space:
INFO - 16:25:36:       +------+-------------+---------------------+-------------+-------+
INFO - 16:25:36:       | name | lower_bound |        value        | upper_bound | type  |
INFO - 16:25:36:       +------+-------------+---------------------+-------------+-------+
INFO - 16:25:36:       | x[0] |      0      |  0.4836327595359132 |      1      | float |
INFO - 16:25:36:       | x[1] |      0      |  0.9999999999999998 |      1      | float |
INFO - 16:25:36:       | x[2] |      0      | 0.08671677713547089 |      1      | float |
INFO - 16:25:36:       | x[3] |      0      |  0.9085357909356101 |      1      | float |
INFO - 16:25:36:       | x[4] |      0      |  0.2480176979962943 |      1      | float |
INFO - 16:25:36:       +------+-------------+---------------------+-------------+-------+

Optimization result:
Design variables: [0.48363276 1.         0.08671678 0.90853579 0.2480177 ]
Objective function: 0.414721553468123
Feasible solution: True


## Post-process the results¶

execute_post(problem, "OptHistoryView", save=False, show=True)

<gemseo.post.opt_history_view.OptHistoryView object at 0x7fea48558040>


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

Gallery generated by Sphinx-Gallery