Gradient Sensitivity

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

from gemseo.api import configure_logger
from gemseo.api import create_discipline
from gemseo.api import create_scenario
from gemseo.problems.sobieski.core.problem import SobieskiProblem
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.

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().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 - 15:00:45:
    INFO - 15:00:45: *** Start MDOScenario execution ***
    INFO - 15:00:45: MDOScenario
    INFO - 15:00:45:    Disciplines: SobieskiPropulsion SobieskiAerodynamics SobieskiStructure SobieskiMission
    INFO - 15:00:45:    MDO formulation: MDF
    INFO - 15:00:45: Optimization problem:
    INFO - 15:00:45:    minimize -y_4(x_shared, x_1, x_2, x_3)
    INFO - 15:00:45:    with respect to x_1, x_2, x_3, x_shared
    INFO - 15:00:45:    subject to constraints:
    INFO - 15:00:45:       g_1(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 15:00:45:       g_2(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 15:00:45:       g_3(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 15:00:45:    over the design space:
    INFO - 15:00:45:    +----------+-------------+-------+-------------+-------+
    INFO - 15:00:45:    | name     | lower_bound | value | upper_bound | type  |
    INFO - 15:00:45:    +----------+-------------+-------+-------------+-------+
    INFO - 15:00:45:    | x_shared |     0.01    |  0.05 |     0.09    | float |
    INFO - 15:00:45:    | x_shared |    30000    | 45000 |    60000    | float |
    INFO - 15:00:45:    | x_shared |     1.4     |  1.6  |     1.8     | float |
    INFO - 15:00:45:    | x_shared |     2.5     |  5.5  |     8.5     | float |
    INFO - 15:00:45:    | x_shared |      40     |   55  |      70     | float |
    INFO - 15:00:45:    | x_shared |     500     |  1000 |     1500    | float |
    INFO - 15:00:45:    | x_1      |     0.1     |  0.25 |     0.4     | float |
    INFO - 15:00:45:    | x_1      |     0.75    |   1   |     1.25    | float |
    INFO - 15:00:45:    | x_2      |     0.75    |   1   |     1.25    | float |
    INFO - 15:00:45:    | x_3      |     0.1     |  0.5  |      1      | float |
    INFO - 15:00:45:    +----------+-------------+-------+-------------+-------+
    INFO - 15:00:45: Solving optimization problem with algorithm SLSQP:
    INFO - 15:00:45: ...   0%|          | 0/10 [00:00<?, ?it]
    INFO - 15:00:47: ...  20%|██        | 2/10 [00:02<00:01,  4.73 it/sec, obj=-2.12e+3]
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067454825944318e-06 is still above the tolerance 1e-06.
    INFO - 15:00:50: ...  30%|███       | 3/10 [00:04<00:03,  2.00 it/sec, obj=-3.81e+3]
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067522741880028e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:50: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.10682022250684e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069132102736372e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067454825944318e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067522741880028e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:51: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.10682022250684e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069132102736372e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067454825944318e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067522741880028e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:52: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.10682022250684e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069132102736372e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067454825944318e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067522741880028e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:53: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.10682022250684e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:54: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069132102736372e-06 is still above the tolerance 1e-06.
    INFO - 15:00:54: ...  40%|████      | 4/10 [00:09<00:05,  1.08 it/sec, obj=-4.01e+3]
 WARNING - 15:00:57: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
    INFO - 15:00:57: ...  50%|█████     | 5/10 [00:12<00:00, 47.71 it/min, obj=-4.51e+3]
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3777923572023366e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:58: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3777923572023366e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 15:00:59: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3777923572023366e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:00: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377945654084145e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3777923572023366e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3780025526238928e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779485439447035e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3776904668827516e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3781026103129487e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377742640146233e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.377997922984005e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:01: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3782574002965124e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:02: MDAJacobi has reached its maximum number of iterations but the normed residual 1.3779467160619637e-06 is still above the tolerance 1e-06.
 WARNING - 15:01:02: MDAJacobi has reached its maximum number of iterations but the normed residual 1.376763131250477e-06 is still above the tolerance 1e-06.
    INFO - 15:01:02: ...  60%|██████    | 6/10 [00:16<00:00, 35.60 it/min, obj=-3.74e+3]
    INFO - 15:01:02: ...  80%|████████  | 8/10 [00:17<00:00, 35.26 it/min, obj=-4.76e+3]
    INFO - 15:01:02: ... 100%|██████████| 10/10 [00:17<00:00, 34.92 it/min, obj=-4.57e+3]
 WARNING - 15:01:02: Optimization found no feasible point !  The least infeasible point is selected.
    INFO - 15:01:02: ... 100%|██████████| 10/10 [00:17<00:00, 34.91 it/min, obj=-4.57e+3]
    INFO - 15:01:02: Optimization result:
    INFO - 15:01:02:    Optimizer info:
    INFO - 15:01:02:       Status: None
    INFO - 15:01:02:       Message: Maximum number of iterations reached. GEMSEO Stopped the driver
    INFO - 15:01:02:       Number of calls to the objective function by the optimizer: 12
    INFO - 15:01:02:    Solution:
 WARNING - 15:01:02:       The solution is not feasible.
    INFO - 15:01:02:       Objective: -3805.197844318766
    INFO - 15:01:02:       Standardized constraints:
    INFO - 15:01:02:          g_1 = [-0.01890636 -0.03395136 -0.04471869 -0.05221743 -0.05764924 -0.13711592
    INFO - 15:01:02:  -0.10288408]
    INFO - 15:01:02:          g_2 = 0.00024768913891715094
    INFO - 15:01:02:          g_3 = [-0.63817382 -0.36182618 -0.13441339 -0.1831937 ]
    INFO - 15:01:02:       Design space:
    INFO - 15:01:02:       +----------+-------------+---------------------+-------------+-------+
    INFO - 15:01:02:       | name     | lower_bound |        value        | upper_bound | type  |
    INFO - 15:01:02:       +----------+-------------+---------------------+-------------+-------+
    INFO - 15:01:02:       | x_shared |     0.01    | 0.06006192228472926 |     0.09    | float |
    INFO - 15:01:02:       | x_shared |    30000    |        60000        |    60000    | float |
    INFO - 15:01:02:       | x_shared |     1.4     |  1.400471025224229  |     1.8     | float |
    INFO - 15:01:02:       | x_shared |     2.5     |         2.5         |     8.5     | float |
    INFO - 15:01:02:       | x_shared |      40     |          70         |      70     | float |
    INFO - 15:01:02:       | x_shared |     500     |         1500        |     1500    | float |
    INFO - 15:01:02:       | x_1      |     0.1     |  0.3994580569121137 |     0.4     | float |
    INFO - 15:01:02:       | x_1      |     0.75    |         0.75        |     1.25    | float |
    INFO - 15:01:02:       | x_2      |     0.75    |         0.75        |     1.25    | float |
    INFO - 15:01:02:       | x_3      |     0.1     |  0.1352994187733632 |      1      | float |
    INFO - 15:01:02:       +----------+-------------+---------------------+-------------+-------+
    INFO - 15:01:02: *** End MDOScenario execution (time: 0:00:17.199981) ***

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

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: 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/envs/develop/lib/python3.9/site-packages/gemseo/post/gradient_sensitivity.py:159: UserWarning: FixedFormatter should only be used together with FixedLocator
  axe.set_xticklabels(design_names, fontsize=font_size, rotation=rotation)

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

Gallery generated by Sphinx-Gallery