# Copyright 2021 IRT Saint Exupéry, https://www.irt-saintexupery.com
#
# This work is licensed under a BSD 0-Clause License.
#
# Permission to use, copy, modify, and/or distribute this software
# for any purpose with or without fee is hereby granted.
#
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL
# THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT,
# OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING
# FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION
# WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
"""Sample several disciplines.
==========================

The :class:`.DOEScenario` class is used to solve trade-off studies,
based on a design space, an objective and optional constraints.
But for a simple need of sampling disciplines,
this class is not very appropriate
because the notions of objective, which is mandatory, and constraints do not make sense
and the same for the log including information related to an optimization problem.
Rather than using this class,
you can consider the :func:`.sample_disciplines` function
whose API has been designed fro sampling purposes.
"""

from __future__ import annotations

from gemseo import sample_disciplines
from gemseo.algos.design_space import DesignSpace
from gemseo.disciplines.analytic import AnalyticDiscipline

# %%
# First,
# create the disciplines:
disciplines = [
    AnalyticDiscipline({"y1": "x0+x1+y2"}),
    AnalyticDiscipline({"y2": "x0+x2+2*y1"}),
    AnalyticDiscipline({"y0": "x0+y1+y2"}),
]

# %%
# Then,
# create the input space:
input_space = DesignSpace()
input_space.add_variable("x0", lower_bound=0.0, upper_bound=1.0)
input_space.add_variable("x1", lower_bound=0.0, upper_bound=1.0)
input_space.add_variable("x2", lower_bound=0.0, upper_bound=1.0)

# %%
# Lastly,
# sample these disciplines over the input space
# with the outputs of interest, the number of samples and the name of the DOE algorithm:
io_dataset = sample_disciplines(
    disciplines, input_space, ["y0", "y2"], algo_name="PYDOE_FULLFACT", n_samples=10
)
io_dataset

# %%
# Note that this function creates an :class:`.MDF` formulation
# and samples the top-level disciplines generated by this MDO formulation.
# The ``formulation`` and ``formulation_options`` arguments
# allow to customize the MDO formulation
# and the options of the DOE algorithm can be passed as keyword arguments.
