auto_py_discipline module¶
MDODiscipline builder from a python function¶
-
class
gemseo.core.auto_py_discipline.
AutoDiscDataProcessor
(out_names)[source]¶ Bases:
gemseo.core.data_processor.DataProcessor
A data preprocessor that converts all GEMSEO scalar input data to floats, and converts all discipline output data to numpy arrays.
Construcor
- Parameters
out_names (list(str)) – names of the outputs
-
class
gemseo.core.auto_py_discipline.
AutoPyDiscipline
(py_func, py_jac=None, use_arrays=False, write_schema=False)[source]¶ Bases:
gemseo.core.discipline.MDODiscipline
A simplified and straightforward way of integrating a discipline from a python function.
Examples
>>> from gemseo.core.auto_py_discipline import AutoPyDiscipline >>> from numpy import array >>> def my_function(x=0., y=0.): >>> z = x + 2*y >>> return z >>> discipline = AutoPyDiscipline(py_func=my_function) >>> discipline.execute() {'x': array([0.]), 'y': array([0.]), u'z': array([0.])} >>> discipline.execute({'x': array([1.]), 'y':array([-3.2])}) {'x': array([1.]), 'y': array([-3.2]), u'z': array([-5.4])}
There are a few constraints:
only one return statement,
return must return a variable reference or a list of references,
only floats or arrays as inputs and outputs.
See also
gemseo.core.discipline.MDODiscipline
abstract class defining the key concept of discipline
Constructor
- Parameters
py_func (function) – the python function to be used to generate the MDODiscipline.
use_arrays (bool) – if True, the function is expected to take arrays as inputs and give outputs as arrays.
py_jac (function) – pointer to the function jacobian; the jacobian must be a 2D numpy array.
write_schema (bool) – if True, write the json schema on the disk