Note
Click here to download the full example code
Create a DOE Scenario¶
from __future__ import division, unicode_literals
from gemseo.api import (
configure_logger,
create_design_space,
create_discipline,
create_scenario,
get_available_doe_algorithms,
get_available_post_processings,
)
configure_logger()
Out:
<RootLogger root (INFO)>
Let \((P)\) be a simple optimization problem:
In this example, we will see how to use GEMSEO to solve this problem \((P)\) by means of a Design Of Experiments (DOE)
Define the discipline¶
Firstly, by means of the create_discipline()
API function,
we create an MDODiscipline
of AnalyticDiscipline
type
from a Python function:
expressions_dict = {"y": "x1+x2"}
discipline = create_discipline("AnalyticDiscipline", expressions_dict=expressions_dict)
Now, we want to minimize this MDODiscipline
over a design of experiments (DOE).
Define the design space¶
For that, by means of the create_design_space()
API function,
we define the DesignSpace
\([-5, 5]\times[-5, 5]\)
by using its DesignSpace.add_variable()
method.
design_space = create_design_space()
design_space.add_variable("x1", 1, l_b=-5, u_b=5, var_type="integer")
design_space.add_variable("x2", 1, l_b=-5, u_b=5, var_type="integer")
Define the DOE scenario¶
Then, by means of the create_scenario()
API function,
we define a DOEScenario
from the MDODiscipline
and the DesignSpace
defined above:
scenario = create_scenario(
discipline, "DisciplinaryOpt", "y", design_space, scenario_type="DOE"
)
Execute the DOE scenario¶
Lastly, we solve the OptimizationProblem
included in the
DOEScenario
defined above by minimizing the objective function
over a design of experiments included in the DesignSpace
.
Precisely, we choose a full factorial design of size \(11^2\):
scenario.execute({"algo": "fullfact", "n_samples": 11 ** 2})
Out:
INFO - 12:56:28:
INFO - 12:56:28: *** Start DOE Scenario execution ***
INFO - 12:56:28: DOEScenario
INFO - 12:56:28: Disciplines: AnalyticDiscipline
INFO - 12:56:28: MDOFormulation: DisciplinaryOpt
INFO - 12:56:28: Algorithm: fullfact
INFO - 12:56:28: Optimization problem:
INFO - 12:56:28: Minimize: y(x1, x2)
INFO - 12:56:28: With respect to: x1, x2
INFO - 12:56:28: Full factorial design required. Number of samples along each direction for a design vector of size 2 with 121 samples: 11
INFO - 12:56:28: Final number of samples for DOE = 121 vs 121 requested
INFO - 12:56:28: DOE sampling: 0%| | 0/121 [00:00<?, ?it]
INFO - 12:56:28: DOE sampling: 100%|██████████| 121/121 [00:00<00:00, 1764.23 it/sec, obj=10]
INFO - 12:56:28: Optimization result:
INFO - 12:56:28: Objective value = -10.0
INFO - 12:56:28: The result is feasible.
INFO - 12:56:28: Status: None
INFO - 12:56:28: Optimizer message: None
INFO - 12:56:28: Number of calls to the objective function by the optimizer: 121
INFO - 12:56:28: Design space:
INFO - 12:56:28: +------+-------------+-------+-------------+---------+
INFO - 12:56:28: | name | lower_bound | value | upper_bound | type |
INFO - 12:56:28: +------+-------------+-------+-------------+---------+
INFO - 12:56:28: | x1 | -5 | -5 | 5 | integer |
INFO - 12:56:28: | x2 | -5 | -5 | 5 | integer |
INFO - 12:56:28: +------+-------------+-------+-------------+---------+
INFO - 12:56:28: *** DOE Scenario run terminated ***
{'eval_jac': False, 'algo': 'fullfact', 'n_samples': 121}
The optimum results can be found in the execution log. It is also possible to
extract them by invoking the Scenario.get_optimum()
method. It
returns a dictionary containing the optimum results for the
scenario under consideration:
opt_results = scenario.get_optimum()
print(
"The solution of P is (x*,f(x*)) = ({}, {})".format(
opt_results.x_opt, opt_results.f_opt
),
)
# Available DOE algorithms
# ------------------------
# In order to get the list of available DOE algorithms, use:
algo_list = get_available_doe_algorithms()
print("Available algorithms: {}".format(algo_list))
Out:
The solution of P is (x*,f(x*)) = ([-5. -5.], -10.0)
Available algorithms: ['CustomDOE', 'DiagonalDOE', 'OT_SOBOL', 'OT_RANDOM', 'OT_HASELGROVE', 'OT_REVERSE_HALTON', 'OT_HALTON', 'OT_FAURE', 'OT_MONTE_CARLO', 'OT_FACTORIAL', 'OT_COMPOSITE', 'OT_AXIAL', 'OT_OPT_LHS', 'OT_LHS', 'OT_LHSC', 'OT_FULLFACT', 'OT_SOBOL_INDICES', 'fullfact', 'ff2n', 'pbdesign', 'bbdesign', 'ccdesign', 'lhs']
Available post-processing¶
In order to get the list of available post-processing algorithms, use:
post_list = get_available_post_processings()
print("Available algorithms: {}".format(post_list))
Out:
Available algorithms: ['BasicHistory', 'ConstraintsHistory', 'Correlations', 'GradientSensitivity', 'KMeans', 'ObjConstrHist', 'OptHistoryView', 'ParallelCoordinates', 'ParetoFront', 'QuadApprox', 'RadarChart', 'Robustness', 'SOM', 'ScatterPlotMatrix', 'VariableInfluence']
You can also look at the examples:
Total running time of the script: ( 0 minutes 0.093 seconds)