# 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 - 13:55:06:
INFO - 13:55:06: *** Start MDOScenario execution ***
INFO - 13:55:06: MDOScenario
INFO - 13:55:06:    Disciplines: MainDiscipline ScalableDiscipline[1] ScalableDiscipline[2]
INFO - 13:55:06:    MDO formulation: MDF
INFO - 13:55:06: Optimization problem:
INFO - 13:55:06:    minimize f(x_0, x_1, x_2)
INFO - 13:55:06:    with respect to x_0, x_1, x_2
INFO - 13:55:06:    subject to constraints:
INFO - 13:55:06:       c_1(x_0, x_1, x_2) <= 0.0
INFO - 13:55:06:       c_2(x_0, x_1, x_2) <= 0.0
INFO - 13:55:06:    over the design space:
INFO - 13:55:06:       +--------+-------------+-------+-------------+-------+
INFO - 13:55:06:       | Name   | Lower bound | Value | Upper bound | Type  |
INFO - 13:55:06:       +--------+-------------+-------+-------------+-------+
INFO - 13:55:06:       | x_0    |      0      |  0.5  |      1      | float |
INFO - 13:55:06:       | x_1    |      0      |  0.5  |      1      | float |
INFO - 13:55:06:       | x_2[0] |      0      |  0.5  |      1      | float |
INFO - 13:55:06:       | x_2[1] |      0      |  0.5  |      1      | float |
INFO - 13:55:06:       | x_2[2] |      0      |  0.5  |      1      | float |
INFO - 13:55:06:       +--------+-------------+-------+-------------+-------+
INFO - 13:55:06: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 13:55:06:      1%|          | 1/100 [00:00<00:05, 19.31 it/sec, obj=3.07]
WARNING - 13:55:06: MDAJacobi has reached its maximum number of iterations but the normed residual 2.1168696144554684e-06 is still above the tolerance 1e-06.
INFO - 13:55:07:      2%|▏         | 2/100 [00:00<00:12,  7.86 it/sec, obj=1.21]
INFO - 13:55:07:      3%|▎         | 3/100 [00:00<00:10,  8.95 it/sec, obj=0.991]
INFO - 13:55:07:      4%|▍         | 4/100 [00:00<00:09,  9.71 it/sec, obj=0.986]
INFO - 13:55:07:      5%|▌         | 5/100 [00:00<00:09, 10.21 it/sec, obj=0.982]
INFO - 13:55:07:      6%|▌         | 6/100 [00:00<00:08, 10.58 it/sec, obj=0.971]
INFO - 13:55:07:      7%|▋         | 7/100 [00:00<00:08, 10.84 it/sec, obj=0.97]
INFO - 13:55:07:      8%|▊         | 8/100 [00:00<00:08, 11.03 it/sec, obj=0.969]
INFO - 13:55:07:      9%|▉         | 9/100 [00:00<00:08, 11.19 it/sec, obj=0.969]
INFO - 13:55:07:     10%|█         | 10/100 [00:00<00:07, 11.30 it/sec, obj=0.969]
INFO - 13:55:07:     11%|█         | 11/100 [00:00<00:07, 12.41 it/sec, obj=Not evaluated]
INFO - 13:55:07: Optimization result:
INFO - 13:55:07:    Optimizer info:
INFO - 13:55:07:       Status: None
INFO - 13:55:07:       Message: Successive iterates of the design variables are closer than xtol_rel or xtol_abs. GEMSEO Stopped the driver
INFO - 13:55:07:       Number of calls to the objective function by the optimizer: 11
INFO - 13:55:07:    Solution:
INFO - 13:55:07:       The solution is feasible.
INFO - 13:55:07:       Objective: 0.9692177673322224
INFO - 13:55:07:       Standardized constraints:
INFO - 13:55:07:          c_1 = [-0.68664086 -0.21340455]
INFO - 13:55:07:          c_2 = [-7.31227816e-01 -1.68967484e-01 -2.32695971e-01  1.19487753e-12]
INFO - 13:55:07:       Design space:
INFO - 13:55:07:          +--------+-------------+-----------------------+-------------+-------+
INFO - 13:55:07:          | Name   | Lower bound |         Value         | Upper bound | Type  |
INFO - 13:55:07:          +--------+-------------+-----------------------+-------------+-------+
INFO - 13:55:07:          | x_0    |      0      |   0.7071349698120538  |      1      | float |
INFO - 13:55:07:          | x_1    |      0      |   0.9999999999999997  |      1      | float |
INFO - 13:55:07:          | x_2[0] |      0      | 2.906542539477308e-16 |      1      | float |
INFO - 13:55:07:          | x_2[1] |      0      |   0.5233175560073929  |      1      | float |
INFO - 13:55:07:          | x_2[2] |      0      | 6.286235338479938e-31 |      1      | float |
INFO - 13:55:07:          +--------+-------------+-----------------------+-------------+-------+
INFO - 13:55:07: *** End MDOScenario execution (time: 0:00:00.903895) ***

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


