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

Parameters
  • 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

Parameters
  • 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

Parameters
  • 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

Parameters
  • 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

get_data_dict_repr()[source]

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

Returns

a dict with attributes names as keys

has_args()[source]

Check if MDOFunction has an args

Returns

True if self has an args

has_dim()[source]

Check if MDOFunction has a dimension

Returns

True if self has a dimension

has_expr()[source]

Check if MDOFunction has an expression

Returns

True if self has an expression

has_f_type()[source]

Check if MDOFunction has an type

Returns

True if self has a type

has_jac()[source]

Check if MDOFunction has a jacobian

Returns

True if self has a jacobian

has_outvars()[source]

Check if MDOFunction has an array of input variables

Returns

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

Parameters

kwargs – key value pairs from DICT_REPR_ATTR

is_constraint()[source]

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

offset(value)[source]

Adds an offset value to the function

Parameters

value – the offset value

Returns

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 self.name in the database keys Idem for jac

Parameters
  • 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.

Constructor

Parameters

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.

Parameters
  • 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

Returns

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

Parameters
  • 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