gemseo / core

function module

Functions, f(x), from disciplines execution

class gemseo.core.function.MDOFunction(func, name, f_type=None, jac=None, expr=None, args=None, dim=None, outvars=None, force_real=False)[source]

Bases: object

A container object to represent a function in an MDO process

Initializes the function attributes

  • func – the pointer to the function to be actually called

  • name – the name of the function as a string

  • f_type – the type of function among (obj, eq, ineq, obs)

  • jac – the jacobian

  • expr – the function expression

  • args – the function arguments

  • dim – the output dimension

  • outvars – the array of variable names used as inputs of the function

  • force_real – if True, cast the results to real value

AVAILABLE_TYPES = ['obj', 'eq', 'ineq', 'obs']
DICT_REPR_ATTR = ['name', 'f_type', 'expr', 'args', 'dim']
TYPE_EQ = 'eq'
TYPE_INEQ = 'ineq'
TYPE_OBJ = 'obj'
TYPE_OBS = 'obs'
apply_operator(other_f, operator, operator_repr)[source]

Defines addition/substraction for MDOFunction Supports automatic differentiation if other_f and self have a Jacobian

  • other_f – param operator:

  • operator_repr – the representation as a string

  • operator – the operator as a function pointer

property args

Accessor to the arguments list

check_grad(x_vect, method='FirstOrderFD', step=1e-06, error_max=1e-08)[source]

Checks the gradient of self

  • x_vect – the vector at which the function is checked

  • method – FirstOrderFD or ComplexStep (Default value = “FirstOrderFD”)

  • step – the step for approximation (Default value = 1e-6)

  • error_max – Default value = 1e-8)

property dim

Accessor to the dimension

evaluate(x_vect, force_real=False)[source]

Evaluate the function

  • x_vect – the function argument

  • force_real – if True, cast the results to real value

property expr

Accessor to the expression

property f_type

Accessor to the function type

property func

Accessor to the func property


Returns a dict representation of self for serialization Pointers to functions are removed


a dict with attributes names as keys


Check if MDOFunction has an args


True if self has an args


Check if MDOFunction has a dimension


True if self has a dimension


Check if MDOFunction has an expression


True if self has an expression


Check if MDOFunction has an type


True if self has a type


Check if MDOFunction has a jacobian


True if self has a jacobian


Check if MDOFunction has an array of input variables


True if self has a dimension

static init_from_dict_repr(**kwargs)[source]

Initalizes a new Function from a data dict typically used for deserialization


kwargs – key value pairs from DICT_REPR_ATTR


Returns True if self.f_type is eq or ineq

property jac

Accessor to the jacobian

property n_calls

Returns the number of calls to execute() which triggered the _run() multiprocessing safe

property name

Accessor to the name of the function


Adds an offset value to the function


value – the offset value


the offset function as an MDOFunction

property outvars

Accessor to the array of input variable names used by the function

set_pt_from_database(database, design_space, normalize=False, jac=True, x_tolerance=1e-10)[source]

self.__call__(x) returns f(x) if x is in the database and in the database keys Idem for jac

  • database – the database to read

  • design_space – the design space used for normalization

  • normalize – if True, x_n is unnormalized before call

  • jac – if True, a jacobian pointer is also generated

class gemseo.core.function.MDOFunctionGenerator(*args, **kwargs)[source]

Bases: object

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

It uses closures to generate functions instances from a discipline execution.



discipline – the discipline from which the generator builds functions

get_function(input_names_list, output_names_list, default_inputs=None)[source]

Builds a function from a discipline input and output lists.

  • input_names_list – names of inputs of the disciplines to be inputs of the function

  • output_names_list – names of outputs of the disciplines to be returned by the function

  • default_inputs – a default inputs dict to eventually overload the discipline’s default inputs when evaluating the discipline


the function

class gemseo.core.function.MDOLinearFunction(coefficients, name, f_type=None, args=None)[source]

Bases: gemseo.core.function.MDOFunction

Linear multivariate function with coefficients (a_i) f(x) = sum_{i=1}^n a_i * x_i

Initialize the function attributes

  • coefficients – coefficients of the linear function

  • name – the name of the function as a string

  • f_type – the type of function among (obj, eq, ineq)

  • args – the function arguments

class gemseo.core.function.NotImplementedCallable[source]

Bases: object

A not implemented callable object