Note
Go to the end to download the full example code
BiLevel-based MDO on the Sobieski SSBJ test case¶
from __future__ import annotations
from copy import deepcopy
from logging import WARNING
from gemseo import configure_logger
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo import execute_post
from gemseo.problems.sobieski.core.design_space import SobieskiDesignSpace
configure_logger()
<RootLogger root (INFO)>
Instantiate the disciplines¶
First, we instantiate the four disciplines of the use case:
SobieskiPropulsion
,
SobieskiAerodynamics
,
SobieskiMission
and SobieskiStructure
.
propu, aero, mission, struct = create_discipline([
"SobieskiPropulsion",
"SobieskiAerodynamics",
"SobieskiMission",
"SobieskiStructure",
])
Build, execute and post-process the scenario¶
Then, we build the scenario which links the disciplines
with the formulation and the optimization algorithm. Here, we use the
BiLevel
formulation. We tell the scenario to minimize -y_4
instead of minimizing y_4 (range), which is the default option.
We need to define the design space.
design_space = SobieskiDesignSpace()
Then, we build a sub-scenario for each strongly coupled disciplines, using the following algorithm, maximum number of iterations and algorithm options:
algo_options = {
"xtol_rel": 1e-7,
"xtol_abs": 1e-7,
"ftol_rel": 1e-7,
"ftol_abs": 1e-7,
"ineq_tolerance": 1e-4,
}
sub_sc_opts = {"max_iter": 30, "algo": "SLSQP", "algo_options": algo_options}
Build a sub-scenario for Propulsion¶
This sub-scenario will minimize SFC.
sc_prop = create_scenario(
propu,
"DisciplinaryOpt",
"y_34",
design_space.filter("x_3", copy=True),
name="PropulsionScenario",
)
sc_prop.default_inputs = sub_sc_opts
sc_prop.add_constraint("g_3", constraint_type="ineq")
Build a sub-scenario for Aerodynamics¶
This sub-scenario will minimize L/D.
sc_aero = create_scenario(
aero,
"DisciplinaryOpt",
"y_24",
design_space.filter("x_2", copy=True),
name="AerodynamicsScenario",
maximize_objective=True,
)
sc_aero.default_inputs = sub_sc_opts
sc_aero.add_constraint("g_2", constraint_type="ineq")
Build a sub-scenario for Structure¶
This sub-scenario will maximize log(aircraft total weight / (aircraft total weight - fuel weight)).
sc_str = create_scenario(
struct,
"DisciplinaryOpt",
"y_11",
design_space.filter("x_1", copy=True),
name="StructureScenario",
maximize_objective=True,
)
sc_str.add_constraint("g_1", constraint_type="ineq")
sc_str.default_inputs = sub_sc_opts
Build a scenario for Mission¶
This scenario is based on the three previous sub-scenarios and on the Mission and aims to maximize the range (Breguet).
system_scenario = create_scenario(
[sc_prop, sc_aero, sc_str, mission],
"BiLevel",
"y_4",
design_space.filter("x_shared", copy=True),
apply_cstr_tosub_scenarios=False,
parallel_scenarios=False,
multithread_scenarios=True,
tolerance=1e-14,
max_mda_iter=30,
maximize_objective=True,
sub_scenarios_log_level=WARNING,
)
system_scenario.add_constraint(["g_1", "g_2", "g_3"], constraint_type="ineq")
Visualize the XDSM¶
Generate the XDSM on the fly:
log_workflow_status=True
will log the status of the workflow in the console,save_html
(defaultTrue
) will generate a self-contained HTML file, that can be automatically opened usingshow_html=True
.
system_scenario.xdsmize(save_html=False)
Execute the main scenario¶
system_scenario.execute({
"max_iter": 50,
"algo": "NLOPT_COBYLA",
"algo_options": algo_options,
})
INFO - 13:09:15:
INFO - 13:09:15: *** Start MDOScenario execution ***
INFO - 13:09:15: MDOScenario
INFO - 13:09:15: Disciplines: AerodynamicsScenario PropulsionScenario SobieskiMission StructureScenario
INFO - 13:09:15: MDO formulation: BiLevel
INFO - 13:09:16: Optimization problem:
INFO - 13:09:16: minimize -y_4(x_shared)
INFO - 13:09:16: with respect to x_shared
INFO - 13:09:16: subject to constraints:
INFO - 13:09:16: g_1_g_2_g_3(x_shared) <= 0.0
INFO - 13:09:16: over the design space:
INFO - 13:09:16: +-------------+-------------+-------+-------------+-------+
INFO - 13:09:16: | Name | Lower bound | Value | Upper bound | Type |
INFO - 13:09:16: +-------------+-------------+-------+-------------+-------+
INFO - 13:09:16: | x_shared[0] | 0.01 | 0.05 | 0.09 | float |
INFO - 13:09:16: | x_shared[1] | 30000 | 45000 | 60000 | float |
INFO - 13:09:16: | x_shared[2] | 1.4 | 1.6 | 1.8 | float |
INFO - 13:09:16: | x_shared[3] | 2.5 | 5.5 | 8.5 | float |
INFO - 13:09:16: | x_shared[4] | 40 | 55 | 70 | float |
INFO - 13:09:16: | x_shared[5] | 500 | 1000 | 1500 | float |
INFO - 13:09:16: +-------------+-------------+-------+-------------+-------+
INFO - 13:09:16: Solving optimization problem with algorithm NLOPT_COBYLA:
INFO - 13:09:16: 2%|▏ | 1/50 [00:00<00:20, 2.42 it/sec, obj=-553]
WARNING - 13:09:16: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:16: The solution is not feasible.
INFO - 13:09:16: 4%|▍ | 2/50 [00:00<00:17, 2.74 it/sec, obj=-574]
WARNING - 13:09:16: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:16: The solution is not feasible.
INFO - 13:09:17: 6%|▌ | 3/50 [00:01<00:16, 2.92 it/sec, obj=-813]
WARNING - 13:09:17: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:17: The solution is not feasible.
INFO - 13:09:17: 8%|▊ | 4/50 [00:01<00:15, 3.01 it/sec, obj=-751]
WARNING - 13:09:17: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:17: The solution is not feasible.
INFO - 13:09:17: 10%|█ | 5/50 [00:01<00:15, 2.85 it/sec, obj=-734]
WARNING - 13:09:17: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:17: The solution is not feasible.
INFO - 13:09:18: 12%|█▏ | 6/50 [00:02<00:14, 2.96 it/sec, obj=-977]
WARNING - 13:09:18: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:18: The solution is not feasible.
INFO - 13:09:18: 14%|█▍ | 7/50 [00:02<00:14, 2.94 it/sec, obj=-1.05e+3]
WARNING - 13:09:18: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:18: The solution is not feasible.
INFO - 13:09:18: 16%|█▌ | 8/50 [00:02<00:14, 2.92 it/sec, obj=-1.67e+3]
INFO - 13:09:19: 18%|█▊ | 9/50 [00:03<00:14, 2.92 it/sec, obj=-1.73e+3]
WARNING - 13:09:19: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:19: The solution is not feasible.
INFO - 13:09:19: 20%|██ | 10/50 [00:03<00:13, 2.87 it/sec, obj=-2.59e+3]
INFO - 13:09:19: 22%|██▏ | 11/50 [00:03<00:13, 2.89 it/sec, obj=-2.94e+3]
WARNING - 13:09:20: MDAJacobi has reached its maximum number of iterations but the normed residual 3.529834961324977e-13 is still above the tolerance 1e-14.
INFO - 13:09:20: 24%|██▍ | 12/50 [00:04<00:13, 2.80 it/sec, obj=-2.64e+3]
WARNING - 13:09:20: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:20: The solution is not feasible.
INFO - 13:09:20: 26%|██▌ | 13/50 [00:04<00:13, 2.83 it/sec, obj=-2.85e+3]
WARNING - 13:09:20: MDAJacobi has reached its maximum number of iterations but the normed residual 1.8156061753512135e-13 is still above the tolerance 1e-14.
WARNING - 13:09:21: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:21: 28%|██▊ | 14/50 [00:05<00:12, 2.79 it/sec, obj=-2.79e+3]
WARNING - 13:09:21: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:21: The solution is not feasible.
INFO - 13:09:21: 30%|███ | 15/50 [00:05<00:12, 2.73 it/sec, obj=-2.4e+3]
INFO - 13:09:21: 32%|███▏ | 16/50 [00:05<00:12, 2.78 it/sec, obj=-3.07e+3]
WARNING - 13:09:21: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7359275648513364e-14 is still above the tolerance 1e-14.
WARNING - 13:09:21: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:21: The solution is not feasible.
INFO - 13:09:22: 34%|███▍ | 17/50 [00:06<00:11, 2.80 it/sec, obj=-3.01e+3]
INFO - 13:09:22: 36%|███▌ | 18/50 [00:06<00:11, 2.84 it/sec, obj=-3.39e+3]
INFO - 13:09:22: 38%|███▊ | 19/50 [00:06<00:10, 2.87 it/sec, obj=-3.84e+3]
WARNING - 13:09:22: MDAJacobi has reached its maximum number of iterations but the normed residual 5.2662231734593133e-14 is still above the tolerance 1e-14.
INFO - 13:09:22: 40%|████ | 20/50 [00:06<00:10, 2.88 it/sec, obj=-3.58e+3]
INFO - 13:09:23: 42%|████▏ | 21/50 [00:07<00:09, 2.91 it/sec, obj=-3.66e+3]
INFO - 13:09:23: 44%|████▍ | 22/50 [00:07<00:09, 2.93 it/sec, obj=-3.78e+3]
INFO - 13:09:23: 46%|████▌ | 23/50 [00:07<00:09, 2.96 it/sec, obj=-3.55e+3]
INFO - 13:09:24: 48%|████▊ | 24/50 [00:08<00:08, 2.95 it/sec, obj=-3.33e+3]
INFO - 13:09:24: 50%|█████ | 25/50 [00:08<00:08, 2.96 it/sec, obj=-3.55e+3]
INFO - 13:09:24: 52%|█████▏ | 26/50 [00:08<00:08, 2.99 it/sec, obj=-3.96e+3]
WARNING - 13:09:24: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:24: The solution is not feasible.
INFO - 13:09:24: 54%|█████▍ | 27/50 [00:08<00:07, 3.04 it/sec, obj=-3.96e+3]
WARNING - 13:09:25: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7359275648513364e-14 is still above the tolerance 1e-14.
WARNING - 13:09:25: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:25: The solution is not feasible.
INFO - 13:09:25: 56%|█████▌ | 28/50 [00:09<00:07, 3.05 it/sec, obj=-3.85e+3]
WARNING - 13:09:25: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:25: 58%|█████▊ | 29/50 [00:09<00:06, 3.06 it/sec, obj=-3.93e+3]
WARNING - 13:09:25: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:25: The solution is not feasible.
WARNING - 13:09:25: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:25: 60%|██████ | 30/50 [00:09<00:06, 3.08 it/sec, obj=-3.94e+3]
WARNING - 13:09:25: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7359275648513364e-14 is still above the tolerance 1e-14.
WARNING - 13:09:25: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:25: The solution is not feasible.
WARNING - 13:09:26: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:26: 62%|██████▏ | 31/50 [00:10<00:06, 3.07 it/sec, obj=-3.96e+3]
WARNING - 13:09:26: Optimization found no feasible point ! The least infeasible point is selected.
WARNING - 13:09:26: The solution is not feasible.
INFO - 13:09:26: 64%|██████▍ | 32/50 [00:10<00:05, 3.10 it/sec, obj=-3.94e+3]
INFO - 13:09:26: 66%|██████▌ | 33/50 [00:10<00:05, 3.14 it/sec, obj=-3.94e+3]
INFO - 13:09:26: 68%|██████▊ | 34/50 [00:10<00:05, 3.17 it/sec, obj=-3.94e+3]
INFO - 13:09:26: 70%|███████ | 35/50 [00:10<00:04, 3.19 it/sec, obj=-3.95e+3]
INFO - 13:09:27: 72%|███████▏ | 36/50 [00:11<00:04, 3.22 it/sec, obj=-3.96e+3]
INFO - 13:09:27: 74%|███████▍ | 37/50 [00:11<00:04, 3.25 it/sec, obj=-3.96e+3]
INFO - 13:09:27: 76%|███████▌ | 38/50 [00:11<00:03, 3.27 it/sec, obj=-3.96e+3]
INFO - 13:09:27: 78%|███████▊ | 39/50 [00:11<00:03, 3.30 it/sec, obj=-3.96e+3]
INFO - 13:09:27: 80%|████████ | 40/50 [00:11<00:02, 3.34 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 82%|████████▏ | 41/50 [00:12<00:02, 3.38 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 84%|████████▍ | 42/50 [00:12<00:02, 3.42 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 86%|████████▌ | 43/50 [00:12<00:02, 3.46 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 88%|████████▊ | 44/50 [00:12<00:01, 3.49 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 90%|█████████ | 45/50 [00:12<00:01, 3.52 it/sec, obj=-3.96e+3]
INFO - 13:09:28: 92%|█████████▏| 46/50 [00:12<00:01, 3.55 it/sec, obj=-3.96e+3]
WARNING - 13:09:29: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7359275648513364e-14 is still above the tolerance 1e-14.
WARNING - 13:09:29: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:29: 94%|█████████▍| 47/50 [00:13<00:00, 3.53 it/sec, obj=-3.96e+3]
INFO - 13:09:29: 96%|█████████▌| 48/50 [00:13<00:00, 3.56 it/sec, obj=-3.96e+3]
WARNING - 13:09:29: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7359275648513364e-14 is still above the tolerance 1e-14.
WARNING - 13:09:29: MDAJacobi has reached its maximum number of iterations but the normed residual 2.6870836615612218e-14 is still above the tolerance 1e-14.
INFO - 13:09:29: 98%|█████████▊| 49/50 [00:13<00:00, 3.55 it/sec, obj=-3.96e+3]
INFO - 13:09:29: 100%|██████████| 50/50 [00:13<00:00, 3.58 it/sec, obj=-3.96e+3]
INFO - 13:09:29: Optimization result:
INFO - 13:09:29: Optimizer info:
INFO - 13:09:29: Status: None
INFO - 13:09:29: Message: Maximum number of iterations reached. GEMSEO Stopped the driver
INFO - 13:09:29: Number of calls to the objective function by the optimizer: 52
INFO - 13:09:29: Solution:
INFO - 13:09:29: The solution is feasible.
INFO - 13:09:29: Objective: -3963.380012270178
INFO - 13:09:29: Standardized constraints:
INFO - 13:09:29: g_1_g_2_g_3 = [-1.80509341e-02 -3.33391490e-02 -4.42438091e-02 -5.18299820e-02
INFO - 13:09:29: -5.73221710e-02 -1.37208650e-01 -1.02791350e-01 0.00000000e+00
INFO - 13:09:29: -7.67186463e-01 -2.32813537e-01 -8.88178420e-16 -1.83255000e-01]
INFO - 13:09:29: Design space:
INFO - 13:09:29: +-------------+-------------+---------------------+-------------+-------+
INFO - 13:09:29: | Name | Lower bound | Value | Upper bound | Type |
INFO - 13:09:29: +-------------+-------------+---------------------+-------------+-------+
INFO - 13:09:29: | x_shared[0] | 0.01 | 0.05999999999999998 | 0.09 | float |
INFO - 13:09:29: | x_shared[1] | 30000 | 60000 | 60000 | float |
INFO - 13:09:29: | x_shared[2] | 1.4 | 1.4 | 1.8 | float |
INFO - 13:09:29: | x_shared[3] | 2.5 | 2.5 | 8.5 | float |
INFO - 13:09:29: | x_shared[4] | 40 | 70 | 70 | float |
INFO - 13:09:29: | x_shared[5] | 500 | 1500 | 1500 | float |
INFO - 13:09:29: +-------------+-------------+---------------------+-------------+-------+
INFO - 13:09:29: *** End MDOScenario execution (time: 0:00:13.994958) ***
{'max_iter': 50, 'algo_options': {'xtol_rel': 1e-07, 'xtol_abs': 1e-07, 'ftol_rel': 1e-07, 'ftol_abs': 1e-07, 'ineq_tolerance': 0.0001}, 'algo': 'NLOPT_COBYLA'}
Plot the history of the MDA residuals¶
For the first MDA:
system_scenario.formulation.mda1.plot_residual_history(save=False, show=True)
# For the second MDA:
system_scenario.formulation.mda2.plot_residual_history(save=False, show=True)
Plot the system optimization history view¶
system_scenario.post_process("OptHistoryView", save=False, show=True)
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f8b9ea7e760>
Plot the structure optimization histories of the 2 first iterations¶
struct_databases = system_scenario.formulation.scenario_adapters[2].databases
for database in struct_databases[:2]:
opt_problem = deepcopy(sc_str.formulation.opt_problem)
opt_problem.database = database
execute_post(opt_problem, "OptHistoryView", save=False, show=True)
for disc in [propu, aero, mission, struct]:
print(f"{disc.name}: {disc.n_calls} calls.")
SobieskiPropulsion: 1291 calls.
SobieskiAerodynamics: 1458 calls.
SobieskiMission: 50 calls.
SobieskiStructure: 1506 calls.
Total running time of the script: (0 minutes 19.003 seconds)