Note
Click here to download the full example code
Scalable study¶
We want to compare IDF
and MDF
formulations
with respect to the problem dimension for the aerostructure problem.
For that,
we use the ScalabilityStudy
and PostScalabilityStudy
classes.
from __future__ import annotations
from gemseo.api import configure_logger
from gemseo.api import create_discipline
from gemseo.api import create_scenario
from gemseo.problems.aerostructure.aerostructure_design_space import (
AerostructureDesignSpace,
)
from gemseo.problems.scalable.data_driven.api import create_scalability_study
from gemseo.problems.scalable.data_driven.api import plot_scalability_results
configure_logger()
<RootLogger root (INFO)>
Create the disciplinary datasets¶
First of all, we create the disciplinary Dataset
datasets
based on a DiagonalDOE
.
datasets = {}
disciplines = create_discipline(["Aerodynamics", "Structure", "Mission"])
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[discipline.name] = scenario.export_to_dataset(
name=discipline.name, opt_naming=False
)
/home/docs/checkouts/readthedocs.org/user_builds/gemseo/envs/4.3.0.post0/lib/python3.9/site-packages/gemseo/algos/design_space.py:458: ComplexWarning: Casting complex values to real discards the imaginary part
self.__current_value[name] = array_value.astype(
INFO - 16:57:18:
INFO - 16:57:18: *** Start DOEScenario execution ***
INFO - 16:57:18: DOEScenario
INFO - 16:57:18: Disciplines: Aerodynamics
INFO - 16:57:18: MDO formulation: DisciplinaryOpt
INFO - 16:57:18: Optimization problem:
INFO - 16:57:18: minimize drag(thick_airfoils, sweep, displ)
INFO - 16:57:18: with respect to displ, sweep, thick_airfoils
INFO - 16:57:18: over the design space:
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | thick_airfoils | 5 | 15 | 25 | float |
INFO - 16:57:18: | sweep | 10 | 25 | 35 | float |
INFO - 16:57:18: | displ | -1000 | -700 | 1000 | float |
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: Solving optimization problem with algorithm DiagonalDOE:
INFO - 16:57:18: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 16:57:18: ... 10%|█ | 1/10 [00:00<00:00, 245.74 it/sec, obj=422]
INFO - 16:57:18: ... 20%|██ | 2/10 [00:00<00:00, 392.84 it/sec, obj=336]
INFO - 16:57:18: ... 30%|███ | 3/10 [00:00<00:00, 484.39 it/sec, obj=250]
INFO - 16:57:18: ... 40%|████ | 4/10 [00:00<00:00, 558.50 it/sec, obj=166]
INFO - 16:57:18: ... 50%|█████ | 5/10 [00:00<00:00, 618.25 it/sec, obj=82.3]
INFO - 16:57:18: ... 60%|██████ | 6/10 [00:00<00:00, 663.32 it/sec, obj=-.0983]
INFO - 16:57:18: ... 70%|███████ | 7/10 [00:00<00:00, 690.83 it/sec, obj=-81.6]
INFO - 16:57:18: ... 80%|████████ | 8/10 [00:00<00:00, 719.42 it/sec, obj=-162]
INFO - 16:57:18: ... 90%|█████████ | 9/10 [00:00<00:00, 746.88 it/sec, obj=-242]
INFO - 16:57:18: ... 100%|██████████| 10/10 [00:00<00:00, 770.26 it/sec, obj=-320]
INFO - 16:57:18: Optimization result:
INFO - 16:57:18: Optimizer info:
INFO - 16:57:18: Status: None
INFO - 16:57:18: Message: None
INFO - 16:57:18: Number of calls to the objective function by the optimizer: 10
INFO - 16:57:18: Solution:
INFO - 16:57:18: Objective: -319.99905478395067
INFO - 16:57:18: Design space:
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | thick_airfoils | 5 | 25 | 25 | float |
INFO - 16:57:18: | sweep | 10 | 35 | 35 | float |
INFO - 16:57:18: | displ | -1000 | 1000 | 1000 | float |
INFO - 16:57:18: +----------------+-------------+-------+-------------+-------+
INFO - 16:57:18: *** End DOEScenario execution (time: 0:00:00.022479) ***
INFO - 16:57:18:
INFO - 16:57:18: *** Start DOEScenario execution ***
INFO - 16:57:18: DOEScenario
INFO - 16:57:18: Disciplines: Structure
INFO - 16:57:18: MDO formulation: DisciplinaryOpt
INFO - 16:57:18: Optimization problem:
INFO - 16:57:18: minimize mass(thick_panels, sweep, forces)
INFO - 16:57:18: with respect to forces, sweep, thick_panels
INFO - 16:57:18: over the design space:
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | thick_panels | 1 | 3 | 20 | float |
INFO - 16:57:18: | sweep | 10 | 25 | 35 | float |
INFO - 16:57:18: | forces | -1000 | 400 | 1000 | float |
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: Solving optimization problem with algorithm DiagonalDOE:
INFO - 16:57:18: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 16:57:18: ... 10%|█ | 1/10 [00:00<00:00, 250.39 it/sec, obj=100]
INFO - 16:57:18: ... 20%|██ | 2/10 [00:00<00:00, 386.96 it/sec, obj=4.48e+4]
INFO - 16:57:18: ... 30%|███ | 3/10 [00:00<00:00, 490.91 it/sec, obj=8.94e+4]
INFO - 16:57:18: ... 40%|████ | 4/10 [00:00<00:00, 567.74 it/sec, obj=1.34e+5]
INFO - 16:57:18: ... 50%|█████ | 5/10 [00:00<00:00, 623.67 it/sec, obj=1.79e+5]
INFO - 16:57:18: ... 60%|██████ | 6/10 [00:00<00:00, 658.57 it/sec, obj=2.23e+5]
INFO - 16:57:18: ... 70%|███████ | 7/10 [00:00<00:00, 679.92 it/sec, obj=2.68e+5]
INFO - 16:57:18: ... 80%|████████ | 8/10 [00:00<00:00, 712.39 it/sec, obj=3.13e+5]
INFO - 16:57:18: ... 90%|█████████ | 9/10 [00:00<00:00, 735.41 it/sec, obj=3.57e+5]
INFO - 16:57:18: ... 100%|██████████| 10/10 [00:00<00:00, 750.23 it/sec, obj=4.02e+5]
INFO - 16:57:18: Optimization result:
INFO - 16:57:18: Optimizer info:
INFO - 16:57:18: Status: None
INFO - 16:57:18: Message: None
INFO - 16:57:18: Number of calls to the objective function by the optimizer: 10
INFO - 16:57:18: Solution:
INFO - 16:57:18: Objective: 100.08573388203513
INFO - 16:57:18: Design space:
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: | thick_panels | 1 | 1 | 20 | float |
INFO - 16:57:18: | sweep | 10 | 10 | 35 | float |
INFO - 16:57:18: | forces | -1000 | -1000 | 1000 | float |
INFO - 16:57:18: +--------------+-------------+-------+-------------+-------+
INFO - 16:57:18: *** End DOEScenario execution (time: 0:00:00.022424) ***
INFO - 16:57:18:
INFO - 16:57:18: *** Start DOEScenario execution ***
INFO - 16:57:18: DOEScenario
INFO - 16:57:18: Disciplines: Mission
INFO - 16:57:18: MDO formulation: DisciplinaryOpt
INFO - 16:57:18: Optimization problem:
INFO - 16:57:18: minimize range(drag, lift, mass, reserve_fact)
INFO - 16:57:18: with respect to drag, lift, mass, reserve_fact
INFO - 16:57:18: over the design space:
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: | drag | 100 | 340 | 1000 | float |
INFO - 16:57:18: | lift | 0.1 | 0.5 | 1 | float |
INFO - 16:57:18: | mass | 100000 | 100000 | 500000 | float |
INFO - 16:57:18: | reserve_fact | -1000 | 0 | 1000 | float |
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: Solving optimization problem with algorithm DiagonalDOE:
INFO - 16:57:18: ... 0%| | 0/10 [00:00<?, ?it]
INFO - 16:57:18: ... 10%|█ | 1/10 [00:00<00:00, 264.86 it/sec, obj=8e+3+j]
INFO - 16:57:18: ... 20%|██ | 2/10 [00:00<00:00, 413.09 it/sec, obj=5.54e+3+j]
INFO - 16:57:18: ... 30%|███ | 3/10 [00:00<00:00, 508.09 it/sec, obj=4.24e+3+j]
INFO - 16:57:18: ... 40%|████ | 4/10 [00:00<00:00, 568.20 it/sec, obj=3.43e+3+j]
INFO - 16:57:18: ... 50%|█████ | 5/10 [00:00<00:00, 613.01 it/sec, obj=2.88e+3+j]
INFO - 16:57:18: ... 60%|██████ | 6/10 [00:00<00:00, 657.40 it/sec, obj=2.48e+3+j]
INFO - 16:57:18: ... 70%|███████ | 7/10 [00:00<00:00, 693.42 it/sec, obj=2.18e+3+j]
INFO - 16:57:18: ... 80%|████████ | 8/10 [00:00<00:00, 713.00 it/sec, obj=1.95e+3+j]
INFO - 16:57:18: ... 90%|█████████ | 9/10 [00:00<00:00, 732.49 it/sec, obj=1.76e+3+j]
INFO - 16:57:18: ... 100%|██████████| 10/10 [00:00<00:00, 754.63 it/sec, obj=1.6e+3+j]
INFO - 16:57:18: Optimization result:
INFO - 16:57:18: Optimizer info:
INFO - 16:57:18: Status: None
INFO - 16:57:18: Message: None
INFO - 16:57:18: Number of calls to the objective function by the optimizer: 10
INFO - 16:57:18: Solution:
INFO - 16:57:18: Objective: (1600+0j)
INFO - 16:57:18: Design space:
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: | name | lower_bound | value | upper_bound | type |
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: | drag | 100 | 1000 | 1000 | float |
INFO - 16:57:18: | lift | 0.1 | 1 | 1 | float |
INFO - 16:57:18: | mass | 100000 | 500000 | 500000 | float |
INFO - 16:57:18: | reserve_fact | -1000 | 1000 | 1000 | float |
INFO - 16:57:18: +--------------+-------------+--------+-------------+-------+
INFO - 16:57:18: *** End DOEScenario execution (time: 0:00:00.022858) ***
Define the design problem¶
Then, we instantiate a ScalabilityStudy
from the definition of the design problem, expressed in terms of
objective function (to maximize or minimize),
design variables (local and global)
and constraints (equality and inequality).
We can also specify the coupling variables that we could scale.
Note that this information is only required by the scaling stage.
Indeed, MDO formulations know perfectly
how to automatically recognize the coupling variables.
Lastly, we can specify some properties of the scalable methodology
such as the fill factor
describing the level of dependence between inputs and outputs.
study = create_scalability_study(
objective="range",
design_variables=["thick_airfoils", "thick_panels", "sweep"],
eq_constraints=["c_rf"],
ineq_constraints=["c_lift"],
maximize_objective=True,
coupling_variables=["forces", "displ"],
fill_factor=-1,
)
INFO - 16:57:18: Initialize the scalability study
INFO - 16:57:18: Create directories
INFO - 16:57:18: Working directory: study
INFO - 16:57:18: Post-processing: study/visualization
INFO - 16:57:18: Optimization history view: study/visualization/optimization_history
INFO - 16:57:18: Scalability views: study/visualization/scalability_study
INFO - 16:57:18: Dependency matrices: study/visualization/dependency_matrix
INFO - 16:57:18: Results: study/results
INFO - 16:57:18: Optimization problem
INFO - 16:57:18: Objective: maximize range
INFO - 16:57:18: Design variables: ['thick_airfoils', 'thick_panels', 'sweep']
INFO - 16:57:18: Equality constraints: ['c_rf']
INFO - 16:57:18: Inequality constraints: ['c_lift']
INFO - 16:57:18: Study properties
INFO - 16:57:18: Default fill factor: -1
INFO - 16:57:18: Active probability: 0.1
INFO - 16:57:18: Feasibility level: 0.8
INFO - 16:57:18: Start at equilibrium: True
INFO - 16:57:18: Early stopping: True
Add the disciplinary datasets¶
study.add_discipline(datasets["Aerodynamics"])
study.add_discipline(datasets["Structure"])
study.add_discipline(datasets["Mission"])
INFO - 16:57:18: Add scalable discipline # 1
INFO - 16:57:18: Name: Aerodynamics
INFO - 16:57:18: Inputs: thick_airfoils(1), sweep(1), displ(1)
INFO - 16:57:18: Outputs: drag(1), forces(1), lift(1)
INFO - 16:57:18: Built from 10
INFO - 16:57:18: Add scalable discipline # 2
INFO - 16:57:18: Name: Structure
INFO - 16:57:18: Inputs: thick_panels(1), sweep(1), forces(1)
INFO - 16:57:18: Outputs: displ(1), mass(1), reserve_fact(1)
INFO - 16:57:18: Built from 10
INFO - 16:57:18: Add scalable discipline # 3
INFO - 16:57:18: Name: Mission
INFO - 16:57:18: Inputs: drag(1), lift(1), mass(1), reserve_fact(1)
INFO - 16:57:18: Outputs: c_lift(1), c_rf(1), range(1)
INFO - 16:57:18: Built from 10
Add the optimization strategies¶
Then, we define the different optimization strategies we want to compare: In this case, the strategies are:
MDF
formulation with the"NLOPT_SLSQP"
optimization algorithm and no more than 100 iterations,IDF
formulation with the"NLOPT_SLSQP"
optimization algorithm and no more than 100 iterations,
Note that in this case, we compare MDO formulations but we could easily compare optimization algorithms.
study.add_optimization_strategy("NLOPT_SLSQP", 100, "MDF")
study.add_optimization_strategy("NLOPT_SLSQP", 100, "IDF")
INFO - 16:57:18: Add optimization strategy # 1
INFO - 16:57:18: Algorithm: NLOPT_SLSQP
INFO - 16:57:18: Algorithm options: max_iter(100)
INFO - 16:57:18: Formulation: MDF
INFO - 16:57:18: Formulation options: None
INFO - 16:57:18: Add optimization strategy # 2
INFO - 16:57:18: Algorithm: NLOPT_SLSQP
INFO - 16:57:18: Algorithm options: max_iter(100)
INFO - 16:57:18: Formulation: IDF
INFO - 16:57:18: Formulation options: None
Add the scaling strategy¶
After that, we define the different scaling strategies for which we want to compare the optimization strategies. In this case, the strategies are:
All design parameters have a size equal to 1,
All design parameters have a size equal to 20.
To do that, we pass design_size=[1, 20]
to the ScalabilityStudy.add_scaling_strategies()
method.
design_size
expects either:
a list of integer where the ith component is the size for the ith scaling strategy,
an integer changing the fixed size (if
None
, use the original size).
Note that we could also compare the optimization strategies while
varying the size of the different coupling variables (use
coupling_size
),varying the size of the different equality constraints (use
eq_size
),varying the size of the different inequality constraints (use
ineq_size
),varying the size of any variable (use
variables
),
where the corresponding arguments works in the same way as design_size
,
except for variables
which expects a list of dictionary
whose keys are variables names and values are variables sizes.
In this way, we can use this argument to fine-tune a scaling strategy
to very specific variables, e.g. local variables.
study.add_scaling_strategies(design_size=[1, 20])
INFO - 16:57:18: Add scaling strategies
INFO - 16:57:18: Number of strategies: 2
INFO - 16:57:18: Strategy # 1
INFO - 16:57:18: Design variables: 1
INFO - 16:57:18: Coupling variables: None
INFO - 16:57:18: Equality constraints: None
INFO - 16:57:18: Inequality constraints: None
INFO - 16:57:18: Variables: None
INFO - 16:57:18: Strategy # 2
INFO - 16:57:18: Design variables: 20
INFO - 16:57:18: Coupling variables: None
INFO - 16:57:18: Equality constraints: None
INFO - 16:57:18: Inequality constraints: None
INFO - 16:57:18: Variables: None
Execute the scalable study¶
Then, we execute the scalability study,
i.e. to build and execute a ScalableProblem
for each optimization strategy and each scaling strategy,
and repeat it 2 times in order to get statistics on the results
(because the ScalableDiagonalModel
relies on stochastic features.
study.execute(n_replicates=2)
INFO - 16:57:18: Execute scalability study 2 times
INFO - 16:57:18: Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 1/2
WARNING - 16:57:19: MDAJacobi has reached its maximum number of iterations but the normed residual 0.5 is still above the tolerance 1e-06.
WARNING - 16:57:19: MDAJacobi has reached its maximum number of iterations but the normed residual 0.5 is still above the tolerance 1e-06.
INFO - 16:57:21: Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 2/2
ERROR - 16:57:22: NLopt run failed: NLopt roundoff-limited, RoundoffLimited
INFO - 16:57:24: Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 1/2
INFO - 16:57:31: Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 2/2
INFO - 16:57:37: Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 1/2
INFO - 16:57:40: Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 2/2
INFO - 16:57:43: Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 1/2
INFO - 16:57:48: Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 2/2
[<gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc3897be80>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc55a24190>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc556f01f0>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc562b0610>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc55686df0>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc386477c0>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc44122340>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7fbc558348b0>]
Look at the dependency matrices¶
Here are the dependency matrices obtained with the 1st replicate when
design_size=10
.
Aerodynamics¶

Structure¶

Mission¶

Look at optimization histories¶
Here are the optimization histories obtained with the 1st replicate when
design_size=10
, where the left side represents the MDF
formulation
while the right one represents the IDF
formulation.
Objective function¶


Design variables¶


Equality constraints¶


Inequality constraints¶


Post-process the results¶
Lastly, we plot the results.
Because of the replicates,
the latter are not displayed as one line per optimization strategy
w.r.t. scaling strategy,
but as one series of boxplots per optimization strategy w.r.t. scaling strategy,
where the boxplots represents the variability due to the 10 replicates.
In this case, it seems that
the MDF
formulation is more expensive than the IDF
one
when the design space dimension increases
while they seems to be the same when each design parameter has a size equal to 1.
post = plot_scalability_results("study")
post.labelize_scaling_strategy("Number of design parameters per type.")
post.plot(xmargin=3.0, xticks=[1.0, 20.0], xticks_labels=["1", "20"], widths=1.0)
INFO - 16:57:53: Post-process for scalability study
INFO - 16:57:53: Working directory: study
INFO - 16:57:53: Save exec_time plot in study/visualization/scalability_study/exec_time.png
INFO - 16:57:54: Save n_calls plot in study/visualization/scalability_study/n_calls.png
INFO - 16:57:54: Save n_calls_linearize plot in study/visualization/scalability_study/n_calls_linearize.png
INFO - 16:57:54: Save total_calls plot in study/visualization/scalability_study/total_calls.png
INFO - 16:57:54: Save is_feasible plot in study/visualization/scalability_study/is_feasible.png
INFO - 16:57:54: Execute post-processing
INFO - 16:57:54: Type: replicate

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