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.algos.opt.nlopt.settings.nlopt_cobyla_settings import NLOPT_COBYLA_Settings
from gemseo.algos.opt.scipy_local.settings.slsqp import SLSQP_Settings
from gemseo.problems.mdo.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 settings:

slsqp_settings = SLSQP_Settings(
    max_iter=30,
    xtol_rel=1e-7,
    xtol_abs=1e-7,
    ftol_rel=1e-7,
    ftol_abs=1e-7,
    ineq_tolerance=1e-4,
)

cobyla_settings = NLOPT_COBYLA_Settings(
    max_iter=50,
    xtol_rel=1e-7,
    xtol_abs=1e-7,
    ftol_rel=1e-7,
    ftol_abs=1e-7,
    ineq_tolerance=1e-4,
)

Build a sub-scenario for Propulsion#

This sub-scenario will minimize SFC.

sc_prop = create_scenario(
    propu,
    "y_34",
    design_space.filter("x_3", copy=True),
    name="PropulsionScenario",
    formulation_name="DisciplinaryOpt",
)
sc_prop.set_algorithm(slsqp_settings)
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,
    "y_24",
    design_space.filter("x_2", copy=True),
    name="AerodynamicsScenario",
    maximize_objective=True,
    formulation_name="DisciplinaryOpt",
)
sc_aero.set_algorithm(slsqp_settings)
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,
    "y_11",
    design_space.filter("x_1", copy=True),
    name="StructureScenario",
    maximize_objective=True,
    formulation_name="DisciplinaryOpt",
)
sc_str.add_constraint("g_1", constraint_type="ineq")
sc_str.set_algorithm(slsqp_settings)

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],
    "y_4",
    design_space.filter("x_shared", copy=True),
    apply_cstr_tosub_scenarios=False,
    parallel_scenarios=False,
    multithread_scenarios=True,
    main_mda_settings={"tolerance": 1e-14, "max_mda_iter": 30},
    maximize_objective=True,
    sub_scenarios_log_level=WARNING,
    formulation_name="BiLevel",
)
system_scenario.add_constraint(["g_1", "g_2", "g_3"], constraint_type="ineq")
WARNING - 11:48:27: Unsupported feature 'minItems' in JSONGrammar 'SobieskiMission_discipline_output' for property 'y_4' in conversion to SimpleGrammar.
WARNING - 11:48:27: Unsupported feature 'maxItems' in JSONGrammar 'SobieskiMission_discipline_output' for property 'y_4' in conversion to SimpleGrammar.

Tip

When running BiLevel scenarios, it is interesting to access the optimization history of the sub-scenarios for each system iteration. By default, the setting keep_opt_history is set to True. This allows you to store in memory the databases of the sub-scenarios (see the last section of this example for more details). In some cases, storing the databases in memory can take up too much space and cause performance issues. In these cases, set keep_opt_history=False and save the databases to the disk using save_opt_history=True.

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 (default True) will generate a self-contained HTML file, that can be automatically opened using show_html=True.

system_scenario.xdsmize(save_html=False, pdf_build=False)


Execute the main scenario#

system_scenario.execute(cobyla_settings)
   INFO - 11:48:27: *** Start MDOScenario execution ***
   INFO - 11:48:27: MDOScenario
   INFO - 11:48:27:    Disciplines: AerodynamicsScenario PropulsionScenario SobieskiMission StructureScenario
   INFO - 11:48:27:    MDO formulation: BiLevel
   INFO - 11:48:27: Optimization problem:
   INFO - 11:48:27:    minimize -y_4(x_shared)
   INFO - 11:48:27:    with respect to x_shared
   INFO - 11:48:27:    subject to constraints:
   INFO - 11:48:27:       g_1_g_2_g_3(x_shared) <= 0
   INFO - 11:48:27:    over the design space:
   INFO - 11:48:27:       +-------------+-------------+-------+-------------+-------+
   INFO - 11:48:27:       | Name        | Lower bound | Value | Upper bound | Type  |
   INFO - 11:48:27:       +-------------+-------------+-------+-------------+-------+
   INFO - 11:48:27:       | x_shared[0] |     0.01    |  0.05 |     0.09    | float |
   INFO - 11:48:27:       | x_shared[1] |    30000    | 45000 |    60000    | float |
   INFO - 11:48:27:       | x_shared[2] |     1.4     |  1.6  |     1.8     | float |
   INFO - 11:48:27:       | x_shared[3] |     2.5     |  5.5  |     8.5     | float |
   INFO - 11:48:27:       | x_shared[4] |      40     |   55  |      70     | float |
   INFO - 11:48:27:       | x_shared[5] |     500     |  1000 |     1500    | float |
   INFO - 11:48:27:       +-------------+-------------+-------+-------------+-------+
   INFO - 11:48:27: Solving optimization problem with algorithm NLOPT_COBYLA:
   INFO - 11:48:27:      2%|▏         | 1/50 [00:00<00:07,  6.51 it/sec, obj=-553]
