Note
Click here to download the full example code
BiLevel-based DOE on the Sobieski SSBJ test case¶
from __future__ import division, unicode_literals
from copy import deepcopy
from os import name as os_name
from matplotlib import pyplot as plt
from gemseo.api import configure_logger, create_discipline, create_scenario
from gemseo.problems.sobieski.core import SobieskiProblem
IS_NT = os_name == "nt"
configure_logger()
Out:
<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 = SobieskiProblem().read_design_space()
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=deepcopy(design_space).filter("x_3"),
name="PropulsionScenario",
)
Build a sub-scenario for Aerodynamics¶
This sub-scenario will minimize L/D.
sc_aero = create_scenario(
aero,
"DisciplinaryOpt",
"y_24",
deepcopy(design_space).filter("x_2"),
name="AerodynamicsScenario",
maximize_objective=True,
)
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",
deepcopy(design_space).filter("x_1"),
name="StructureScenario",
maximize_objective=True,
)
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).
sub_disciplines = [sc_prop, sc_aero, sc_str] + [mission]
design_space = deepcopy(design_space).filter("x_shared")
system_scenario = create_scenario(
sub_disciplines,
"BiLevel",
"y_4",
design_space,
parallel_scenarios=False,
reset_x0_before_opt=True,
scenario_type="DOE",
)
Note
Setting reset_x0_before_opt=True
is mandatory when doing a DOE
in parallel. If we want reproducible results, don’t reuse previous xopt.
system_scenario.formulation.mda1.warm_start = False
system_scenario.formulation.mda2.warm_start = False
Note
This is mandatory when doing a DOE in parallel if we want always exactly the same results, don’t warm start mda1 to have exactly the same process whatever the execution order and process dispatch.
for sub_sc in sub_disciplines[0:3]:
sub_sc.default_inputs = {"max_iter": 20, "algo": "L-BFGS-B"}
n_processes = 4
if IS_NT: # Under windows, dont do multiprocessing
n_processes = 1
run_inputs = {
"n_samples": 30,
"algo": "lhs",
"algo_options": {"n_processes": n_processes},
}
system_scenario.execute(run_inputs)
system_scenario.print_execution_metrics()
Out:
INFO - 09:24:14:
INFO - 09:24:14: *** Start DOE Scenario execution ***
INFO - 09:24:14: DOEScenario
INFO - 09:24:14: Disciplines: PropulsionScenario AerodynamicsScenario StructureScenario SobieskiMission
INFO - 09:24:14: MDOFormulation: BiLevel
INFO - 09:24:14: Algorithm: lhs
INFO - 09:24:14: Optimization problem:
INFO - 09:24:14: Minimize: y_4(x_shared)
INFO - 09:24:14: With respect to: x_shared
INFO - 09:24:14: DOE sampling: 0%| | 0/30 [00:00<?, ?it]
INFO - 09:24:14: Running DOE in parallel on n_processes = 4
ERROR - 09:24:15: Failed to execute task indexed 0
ERROR - 09:24:15: math domain error
INFO - 09:24:22: DOE sampling: 0%| | 0/30 [00:07<00:07, 3.80 it/sec]
INFO - 09:24:22: Optimization result:
INFO - 09:24:22: Objective value = 292.91178826079175
INFO - 09:24:22: The result is feasible.
INFO - 09:24:22: Status: None
INFO - 09:24:22: Optimizer message: None
INFO - 09:24:22: Number of calls to the objective function by the optimizer: 30
INFO - 09:24:22: Design Space:
INFO - 09:24:22: +----------+-------------+---------------------+-------------+-------+
INFO - 09:24:22: | name | lower_bound | value | upper_bound | type |
INFO - 09:24:22: +----------+-------------+---------------------+-------------+-------+
INFO - 09:24:22: | x_shared | 0.01 | 0.04666883227502976 | 0.09 | float |
INFO - 09:24:22: | x_shared | 30000 | 37789.27932845149 | 60000 | float |
INFO - 09:24:22: | x_shared | 1.4 | 1.667044086506944 | 1.8 | float |
INFO - 09:24:22: | x_shared | 2.5 | 8.29772323088249 | 8.5 | float |
INFO - 09:24:22: | x_shared | 40 | 42.41730480236713 | 70 | float |
INFO - 09:24:22: | x_shared | 500 | 724.9388551459947 | 1500 | float |
INFO - 09:24:22: +----------+-------------+---------------------+-------------+-------+
INFO - 09:24:22: *** DOE Scenario run terminated ***
INFO - 09:24:22: * Scenario Executions statistics *
INFO - 09:24:22: * Discipline: PropulsionScenario
INFO - 09:24:22: Executions number: 30
INFO - 09:24:22: Execution time: 1.4670365630008746 s
INFO - 09:24:22: Linearizations number: 0
INFO - 09:24:22: * Discipline: AerodynamicsScenario
INFO - 09:24:22: Executions number: 30
INFO - 09:24:22: Execution time: 2.0625491420003073 s
INFO - 09:24:22: Linearizations number: 0
INFO - 09:24:22: * Discipline: StructureScenario
INFO - 09:24:22: Executions number: 30
INFO - 09:24:22: Execution time: 11.280604358999426 s
INFO - 09:24:22: Linearizations number: 0
INFO - 09:24:22: * Discipline: SobieskiMission
INFO - 09:24:22: Executions number: 29
INFO - 09:24:22: Execution time: 0.0010353690001920768 s
INFO - 09:24:22: Linearizations number: 0
INFO - 09:24:22: Total number of executions calls 119
INFO - 09:24:22: Total number of linearizations 0
Plot the optimization history view¶
system_scenario.post_process("OptHistoryView", show=False, save=False)
Out:
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f61b89fc7c0>
Plot the scatter matrix¶
system_scenario.post_process(
"ScatterPlotMatrix", show=False, save=False, variables_list=["y_4", "x_shared"]
)
Out:
<gemseo.post.scatter_mat.ScatterPlotMatrix object at 0x7f61b8d12730>
Plot parallel coordinates¶
system_scenario.post_process("ParallelCoordinates", show=False, save=False)
Out:
<gemseo.post.para_coord.ParallelCoordinates object at 0x7f61b88a1f70>
Plot correlations¶
system_scenario.post_process("Correlations", show=False, save=False)
# Workaround for HTML rendering, instead of ``show=True``
plt.show()
Out:
INFO - 09:24:26: Detected 0 correlations > 0.95
Total running time of the script: ( 0 minutes 12.087 seconds)