Optimization History View

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

from __future__ import annotations

from gemseo import configure_logger
from gemseo import create_discipline
from gemseo import create_scenario
from gemseo.problems.sobieski.core.problem import SobieskiProblem

Import

The first step is to import some high-level functions and a method to get the design space.

configure_logger()
<RootLogger root (INFO)>

Description

The OptHistoryView post-processing creates a series of plots:

  • The design variables history - This graph shows the normalized values of the design variables, the \(y\) axis is the index of the inputs in the vector; and the \(x\) axis represents the iterations.

  • The objective function history - It shows the evolution of the objective value during the optimization.

  • The distance to the best design variables - Plots the vector \(log( ||x-x^*|| )\) in log scale.

  • The history of the Hessian approximation of the objective - Plots an approximation of the second order derivatives of the objective function \(\frac{\partial^2 f(x)}{\partial x^2}\), which is a measure of the sensitivity of the function with respect to the design variables, and of the anisotropy of the problem (differences of curvatures in the design space).

  • The inequality constraint history - Portrays the evolution of the values of the constraints. The inequality constraints must be non-positive, that is why the plot must be green or white for satisfied constraints (white = active, red = violated). For an IDF formulation, an additional plot is created to track the equality constraint history.

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()
for constraint in ["g_1", "g_2", "g_3"]:
    scenario.add_constraint(constraint, "ineq")
