{ "cells": [ { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "%matplotlib inline" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "\n# Dataset from an optimization problem\n\nIn this example, we will see how to build a :class:`.Dataset` from objects\nof an :class:`.OptimizationProblem`.\nFor that, we need to import this :class:`.Dataset` class:\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.sellar.sellar_design_space import SellarDesignSpace\n\nconfigure_logger()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Synthetic data\nWe can sample the :class:`.Sellar1` discipline and use the\ncorresponding :class:`.OptimizationProblem`:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "discipline = create_discipline(\"Sellar1\")\ndesign_space = SellarDesignSpace().filter(discipline.get_input_data_names())\n\nscenario = create_scenario(\n [discipline], \"DisciplinaryOpt\", \"y_1\", design_space, scenario_type=\"DOE\"\n)\nscenario.execute({\"algo\": \"lhs\", \"n_samples\": 5})\nopt_problem = scenario.formulation.opt_problem" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Create a dataset\nWe can easily build a dataset from this :class:`.OptimizationProblem`:\neither by separating the design parameters from the function\n(default option):\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dataset = opt_problem.export_to_dataset(\"sellar1_doe\")\nprint(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or by considering all features as default parameters:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dataset = opt_problem.export_to_dataset(\"sellar1_doe\", categorize=False)\nprint(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "or by using an input-output naming rather than an optimization naming:\n\n" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "collapsed": false }, "outputs": [], "source": [ "dataset = opt_problem.export_to_dataset(\"sellar1_doe\", opt_naming=False)\nprint(dataset)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
Only design variables and functions (objective function, constraints) are\n stored in the database. If you want to store state variables, you must add\n them as observables before the problem is executed. Use the\n :meth:`~gemseo.core.scenario.Scenario.add_observable` method.