WARNING - 11:48:27: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:27:       The solution is not feasible.
   INFO - 11:48:27:      4%|▍         | 2/50 [00:00<00:07,  6.59 it/sec, obj=-574]
WARNING - 11:48:27: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:27:       The solution is not feasible.
   INFO - 11:48:27:      6%|▌         | 3/50 [00:00<00:07,  6.68 it/sec, obj=-813]
WARNING - 11:48:28: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:28:       The solution is not feasible.
   INFO - 11:48:28:      8%|▊         | 4/50 [00:00<00:07,  6.51 it/sec, obj=-751]
WARNING - 11:48:28: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:28:       The solution is not feasible.
   INFO - 11:48:28:     10%|█         | 5/50 [00:00<00:07,  5.93 it/sec, obj=-734]
WARNING - 11:48:28: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:28:       The solution is not feasible.
   INFO - 11:48:28:     12%|█▏        | 6/50 [00:00<00:07,  6.11 it/sec, obj=-977]
WARNING - 11:48:28: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:28:       The solution is not feasible.
   INFO - 11:48:28:     14%|█▍        | 7/50 [00:01<00:07,  5.90 it/sec, obj=-1.05e+3]
WARNING - 11:48:28: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:28:       The solution is not feasible.
   INFO - 11:48:28:     16%|█▌        | 8/50 [00:01<00:07,  5.84 it/sec, obj=-1.67e+3]
   INFO - 11:48:29:     18%|█▊        | 9/50 [00:01<00:07,  5.83 it/sec, obj=-1.73e+3]
WARNING - 11:48:29: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:29:       The solution is not feasible.
   INFO - 11:48:29:     20%|██        | 10/50 [00:01<00:06,  5.76 it/sec, obj=-2.59e+3]
   INFO - 11:48:29:     22%|██▏       | 11/50 [00:01<00:06,  5.76 it/sec, obj=-2.94e+3]
WARNING - 11:48:29: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:29:       The solution is not feasible.
   INFO - 11:48:29:     24%|██▍       | 12/50 [00:02<00:06,  5.67 it/sec, obj=-2.39e+3]
   INFO - 11:48:29:     26%|██▌       | 13/50 [00:02<00:06,  5.67 it/sec, obj=-2.66e+3]
WARNING - 11:48:29: MDAJacobi has reached its maximum number of iterations, but the normalized residual norm 4.00581977874369e-13 is still above the tolerance 1e-14.
   INFO - 11:48:30:     28%|██▊       | 14/50 [00:02<00:06,  5.64 it/sec, obj=-2.54e+3]
WARNING - 11:48:30: MDAJacobi has reached its maximum number of iterations, but the normalized residual norm 2.6870836615612218e-14 is still above the tolerance 1e-14.
   INFO - 11:48:30:     30%|███       | 15/50 [00:02<00:06,  5.51 it/sec, obj=-2.51e+3]
WARNING - 11:48:30: MDAJacobi has reached its maximum number of iterations, but the normalized residual norm 2.6870836615612218e-14 is still above the tolerance 1e-14.
   INFO - 11:48:30:     32%|███▏      | 16/50 [00:02<00:06,  5.47 it/sec, obj=-2.2e+3]
   INFO - 11:48:30:     34%|███▍      | 17/50 [00:03<00:06,  5.50 it/sec, obj=-2.76e+3]
   INFO - 11:48:30:     36%|███▌      | 18/50 [00:03<00:05,  5.46 it/sec, obj=-2.47e+3]
