gemseo / core

formulation module

Baseclass for all formulations

class gemseo.core.formulation.MDOFormulation(disciplines, objective_name, design_space, maximize_objective=False, **options)[source]

Bases: object

Abstract MDO formulation class To be extended in subclasses for use.

The MDOFormulation creates the objective function and constraints from the disciplines.

It defines the process implicitly.

The link between MDODisciplines and objective functions and constraints is made with MDOFunctionGenerator, which generates MDOFunctions from the disciplines.

Constructor, initializes the objective functions and constraints

Parameters
  • disciplines – the disciplines list

  • reference_input_data – the base input data dict for the disciplines

  • objective_name – the objective function data name

  • design_space – the design space

  • maximize_objective – if True, the objective function is maximized, by default, a minimization is performed

NAME = 'MDOFormulation'
add_constraint(output_name, constraint_type='eq', constraint_name=None, value=None, positive=False)[source]

Add a user constraint, i.e. a design constraint in addition to formulation specific constraints such as targets in IDF. The strategy of repartition of constraints is defined in the formulation class.

Parameters
  • output_name – the output name to be used as constraint for instance, if g_1 is given and constraint_type=”eq”, g_1=0 will be added as constraint to the optimizer

  • constraint_type – the type of constraint, “eq” for equality, “ineq” for inequality constraint (Default value = MDOFunction.TYPE_EQ)

  • constraint_name – name of the constraint to be stored, if None, generated from the output name (Default value = None)

  • value – Default value = None)

  • positive – Default value = False)

Returns

the constraint as an MDOFunction False if the formulation does not dispatch the constraint to the optimizers itself

add_observable(output_names, observable_name=None, discipline=None)[source]

Adds observable to the optimization problem. The repartition strategy of the observable is defined in the formulation class.

Parameters
  • output_names (str or list(str)) – names of the outputs to observe

  • observable_name (str) – name of the observable, optional.

  • discipline (MDODiscipline) – if None, detected from inner disciplines, otherwise the discipline used to build the function (Default value = None)

static check_disciplines(disciplines)[source]

Sets the disciplines.

Parameters

disciplines – the disciplines list

property design_space

Proxy for formulation.design_space

Returns

the design space

classmethod get_default_sub_options_values(**options)[source]

When some options of the formulation depend on higher level options, a sub option defaults may be specified here, mainly for use in the API

Parameters

options – options dict required to deduce the sub options grammar

Returns

None, or the sub options defaults

get_expected_dataflow()[source]

Returns the expected data exchange sequence, uUsed for xdsm representation to be overloaded by subclasses

Returns

array of tuples (disc_from, disc_to, array of variable names)

get_expected_workflow()[source]

Returns the sequence of execution of the disciplines to be expected regarding the implementation. The returned value is an array containing disciplines, tuples of disciplines for concurrent execution. 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

array containing disciplines or tuples of disciplines. Used for xdsm representation To be overloaded by subclasses.

get_optim_variables_names()[source]

Gets 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

optimization unknown names

get_sub_disciplines()[source]

Accessor to the sub disciplines. Lists the sub scenarios’ disciplines.

Returns

list of sub disciplines

classmethod get_sub_options_grammar(**options)[source]

When some options of the formulation depend on higher level options, a sub option schema may be specified here, mainly for use in the API

Parameters

options – options dict required to deduce the sub options grammar

Returns

None, or the sub options grammar

get_sub_scenarios()[source]

Lists the disciplines that are actually scenarios

Returns

the list of scenarios

get_top_level_disc()[source]

Returns the disciplines which inputs are required to run the associated scenario By default, returns all disciplines To be overloaded by subclasses

Returns

the list of top level disciplines

get_x_names_of_disc(discipline)[source]

Gets the design variables names of a given discipline

Parameters

discipline – the discipline

Returns

design variables names

mask_x(masking_data_names, x_vect, all_data_names=None)[source]

Masks a vector x_vect, using names masking_data_names, and with respect to reference names all_data_names

Parameters
  • masking_data_names – the names of data to keep

  • x_vect – the vector to mask

  • all_data_names – reference data names, if None, self.get_optim_variables_names() used instead (Default value = None)

Returns

masked x_vect

mask_x_swap_order(masking_data_names, x_vect, all_data_names=None)[source]

Masks a vector x_vect, using names masking_data_names, and with respect to reference names all_data_names possibly swaps the order of the x_vect values if data names orders are inconsistent between masking_data_names and all_data_names

Parameters
  • masking_data_names – the names of data to keep

  • x_vect – the vector to mask

  • all_data_names – reference data names, if None, self.get_optim_variables_names() used instead (Default value = None)

Returns

masked x_vect

unmask_x(masking_data_names, x_masked, all_data_names=None, x_full=None)[source]

Unmasks a vector x, using names masking_data_names, and with respect to reference names all_data_names

Parameters
  • masking_data_names – the names of data to keep

  • x_masked – the vector to unmask

  • all_data_names – reference data names, if None, self.get_optim_variables_names() used instead (Default value = None)

  • x_full – the default values for the full vector, if None, np.zeros() is used

Returns

unmasked x

unmask_x_swap_order(masking_data_names, x_masked, all_data_names=None, x_full=None)[source]

Unmasks a vector x, using names masking_data_names, and with respect to reference names all_data_names eventually swaps the order of the x values if data names order are inconsistent between masking_data_names and all_data_names

Parameters
  • masking_data_names – the names of data to keep

  • x_masked – the masked vector

  • all_data_names – reference data names, if None, self.get_optim_variables_names() used instead (Default value = None)

  • x_full – the default values for the full vector, if None, np.zeros() is used

Returns

unmasked x