gemseo / disciplines / scenario_adapters

Show inherited members

mdo_scenario_adapter module

A discipline running a scenario.

class gemseo.disciplines.scenario_adapters.mdo_scenario_adapter.MDOScenarioAdapter(scenario, input_names, output_names, reset_x0_before_opt=False, set_x0_before_opt=False, set_bounds_before_opt=False, cache_type=CacheType.SIMPLE, output_multipliers=False, grammar_type=GrammarType.JSON, name=None, keep_opt_history=False, opt_history_file_prefix='', scenario_log_level=None)[source]

Bases: MDODiscipline

An adapter class for MDO Scenario.

The specified input variables update the default input data of the top level discipline while the output ones filter the output data from the top level discipline outputs.

Initialize self. See help(type(self)) for accurate signature.

Parameters:
  • scenario (Scenario) – The scenario to adapt.

  • input_names (Sequence[str]) – The inputs to overload at sub-scenario execution.

  • output_names (Sequence[str]) – The outputs to get from the sub-scenario execution.

  • reset_x0_before_opt (bool) –

    If True, reset the initial guess before running the sub optimization.

    By default it is set to False.

  • set_x0_before_opt (bool) –

    If True, set the initial guess of the sub-scenario. This is useful for multi-start optimization.

    By default it is set to False.

  • set_bounds_before_opt (bool) –

    If True, set the bounds of the design space. This is useful for trust regions.

    By default it is set to False.

  • cache_type (MDODiscipline.CacheType) –

    The type of cache policy.

    By default it is set to “SimpleCache”.

  • output_multipliers (bool) –

    If True, the Lagrange multipliers of the scenario optimal solution are computed and added to the outputs.

    By default it is set to False.

  • grammar_type (MDODiscipline.GrammarType) –

    The type of the input and output grammars.

    By default it is set to “JSONGrammar”.

  • name (str | None) – The name of the scenario adapter. If None, use the name of the scenario adapter suffixed by "_adapter".

  • keep_opt_history (bool) –

    Whether to keep databases copies after each execution.

    By default it is set to False.

  • opt_history_file_prefix (str) –

    The base name for the databases to be exported. The full names of the databases are built from the provided base name suffixed by "_i.h5" where i is replaced by the execution number, i.e the number of stored databases. If empty, the databases are not exported. The databases can be exported only is keep_opt_history=True.

    By default it is set to “”.

  • scenario_log_level (int | None) – The level of the root logger during the scenario execution. If None, do not change the level of the root logger.

Raises:

ValueError – If both reset_x0_before_opt and set_x0_before_opt are True.

add_outputs(output_names)[source]

Add outputs to the scenario adapter.

Parameters:

output_names (Iterable[str]) – The names of the outputs to be added.

Return type:

None

static get_bnd_mult_name(variable_name, is_upper)[source]

Return the name of the lower bound-constraint multiplier of a variable.

Parameters:
  • variable_name (str) – The name of the variable.

  • is_upper (bool) – If True, return name of the upper bound-constraint multiplier. Otherwise, return the name of the lower bound-constraint multiplier.

Returns:

The name of a bound-constraint multiplier.

Return type:

str

static get_cstr_mult_name(constraint_name)[source]

Return the name of the multiplier of a constraint.

Parameters:

constraint_name (str) – The name of the constraint.

Returns:

The name of the multiplier.

Return type:

str

get_expected_dataflow()[source]

Return the expected data exchange sequence.

This method is used for the XDSM representation.

The default expected data exchange sequence is an empty list.

See also

MDOFormulation.get_expected_dataflow

Returns:

The data exchange arcs.

Return type:

list[tuple[MDODiscipline, MDODiscipline, list[str]]]

get_expected_workflow()[source]

Return the expected execution sequence.

This method is used for the XDSM representation.

The default expected execution sequence is the execution of the discipline itself.

See also

MDOFormulation.get_expected_workflow

Returns:

The expected execution sequence.

Return type:

LoopExecSequence

LOWER_BND_SUFFIX = '_lower_bnd'
MULTIPLIER_SUFFIX = '_multiplier'
UPPER_BND_SUFFIX = '_upper_bnd'
cache: AbstractCache | None

The cache containing one or several executions of the discipline according to the cache policy.

data_processor: DataProcessor

A tool to pre- and post-process discipline data.

databases: list[Database]

The copies of the scenario databases after execution.

exec_for_lin: bool

Whether the last execution was due to a linearization.

input_grammar: BaseGrammar

The input grammar.

jac: MutableMapping[str, MutableMapping[str, ndarray | csr_array | JacobianOperator]]

The Jacobians of the outputs wrt inputs.

The structure is {output: {input: matrix}}.

keep_opt_history: bool

Whether to keep databases copies after each execution.

name: str

The name of the discipline.

output_grammar: BaseGrammar

The output grammar.

post_optimal_analysis: PostOptimalAnalysis

The post-optimal analysis.

re_exec_policy: ReExecutionPolicy

The policy to re-execute the same discipline.

residual_variables: dict[str, str]

The output variables mapping to their inputs, to be considered as residuals; they shall be equal to zero.

run_solves_residuals: bool

Whether the run method shall solve the residuals.

scenario: Scenario

The scenario to be adapted.

Examples using MDOScenarioAdapter

Multistart optimization

Multistart optimization