WARNING - 11:48:30: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:30:       The solution is not feasible.
   INFO - 11:48:31:     38%|███▊      | 19/50 [00:03<00:05,  5.46 it/sec, obj=-2.97e+3]
   INFO - 11:48:31:     40%|████      | 20/50 [00:03<00:05,  5.51 it/sec, obj=-2.51e+3]
   INFO - 11:48:31:     42%|████▏     | 21/50 [00:03<00:05,  5.57 it/sec, obj=-2.85e+3]
   INFO - 11:48:31:     44%|████▍     | 22/50 [00:03<00:05,  5.57 it/sec, obj=-2.99e+3]
   INFO - 11:48:31:     46%|████▌     | 23/50 [00:04<00:04,  5.62 it/sec, obj=-2.7e+3]
   INFO - 11:48:31:     48%|████▊     | 24/50 [00:04<00:04,  5.64 it/sec, obj=-3.1e+3]
   INFO - 11:48:31:     50%|█████     | 25/50 [00:04<00:04,  5.71 it/sec, obj=-2.8e+3]
   INFO - 11:48:32:     52%|█████▏    | 26/50 [00:04<00:04,  5.68 it/sec, obj=-3.07e+3]
   INFO - 11:48:32:     54%|█████▍    | 27/50 [00:04<00:04,  5.74 it/sec, obj=-3.15e+3]
WARNING - 11:48:32: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:32:       The solution is not feasible.
   INFO - 11:48:32:     56%|█████▌    | 28/50 [00:04<00:03,  5.68 it/sec, obj=-2.8e+3]
WARNING - 11:48:32: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:32:       The solution is not feasible.
WARNING - 11:48:32: MDAJacobi has reached its maximum number of unsuccessful iterations, but the normalized residual norm 2.6870836615612218e-14 is still above the tolerance 1e-14.
   INFO - 11:48:32:     58%|█████▊    | 29/50 [00:05<00:03,  5.69 it/sec, obj=-3.14e+3]
WARNING - 11:48:32: Optimization found no feasible point; the least infeasible point is selected.
WARNING - 11:48:32:       The solution is not feasible.
   INFO - 11:48:32:     60%|██████    | 30/50 [00:05<00:03,  5.74 it/sec, obj=-3.12e+3]
WARNING - 11:48:32: MDAJacobi has reached its maximum number of unsuccessful iterations, but the normalized residual norm 1.7359275648513364e-14 is still above the tolerance 1e-14.
   INFO - 11:48:32:     62%|██████▏   | 31/50 [00:05<00:03,  5.79 it/sec, obj=-3.12e+3]
WARNING - 11:48:33: MDAJacobi has reached its maximum number of unsuccessful iterations, but the normalized residual norm 2.6870836615612218e-14 is still above the tolerance 1e-14.
   INFO - 11:48:33:     64%|██████▍   | 32/50 [00:05<00:03,  5.83 it/sec, obj=-3.12e+3]
   INFO - 11:48:33:     66%|██████▌   | 33/50 [00:05<00:02,  5.88 it/sec, obj=-3.22e+3]
   INFO - 11:48:33:     68%|██████▊   | 34/50 [00:05<00:02,  5.93 it/sec, obj=-3.12e+3]
   INFO - 11:48:33:     70%|███████   | 35/50 [00:05<00:02,  5.96 it/sec, obj=-3.13e+3]
   INFO - 11:48:33:     72%|███████▏  | 36/50 [00:05<00:02,  6.01 it/sec, obj=-3.11e+3]
   INFO - 11:48:33:     74%|███████▍  | 37/50 [00:06<00:02,  6.06 it/sec, obj=-3.14e+3]
   INFO - 11:48:33:     76%|███████▌  | 38/50 [00:06<00:01,  6.10 it/sec, obj=-3.16e+3]
   INFO - 11:48:33:     78%|███████▊  | 39/50 [00:06<00:01,  6.13 it/sec, obj=-3.2e+3]
WARNING - 11:48:33: MDAJacobi has reached its maximum number of unsuccessful iterations, but the normalized residual norm 1.7359275648513364e-14 is still above the tolerance 1e-14.
   INFO - 11:48:34:     80%|████████  | 40/50 [00:06<00:01,  6.17 it/sec, obj=-3.16e+3]
   INFO - 11:48:34:     82%|████████▏ | 41/50 [00:06<00:01,  6.21 it/sec, obj=-3.16e+3]
   INFO - 11:48:34:     84%|████████▍ | 42/50 [00:06<00:01,  6.25 it/sec, obj=-3.15e+3]
   INFO - 11:48:34:     86%|████████▌ | 43/50 [00:06<00:01,  6.29 it/sec, obj=-3.17e+3]
   INFO - 11:48:34:     88%|████████▊ | 44/50 [00:06<00:00,  6.32 it/sec, obj=-3.18e+3]
   INFO - 11:48:34:     90%|█████████ | 45/50 [00:07<00:00,  6.36 it/sec, obj=-3.19e+3]
