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/develop/lib/python3.9/site-packages/gemseo/algos/design_space.py:459: ComplexWarning: Casting complex values to real discards the imaginary part
  self.__current_value[name] = array_value.astype(
    INFO - 20:59:30:
    INFO - 20:59:30: *** Start DOEScenario execution ***
    INFO - 20:59:30: DOEScenario
    INFO - 20:59:30:    Disciplines: Aerodynamics
    INFO - 20:59:30:    MDO formulation: DisciplinaryOpt
    INFO - 20:59:30: Optimization problem:
    INFO - 20:59:30:    minimize drag(thick_airfoils, sweep, displ)
    INFO - 20:59:30:    with respect to displ, sweep, thick_airfoils
    INFO - 20:59:30:    over the design space:
    INFO - 20:59:30:    +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:    | name           | lower_bound | value | upper_bound | type  |
    INFO - 20:59:30:    +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:    | thick_airfoils |      5      |   15  |      25     | float |
    INFO - 20:59:30:    | sweep          |      10     |   25  |      35     | float |
    INFO - 20:59:30:    | displ          |    -1000    |  -700 |     1000    | float |
    INFO - 20:59:30:    +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30: Solving optimization problem with algorithm DiagonalDOE:
    INFO - 20:59:30: ...   0%|          | 0/10 [00:00<?, ?it]
    INFO - 20:59:30: ... 100%|██████████| 10/10 [00:00<00:00, 822.74 it/sec, obj=-320]
    INFO - 20:59:30: Optimization result:
    INFO - 20:59:30:    Optimizer info:
    INFO - 20:59:30:       Status: None
    INFO - 20:59:30:       Message: None
    INFO - 20:59:30:       Number of calls to the objective function by the optimizer: 10
    INFO - 20:59:30:    Solution:
    INFO - 20:59:30:       Objective: -319.99905478395067
    INFO - 20:59:30:       Design space:
    INFO - 20:59:30:       +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:       | name           | lower_bound | value | upper_bound | type  |
    INFO - 20:59:30:       +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:       | thick_airfoils |      5      |   25  |      25     | float |
    INFO - 20:59:30:       | sweep          |      10     |   35  |      35     | float |
    INFO - 20:59:30:       | displ          |    -1000    |  1000 |     1000    | float |
    INFO - 20:59:30:       +----------------+-------------+-------+-------------+-------+
    INFO - 20:59:30: *** End DOEScenario execution (time: 0:00:00.022550) ***
    INFO - 20:59:30:
    INFO - 20:59:30: *** Start DOEScenario execution ***
    INFO - 20:59:30: DOEScenario
    INFO - 20:59:30:    Disciplines: Structure
    INFO - 20:59:30:    MDO formulation: DisciplinaryOpt
    INFO - 20:59:30: Optimization problem:
    INFO - 20:59:30:    minimize mass(thick_panels, sweep, forces)
    INFO - 20:59:30:    with respect to forces, sweep, thick_panels
    INFO - 20:59:30:    over the design space:
    INFO - 20:59:30:    +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:    | name         | lower_bound | value | upper_bound | type  |
    INFO - 20:59:30:    +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:    | thick_panels |      1      |   3   |      20     | float |
    INFO - 20:59:30:    | sweep        |      10     |   25  |      35     | float |
    INFO - 20:59:30:    | forces       |    -1000    |  400  |     1000    | float |
    INFO - 20:59:30:    +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30: Solving optimization problem with algorithm DiagonalDOE:
    INFO - 20:59:30: ...   0%|          | 0/10 [00:00<?, ?it]
    INFO - 20:59:30: ... 100%|██████████| 10/10 [00:00<00:00, 846.29 it/sec, obj=4.02e+5]
    INFO - 20:59:30: Optimization result:
    INFO - 20:59:30:    Optimizer info:
    INFO - 20:59:30:       Status: None
    INFO - 20:59:30:       Message: None
    INFO - 20:59:30:       Number of calls to the objective function by the optimizer: 10
    INFO - 20:59:30:    Solution:
    INFO - 20:59:30:       Objective: 100.08573388203513
    INFO - 20:59:30:       Design space:
    INFO - 20:59:30:       +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:       | name         | lower_bound | value | upper_bound | type  |
    INFO - 20:59:30:       +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30:       | thick_panels |      1      |   1   |      20     | float |
    INFO - 20:59:30:       | sweep        |      10     |   10  |      35     | float |
    INFO - 20:59:30:       | forces       |    -1000    | -1000 |     1000    | float |
    INFO - 20:59:30:       +--------------+-------------+-------+-------------+-------+
    INFO - 20:59:30: *** End DOEScenario execution (time: 0:00:00.022036) ***
    INFO - 20:59:30:
    INFO - 20:59:30: *** Start DOEScenario execution ***
    INFO - 20:59:30: DOEScenario
    INFO - 20:59:30:    Disciplines: Mission
    INFO - 20:59:30:    MDO formulation: DisciplinaryOpt
    INFO - 20:59:30: Optimization problem:
    INFO - 20:59:30:    minimize range(drag, lift, mass, reserve_fact)
    INFO - 20:59:30:    with respect to drag, lift, mass, reserve_fact
    INFO - 20:59:30:    over the design space:
    INFO - 20:59:30:    +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30:    | name         | lower_bound | value  | upper_bound | type  |
    INFO - 20:59:30:    +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30:    | drag         |     100     |  340   |     1000    | float |
    INFO - 20:59:30:    | lift         |     0.1     |  0.5   |      1      | float |
    INFO - 20:59:30:    | mass         |    100000   | 100000 |    500000   | float |
    INFO - 20:59:30:    | reserve_fact |    -1000    |   0    |     1000    | float |
    INFO - 20:59:30:    +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30: Solving optimization problem with algorithm DiagonalDOE:
    INFO - 20:59:30: ...   0%|          | 0/10 [00:00<?, ?it]
    INFO - 20:59:30: ... 100%|██████████| 10/10 [00:00<00:00, 828.80 it/sec, obj=1.6e+3+j]
    INFO - 20:59:30: Optimization result:
    INFO - 20:59:30:    Optimizer info:
    INFO - 20:59:30:       Status: None
    INFO - 20:59:30:       Message: None
    INFO - 20:59:30:       Number of calls to the objective function by the optimizer: 10
    INFO - 20:59:30:    Solution:
    INFO - 20:59:30:       Objective: (1600+0j)
    INFO - 20:59:30:       Design space:
    INFO - 20:59:30:       +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30:       | name         | lower_bound | value  | upper_bound | type  |
    INFO - 20:59:30:       +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30:       | drag         |     100     |  1000  |     1000    | float |
    INFO - 20:59:30:       | lift         |     0.1     |   1    |      1      | float |
    INFO - 20:59:30:       | mass         |    100000   | 500000 |    500000   | float |
    INFO - 20:59:30:       | reserve_fact |    -1000    |  1000  |     1000    | float |
    INFO - 20:59:30:       +--------------+-------------+--------+-------------+-------+
    INFO - 20:59:30: *** End DOEScenario execution (time: 0:00:00.022759) ***

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 - 20:59:30: Initialize the scalability study
INFO - 20:59:30:    Create directories
INFO - 20:59:30:       Working directory: study
INFO - 20:59:30:       Post-processing: study/visualization
INFO - 20:59:30:       Optimization history view: study/visualization/optimization_history
INFO - 20:59:30:       Scalability views: study/visualization/scalability_study
INFO - 20:59:30:       Dependency matrices: study/visualization/dependency_matrix
INFO - 20:59:30:       Results: study/results
INFO - 20:59:30:    Optimization problem
INFO - 20:59:30:       Objective: maximize range
INFO - 20:59:30:       Design variables: ['thick_airfoils', 'thick_panels', 'sweep']
INFO - 20:59:30:       Equality constraints: ['c_rf']
INFO - 20:59:30:       Inequality constraints: ['c_lift']
INFO - 20:59:30:    Study properties
INFO - 20:59:30:       Default fill factor: -1
INFO - 20:59:30:       Active probability: 0.1
INFO - 20:59:30:       Feasibility level: 0.8
INFO - 20:59:30:       Start at equilibrium: True
INFO - 20:59:30:       Early stopping: True

Add the disciplinary datasets

study.add_discipline(datasets["Aerodynamics"])
study.add_discipline(datasets["Structure"])
study.add_discipline(datasets["Mission"])
INFO - 20:59:30: Add scalable discipline # 1
INFO - 20:59:30:    Name: Aerodynamics
INFO - 20:59:30:    Inputs: displ(1), sweep(1), thick_airfoils(1)
INFO - 20:59:30:    Outputs: drag(1), forces(1), lift(1)
INFO - 20:59:30:    Built from 10
INFO - 20:59:30: Add scalable discipline # 2
INFO - 20:59:30:    Name: Structure
INFO - 20:59:30:    Inputs: forces(1), sweep(1), thick_panels(1)
INFO - 20:59:30:    Outputs: displ(1), mass(1), reserve_fact(1)
INFO - 20:59:30:    Built from 10
INFO - 20:59:30: Add scalable discipline # 3
INFO - 20:59:30:    Name: Mission
INFO - 20:59:30:    Inputs: drag(1), lift(1), mass(1), reserve_fact(1)
INFO - 20:59:30:    Outputs: c_lift(1), c_rf(1), range(1)
INFO - 20:59:30:    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 - 20:59:30: Add optimization strategy # 1
INFO - 20:59:30:    Algorithm: NLOPT_SLSQP
INFO - 20:59:30:    Algorithm options: max_iter(100)
INFO - 20:59:30:    Formulation: MDF
INFO - 20:59:30:    Formulation options: None
INFO - 20:59:30: Add optimization strategy # 2
INFO - 20:59:30:    Algorithm: NLOPT_SLSQP
INFO - 20:59:30:    Algorithm options: max_iter(100)
INFO - 20:59:30:    Formulation: IDF
INFO - 20:59:30:    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:

  1. All design parameters have a size equal to 1,

  2. 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 - 20:59:30: Add scaling strategies
INFO - 20:59:30:    Number of strategies: 2
INFO - 20:59:30:    Strategy # 1
INFO - 20:59:30:       Design variables: 1
INFO - 20:59:30:       Coupling variables: None
INFO - 20:59:30:       Equality constraints: None
INFO - 20:59:30:       Inequality constraints: None
INFO - 20:59:30:       Variables: None
INFO - 20:59:30:    Strategy # 2
INFO - 20:59:30:       Design variables: 20
INFO - 20:59:30:       Coupling variables: None
INFO - 20:59:30:       Equality constraints: None
INFO - 20:59:30:       Inequality constraints: None
INFO - 20:59:30:       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 - 20:59:30: Execute scalability study 2 times
    INFO - 20:59:30:    Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 1/2
 WARNING - 20:59:31: MDAJacobi has reached its maximum number of iterations but the normed residual 0.7071067811865476 is still above the tolerance 1e-06.
 WARNING - 20:59:31: MDAJacobi has reached its maximum number of iterations but the normed residual 0.25 is still above the tolerance 1e-06.
    INFO - 20:59:33:    Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 2/2
   ERROR - 20:59:34: NLopt run failed: NLopt roundoff-limited, RoundoffLimited
    INFO - 20:59:36:    Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 1/2
    INFO - 20:59:45:    Formulation: MDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 2/2
    INFO - 20:59:51:    Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 1/2
    INFO - 20:59:54:    Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 1/2 - Replicate: 2/2
    INFO - 20:59:57:    Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 1/2
    INFO - 21:00:02:    Formulation: IDF - Algo: NLOPT_SLSQP - Scaling: 2/2 - Replicate: 2/2

[<gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f315f3d9460>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f315fc958e0>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f319cee4e80>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f315fd66550>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f317c632160>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f317c54cb20>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f315e885c70>, <gemseo.problems.scalable.data_driven.study.result.ScalabilityResult object at 0x7f315fdd73a0>]

Look at the dependency matrices

Here are the dependency matrices obtained with the 1st replicate when design_size=10.

Aerodynamics

../../_images/2_1_sdm_Aerodynamics_dependency-1.png

Structure

../../_images/2_1_sdm_Structure_dependency-1.png

Mission

../../_images/2_1_sdm_Mission_dependency-1.png

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

../../_images/MDF_2_1_obj_history-1.png ../../_images/IDF_2_1_obj_history-1.png

Design variables

../../_images/MDF_2_1_variables_history-1.png ../../_images/IDF_2_1_variables_history-1.png

Equality constraints

../../_images/MDF_2_1_eq_constraints_history-1.png ../../_images/IDF_2_1_eq_constraints_history-1.png

Inequality constraints

../../_images/MDF_2_1_ineq_constraints_history-1.png ../../_images/IDF_2_1_ineq_constraints_history-1.png

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)
  • scalable study
  • scalable study
  • scalable study
  • scalable study
  • scalable study
INFO - 21:00:07: Post-process for scalability study
INFO - 21:00:07:    Working directory: study
INFO - 21:00:07:    Save exec_time plot in study/visualization/scalability_study/exec_time.png
INFO - 21:00:07:    Save n_calls plot in study/visualization/scalability_study/n_calls.png
INFO - 21:00:07:    Save n_calls_linearize plot in study/visualization/scalability_study/n_calls_linearize.png
INFO - 21:00:07:    Save total_calls plot in study/visualization/scalability_study/total_calls.png
INFO - 21:00:07:    Save is_feasible plot in study/visualization/scalability_study/is_feasible.png
INFO - 21:00:07: Execute post-processing
INFO - 21:00:07:    Type: replicate
../../_images/exec_time-1.png

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

Gallery generated by Sphinx-Gallery