{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Basic history\n\nIn this example, we illustrate the use of the :class:`.BasicHistory` plot\non the Sobieski's SSBJ problem.\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "from __future__ import annotations\n\nfrom gemseo.api import configure_logger\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario\nfrom gemseo.problems.sobieski.core.problem import SobieskiProblem\nfrom matplotlib import pyplot as plt" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Import\nThe first step is to import some functions from the API\nand a method to get the design space.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "configure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Description\nThe :class:`~gemseo.post.basic_history.BasicHistory` post-processing\nplots any of the constraint or objective functions\nw.r.t. the optimization iterations or sampling snapshots.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create disciplines\nAt this point, we instantiate the disciplines of Sobieski's SSBJ problem:\nPropulsion, Aerodynamics, Structure and Mission\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "disciplines = create_discipline(\n [\n \"SobieskiPropulsion\",\n \"SobieskiAerodynamics\",\n \"SobieskiStructure\",\n \"SobieskiMission\",\n ]\n)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create design space\nWe also read the design space from the :class:`.SobieskiProblem`.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "design_space = SobieskiProblem().design_space" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create and execute scenario\nThe next step is to build an MDO scenario in order to maximize the range,\nencoded 'y_4', with respect to the design parameters, while satisfying the\ninequality constraints 'g_1', 'g_2' and 'g_3'. We can use the MDF formulation,\nthe SLSQP optimization algorithm\nand a maximum number of iterations equal to 100.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scenario = create_scenario(\n disciplines,\n formulation=\"MDF\",\n objective_name=\"y_4\",\n maximize_objective=True,\n design_space=design_space,\n)\nscenario.set_differentiation_method(\"user\")\nfor constraint in [\"g_1\", \"g_2\", \"g_3\"]:\n scenario.add_constraint(constraint, \"ineq\")\nscenario.execute({\"algo\": \"SLSQP\", \"max_iter\": 10})" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Post-process scenario\nLastly, we post-process the scenario by means of the :class:`.BasicHistory`\nplot which plots any of the constraint or objective functions\nw.r.t. optimization iterations or sampling snapshots.\n\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ ".. tip::\n\n Each post-processing method requires different inputs and offers a variety\n of customization options. Use the API function\n :meth:`~gemseo.api.get_post_processing_options_schema` to print a table with\n the options for any post-processing algorithm.\n Or refer to our dedicated page:\n `gen_post_algos`.\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "scenario.post_process(\n \"BasicHistory\", variable_names=[\"g_1\", \"g_2\", \"g_3\"], save=False, show=False\n)\nscenario.post_process(\"BasicHistory\", variable_names=[\"y_4\"], save=False, show=False)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Set the boolean instance attribute\n :attr:`.OptimizationProblem.use_standardized_objective` to ``False``\n to plot the objective to maximize as a performance function.