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 - 10:02:37:
    INFO - 10:02:37: *** Start MDOScenario execution ***
    INFO - 10:02:37: MDOScenario
    INFO - 10:02:37:    Disciplines: SobieskiPropulsion SobieskiAerodynamics SobieskiStructure SobieskiMission
    INFO - 10:02:37:    MDO formulation: MDF
    INFO - 10:02:37: Optimization problem:
    INFO - 10:02:37:    minimize -y_4(x_shared, x_1, x_2, x_3)
    INFO - 10:02:37:    with respect to x_1, x_2, x_3, x_shared
    INFO - 10:02:37:    subject to constraints:
    INFO - 10:02:37:       g_1(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 10:02:37:       g_2(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 10:02:37:       g_3(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 10:02:37:    over the design space:
    INFO - 10:02:37:    +----------+-------------+-------+-------------+-------+
    INFO - 10:02:37:    | name     | lower_bound | value | upper_bound | type  |
    INFO - 10:02:37:    +----------+-------------+-------+-------------+-------+
    INFO - 10:02:37:    | x_shared |     0.01    |  0.05 |     0.09    | float |
    INFO - 10:02:37:    | x_shared |    30000    | 45000 |    60000    | float |
    INFO - 10:02:37:    | x_shared |     1.4     |  1.6  |     1.8     | float |
    INFO - 10:02:37:    | x_shared |     2.5     |  5.5  |     8.5     | float |
    INFO - 10:02:37:    | x_shared |      40     |   55  |      70     | float |
    INFO - 10:02:37:    | x_shared |     500     |  1000 |     1500    | float |
    INFO - 10:02:37:    | x_1      |     0.1     |  0.25 |     0.4     | float |
    INFO - 10:02:37:    | x_1      |     0.75    |   1   |     1.25    | float |
    INFO - 10:02:37:    | x_2      |     0.75    |   1   |     1.25    | float |
    INFO - 10:02:37:    | x_3      |     0.1     |  0.5  |      1      | float |
    INFO - 10:02:37:    +----------+-------------+-------+-------------+-------+
    INFO - 10:02:37: Solving optimization problem with algorithm SLSQP:
    INFO - 10:02:37: ...   0%|          | 0/10 [00:00<?, ?it]
    INFO - 10:02:39: ...  20%|██        | 2/10 [00:02<00:01,  4.71 it/sec, obj=-2.12e+3]
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067738728359277e-06 is still above the tolerance 1e-06.
    INFO - 10:02:42: ...  30%|███       | 3/10 [00:05<00:03,  1.99 it/sec, obj=-3.81e+3]
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068245019970912e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:42: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068104192521803e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069168537347672e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067738728359277e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068245019970912e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:43: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068104192521803e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069168537347672e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067738728359277e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068245019970912e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:44: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068104192521803e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069168537347672e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067738728359277e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068245019970912e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.106813064067522e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:45: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067846748313078e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068165770949126e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068099188494698e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067815296068116e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1067873198565832e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068260032962304e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1068104192521803e-06 is still above the tolerance 1e-06.
 WARNING - 10:02:46: MDAJacobi has reached its maximum number of iterations but the normed residual 1.1069168537347672e-06 is still above the tolerance 1e-06.
    INFO - 10:02:46: ...  40%|████      | 4/10 [00:09<00:05,  1.07 it/sec, obj=-3.96e+3]
 WARNING - 10:02:50: Optimization found no feasible point !  The least infeasible point is selected.
    INFO - 10:02:50: ...  40%|████      | 4/10 [00:12<00:00, 47.20 it/min, obj=-3.96e+3]
    INFO - 10:02:50: Optimization result:
    INFO - 10:02:50:    Optimizer info:
    INFO - 10:02:50:       Status: 8
    INFO - 10:02:50:       Message: Positive directional derivative for linesearch
    INFO - 10:02:50:       Number of calls to the objective function by the optimizer: 5
    INFO - 10:02:50:    Solution:
 WARNING - 10:02:50:       The solution is not feasible.
    INFO - 10:02:50:       Objective: -3963.4793655945646
    INFO - 10:02:50:       Standardized constraints:
    INFO - 10:02:50:          g_1 = [-0.01805514 -0.03334218 -0.04424616 -0.0518319  -0.0573238  -0.13720865
    INFO - 10:02:50:  -0.10279135]
    INFO - 10:02:50:          g_2 = 1.3880494162954449e-06
    INFO - 10:02:50:          g_3 = [-7.67293720e-01 -2.32706280e-01  1.49314966e-04 -1.83255000e-01]
    INFO - 10:02:50:       Design space:
    INFO - 10:02:50:       +----------+-------------+---------------------+-------------+-------+
    INFO - 10:02:50:       | name     | lower_bound |        value        | upper_bound | type  |
    INFO - 10:02:50:       +----------+-------------+---------------------+-------------+-------+
    INFO - 10:02:50:       | x_shared |     0.01    | 0.06000034701235407 |     0.09    | float |
    INFO - 10:02:50:       | x_shared |    30000    |        60000        |    60000    | float |
    INFO - 10:02:50:       | x_shared |     1.4     |         1.4         |     1.8     | float |
    INFO - 10:02:50:       | x_shared |     2.5     |         2.5         |     8.5     | float |
    INFO - 10:02:50:       | x_shared |      40     |          70         |      70     | float |
    INFO - 10:02:50:       | x_shared |     500     |         1500        |     1500    | float |
    INFO - 10:02:50:       | x_1      |     0.1     |         0.4         |     0.4     | float |
    INFO - 10:02:50:       | x_1      |     0.75    |         0.75        |     1.25    | float |
    INFO - 10:02:50:       | x_2      |     0.75    |         0.75        |     1.25    | float |
    INFO - 10:02:50:       | x_3      |     0.1     |  0.1562680753252128 |      1      | float |
    INFO - 10:02:50:       +----------+-------------+---------------------+-------------+-------+
    INFO - 10:02:50: *** End MDOScenario execution (time: 0:00:12.724019) ***

{'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/4.0.1/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 13.498 seconds)

Gallery generated by Sphinx-Gallery