gemseo / core

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

post_process_data(data)[source]

Execute a post processing of discipline output data after the _run method of the discipline, before they are checked by MDODiscipline.check_output_data,

Parameters

data (dict) – the output data to process.

Returns

the processed output data.

Return type

dict

pre_process_data(data)[source]

Execute a pre processing of input data after they are checked by MDODiscipline.check_data, and before the _run method of the discipline is called.

Parameters

data (dict) – the input data to process.

Returns

the processed input data

Return type

dict

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

static get_return_spec_fromstr(return_line)[source]

Get the specifications returned by a python function

Parameters

return_line (str) – the python line containing return statement

Returns

returned string output specifications

Return type

str

gemseo.core.auto_py_discipline.to_arrays_dict(in_dict)[source]

Ensure that a dict of data values are arrays.

Parameters

in_dict – the dict to be ensured.

Returns

ensured data dict

Return type

dict