gemseo_umdo / formulations

sampling module¶

Sampling for multidisciplinary design problems under uncertainty.

Sampling is an UMDOFormulation estimating the statistics with (quasi) Monte Carlo techniques.

E.g. $$\mathbb{E}[f(x,U)] \approx \frac{1}{N}\sum_{i=1}^N f\left(x,U^{(i)}\right)$$ or $$\mathbb{V}[f(x,U)] \approx \frac{1}{N}\sum_{i=1}^N \left(f\left(x,U^{(i)}\right)- \frac{1}{N}\sum_{j=1}^N f\left(x,U^{(j)}\right)\right)^2$$ where $$U$$ is normally distributed with mean $$\mu$$ and unit variance $$\sigma$$ and $$U^{(1)},\ldots,U^{(1)}$$ are $$N$$ realizations of $$U$$ obtained with an optimized Latin hypercube sampling technique.

class gemseo_umdo.formulations.sampling.Sampling(disciplines, objective_name, design_space, mdo_formulation, uncertain_space, objective_statistic_name, n_samples, objective_statistic_parameters=None, maximize_objective=False, grammar_type='JSONGrammar', algo='OT_OPT_LHS', algo_options=None, seed=1, **options)[source]

Sampling-based robust MDO formulation.

# noqa: D205 D212 D415

Parameters
• disciplines (Sequence[MDODiscipline]) – The disciplines.

• objective_name (str) – The name of the objective function. If a sequence is passed, a vector objective function is created.

• design_space (DesignSpace) – The design space.

• mdo_formulation (MDOFormulation) – The class name of the MDO formulation, e.g. “MDF”.

• uncertain_space (ParameterSpace) – The uncertain variables with their probability distributions.

• objective_statistic_name (str) – The name of the statistic to be applied to the objective.

• n_samples (int) – The number of samples, i.e. the size of the DOE.

• objective_statistic_parameters (Mapping[str, Any] | None) –

The values of the parameters of the statistic to be applied to the objective, if any.

By default it is set to None.

• maximize_objective (bool) –

If True, the objective function is maximized.

By default it is set to False.

• grammar_type (str) –

The type of the input and output grammars, either MDODiscipline.JSON_GRAMMAR_TYPE or MDODiscipline.SIMPLE_GRAMMAR_TYPE.

By default it is set to JSONGrammar.

• algo (str) –

The name of the DOE algorithm.

By default it is set to OT_OPT_LHS.

• algo_options (Mapping[str, Any] | None) –

The options of the DOE algorithm.

By default it is set to None.

• seed (int) –

The description is missing.

By default it is set to 1.

• **options (Any) – The options of the formulation.

Return type

None

add_constraint(output_name, statistic_name, constraint_type='ineq', constraint_name=None, value=None, positive=False, **statistic_parameters)

# noqa: D205 D212 D415

Parameters
• output_name (str | Sequence[str]) – The name of the output to be used as a constraint. For instance, if g_1 is given and constraint_type=”eq”, g_1=0 will be added as a constraint to the optimizer.

• statistic_name (str) – The name of the statistic to be applied to the constraint.

• constraint_type (str) –

The type of constraint, either “eq” for equality constraint or “ineq” for inequality constraint.

By default it is set to ineq.

• constraint_name (str | None) –

The name of the constraint to be stored, If None, the name is generated from the output name.

By default it is set to None.

• value (float | None) –

The value of activation of the constraint. If None, the value is equal to 0.

By default it is set to None.

• positive (bool) –

If True, the inequality constraint is positive.

By default it is set to False.

• **statistic_parameters – The description is missing.

Return type

None

# noqa: D205 D212 D415

Parameters
• output_names (Sequence[str]) – The name(s) of the output(s) to observe.

• statistic_name (str) – The name of the statistic to be applied to the observable.

• observable_name (Sequence[str] | None) –

The name of the observable.

By default it is set to None.

• discipline (MDODiscipline | None) –

The discipline computing the observed outputs. If None, the discipline is detected from inner disciplines.

By default it is set to None.

• **statistic_parameters (Any) – The description is missing.

Return type

None

compute_samples(problem)[source]

Evaluate the functions of a problem with a DOE algorithm.

Parameters

problem (gemseo.algos.opt_problem.OptimizationProblem) – The problem.

Return type

None

classmethod get_default_sub_options_values(**options)

Get the default values of the sub-options of the formulation.

When some options of the formulation depend on higher level options, the default values of these sub-options may be obtained here, mainly for use in the API.

Parameters

**options (str) – The options required to deduce the sub-options grammar.

Returns

Either None or the sub-options default values.

Return type

dict

get_expected_dataflow()

Get the expected data exchange sequence.

