cosapp.systems.metamodels¶
System tuned to support meta-models.
Classes
|
Based |
- class cosapp.systems.metamodels.MetaSystem(name: str, data: str | ~pandas.core.frame.DataFrame, mapping: ~typing.Dict[str, str] | None = None, default_model: ~typing.Type[~cosapp.utils.surrogate_models.base.SurrogateModel] = <class 'cosapp.utils.surrogate_models.nearest_neighbor.NearestNeighbor'>, **kwargs)[source]¶
Bases:
System
Based
System
to insert meta-system inside CoSApp.- Parameters:
data (str or pandas.DataFrame)
mapping (Dict[str, str], optional)
default_model (Type[SurrogateModel], optional) – Default surrogate model; default NearestNeighbor with RBF interpolator
name (str, optional) – Name of the System; default ‘undefined’
- models¶
Dictionary of surrogate model for each output variables
- Type:
dict[str, SurrogateModel]
- _trained¶
Are the surrogate models trained?
- Type:
bool
- _default_model¶
Default surrogate model to use
- Type:
Type[SurrogateModel]
- _input_names¶
List of port variable names (port.`variable`)
- Type:
list of str
Examples
As for classical
System
, this class needs to be subclassed to be meaning full.>>> class XPort(Port): >>> def setup(self): >>> self.add_variable('x') >>> >>> class OutPort(Port): >>> def setup(self): >>> self.add_variable('sin') >>> self.add_variable('cos') >>> >>> class MetaA(MetaSystem): >>> def setup(self): >>> self.add_input(XPort, 'in_') >>> self.add_output(OutPort, 'out', model=NearestNeighbor)
- add_output(port_class: Type[Port], name: str, variables: Dict[str, Any] | None = None, model: Type[SurrogateModel] | Dict[str, SurrogateModel] | None = None) Port [source]¶
Add an output Port to the System.
This function cannot be called outside System.setup.
- Parameters:
port_class (type) – Class of the Port to create
name (str) – Port name
variables (Dict[str, Any], optional) – Dictionary of initial values (default: None)
model (Type[Surrogate] or Dict[str, SurrogateModel], optional) – Surrogate default model type or mapping of surrogate model with output names; default NearestNeighbor.
- Returns:
The created port
- Return type:
Examples
>>> class MyPort(Port): >>> def setup(self): >>> self.add_variable('x') >>> self.add_variable('y') >>> >>> class MySystem(System): >>> def setup(self): >>> self.add_output(MyPort, 'output_x') >>> self.add_output(MyPort, 'output_y', model=NearestNeighbor) >>> self.add_output(MyPort, 'output_z', model={'x': NearestNeighbor, >>> 'y': FloatKrigingSurrogate})
- add_outward(definition: str | Dict[str, Any], value: Any = 1, unit: str = '', dtype: type | None = None, valid_range: Tuple[Any, Any] | None = None, invalid_comment: str = '', limits: Tuple[Any, Any] | None = None, out_of_limits_comment: str = '', desc: str = '', scope: Scope = Scope.PUBLIC, model: Type[SurrogateModel] | Dict[str, SurrogateModel] | None = None) None [source]¶
Add a outward variable to the System.
A outward variable is calculated by the System. But its value is not mandatory in any variables fluxes between this System and another one.
An unique outward variable can be defined by providing directly all arguments. And multiple outward variables can be defined by passing a dict of pair (str, Any) with an entry for each variable.
This function cannot be called outside
setup()
.- Parameters:
definition (str or Dict[str, Any]) – Name of the unique variable or a dictionary for multiple variables at once
value (Any, optional) – Value of the variable if definition is a str; default 1
unit (str, optional) – Variable unit; default empty string (i.e. dimensionless)
dtype (type or iterable of types, optional) – Variable type; default None (i.e. type of initial value)
valid_range (Tuple[Any, Any], optional) – Validity range of the variable; default None (i.e. all values are valid)
invalid_comment (str, optional) – Comment to show in case the value is not valid; default ‘’
limits (Tuple[Any, Any], optional) – Limits over which the use of the model is wrong; default valid_range
out_of_limits_comment (str, optional) – Comment to show in case the value is not valid; default ‘’
desc (str, optional) – Variable description; default ‘’
scope (Scope {PRIVATE, PROTECTED, PUBLIC}, optional) – Variable visibility; default PUBLIC
Examples
To add an unique variable, arguments must be directly specified.
>>> system.add_outward('info', 2.)
To add multiple variables, a dictionary with one key per outward variable should be provided.
>>> system.add_inward({ >>> 'info1': 42., >>> 'info2': False >>> })
- models¶
- update()[source]¶
Perform complex tasks due to data change.
Some parameters may be a file used to initialize a complex object. Updating that parameter may imply the modification of that complex object. This should be done in this method.
Examples
>>> class TableModel(System): >>> >>> def setup(self): >>> # Add a inwards to the file containing the table values >>> self.add_inward('table_file', '{myProject}/ressources/my_table.csv') >>> # Set a object able to interpolate the table >>> self.add_outward('table', Table(self.table_file)) >>> >>> def update(self): >>> # Update the table object as the source file may have been updated. >>> self.table = Table(self.table_file)
Notes
This method is called systematically after the
setup()
call. Otherwise the user is responsible to explicitly call it when needed.