## Post-process the results¶

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

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


## Solve the associated quadratic programming problem¶

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

    INFO - 13:55:08: Optimization problem:
INFO - 13:55:08:    minimize f = 0.5x'Qx + c'x + d
INFO - 13:55:08:    with respect to x
INFO - 13:55:08:    subject to constraints:
INFO - 13:55:08:       g: Ax-b <= 0 <= 0.0
INFO - 13:55:08:    over the design space:
INFO - 13:55:08:       +------+-------------+-------+-------------+-------+
INFO - 13:55:08:       | Name | Lower bound | Value | Upper bound | Type  |
INFO - 13:55:08:       +------+-------------+-------+-------------+-------+
INFO - 13:55:08:       | x[0] |      0      |  0.5  |      1      | float |
INFO - 13:55:08:       | x[1] |      0      |  0.5  |      1      | float |
INFO - 13:55:08:       | x[2] |      0      |  0.5  |      1      | float |
INFO - 13:55:08:       | x[3] |      0      |  0.5  |      1      | float |
INFO - 13:55:08:       | x[4] |      0      |  0.5  |      1      | float |
INFO - 13:55:08:       +------+-------------+-------+-------------+-------+
INFO - 13:55:08: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 13:55:08:      1%|          | 1/100 [00:00<00:00, 2317.30 it/sec, obj=3.07]
INFO - 13:55:08:      2%|▏         | 2/100 [00:00<00:00, 649.57 it/sec, obj=1.21]
INFO - 13:55:08:      3%|▎         | 3/100 [00:00<00:00, 643.17 it/sec, obj=0.991]
INFO - 13:55:08:      4%|▍         | 4/100 [00:00<00:00, 639.86 it/sec, obj=0.986]
INFO - 13:55:08:      5%|▌         | 5/100 [00:00<00:00, 643.91 it/sec, obj=0.982]
INFO - 13:55:08:      6%|▌         | 6/100 [00:00<00:00, 635.02 it/sec, obj=0.971]
INFO - 13:55:08:      7%|▋         | 7/100 [00:00<00:00, 637.21 it/sec, obj=0.97]
ERROR - 13:55:08: NLopt run failed: NLopt roundoff-limited, RoundoffLimited
Traceback (most recent call last):
File "/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.3.0/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/5.3.0/lib/python3.9/site-packages/nlopt/nlopt.py", line 335, in optimize
return _nlopt.opt_optimize(self, *args)
nlopt.RoundoffLimited: NLopt roundoff-limited
INFO - 13:55:08:      8%|▊         | 8/100 [00:00<00:00, 610.18 it/sec, obj=0.969]
INFO - 13:55:08: Optimization result:
INFO - 13:55:08:    Optimizer info:
INFO - 13:55:08:       Status: None
INFO - 13:55:08:       Message:  GEMSEO Stopped the driver
INFO - 13:55:08:       Number of calls to the objective function by the optimizer: 9
INFO - 13:55:08:    Solution:
INFO - 13:55:08:       The solution is feasible.
INFO - 13:55:08:       Objective: 0.9692176254005034
INFO - 13:55:08:       Standardized constraints:
INFO - 13:55:08:          g = [-6.86640980e-01 -2.13404451e-01 -7.31227677e-01 -1.68967471e-01
INFO - 13:55:08:  -2.32695870e-01 -2.22044605e-15]
INFO - 13:55:08:       Design space:
INFO - 13:55:08:          +------+-------------+--------------------+-------------+-------+
INFO - 13:55:08:          | Name | Lower bound |       Value        | Upper bound | Type  |
INFO - 13:55:08:          +------+-------------+--------------------+-------------+-------+
INFO - 13:55:08:          | x[0] |      0      | 0.7071348743877915 |      1      | float |
INFO - 13:55:08:          | x[1] |      0      |         1          |      1      | float |
INFO - 13:55:08:          | x[2] |      0      |         0          |      1      | float |
INFO - 13:55:08:          | x[3] |      0      | 0.5233180438726639 |      1      | float |
INFO - 13:55:08:          | x[4] |      0      |         0          |      1      | float |
INFO - 13:55:08:          +------+-------------+--------------------+-------------+-------+

Optimization result:
• Design variables: [0.70713487 1. 0. 0.52331804 0. ]
• Objective function: 0.9692176254005034
• Feasible solution: True

## Post-process the results¶

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

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


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

Gallery generated by Sphinx-Gallery