Gradient Sensitivity

In this example, we illustrate the use of the GradientSensitivity plot on the Sobieski’s SSBJ problem.

from __future__ import division, unicode_literals

from matplotlib import pyplot as plt

Import

The first step is to import some functions from the API and a method to get the design space.

from gemseo.api import configure_logger, create_discipline, create_scenario
from gemseo.problems.sobieski.core import SobieskiProblem

configure_logger()

Out:

<RootLogger root (INFO)>

Description

The GradientSensitivity post-processing builds histograms of derivatives of the objective and the constraints.

Create disciplines

At this point, we instantiate the disciplines of Sobieski’s SSBJ problem: Propulsion, Aerodynamics, Structure and Mission

disciplines = create_discipline(
    [
        "SobieskiPropulsion",
        "SobieskiAerodynamics",
        "SobieskiStructure",
        "SobieskiMission",
    ]
)

Create design space

We also read the design space from the SobieskiProblem.

design_space = SobieskiProblem().read_design_space()

Create and execute scenario

The next step is to build an MDO scenario in order to maximize the range, encoded ‘y_4’, with respect to the design parameters, while satisfying the inequality constraints ‘g_1’, ‘g_2’ and ‘g_3’. We can use the MDF formulation, the SLSQP optimization algorithm and a maximum number of iterations equal to 100.

scenario = create_scenario(
    disciplines,
    formulation="MDF",
    objective_name="y_4",
    maximize_objective=True,
    design_space=design_space,
)
scenario.set_differentiation_method("finite_differences")
for constraint in ["g_1", "g_2", "g_3"]:
    scenario.add_constraint(constraint, "ineq")
scenario.execute({"algo": "SLSQP", "max_iter": 10})

