Note
Go to the end to download the full example code
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:51:39:
INFO - 13:51:39: *** Start MDOScenario execution ***
INFO - 13:51:39: MDOScenario
INFO - 13:51:39: Disciplines: MainDiscipline ScalableDiscipline[1] ScalableDiscipline[2]
INFO - 13:51:39: MDO formulation: MDF
INFO - 13:51:39: Optimization problem:
INFO - 13:51:39: minimize f(x_0, x_1, x_2)
INFO - 13:51:39: with respect to x_0, x_1, x_2
INFO - 13:51:39: subject to constraints:
INFO - 13:51:39: c_1(x_0, x_1, x_2) <= 0.0
INFO - 13:51:39: c_2(x_0, x_1, x_2) <= 0.0
INFO - 13:51:39: over the design space:
INFO - 13:51:39: +--------+-------------+-------+-------------+-------+----------------------+
INFO - 13:51:39: | name | lower_bound | value | upper_bound | type | Initial distribution |
INFO - 13:51:39: +--------+-------------+-------+-------------+-------+----------------------+
INFO - 13:51:39: | x_0 | 0 | 0.5 | 1 | float | |
INFO - 13:51:39: | x_1 | 0 | 0.5 | 1 | float | |
INFO - 13:51:39: | x_2[0] | 0 | 0.5 | 1 | float | |
INFO - 13:51:39: | x_2[1] | 0 | 0.5 | 1 | float | |
INFO - 13:51:39: | x_2[2] | 0 | 0.5 | 1 | float | |
INFO - 13:51:39: +--------+-------------+-------+-------------+-------+----------------------+
INFO - 13:51:39: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 13:51:39: ... 0%| | 0/100 [00:00<?, ?it]
INFO - 13:51:40: ... 1%| | 1/100 [00:00<00:04, 20.92 it/sec, obj=1]
INFO - 13:51:40: ... 2%|▏ | 2/100 [00:00<00:10, 9.56 it/sec, obj=0.921]
INFO - 13:51:40: ... 3%|▎ | 3/100 [00:00<00:06, 14.31 it/sec, obj=0.513]
INFO - 13:51:40: ... 4%|▍ | 4/100 [00:00<00:09, 9.82 it/sec, obj=0.438]
INFO - 13:51:40: ... 5%|▌ | 5/100 [00:00<00:09, 10.36 it/sec, obj=0.418]
INFO - 13:51:40: ... 6%|▌ | 6/100 [00:00<00:08, 10.77 it/sec, obj=0.416]
INFO - 13:51:40: ... 7%|▋ | 7/100 [00:00<00:08, 11.05 it/sec, obj=0.415]
INFO - 13:51:40: ... 8%|▊ | 8/100 [00:00<00:08, 11.28 it/sec, obj=0.415]
INFO - 13:51:40: ... 9%|▉ | 9/100 [00:00<00:07, 11.47 it/sec, obj=0.415]
INFO - 13:51:40: ... 10%|█ | 10/100 [00:00<00:07, 11.62 it/sec, obj=0.415]
INFO - 13:51:40: ... 11%|█ | 11/100 [00:00<00:07, 11.74 it/sec, obj=0.415]
INFO - 13:51:40: ... 12%|█▏ | 12/100 [00:00<00:07, 12.45 it/sec, obj=0.415]
INFO - 13:51:40: ... 13%|█▎ | 13/100 [00:00<00:06, 13.48 it/sec, obj=0.415]
INFO - 13:51:40: Optimization result:
INFO - 13:51:40: Optimizer info:
INFO - 13:51:40: Status: None
INFO - 13:51:40: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 13:51:40: Number of calls to the objective function by the optimizer: 15
INFO - 13:51:40: Solution:
INFO - 13:51:40: The solution is feasible.
INFO - 13:51:40: Objective: 0.4147214093889784
INFO - 13:51:40: Standardized constraints:
INFO - 13:51:40: c_1 = [-0.32430622 -0.43254409]
INFO - 13:51:40: c_2 = [ 2.44645415e-11 -2.51297060e-01 -2.35380107e-01 -4.99968067e-01]
INFO - 13:51:40: Scalable design space:
INFO - 13:51:40: +--------+-------------+---------------------+-------------+-------+----------------------+
INFO - 13:51:40: | name | lower_bound | value | upper_bound | type | Initial distribution |
INFO - 13:51:40: +--------+-------------+---------------------+-------------+-------+----------------------+
INFO - 13:51:40: | x_0 | 0 | 0.4836326345734573 | 1 | float | |
INFO - 13:51:40: | x_1 | 0 | 0.9999999999999998 | 1 | float | |
INFO - 13:51:40: | x_2[0] | 0 | 0.08671679318925574 | 1 | float | |
INFO - 13:51:40: | x_2[1] | 0 | 0.9085357497327241 | 1 | float | |
INFO - 13:51:40: | x_2[2] | 0 | 0.2480176751996585 | 1 | float | |
INFO - 13:51:40: +--------+-------------+---------------------+-------------+-------+----------------------+
INFO - 13:51:40: *** End MDOScenario execution (time: 0:00:00.982792) ***
{'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 0x7f0078a77ac0>
Solve the associated quadratic programming problem¶
problem = problem.create_quadratic_programming_problem()
execute_algo(problem, algo_name="NLOPT_SLSQP", max_iter=100)
INFO - 13:51:42: Optimization problem:
INFO - 13:51:42: minimize f = 0.5x'Qx + c'x + d
INFO - 13:51:42: with respect to x
INFO - 13:51:42: subject to constraints:
INFO - 13:51:42: g: Ax-b <= 0 <= 0.0
INFO - 13:51:42: over the design space:
INFO - 13:51:42: +------+-------------+-------+-------------+-------+
INFO - 13:51:42: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:42: +------+-------------+-------+-------------+-------+
INFO - 13:51:42: | x[0] | 0 | 0.5 | 1 | float |
INFO - 13:51:42: | x[1] | 0 | 0.5 | 1 | float |
INFO - 13:51:42: | x[2] | 0 | 0.5 | 1 | float |
INFO - 13:51:42: | x[3] | 0 | 0.5 | 1 | float |
INFO - 13:51:42: | x[4] | 0 | 0.5 | 1 | float |
INFO - 13:51:42: +------+-------------+-------+-------------+-------+
INFO - 13:51:42: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 13:51:42: ... 0%| | 0/100 [00:00<?, ?it]
INFO - 13:51:42: ... 1%| | 1/100 [00:00<00:00, 1800.13 it/sec, obj=1]
INFO - 13:51:42: ... 2%|▏ | 2/100 [00:00<00:00, 493.13 it/sec, obj=0.921]
INFO - 13:51:42: ... 3%|▎ | 3/100 [00:00<00:00, 679.06 it/sec, obj=0.513]
INFO - 13:51:42: ... 4%|▍ | 4/100 [00:00<00:00, 478.91 it/sec, obj=0.438]
INFO - 13:51:42: ... 5%|▌ | 5/100 [00:00<00:00, 449.69 it/sec, obj=0.418]
INFO - 13:51:42: ... 6%|▌ | 6/100 [00:00<00:00, 458.08 it/sec, obj=0.416]
INFO - 13:51:42: ... 7%|▋ | 7/100 [00:00<00:00, 466.54 it/sec, obj=0.415]
INFO - 13:51:42: ... 8%|▊ | 8/100 [00:00<00:00, 462.15 it/sec, obj=0.415]
INFO - 13:51:42: ... 9%|▉ | 9/100 [00:00<00:00, 458.53 it/sec, obj=0.415]
INFO - 13:51:42: ... 10%|█ | 10/100 [00:00<00:00, 464.31 it/sec, obj=0.415]
INFO - 13:51:42: ... 11%|█ | 11/100 [00:00<00:00, 468.14 it/sec, obj=0.415]
INFO - 13:51:42: ... 12%|█▏ | 12/100 [00:00<00:00, 472.87 it/sec, obj=0.415]
INFO - 13:51:42: ... 13%|█▎ | 13/100 [00:00<00:00, 505.74 it/sec, obj=0.415]
INFO - 13:51:42: Optimization result:
INFO - 13:51:42: Optimizer info:
INFO - 13:51:42: Status: None
INFO - 13:51:42: Message: Successive iterates of the objective function are closer than ftol_rel or ftol_abs. GEMSEO Stopped the driver
INFO - 13:51:42: Number of calls to the objective function by the optimizer: 15
INFO - 13:51:42: Solution:
INFO - 13:51:42: The solution is feasible.
INFO - 13:51:42: Objective: 0.414721553468123
INFO - 13:51:42: Standardized constraints:
INFO - 13:51:42: g = [-3.24306238e-01 -4.32544172e-01 -4.44089210e-16 -2.51297007e-01
INFO - 13:51:42: -2.35380057e-01 -4.99968031e-01]
INFO - 13:51:42: Design space:
INFO - 13:51:42: +------+-------------+---------------------+-------------+-------+
INFO - 13:51:42: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:42: +------+-------------+---------------------+-------------+-------+
INFO - 13:51:42: | x[0] | 0 | 0.4836327595359132 | 1 | float |
INFO - 13:51:42: | x[1] | 0 | 0.9999999999999998 | 1 | float |
INFO - 13:51:42: | x[2] | 0 | 0.08671677713547089 | 1 | float |
INFO - 13:51:42: | x[3] | 0 | 0.9085357909356101 | 1 | float |
INFO - 13:51:42: | x[4] | 0 | 0.2480176979962943 | 1 | float |
INFO - 13:51:42: +------+-------------+---------------------+-------------+-------+
Post-process the results¶
execute_post(problem, "OptHistoryView", save=False, show=True)
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f0078c39fd0>
Total running time of the script: (0 minutes 4.003 seconds)