This method is used for the XDSM representation and can be overloaded by subclasses.

Returns

The expected sequence of data exchange where the i-th item is described by the starting discipline, the ending discipline and the coupling variables.

Return type
get_expected_workflow()

Get the expected sequence of execution of the disciplines.

This method is used for the XDSM representation and can be overloaded by subclasses.

For instance:

• [A, B] denotes the execution of A, then the execution of B

• (A, B) denotes the concurrent execution of A and B

• [A, (B, C), D] denotes the execution of A, then the concurrent execution of B and C, then the execution of D.

Returns

A sequence of elements which are either an ExecutionSequence or a tuple of ExecutionSequence for concurrent execution.

Return type
get_optim_variables_names()

Get the optimization unknown names to be provided to the optimizer.

This is different from the design variable names provided by the user, since it depends on the formulation, and can include target values for coupling for instance in IDF.

Returns

The optimization variable names.

Return type

list[str]

get_sub_disciplines()

Accessor to the sub-disciplines.

This method lists the sub scenarios’ disciplines.

Returns

The sub-disciplines.

Return type
classmethod get_sub_options_grammar(**options)

Get the sub-options grammar.

When some options of the formulation depend on higher level options, the schema of the sub-options may be obtained here, mainly for use in the API.

Parameters

**options (str) – The options required to deduce the sub-options grammar.

Returns

Either None or the sub-options grammar.

Return type

gemseo.core.grammars.json_grammar.JSONGrammar

get_sub_scenarios()

List the disciplines that are actually scenarios.

Returns

The scenarios.

Return type
get_top_level_disc()

Return the disciplines which inputs are required to run the scenario.

A formulation seeks to evaluate objective function and constraints from inputs. It structures the optimization problem into multiple levels of disciplines. The disciplines directly depending on these inputs are called top level disciplines.

By default, this method returns all disciplines. This method can be overloaded by subclasses.

Returns

The top level disciplines.

Return type

Mask a vector from a subset of names, with respect to a set of names.

This method eventually swaps the order of the values if the order of the data names is inconsistent between these sets.

Parameters
• masking_data_names (Iterable[str]) – The names of the kept data.

• x_vect – The vector to mask.

• all_data_names (Iterable[str] | None) –

The set of all names. If None, use the design variables stored in the design space.

By default it is set to None.

Returns

The masked version of the input vector.

Raises
• IndexError – when the sizes of variables are inconsistent.

• ValueError – when the names of variables are inconsistent.

Return type

ndarray

get_x_names_of_disc(discipline)

Get the design variables names of a given discipline.

Parameters

discipline (gemseo.core.discipline.MDODiscipline) – The discipline.

Returns

The names of the design variables.

Return type

list[str]

Mask a vector from a subset of names, with respect to a set of names.

This method eventually swaps the order of the values if the order of the data names is inconsistent between these sets.

Parameters
• masking_data_names (Iterable[str]) – The names of the kept data.

• x_vect (ndarray) – The vector to mask.

• all_data_names (Iterable[str] | None) –

The set of all names. If None, use the design variables stored in the design space.

By default it is set to None.

Returns

The masked version of the input vector.

Raises

IndexError – when the sizes of variables are inconsistent.

Return type

ndarray

Unmask a vector from a subset of names, with respect to a set of names.

This method eventually swaps the order of the values if the order of the data names is inconsistent between these sets.

Parameters
• masking_data_names (Iterable[str]) – The names of the kept data.

• all_data_names (Iterable[str] | None) –

The set of all names. If None, use the design variables stored in the design space.

By default it is set to None.

• x_full (ndarray) –

The default values for the full vector. If None, use the zero vector.

By default it is set to None.

Returns

The vector related to the input mask.

Raises

IndexError – when the sizes of variables are inconsistent.

Return type

ndarray

update_top_level_disciplines(design_values)

Update the default input values of the top-level disciplines.

Parameters

design_values (numpy.ndarray) – The values of the design variables to update the default input values of the top-level disciplines.

Return type

None

NAME: ClassVar[str] = 'MDOFormulation'

The name of the MDO formulation.

property available_statistics: list[str]

The names of the statistics to quantify the output uncertainties.

property design_space: gemseo.algos.design_space.DesignSpace

The design space on which the formulation is applied.

disciplines: Sequence[MDODiscipline]

The disciplines of the MDO process.

property mdo_formulation: gemseo.core.formulation.MDOFormulation

The MDO formulation.

opt_problem: OptimizationProblem

The optimization problem generated by the formulation from the disciplines.

processed_functions: list[str]

The names of the functions whose statistics have been estimated.

property uncertain_space: gemseo.algos.parameter_space.ParameterSpace

The uncertain variable space.