gemseo.disciplines.auto_py module#
A discipline interfacing a Python function automatically.
- class AutoDiscDataProcessor[source]#
Bases:
DataProcessorA data processor forcing input data to float and output data to arrays.
Convert all GEMSEO scalar input data to floats, and convert all discipline output data to NumPy arrays.
- post_process_data(data)[source]#
Post-process the output data.
Execute a post-processing of the output data after the
_run()method of the discipline is called, and before they are checked byvalidate_output_data().
- class AutoPyDiscipline(py_func, py_jac=None, name='', use_arrays=False)[source]#
Bases:
DisciplineWrap a Python function into a discipline.
A simplified and straightforward way of integrating a discipline from a Python function that:
returns variables, e.g.
return xorreturn x, y, but no expression likereturn a+borreturn a+b, y,must have a default value per argument if the
AutoPyDisciplineis used by anMDA(deriving fromBaseMDA), as in the case ofMDFandBiLevelformulations, in the presence of strong couplings.
The input names of the discipline are the names of the Python function arguments and the output names are the names of the variable listed in the return statement.
By default, the arguments and returned variables are assumed to be either scalars or NumPy arrays of length greater than 1. When
use_arraysisTrue, the scalar arguments are assumed to be NumPy arrays of length equal to 1. When all the arguments and returned variables have type hints, these types are used by the input and output grammars.The default input values are the default values of the Python function arguments, if any.
This example from the documentation illustrates this feature.
Initialize self. See help(type(self)) for accurate signature.
- Parameters:
py_func (Callable) -- The Python function to compute the outputs from the inputs.
py_jac (Callable | None) -- The Python function to compute the Jacobian from the inputs; its output value must be a 2D NumPy array with rows corresponding to the outputs and columns to the inputs.
name (str) --
The name of the discipline. If empty, use the name of the Python function.
By default it is set to "".
use_arrays (bool) --
Whether the function
py_funcis expected to take arrays as inputs and give outputs as arrays.By default it is set to False.
- Raises:
ValueError -- Either when the function returns an expression or when two return statements use different variables.
- property py_func: Callable#
The Python function to compute the outputs from the inputs.
- property py_jac: Callable#
The Python function to compute the Jacobian from the inputs.