Note
Click here 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 division, unicode_literals
from gemseo.api import configure_logger, create_discipline, create_scenario
from gemseo.problems.aerostructure.aerostructure_design_space import (
AerostructureDesignSpace,
)
from gemseo.problems.scalable.data_driven.problem import ScalableProblem
configure_logger()
Out:
<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"])
for discipline in disciplines:
discipline.set_cache_policy(discipline.MEMORY_FULL_CACHE)
design_space = AerostructureDesignSpace()
design_space.filter(discipline.get_input_data_names())
output = next(iter(discipline.get_output_data_names()))
scenario = create_scenario(
discipline, "DisciplinaryOpt", output, design_space, scenario_type="DOE"
)
scenario.execute({"algo": "DiagonalDOE", "n_samples": 10})
Out:
INFO - 09:23:45:
INFO - 09:23:45: *** Start DOE Scenario execution ***
INFO - 09:23:45: DOEScenario
INFO - 09:23:45: Disciplines: Aerodynamics
INFO - 09:23:45: MDOFormulation: DisciplinaryOpt
INFO - 09:23:45: Algorithm: DiagonalDOE
INFO - 09:23:45: Optimization problem:
INFO - 09:23:45: Minimize: drag(thick_airfoils, sweep, displ)
INFO - 09:23:45: With respect to: thick_airfoils, sweep, displ
INFO - 09:23:45: DOE sampling: 0%| | 0/10 [00:00<?, ?it]
INFO - 09:23:45: DOE sampling: 100%|██████████| 10/10 [00:00<00:00, 451.19 it/sec, obj=-320]
INFO - 09:23:45: Optimization result:
INFO - 09:23:45: Objective value = -319.99905478395067
INFO - 09:23:45: The result is feasible.
INFO - 09:23:45: Status: None
INFO - 09:23:45: Optimizer message: None
INFO - 09:23:45: Number of calls to the objective function by the optimizer: 10
INFO - 09:23:45: Design Space:
INFO - 09:23:45: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:45: | name | lower_bound | value | upper_bound | type |
INFO - 09:23:45: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:45: | thick_airfoils | 5 | 25 | 25 | float |
INFO - 09:23:45: | sweep | 10 | 35 | 35 | float |
INFO - 09:23:45: | displ | -1000 | 1000 | 1000 | float |
INFO - 09:23:45: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:45: *** DOE Scenario run terminated ***
INFO - 09:23:45:
INFO - 09:23:45: *** Start DOE Scenario execution ***
INFO - 09:23:45: DOEScenario
INFO - 09:23:45: Disciplines: Structure
INFO - 09:23:45: MDOFormulation: DisciplinaryOpt
INFO - 09:23:45: Algorithm: DiagonalDOE
INFO - 09:23:45: Optimization problem:
INFO - 09:23:45: Minimize: mass(thick_panels, sweep, forces)
INFO - 09:23:45: With respect to: thick_panels, sweep, forces
INFO - 09:23:45: DOE sampling: 0%| | 0/10 [00:00<?, ?it]
INFO - 09:23:45: DOE sampling: 100%|██████████| 10/10 [00:00<00:00, 382.36 it/sec, obj=4.02e+5]
INFO - 09:23:45: Optimization result:
INFO - 09:23:45: Objective value = 100.08573388203513
INFO - 09:23:45: The result is feasible.
INFO - 09:23:45: Status: None
INFO - 09:23:45: Optimizer message: None
INFO - 09:23:45: Number of calls to the objective function by the optimizer: 10
INFO - 09:23:45: Design Space:
INFO - 09:23:45: +--------------+-------------+-------+-------------+-------+
INFO - 09:23:45: | name | lower_bound | value | upper_bound | type |
INFO - 09:23:45: +--------------+-------------+-------+-------------+-------+
INFO - 09:23:45: | thick_panels | 1 | 1 | 20 | float |
INFO - 09:23:45: | sweep | 10 | 10 | 35 | float |
INFO - 09:23:45: | forces | -1000 | -1000 | 1000 | float |
INFO - 09:23:45: +--------------+-------------+-------+-------------+-------+
INFO - 09:23:45: *** DOE Scenario run terminated ***
INFO - 09:23:45:
INFO - 09:23:45: *** Start DOE Scenario execution ***
INFO - 09:23:45: DOEScenario
INFO - 09:23:45: Disciplines: Mission
INFO - 09:23:45: MDOFormulation: DisciplinaryOpt
INFO - 09:23:45: Algorithm: DiagonalDOE
INFO - 09:23:45: Optimization problem:
INFO - 09:23:45: Minimize: range(drag, lift, mass, reserve_fact)
INFO - 09:23:45: With respect to: drag, lift, mass, reserve_fact
INFO - 09:23:45: DOE sampling: 0%| | 0/10 [00:00<?, ?it]
INFO - 09:23:45: DOE sampling: 100%|██████████| 10/10 [00:00<00:00, 453.12 it/sec, obj=1600.0]
INFO - 09:23:45: Optimization result:
INFO - 09:23:45: Objective value = 1600.0
INFO - 09:23:45: The result is feasible.
INFO - 09:23:45: Status: None
INFO - 09:23:45: Optimizer message: None
INFO - 09:23:45: Number of calls to the objective function by the optimizer: 10
INFO - 09:23:45: Design Space:
INFO - 09:23:45: +--------------+-------------+--------+-------------+-------+
INFO - 09:23:45: | name | lower_bound | value | upper_bound | type |
INFO - 09:23:45: +--------------+-------------+--------+-------------+-------+
INFO - 09:23:45: | drag | 100 | 1000 | 1000 | float |
INFO - 09:23:45: | lift | 0.1 | 1 | 1 | float |
INFO - 09:23:45: | mass | 100000 | 500000 | 500000 | float |
INFO - 09:23:45: | reserve_fact | -1000 | 1000 | 1000 | float |
INFO - 09:23:45: +--------------+-------------+--------+-------------+-------+
INFO - 09:23:45: *** DOE Scenario run terminated ***
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.
datasets = [discipline.cache.export_to_dataset() for discipline in disciplines]
problem = ScalableProblem(
datasets,
design_variables,
objective_function,
eq_constraints,
ineq_constraints,
maximize_objective,
sizes={"sweep": 2},
)
print(problem)
Out:
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.1.0/lib/python3.8/site-packages/gemseo/problems/scalable/data_driven/model.py:150: ComplexWarning: Casting complex values to real discards the imaginary part
data[:, indices] = (value - lower_bound) / (upper_bound - lower_bound)
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: sweep (2), thick_airfoils (1), displ (1), drag (1), forces (1), lift (1), thick_panels (1), mass (1), reserve_fact (1), range (1), c_lift (1), c_rf (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 a 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)
Out:
INFO - 09:23:46: 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})
Out:
INFO - 09:23:46:
INFO - 09:23:46: *** Start MDO Scenario execution ***
INFO - 09:23:46: MDOScenario
INFO - 09:23:46: Disciplines: sdm_Aerodynamics sdm_Structure sdm_Mission
INFO - 09:23:46: MDOFormulation: MDF
INFO - 09:23:46: Algorithm: NLOPT_SLSQP
INFO - 09:23:46: Optimization problem:
INFO - 09:23:46: Minimize: -range(thick_airfoils, thick_panels, sweep)
INFO - 09:23:46: With respect to: thick_airfoils, thick_panels, sweep
INFO - 09:23:46: Subject to constraints:
INFO - 09:23:46: c_lift(thick_airfoils, thick_panels, sweep) <= [0.74804822]
INFO - 09:23:46: c_rf(thick_airfoils, thick_panels, sweep) == 0.4974338463722028
INFO - 09:23:46: Design Space:
INFO - 09:23:46: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:46: | name | lower_bound | value | upper_bound | type |
INFO - 09:23:46: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:46: | thick_airfoils | 0 | 0.5 | 1 | float |
INFO - 09:23:46: | thick_panels | 0 | 0.5 | 1 | float |
INFO - 09:23:46: | sweep | 0 | 0.5 | 1 | float |
INFO - 09:23:46: | sweep | 0 | 0.5 | 1 | float |
INFO - 09:23:46: +----------------+-------------+-------+-------------+-------+
INFO - 09:23:46: Optimization: 0%| | 0/100 [00:00<?, ?it]
INFO - 09:23:46: Optimization: 4%|▍ | 4/100 [00:00<00:00, 800.81 it/sec, obj=0.197]
ERROR - 09:23:46: NLOPT run failed : NLopt roundoff-limited, RoundoffLimited
INFO - 09:23:46: Optimization: 7%|▋ | 7/100 [00:00<00:00, 372.11 it/sec, obj=0.299]
INFO - 09:23:46: Optimization result:
INFO - 09:23:46: Objective value = 0.2985276625156317
INFO - 09:23:46: The result is feasible.
INFO - 09:23:46: Status: None
INFO - 09:23:46: Optimizer message: GEMSEO Stopped the driver
INFO - 09:23:46: Number of calls to the objective function by the optimizer: 8
INFO - 09:23:46: Constraints values w.r.t. 0:
INFO - 09:23:46: c_lift = [-0.49234168]
INFO - 09:23:46: c_rf = -1.4988010832439613e-15
INFO - 09:23:46: Design Space:
INFO - 09:23:46: +----------------+-------------+--------------------+-------------+-------+
INFO - 09:23:46: | name | lower_bound | value | upper_bound | type |
INFO - 09:23:46: +----------------+-------------+--------------------+-------------+-------+
INFO - 09:23:46: | thick_airfoils | 0 | 1 | 1 | float |
INFO - 09:23:46: | thick_panels | 0 | 0.5155052311585078 | 1 | float |
INFO - 09:23:46: | sweep | 0 | 1 | 1 | float |
INFO - 09:23:46: | sweep | 0 | 1 | 1 | float |
INFO - 09:23:46: +----------------+-------------+--------------------+-------------+-------+
INFO - 09:23:46: *** MDO Scenario run terminated in 0:00:00.281022 ***
{'algo': 'NLOPT_SLSQP', 'max_iter': 100}
We can post-process the results.
Here, we use the standard OptHistoryView
.
scenario.post_process("OptHistoryView", save=False, show=True)
Out:
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f61b8c85040>
Total running time of the script: ( 0 minutes 1.261 seconds)