{
  "cells": [
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "%matplotlib inline"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "\n# Use a design of experiments from an array\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "import numpy as np\nfrom gemseo.api import create_design_space\nfrom gemseo.api import create_discipline\nfrom gemseo.api import create_scenario"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Let us consider a discipline implementing the function $y=a*b$\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "discipline = create_discipline(\"AnalyticDiscipline\", expressions={\"y\": \"a*b\"})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "where $a,b\\in\\{1,2,\\ldots,10\\}$:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "design_space = create_design_space()\ndesign_space.add_variable(\"a\", 1, design_space.INTEGER, 1, 10)\ndesign_space.add_variable(\"b\", 1, design_space.INTEGER, 1, 10)"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "We want to evaluate this discipline over this design space\nby using the following input samples:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "sample_1 = [1.0, 2.0]\nsample_2 = [2.0, 3.0]\nsamples = np.array([sample_1, sample_2])"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "For that, we can create a scenario and execute it with a :class:`.CustomDOE`\nwith the option \"samples\":\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "scenario = create_scenario(\n    [discipline], \"DisciplinaryOpt\", \"y\", design_space, scenario_type=\"DOE\"\n)\nscenario.execute({\"algo\": \"CustomDOE\", \"algo_options\": {\"samples\": samples}})"
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {},
      "source": [
        "Then,\nwe can display the content of the database as a dataframe\nand check the values of the output,\nwhich should be the product of $a$ and $b$:\n\n"
      ]
    },
    {
      "cell_type": "code",
      "execution_count": null,
      "metadata": {
        "collapsed": false
      },
      "outputs": [],
      "source": [
        "opt_problem = scenario.formulation.opt_problem\ndataset = opt_problem.export_to_dataset(name=\"custom_sampling\", opt_naming=False)\nprint(dataset.export_to_dataframe())"
      ]
    }
  ],
  "metadata": {
    "kernelspec": {
      "display_name": "Python 3",
      "language": "python",
      "name": "python3"
    },
    "language_info": {
      "codemirror_mode": {
        "name": "ipython",
        "version": 3
      },
      "file_extension": ".py",
      "mimetype": "text/x-python",
      "name": "python",
      "nbconvert_exporter": "python",
      "pygments_lexer": "ipython3",
      "version": "3.9.13"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}