gemseo.algos.problem_function module#
A function to be attached to a problem.
- class ProblemFunction(function, output_evaluation_sequence, jacobian_evaluation_sequence, with_normalized_inputs, database, counter, stop_if_nan, design_space, store_jacobian=True, differentiation_method=None, **differentiation_method_options)[source]#
Bases:
MDOFunction
,Serializable
A function to be attached to a problem.
- Parameters:
function (MDOFunction) -- The original function.
output_evaluation_sequence (Iterable[Callable[[NumberArray], NumberArray]]) -- The execution sequence to compute an output value from an input value.
jacobian_evaluation_sequence (Iterable[Callable[[NumberArray], NumberArray]]) -- The execution sequence to compute a Jacobian from an input value.
with_normalized_inputs (bool) -- Whether the function expects normalized inputs.
database (Database | None) -- The database to store and retrieve the evaluations; if
None
, do not use database.counter (EvaluationCounter) -- The counter of evaluations.
stop_if_nan (bool) -- Whether the evaluation stops when a function returns
NaN
.design_space (DesignSpace) -- The design space on which to evaluate the function.
store_jacobian (bool) --
Whether to store the Jacobian matrices in the database.
By default it is set to True.
differentiation_method (ApproximationMode | None) -- The differentiation method to compute the Jacobian. If
None
, use the original derivatives.**differentiation_method_options (Any) -- The options of the differentiation method.
- static check_function_output_includes_nan(value, stop_if_nan=True, function_name='', xu_vect=None)[source]#
Check if an array contains a NaN value.
- Parameters:
value (ndarray) -- The array to be checked.
stop_if_nan (bool) --
Whether to stop if value contains a NaN.
By default it is set to True.
function_name (str) --
The name of the function. If empty, the arguments
function_name
andxu_vect
are ignored.By default it is set to "".
xu_vect (ndarray | None) -- The point at which the function is evaluated.
None
if and only iffunction_name
is empty.
- Raises:
DesvarIsNan -- If the value is a function input containing a NaN.
FunctionIsNan -- If the value is a function output containing a NaN.
- Return type:
None
- evaluate(x_vect)[source]#
Evaluate the function and store the output value in
last_eval
.When the output dimension
dim
is not defined, it is inferred on the first evaluation.- Parameters:
x_vect (NumberArray) -- The input value of the function.
- Returns:
Either the raw output value or its real part when
force_real
is True.- Return type:
OutputType
- property func: Callable[[ndarray[Any, dtype[number[Any]]]], ndarray[Any, dtype[number[Any]]] | Complex]#
The wrapped function.
- property n_calls: int#
The number of times the function has been evaluated.
This count is both multiprocess- and multithread-safe, thanks to the locking process used by
MDOFunction.evaluate()
.