WARNING - 11:48:34: MDAJacobi has reached its maximum number of unsuccessful iterations, but the normalized residual norm 1.7359275648513364e-14 is still above the tolerance 1e-14.
   INFO - 11:48:34:     92%|█████████▏| 46/50 [00:07<00:00,  6.37 it/sec, obj=-3.2e+3]
   INFO - 11:48:34:     94%|█████████▍| 47/50 [00:07<00:00,  6.40 it/sec, obj=-3.21e+3]
   INFO - 11:48:34:     96%|█████████▌| 48/50 [00:07<00:00,  6.43 it/sec, obj=-3.22e+3]
WARNING - 11:48:35: MDAJacobi has reached its maximum number of iterations, but the normalized residual norm 2.6870836615612218e-14 is still above the tolerance 1e-14.
   INFO - 11:48:35:     98%|█████████▊| 49/50 [00:07<00:00,  6.44 it/sec, obj=-3.23e+3]
   INFO - 11:48:35:    100%|██████████| 50/50 [00:07<00:00,  6.47 it/sec, obj=-3.24e+3]
   INFO - 11:48:35: Optimization result:
   INFO - 11:48:35:    Optimizer info:
   INFO - 11:48:35:       Status: None
   INFO - 11:48:35:       Message: Maximum number of iterations reached. GEMSEO stopped the driver.
   INFO - 11:48:35:       Number of calls to the objective function by the optimizer: 52
   INFO - 11:48:35:    Solution:
   INFO - 11:48:35:       The solution is feasible.
   INFO - 11:48:35:       Objective: -3238.8281256729097
   INFO - 11:48:35:       Standardized constraints:
   INFO - 11:48:35:          g_1_g_2_g_3 = [-3.41837669e-12 -1.26719778e-02 -2.55059750e-02 -3.52857360e-02
   INFO - 11:48:35:  -4.26719778e-02 -1.80140386e-01 -5.98596144e-02  0.00000000e+00
   INFO - 11:48:35:  -7.67083754e-01 -2.32916246e-01  0.00000000e+00 -1.83208648e-01]
   INFO - 11:48:35:       Design space:
   INFO - 11:48:35:          +-------------+-------------+---------------------+-------------+-------+
   INFO - 11:48:35:          | Name        | Lower bound |        Value        | Upper bound | Type  |
   INFO - 11:48:35:          +-------------+-------------+---------------------+-------------+-------+
   INFO - 11:48:35:          | x_shared[0] |     0.01    | 0.05999999999999999 |     0.09    | float |
   INFO - 11:48:35:          | x_shared[1] |    30000    |        60000        |    60000    | float |
   INFO - 11:48:35:          | x_shared[2] |     1.4     |  1.400356170737944  |     1.8     | float |
   INFO - 11:48:35:          | x_shared[3] |     2.5     |  3.729810789921248  |     8.5     | float |
   INFO - 11:48:35:          | x_shared[4] |      40     |          70         |      70     | float |
   INFO - 11:48:35:          | x_shared[5] |     500     |         1500        |     1500    | float |
   INFO - 11:48:35:          +-------------+-------------+---------------------+-------------+-------+
   INFO - 11:48:35: *** End MDOScenario execution (time: 0:00:07.733525) ***

Plot the history of the MDA residuals#

For the first MDA:

system_scenario.formulation.mda1.plot_residual_history(save=False, show=True)
MDAJacobi: residual plot

For the second MDA:

system_scenario.formulation.mda2.plot_residual_history(save=False, show=True)
MDAJacobi: residual plot

Plot the system optimization history view#

system_scenario.post_process(post_name="OptHistoryView", save=False, show=True)
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Evolution of the distance to the optimum
  • Evolution of the inequality constraints
<gemseo.post.opt_history_view.OptHistoryView object at 0x7048fb9950a0>

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.optimization_problem)
    opt_problem.database = database
    execute_post(opt_problem, post_name="OptHistoryView", save=False, show=True)

for disc in [propu, aero, mission, struct]:
    print(f"{disc.name}: {disc.execution_statistics.n_executions} calls.")
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Evolution of the distance to the optimum
  • Evolution of the inequality constraints
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Evolution of the distance to the optimum
  • Evolution of the inequality constraints
SobieskiPropulsion: 1637 calls.
SobieskiAerodynamics: 1760 calls.
SobieskiMission: 50 calls.
SobieskiStructure: 1941 calls.

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

Gallery generated by Sphinx-Gallery