Out:

    INFO - 14:41:58:
    INFO - 14:41:58: *** Start MDO Scenario execution ***
    INFO - 14:41:58: MDOScenario
    INFO - 14:41:58:    Disciplines: SobieskiPropulsion SobieskiAerodynamics SobieskiStructure SobieskiMission
    INFO - 14:41:58:    MDOFormulation: MDF
    INFO - 14:41:58:    Algorithm: SLSQP
    INFO - 14:41:58: Optimization problem:
    INFO - 14:41:58:    Minimize: -y_4(x_shared, x_1, x_2, x_3)
    INFO - 14:41:58:    With respect to: x_shared, x_1, x_2, x_3
    INFO - 14:41:58:    Subject to constraints:
    INFO - 14:41:58:       g_1(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 14:41:58:       g_2(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 14:41:58:       g_3(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 14:41:58: Design space:
    INFO - 14:41:58: +----------+-------------+-------+-------------+-------+
    INFO - 14:41:58: | name     | lower_bound | value | upper_bound | type  |
    INFO - 14:41:58: +----------+-------------+-------+-------------+-------+
    INFO - 14:41:58: | x_shared |     0.01    |  0.05 |     0.09    | float |
    INFO - 14:41:58: | x_shared |    30000    | 45000 |    60000    | float |
    INFO - 14:41:58: | x_shared |     1.4     |  1.6  |     1.8     | float |
    INFO - 14:41:58: | x_shared |     2.5     |  5.5  |     8.5     | float |
    INFO - 14:41:58: | x_shared |      40     |   55  |      70     | float |
    INFO - 14:41:58: | x_shared |     500     |  1000 |     1500    | float |
    INFO - 14:41:58: | x_1      |     0.1     |  0.25 |     0.4     | float |
    INFO - 14:41:58: | x_1      |     0.75    |   1   |     1.25    | float |
    INFO - 14:41:58: | x_2      |     0.75    |   1   |     1.25    | float |
    INFO - 14:41:58: | x_3      |     0.1     |  0.5  |      1      | float |
    INFO - 14:41:58: +----------+-------------+-------+-------------+-------+
    INFO - 14:41:58: Optimization:   0%|          | 0/10 [00:00<?, ?it]
    INFO - 14:42:00: Optimization:  20%|██        | 2/10 [00:01<00:01,  5.30 it/sec, obj=2.12e+3]
    INFO - 14:42:02: Optimization:  30%|███       | 3/10 [00:04<00:03,  2.22 it/sec, obj=3.79e+3]
    INFO - 14:42:06: Optimization:  40%|████      | 4/10 [00:08<00:05,  1.19 it/sec, obj=4.01e+3]
 WARNING - 14:42:09: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
    INFO - 14:42:09: Optimization:  50%|█████     | 5/10 [00:11<00:00, 52.57 it/min, obj=4.51e+3]
 WARNING - 14:42:09: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3778434716154599e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:10: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3778434716154599e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:11: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3778434716154599e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3778434716154599e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:12: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
    INFO - 14:42:13: Optimization:  60%|██████    | 6/10 [00:15<00:00, 39.07 it/min, obj=4.52e+3]
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1177878724838186e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:13: MDAJacobi has reached its maximum number of iterations but the normed residual 1.2441814738218321e-06 is still above the tolerance 1e-06.
    INFO - 14:42:13: Optimization:  80%|████████  | 8/10 [00:15<00:00, 38.61 it/min, obj=4.51e+3]
 WARNING - 14:42:14: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3097841302240645e-06 is still above the tolerance 1e-06.
 WARNING - 14:42:14: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3435518312233814e-06 is still above the tolerance 1e-06.
    INFO - 14:42:14: Optimization: 100%|██████████| 10/10 [00:15<00:00, 38.16 it/min, obj=4.51e+3]
 WARNING - 14:42:14: Optimization found no feasible point !  The least infeasible point is selected.
    INFO - 14:42:14: Optimization: 100%|██████████| 10/10 [00:15<00:00, 38.15 it/min, obj=4.51e+3]
    INFO - 14:42:14: Optimization result:
    INFO - 14:42:14: Objective value = 3789.3185446884972
    INFO - 14:42:14: The result is not feasible.
    INFO - 14:42:14: Status: None
    INFO - 14:42:14: Optimizer message: Maximum number of iterations reached. GEMSEO Stopped the driver
    INFO - 14:42:14: Number of calls to the objective function by the optimizer: 12
    INFO - 14:42:14: Constraints values:
    INFO - 14:42:14:    g_1 = [-0.01968861 -0.03451033 -0.04515197 -0.0525708  -0.05794746 -0.13703141
    INFO - 14:42:14:  -0.10296859]
    INFO - 14:42:14:    g_2 = 0.0004732410401158127
    INFO - 14:42:14:    g_3 = [-0.62555576 -0.37444424 -0.14466936 -0.18313783]
    INFO - 14:42:14: Design space:
    INFO - 14:42:14: +----------+-------------+---------------------+-------------+-------+
    INFO - 14:42:14: | name     | lower_bound |        value        | upper_bound | type  |
    INFO - 14:42:14: +----------+-------------+---------------------+-------------+-------+
    INFO - 14:42:14: | x_shared |     0.01    | 0.06011831026002896 |     0.09    | float |
    INFO - 14:42:14: | x_shared |    30000    |        60000        |    60000    | float |
    INFO - 14:42:14: | x_shared |     1.4     |  1.400900029003249  |     1.8     | float |
    INFO - 14:42:14: | x_shared |     2.5     |         2.5         |     8.5     | float |
    INFO - 14:42:14: | x_shared |      40     |          70         |      70     | float |
    INFO - 14:42:14: | x_shared |     500     |         1500        |     1500    | float |
    INFO - 14:42:14: | x_1      |     0.1     |  0.3989644630096731 |     0.4     | float |
    INFO - 14:42:14: | x_1      |     0.75    |         0.75        |     1.25    | float |
    INFO - 14:42:14: | x_2      |     0.75    |         0.75        |     1.25    | float |
    INFO - 14:42:14: | x_3      |     0.1     |  0.1337468319957488 |      1      | float |
    INFO - 14:42:14: +----------+-------------+---------------------+-------------+-------+
    INFO - 14:42:14: *** MDO Scenario run terminated in 0:00:15.735393 ***

{'algo': 'SLSQP', 'max_iter': 10}

Post-process scenario

Lastly, we post-process the scenario by means of the GradientSensitivity plot which builds histograms of derivatives of objective and constraints.

Tip

Each post-processing method requires different inputs and offers a variety of customization options. Use the API function get_post_processing_options_schema() to print a table with the options for any post-processing algorithm. Or refer to our dedicated page: Options for Post-processing algorithms.

scenario.post_process("GradientSensitivity", save=False, show=False)
# Workaround for HTML rendering, instead of ``show=True``
plt.show()
Derivatives of objective and constraints with respect to design variables, -y_4, g_1_0, g_1_1, g_1_2, g_1_3, g_1_4, g_1_5, g_1_6, g_2, g_3_0, g_3_1, g_3_2, g_3_3

Out:

/home/docs/checkouts/readthedocs.org/user_builds/gemseo/conda/3.2.2/lib/python3.8/site-packages/gemseo/post/gradient_sensitivity.py:163: UserWarning: FixedFormatter should only be used together with FixedLocator
  axe.set_xticklabels(x_labels, fontsize=12, rotation=90)

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

Gallery generated by Sphinx-Gallery