Note
Go to the end to download the full example code
Scalable problem¶
We want to solve the Aerostructure MDO problem
by means of the MDF
formulation
with a higher dimension for the sweep parameter.
For that, we use the ScalableProblem
class.
from __future__ import annotations
from gemseo import configure_logger
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo.problems.aerostructure.aerostructure_design_space import (
AerostructureDesignSpace,
)
from gemseo.problems.scalable.data_driven.problem import ScalableProblem
configure_logger()
<RootLogger root (INFO)>
Define the design problem¶
In a first step, we define the design problem in terms of objective function (to maximize or minimize), design variables (local and global) and constraints (equality and inequality).
design_variables = ["thick_airfoils", "thick_panels", "sweep"]
objective_function = "range"
eq_constraints = ["c_rf"]
ineq_constraints = ["c_lift"]
maximize_objective = True
Create the disciplinary datasets¶
Then, we create the disciplinary AbstractFullCache
datasets
based on a DiagonalDOE
.
disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"])
datasets = []
for discipline in disciplines:
design_space = AerostructureDesignSpace()
design_space.filter(discipline.get_input_data_names())
output_names = iter(discipline.get_output_data_names())
scenario = create_scenario(
discipline,
"DisciplinaryOpt",
next(output_names),
design_space,
scenario_type="DOE",
)
for output_name in output_names:
scenario.add_observable(output_name)
scenario.execute({"algo": "DiagonalDOE", "n_samples": 10})
datasets.append(scenario.to_dataset(name=discipline.name, opt_naming=False))
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.1.0/lib/python3.9/site-packages/gemseo/algos/design_space.py:444: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 13:51:48:
INFO - 13:51:48: *** Start DOEScenario execution ***
INFO - 13:51:48: DOEScenario
INFO - 13:51:48: Disciplines: Aerodynamics
INFO - 13:51:48: MDO formulation: DisciplinaryOpt
INFO - 13:51:48: Optimization problem:
INFO - 13:51:48: minimize drag(thick_airfoils, sweep, displ)
INFO - 13:51:48: with respect to displ, sweep, thick_airfoils
INFO - 13:51:48: over the design space:
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | thick_airfoils | 5 | 15 | 25 | float |
INFO - 13:51:48: | sweep | 10 | 25 | 35 | float |
INFO - 13:51:48: | displ | -1000 | -700 | 1000 | float |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: Solving optimization problem with algorithm DiagonalDOE:
INFO - 13:51:48: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 13:51:48: ... 10%|█ | 1/10 [00:00<00:00, 200.81 it/sec, obj=422]
INFO - 13:51:48: ... 20%|██ | 2/10 [00:00<00:00, 308.40 it/sec, obj=336]
INFO - 13:51:48: ... 30%|███ | 3/10 [00:00<00:00, 392.91 it/sec, obj=250]
INFO - 13:51:48: ... 40%|████ | 4/10 [00:00<00:00, 455.62 it/sec, obj=166]
INFO - 13:51:48: ... 50%|█████ | 5/10 [00:00<00:00, 506.56 it/sec, obj=82.3]
INFO - 13:51:48: ... 60%|██████ | 6/10 [00:00<00:00, 550.57 it/sec, obj=-.0983]
INFO - 13:51:48: ... 70%|███████ | 7/10 [00:00<00:00, 583.20 it/sec, obj=-81.6]
INFO - 13:51:48: ... 80%|████████ | 8/10 [00:00<00:00, 596.95 it/sec, obj=-162]
INFO - 13:51:48: ... 90%|█████████ | 9/10 [00:00<00:00, 623.08 it/sec, obj=-242]
INFO - 13:51:48: ... 100%|██████████| 10/10 [00:00<00:00, 646.00 it/sec, obj=-320]
INFO - 13:51:48: Optimization result:
INFO - 13:51:48: Optimizer info:
INFO - 13:51:48: Status: None
INFO - 13:51:48: Message: None
INFO - 13:51:48: Number of calls to the objective function by the optimizer: 10
INFO - 13:51:48: Solution:
INFO - 13:51:48: Objective: -319.99905478395067
INFO - 13:51:48: Aerostructure design space:
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | thick_airfoils | 5 | 25 | 25 | float |
INFO - 13:51:48: | sweep | 10 | 35 | 35 | float |
INFO - 13:51:48: | displ | -1000 | 1000 | 1000 | float |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: *** End DOEScenario execution (time: 0:00:00.028377) ***
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.1.0/lib/python3.9/site-packages/gemseo/algos/design_space.py:444: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 13:51:48:
INFO - 13:51:48: *** Start DOEScenario execution ***
INFO - 13:51:48: DOEScenario
INFO - 13:51:48: Disciplines: Structure
INFO - 13:51:48: MDO formulation: DisciplinaryOpt
INFO - 13:51:48: Optimization problem:
INFO - 13:51:48: minimize mass(thick_panels, sweep, forces)
INFO - 13:51:48: with respect to forces, sweep, thick_panels
INFO - 13:51:48: over the design space:
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | thick_panels | 1 | 3 | 20 | float |
INFO - 13:51:48: | sweep | 10 | 25 | 35 | float |
INFO - 13:51:48: | forces | -1000 | 400 | 1000 | float |
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: Solving optimization problem with algorithm DiagonalDOE:
INFO - 13:51:48: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 13:51:48: ... 10%|█ | 1/10 [00:00<00:00, 196.57 it/sec, obj=100]
INFO - 13:51:48: ... 20%|██ | 2/10 [00:00<00:00, 316.19 it/sec, obj=4.48e+4]
INFO - 13:51:48: ... 30%|███ | 3/10 [00:00<00:00, 405.22 it/sec, obj=8.94e+4]
INFO - 13:51:48: ... 40%|████ | 4/10 [00:00<00:00, 473.97 it/sec, obj=1.34e+5]
INFO - 13:51:48: ... 50%|█████ | 5/10 [00:00<00:00, 526.21 it/sec, obj=1.79e+5]
INFO - 13:51:48: ... 60%|██████ | 6/10 [00:00<00:00, 570.99 it/sec, obj=2.23e+5]
INFO - 13:51:48: ... 70%|███████ | 7/10 [00:00<00:00, 606.40 it/sec, obj=2.68e+5]
INFO - 13:51:48: ... 80%|████████ | 8/10 [00:00<00:00, 636.80 it/sec, obj=3.13e+5]
INFO - 13:51:48: ... 90%|█████████ | 9/10 [00:00<00:00, 660.31 it/sec, obj=3.57e+5]
INFO - 13:51:48: ... 100%|██████████| 10/10 [00:00<00:00, 679.92 it/sec, obj=4.02e+5]
INFO - 13:51:48: Optimization result:
INFO - 13:51:48: Optimizer info:
INFO - 13:51:48: Status: None
INFO - 13:51:48: Message: None
INFO - 13:51:48: Number of calls to the objective function by the optimizer: 10
INFO - 13:51:48: Solution:
INFO - 13:51:48: Objective: 100.08573388203513
INFO - 13:51:48: Aerostructure design space:
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | thick_panels | 1 | 1 | 20 | float |
INFO - 13:51:48: | sweep | 10 | 10 | 35 | float |
INFO - 13:51:48: | forces | -1000 | -1000 | 1000 | float |
INFO - 13:51:48: +--------------+-------------+-------+-------------+-------+
INFO - 13:51:48: *** End DOEScenario execution (time: 0:00:00.027544) ***
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/5.1.0/lib/python3.9/site-packages/gemseo/algos/design_space.py:444: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 13:51:48:
INFO - 13:51:48: *** Start DOEScenario execution ***
INFO - 13:51:48: DOEScenario
INFO - 13:51:48: Disciplines: Mission
INFO - 13:51:48: MDO formulation: DisciplinaryOpt
INFO - 13:51:48: Optimization problem:
INFO - 13:51:48: minimize range(drag, lift, mass, reserve_fact)
INFO - 13:51:48: with respect to drag, lift, mass, reserve_fact
INFO - 13:51:48: over the design space:
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: | drag | 100 | 340 | 1000 | float |
INFO - 13:51:48: | lift | 0.1 | 0.5 | 1 | float |
INFO - 13:51:48: | mass | 100000 | 100000 | 500000 | float |
INFO - 13:51:48: | reserve_fact | -1000 | 0 | 1000 | float |
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: Solving optimization problem with algorithm DiagonalDOE:
INFO - 13:51:48: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 13:51:48: ... 10%|█ | 1/10 [00:00<00:00, 216.45 it/sec, obj=8e+3+j]
INFO - 13:51:48: ... 20%|██ | 2/10 [00:00<00:00, 338.36 it/sec, obj=5.54e+3+j]
INFO - 13:51:48: ... 30%|███ | 3/10 [00:00<00:00, 414.94 it/sec, obj=4.24e+3+j]
INFO - 13:51:48: ... 40%|████ | 4/10 [00:00<00:00, 474.93 it/sec, obj=3.43e+3+j]
INFO - 13:51:48: ... 50%|█████ | 5/10 [00:00<00:00, 524.92 it/sec, obj=2.88e+3+j]
INFO - 13:51:48: ... 60%|██████ | 6/10 [00:00<00:00, 564.10 it/sec, obj=2.48e+3+j]
INFO - 13:51:48: ... 70%|███████ | 7/10 [00:00<00:00, 593.18 it/sec, obj=2.18e+3+j]
INFO - 13:51:48: ... 80%|████████ | 8/10 [00:00<00:00, 622.40 it/sec, obj=1.95e+3+j]
INFO - 13:51:48: ... 90%|█████████ | 9/10 [00:00<00:00, 646.42 it/sec, obj=1.76e+3+j]
INFO - 13:51:48: ... 100%|██████████| 10/10 [00:00<00:00, 665.49 it/sec, obj=1.6e+3+j]
INFO - 13:51:48: Optimization result:
INFO - 13:51:48: Optimizer info:
INFO - 13:51:48: Status: None
INFO - 13:51:48: Message: None
INFO - 13:51:48: Number of calls to the objective function by the optimizer: 10
INFO - 13:51:48: Solution:
INFO - 13:51:48: Objective: (1600+0j)
INFO - 13:51:48: Aerostructure design space:
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: | drag | 100 | 1000 | 1000 | float |
INFO - 13:51:48: | lift | 0.1 | 1 | 1 | float |
INFO - 13:51:48: | mass | 100000 | 500000 | 500000 | float |
INFO - 13:51:48: | reserve_fact | -1000 | 1000 | 1000 | float |
INFO - 13:51:48: +--------------+-------------+--------+-------------+-------+
INFO - 13:51:48: *** End DOEScenario execution (time: 0:00:00.027669) ***
Instantiate a scalable problem¶
In a third stage, we instantiate a ScalableProblem
from these disciplinary datasets and from the definition of the MDO problem.
We also increase the dimension of the sweep parameter.
problem = ScalableProblem(
datasets,
design_variables,
objective_function,
eq_constraints,
ineq_constraints,
maximize_objective,
sizes={"sweep": 2},
)
print(problem)
MDO problem
Disciplines: Aerodynamics, Structure, Mission
Design variables: thick_airfoils, thick_panels, sweep
Objective function: range (to maximize)
Inequality constraints: c_lift
Equality constraints: c_rf
Sizes: displ (1), sweep (2), thick_airfoils (1), drag (1), forces (1), lift (1), thick_panels (1), mass (1), reserve_fact (1), c_lift (1), c_rf (1), range (1)
Note
We could also provide options to the ScalableModel
objects
by means of the constructor of ScalableProblem
,
e.g. fill_factor
in the frame of the ScalableDiagonalModel
.
In this example, we use the standard ones.
Visualize the N2 chart¶
We can see the coupling between disciplines through this N2 chart:
problem.plot_n2_chart(save=False, show=True)
Create an MDO scenario¶
Lastly, we create an MDOScenario
with the MDF
formulation
and start the optimization at equilibrium,
thus ensuring the feasibility of the first iterate.
scenario = problem.create_scenario("MDF", start_at_equilibrium=True)
INFO - 13:51:48: Build a preliminary MDA to start at equilibrium
Note
We could also provide options for the scalable models to the constructor
of ScalableProblem
, e.g. fill_factor
in the frame of
the ScalableDiagonalModel
.
In this example, we use the standard ones.
Once the scenario is created, we can execute it as any scenario.
Here, we use the NLOPT_SLSQP
optimization algorithm
with no more than 100 iterations.
scenario.execute({"algo": "NLOPT_SLSQP", "max_iter": 100})
INFO - 13:51:48:
INFO - 13:51:48: *** Start MDOScenario execution ***
INFO - 13:51:48: MDOScenario
INFO - 13:51:48: Disciplines: sdm_Aerodynamics sdm_Mission sdm_Structure
INFO - 13:51:48: MDO formulation: MDF
INFO - 13:51:48: Optimization problem:
INFO - 13:51:48: minimize -range(thick_airfoils, thick_panels, sweep)
INFO - 13:51:48: with respect to sweep, thick_airfoils, thick_panels
INFO - 13:51:48: subject to constraints:
INFO - 13:51:48: c_lift(thick_airfoils, thick_panels, sweep) <= [0.74804822]
INFO - 13:51:48: c_rf(thick_airfoils, thick_panels, sweep) == 0.4974338463722027
INFO - 13:51:48: over the design space:
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: | thick_airfoils | 0 | 0.5 | 1 | float |
INFO - 13:51:48: | thick_panels | 0 | 0.5 | 1 | float |
INFO - 13:51:48: | sweep[0] | 0 | 0.5 | 1 | float |
INFO - 13:51:48: | sweep[1] | 0 | 0.5 | 1 | float |
INFO - 13:51:48: +----------------+-------------+-------+-------------+-------+
INFO - 13:51:48: Solving optimization problem with algorithm NLOPT_SLSQP:
INFO - 13:51:48: ... 0%| | 0/100 [00:00<?, ?it]
INFO - 13:51:48: ... 1%| | 1/100 [00:00<00:03, 30.42 it/sec, obj=-.168]
INFO - 13:51:48: ... 2%|▏ | 2/100 [00:00<00:12, 7.91 it/sec, obj=-.171]
INFO - 13:51:49: ... 3%|▎ | 3/100 [00:00<00:10, 9.17 it/sec, obj=-.197]
INFO - 13:51:49: ... 4%|▍ | 4/100 [00:00<00:09, 9.76 it/sec, obj=-.286]
INFO - 13:51:49: ... 5%|▌ | 5/100 [00:00<00:09, 10.07 it/sec, obj=-.299]
INFO - 13:51:49: ... 6%|▌ | 6/100 [00:00<00:09, 10.22 it/sec, obj=-.299]
ERROR - 13:51:49: NLopt run failed: NLopt roundoff-limited, RoundoffLimited
INFO - 13:51:49: ... 7%|▋ | 7/100 [00:00<00:07, 11.85 it/sec, obj=-.299]
INFO - 13:51:49: Optimization result:
INFO - 13:51:49: Optimizer info:
INFO - 13:51:49: Status: None
INFO - 13:51:49: Message: GEMSEO Stopped the driver
INFO - 13:51:49: Number of calls to the objective function by the optimizer: 8
INFO - 13:51:49: Solution:
INFO - 13:51:49: The solution is feasible.
INFO - 13:51:49: Objective: -0.29852766251563156
INFO - 13:51:49: Standardized constraints:
INFO - 13:51:49: [c_lift+offset] = [-0.49234168]
INFO - 13:51:49: [c_rf-0.4974338463722027] = -1.27675647831893e-15
INFO - 13:51:49: Design space:
INFO - 13:51:49: +----------------+-------------+--------------------+-------------+-------+
INFO - 13:51:49: | name | lower_bound | value | upper_bound | type |
INFO - 13:51:49: +----------------+-------------+--------------------+-------------+-------+
INFO - 13:51:49: | thick_airfoils | 0 | 1 | 1 | float |
INFO - 13:51:49: | thick_panels | 0 | 0.5155052311585088 | 1 | float |
INFO - 13:51:49: | sweep[0] | 0 | 1 | 1 | float |
INFO - 13:51:49: | sweep[1] | 0 | 1 | 1 | float |
INFO - 13:51:49: +----------------+-------------+--------------------+-------------+-------+
INFO - 13:51:49: *** End MDOScenario execution (time: 0:00:00.606669) ***
{'max_iter': 100, 'algo': 'NLOPT_SLSQP'}
We can post-process the results.
Here, we use the standard OptHistoryView
.
scenario.post_process("OptHistoryView", save=False, show=True)
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f0078d9cc10>
Total running time of the script: (0 minutes 2.431 seconds)