scenario.execute({"algo": "SLSQP", "max_iter": 100})
    INFO - 16:11:57:
    INFO - 16:11:57: *** Start MDOScenario execution ***
    INFO - 16:11:57: MDOScenario
    INFO - 16:11:57:    Disciplines: SobieskiAerodynamics SobieskiMission SobieskiPropulsion SobieskiStructure
    INFO - 16:11:57:    MDO formulation: MDF
    INFO - 16:11:57: Optimization problem:
    INFO - 16:11:57:    minimize -y_4(x_shared, x_1, x_2, x_3)
    INFO - 16:11:57:    with respect to x_1, x_2, x_3, x_shared
    INFO - 16:11:57:    subject to constraints:
    INFO - 16:11:57:       g_1(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 16:11:57:       g_2(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 16:11:57:       g_3(x_shared, x_1, x_2, x_3) <= 0.0
    INFO - 16:11:57:    over the design space:
    INFO - 16:11:57:    +-------------+-------------+-------+-------------+-------+
    INFO - 16:11:57:    | name        | lower_bound | value | upper_bound | type  |
    INFO - 16:11:57:    +-------------+-------------+-------+-------------+-------+
    INFO - 16:11:57:    | x_shared[0] |     0.01    |  0.05 |     0.09    | float |
    INFO - 16:11:57:    | x_shared[1] |    30000    | 45000 |    60000    | float |
    INFO - 16:11:57:    | x_shared[2] |     1.4     |  1.6  |     1.8     | float |
    INFO - 16:11:57:    | x_shared[3] |     2.5     |  5.5  |     8.5     | float |
    INFO - 16:11:57:    | x_shared[4] |      40     |   55  |      70     | float |
    INFO - 16:11:57:    | x_shared[5] |     500     |  1000 |     1500    | float |
    INFO - 16:11:57:    | x_1[0]      |     0.1     |  0.25 |     0.4     | float |
    INFO - 16:11:57:    | x_1[1]      |     0.75    |   1   |     1.25    | float |
    INFO - 16:11:57:    | x_2         |     0.75    |   1   |     1.25    | float |
    INFO - 16:11:57:    | x_3         |     0.1     |  0.5  |      1      | float |
    INFO - 16:11:57:    +-------------+-------------+-------+-------------+-------+
    INFO - 16:11:57: Solving optimization problem with algorithm SLSQP:
    INFO - 16:11:57: ...   0%|          | 0/100 [00:00<?, ?it]
    INFO - 16:11:57: ...   1%|          | 1/100 [00:00<00:09, 10.98 it/sec, obj=-536]
    INFO - 16:11:57: ...   2%|▏         | 2/100 [00:00<00:12,  7.97 it/sec, obj=-2.12e+3]
 WARNING - 16:11:57: MDAJacobi has reached its maximum number of iterations but the normed residual 1.7130677857005655e-05 is still above the tolerance 1e-06.
    INFO - 16:11:58: ...   3%|▎         | 3/100 [00:00<00:14,  6.86 it/sec, obj=-3.75e+3]
    INFO - 16:11:58: ...   4%|▍         | 4/100 [00:00<00:14,  6.58 it/sec, obj=-3.96e+3]
    INFO - 16:11:58: ...   5%|▌         | 5/100 [00:00<00:14,  6.42 it/sec, obj=-3.96e+3]
    INFO - 16:11:58: ...   6%|▌         | 6/100 [00:00<00:14,  6.32 it/sec, obj=-4e+3]
    INFO - 16:11:58: ...   7%|▋         | 7/100 [00:01<00:13,  6.89 it/sec, obj=-3.98e+3]
    INFO - 16:11:58: ...   8%|▊         | 8/100 [00:01<00:12,  7.36 it/sec, obj=-3.97e+3]
    INFO - 16:11:58: ...   9%|▉         | 9/100 [00:01<00:11,  7.77 it/sec, obj=-3.97e+3]
    INFO - 16:11:58: ...  10%|█         | 10/100 [00:01<00:11,  8.14 it/sec, obj=-3.96e+3]
    INFO - 16:11:58: ...  11%|█         | 11/100 [00:01<00:10,  8.46 it/sec, obj=-3.96e+3]
    INFO - 16:11:58: ...  12%|█▏        | 12/100 [00:01<00:10,  8.75 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  13%|█▎        | 13/100 [00:01<00:09,  9.01 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  14%|█▍        | 14/100 [00:01<00:09,  9.25 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  15%|█▌        | 15/100 [00:01<00:08,  9.47 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  16%|█▌        | 16/100 [00:01<00:08,  9.67 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  17%|█▋        | 17/100 [00:01<00:08,  9.34 it/sec, obj=-3.99e+3]
    INFO - 16:11:59: ...  18%|█▊        | 18/100 [00:01<00:08,  9.56 it/sec, obj=-3.98e+3]
    INFO - 16:11:59: ...  19%|█▉        | 19/100 [00:01<00:08,  9.72 it/sec, obj=-3.97e+3]
    INFO - 16:11:59: ...  20%|██        | 20/100 [00:02<00:08,  9.88 it/sec, obj=-3.97e+3]
    INFO - 16:11:59: ...  21%|██        | 21/100 [00:02<00:07, 10.02 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  22%|██▏       | 22/100 [00:02<00:07, 10.15 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  23%|██▎       | 23/100 [00:02<00:07, 10.28 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  24%|██▍       | 24/100 [00:02<00:07, 10.40 it/sec, obj=-3.96e+3]
    INFO - 16:11:59: ...  25%|██▌       | 25/100 [00:02<00:07, 10.51 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  26%|██▌       | 26/100 [00:02<00:06, 10.61 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  27%|██▋       | 27/100 [00:02<00:06, 10.71 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  28%|██▊       | 28/100 [00:02<00:06, 10.40 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  29%|██▉       | 29/100 [00:02<00:06, 10.49 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  30%|███       | 30/100 [00:02<00:06, 10.58 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  31%|███       | 31/100 [00:02<00:06, 10.66 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  32%|███▏      | 32/100 [00:02<00:06, 10.74 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  33%|███▎      | 33/100 [00:03<00:06, 10.82 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  34%|███▍      | 34/100 [00:03<00:06, 10.89 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  35%|███▌      | 35/100 [00:03<00:05, 10.96 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  36%|███▌      | 36/100 [00:03<00:05, 11.02 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  37%|███▋      | 37/100 [00:03<00:05, 11.09 it/sec, obj=-3.96e+3]
    INFO - 16:12:00: ...  38%|███▊      | 38/100 [00:03<00:05, 11.15 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  39%|███▉      | 39/100 [00:03<00:05, 10.90 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  40%|████      | 40/100 [00:03<00:05, 10.96 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  41%|████      | 41/100 [00:03<00:05, 11.02 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  42%|████▏     | 42/100 [00:03<00:05, 11.07 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  43%|████▎     | 43/100 [00:03<00:05, 11.13 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  44%|████▍     | 44/100 [00:03<00:05, 11.18 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  45%|████▌     | 45/100 [00:04<00:04, 11.23 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  46%|████▌     | 46/100 [00:04<00:04, 11.28 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  47%|████▋     | 47/100 [00:04<00:04, 11.32 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  48%|████▊     | 48/100 [00:04<00:04, 11.36 it/sec, obj=-3.96e+3]
    INFO - 16:12:01: ...  49%|████▉     | 49/100 [00:04<00:04, 11.41 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  50%|█████     | 50/100 [00:04<00:04, 11.19 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  51%|█████     | 51/100 [00:04<00:04, 11.23 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  52%|█████▏    | 52/100 [00:04<00:04, 11.28 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  53%|█████▎    | 53/100 [00:04<00:04, 11.32 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  54%|█████▍    | 54/100 [00:04<00:04, 11.36 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  55%|█████▌    | 55/100 [00:04<00:03, 11.40 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  56%|█████▌    | 56/100 [00:04<00:03, 11.44 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  57%|█████▋    | 57/100 [00:04<00:03, 11.47 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  58%|█████▊    | 58/100 [00:05<00:03, 11.51 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  59%|█████▉    | 59/100 [00:05<00:03, 11.54 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: ...  60%|██████    | 60/100 [00:05<00:03, 11.57 it/sec, obj=-3.96e+3]
    INFO - 16:12:02: Optimization result:
    INFO - 16:12:02:    Optimizer info:
    INFO - 16:12:02:       Status: 8
    INFO - 16:12:02:       Message: Positive directional derivative for linesearch
    INFO - 16:12:02:       Number of calls to the objective function by the optimizer: 61
    INFO - 16:12:02:    Solution:
    INFO - 16:12:02:       The solution is feasible.
    INFO - 16:12:02:       Objective: -3963.526590331003
    INFO - 16:12:02:       Standardized constraints:
    INFO - 16:12:02:          g_1 = [-0.01808928 -0.03336673 -0.04426525 -0.0518475  -0.05733697 -0.13720865
    INFO - 16:12:02:  -0.10279135]
    INFO - 16:12:02:          g_2 = 1.2647099197682365e-05
    INFO - 16:12:02:          g_3 = [-7.67217775e-01 -2.32782225e-01  7.01281322e-05 -1.83255000e-01]
    INFO - 16:12:02:       Design space:
    INFO - 16:12:02:       +-------------+-------------+---------------------+-------------+-------+
    INFO - 16:12:02:       | name        | lower_bound |        value        | upper_bound | type  |
    INFO - 16:12:02:       +-------------+-------------+---------------------+-------------+-------+
    INFO - 16:12:02:       | x_shared[0] |     0.01    | 0.06000316177479941 |     0.09    | float |
    INFO - 16:12:02:       | x_shared[1] |    30000    |        60000        |    60000    | float |
    INFO - 16:12:02:       | x_shared[2] |     1.4     |         1.4         |     1.8     | float |
    INFO - 16:12:02:       | x_shared[3] |     2.5     |         2.5         |     8.5     | float |
    INFO - 16:12:02:       | x_shared[4] |      40     |          70         |      70     | float |
    INFO - 16:12:02:       | x_shared[5] |     500     |         1500        |     1500    | float |
    INFO - 16:12:02:       | x_1[0]      |     0.1     |         0.4         |     0.4     | float |
    INFO - 16:12:02:       | x_1[1]      |     0.75    |         0.75        |     1.25    | float |
    INFO - 16:12:02:       | x_2         |     0.75    |         0.75        |     1.25    | float |
    INFO - 16:12:02:       | x_3         |     0.1     |  0.1562557027984589 |      1      | float |
    INFO - 16:12:02:       +-------------+-------------+---------------------+-------------+-------+
    INFO - 16:12:02: *** End MDOScenario execution (time: 0:00:05.306185) ***

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

Post-process scenario

Lastly, we post-process the scenario by means of the OptHistoryView plot which plots the history of optimization for both objective function, constraints, design parameters and distance to the optimum.

Tip

Each post-processing method requires different inputs and offers a variety of customization options. Use the high-level 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(
    "OptHistoryView", save=False, show=True, variable_names=["x_2", "x_1"]
)
  • Evolution of the optimization variables
  • Evolution of the objective value
  • Distance to the optimum
  • Hessian diagonal approximation
  • Evolution of the inequality constraints
<gemseo.post.opt_history_view.OptHistoryView object at 0x7f176859e730>

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

Gallery generated by Sphinx-Gallery