Skip to content
Snippets Groups Projects
Commit a8e8beed authored by Stefano Borini's avatar Stefano Borini
Browse files

documentation

parent 0df633d9
No related branches found
No related tags found
1 merge request!55Remove application and model from bundles. Added plugin reference.
Showing
with 128 additions and 49 deletions
...@@ -19,5 +19,21 @@ class BaseDataSource(ABCHasStrictTraits): ...@@ -19,5 +19,21 @@ class BaseDataSource(ABCHasStrictTraits):
@abc.abstractmethod @abc.abstractmethod
def run(self, model, parameters): def run(self, model, parameters):
"""Executes the data source evaluation/fetching and returns """
the list of results as a DataSourceResult instance.""" Executes the KPI evaluation and returns the results it computes.
Reimplement this method in your specific KPI calculator.
Parameters
----------
model: BaseDataSourceModel
The model of the DataSource, instantiated through create_model()
parameters: DataSourceParameters
a DataResultParameters instance containing the information coming
from the MCO
Returns
-------
DataSourceResult
Instance that holds the results computed by this DataSource.
"""
...@@ -19,6 +19,7 @@ class BaseDataSourceBundle(ABCHasStrictTraits): ...@@ -19,6 +19,7 @@ class BaseDataSourceBundle(ABCHasStrictTraits):
#: A human readable name of the bundle. Spaces allowed #: A human readable name of the bundle. Spaces allowed
name = String() name = String()
#: Reference to the plugin that carries this bundle
plugin = Instance(Plugin) plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs): def __init__(self, plugin, *args, **kwargs):
...@@ -30,13 +31,6 @@ class BaseDataSourceBundle(ABCHasStrictTraits): ...@@ -30,13 +31,6 @@ class BaseDataSourceBundle(ABCHasStrictTraits):
"""Factory method. """Factory method.
Must return the bundle-specific BaseDataSource instance. Must return the bundle-specific BaseDataSource instance.
Parameters
----------
application: Application
The envisage application.
model: BaseDataSourceModel
The model of the data source, instantiated with create_model()
Returns Returns
------- -------
BaseDataSource BaseDataSource
......
...@@ -2,8 +2,14 @@ from traits.api import HasStrictTraits, Array, List, String ...@@ -2,8 +2,14 @@ from traits.api import HasStrictTraits, Array, List, String
class DataSourceParameters(HasStrictTraits): class DataSourceParameters(HasStrictTraits):
"""Contains the parameters as passed from the MCO."""
#: The user-defined names associated to the values.
value_names = List(String) value_names = List(String)
#: The CUBA types associated to the values
value_types = List(String) value_types = List(String)
#: The values as a single array.
values = Array(shape=(None,)) values = Array(shape=(None,))
def __str__(self): def __str__(self):
......
...@@ -4,19 +4,36 @@ from .base_data_source import BaseDataSource ...@@ -4,19 +4,36 @@ from .base_data_source import BaseDataSource
class DataSourceResult(HasTraits): class DataSourceResult(HasTraits):
"""Represents the result of a simulator. """Represents the result of a DataSource evaluation.
It contains the resulting cuba key, the associated uncertainty and the
originating simulator. Note
Difference between uncertainty and quality: uncertainty is a numerical ----
value of the value, as in the case of an experimental simulation. Difference between accuracy and quality:
quality is the level of accuracy of the (e.g. computational) method, as - uncertainty is a numerical quantity defining the accuracy of the value.
the importance and reliability of that value. It should be an enumeration For example, a pressure can be 10.4 +/- 0.1, with 0.1 being the
value such as HIGH, MEDIUM, POOR""" accuracy
- quality is the level of importance and reliability of that value.
It should be considered as a weight of how much trust one should hold
on this information.
"""
#: A reference to the DataSource that computed this result.
originator = Instance(BaseDataSource) originator = Instance(BaseDataSource)
#: The user-defined names associated to each result.
value_names = List(String) value_names = List(String)
#: The CUBA types of each value.
value_types = List(String) value_types = List(String)
#: The values for each entry. Note that this is a NxM array, allowing
#: to propagate more than single scalar values associated to a given value.
values = Array(shape=(None, None)) values = Array(shape=(None, None))
#: If present, the numerical accuracy of the above values.
accuracy = ArrayOrNone(shape=(None, None)) accuracy = ArrayOrNone(shape=(None, None))
#: If present, the assessed quality of the above values.
quality = ArrayOrNone(shape=(None, None)) quality = ArrayOrNone(shape=(None, None))
def __str__(self): def __str__(self):
......
from traits.api import Interface, String from envisage.api import Plugin
from traits.api import Interface, String, Instance
class IDataSourceBundle(Interface): class IDataSourceBundle(Interface):
#: Unique identifier that identifies the bundle uniquely in the """Envisage required interface for the BaseDataSourceBundle.
#: universe of bundles. Create one with the function bundle_id() You should not need to use this directly.
Refer to the BaseDataSourceBundle for documentation.
"""
id = String() id = String()
#: A human readable name of the bundle
name = String() name = String()
plugin = Instance(Plugin)
def create_data_source(self): def create_data_source(self):
"""Factory method. """Factory method.
Must return the bundle-specific BaseDataSource instance. Must return the bundle-specific BaseDataSource instance.
......
...@@ -20,12 +20,22 @@ class BaseKPICalculator(ABCHasStrictTraits): ...@@ -20,12 +20,22 @@ class BaseKPICalculator(ABCHasStrictTraits):
@abc.abstractmethod @abc.abstractmethod
def run(self, model, data_source_results): def run(self, model, data_source_results):
""" """
Executes the KPI evaluation and returns the list of results. Executes the KPI evaluation and returns the results it computes.
Reimplement this method in your specific KPI calculator. Reimplement this method in your specific KPI calculator.
Parameters Parameters
---------- ----------
model: BaseKPICalculatorModel
The model of the KPI Calculator, instantiated through
create_model()
data_source_results: data_source_results:
a list of DataSourceResult instances containing the results of the a list of DataSourceResult instances containing the results of the
evaluation. evaluation. Each DataSourceResult contains the results from one
specific DataSource.
Returns
-------
KPICalculatorResult
Instance that holds the results computed by this KPICalculator.
""" """
...@@ -20,9 +20,17 @@ class BaseKPICalculatorBundle(ABCHasStrictTraits): ...@@ -20,9 +20,17 @@ class BaseKPICalculatorBundle(ABCHasStrictTraits):
#: A UI friendly name for the bundle. Can contain spaces. #: A UI friendly name for the bundle. Can contain spaces.
name = String() name = String()
#: A reference to the plugin that holds this bundle.
plugin = Instance(Plugin) plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs): def __init__(self, plugin, *args, **kwargs):
"""Initializes the instance.
Parameters
----------
plugin: Plugin
The plugin that holds this bundle.
"""
self.plugin = plugin self.plugin = plugin
super(BaseKPICalculatorBundle, self).__init__(*args, **kwargs) super(BaseKPICalculatorBundle, self).__init__(*args, **kwargs)
...@@ -32,13 +40,6 @@ class BaseKPICalculatorBundle(ABCHasStrictTraits): ...@@ -32,13 +40,6 @@ class BaseKPICalculatorBundle(ABCHasStrictTraits):
Creates and returns an instance of a KPI Calculator, associated Creates and returns an instance of a KPI Calculator, associated
to the given application and model. to the given application and model.
Parameters
----------
application: Application
The envisage application.
model: BaseKPICalculatorModel
The model of the calculator, instantiated with create_model()
Returns Returns
------- -------
BaseKPICalculator BaseKPICalculator
......
...@@ -4,7 +4,10 @@ from envisage.plugin import Plugin ...@@ -4,7 +4,10 @@ from envisage.plugin import Plugin
class IKPICalculatorBundle(Interface): class IKPICalculatorBundle(Interface):
"""Envisage required interface for the BaseKPICalculatorBundle. """Envisage required interface for the BaseKPICalculatorBundle.
You should not need to use this directly.""" You should not need to use this directly.
Refer to the BaseKPICalculatorBundle for documentation.
"""
id = String() id = String()
name = String() name = String()
......
...@@ -4,11 +4,24 @@ from .base_kpi_calculator import BaseKPICalculator ...@@ -4,11 +4,24 @@ from .base_kpi_calculator import BaseKPICalculator
class KPICalculatorResult(HasTraits): class KPICalculatorResult(HasTraits):
"""Contains the results from a single KPICalculator evaluation"""
#: The originating KPI calculator
originator = Instance(BaseKPICalculator) originator = Instance(BaseKPICalculator)
#: The user-attributed names of each computed value
value_names = List(String) value_names = List(String)
#: The CUBA types of each of the computed values
value_types = List(String) value_types = List(String)
#: The values, as a single array of values
values = Array(shape=(None, )) values = Array(shape=(None, ))
#: If present, the numerical accuracy of the above values.
accuracy = ArrayOrNone(shape=(None, )) accuracy = ArrayOrNone(shape=(None, ))
#: If present, the quality of the above values.
quality = ArrayOrNone(shape=(None, )) quality = ArrayOrNone(shape=(None, ))
def __str__(self): def __str__(self):
......
...@@ -14,10 +14,24 @@ class BaseMCO(ABCHasStrictTraits): ...@@ -14,10 +14,24 @@ class BaseMCO(ABCHasStrictTraits):
bundle = Instance(IMCOBundle) bundle = Instance(IMCOBundle)
def __init__(self, bundle, *args, **kwargs): def __init__(self, bundle, *args, **kwargs):
"""Initializes the MCO.
Parameters
----------
bundle: BaseMCOBundle
The bundle this BaseMCO belongs to
"""
self.bundle = bundle self.bundle = bundle
super(BaseMCO, self).__init__(*args, **kwargs) super(BaseMCO, self).__init__(*args, **kwargs)
@abc.abstractmethod @abc.abstractmethod
def run(self, model): def run(self, model):
"""Reimplement this method to perform the MCO operations.""" """Performs the actual MCO operations.
pass Reimplement this method to tailor to your MCO.
Parameters
----------
model: BaseMCOModel
An instance of the model information, as created from
create_model()
"""
...@@ -19,6 +19,7 @@ class BaseMCOBundle(ABCHasStrictTraits): ...@@ -19,6 +19,7 @@ class BaseMCOBundle(ABCHasStrictTraits):
#: A user friendly name of the bundle. Spaces allowed. #: A user friendly name of the bundle. Spaces allowed.
name = String() name = String()
#: A reference to the Plugin that holds this bundle.
plugin = Instance(Plugin) plugin = Instance(Plugin)
def __init__(self, plugin, *args, **kwargs): def __init__(self, plugin, *args, **kwargs):
...@@ -31,14 +32,6 @@ class BaseMCOBundle(ABCHasStrictTraits): ...@@ -31,14 +32,6 @@ class BaseMCOBundle(ABCHasStrictTraits):
Creates the optimizer with the given application Creates the optimizer with the given application
and model and returns it to the caller. and model and returns it to the caller.
Parameters
----------
application: Application
The envisage application instance
model: BaseMCOModel
The model to associate to the optimizer, instantiated through
create_model()
Returns Returns
------- -------
BaseMCOOptimizer BaseMCOOptimizer
...@@ -70,11 +63,8 @@ class BaseMCOBundle(ABCHasStrictTraits): ...@@ -70,11 +63,8 @@ class BaseMCOBundle(ABCHasStrictTraits):
"""Factory method. Returns the communicator class that allows """Factory method. Returns the communicator class that allows
exchange between the MCO and the evaluator code. exchange between the MCO and the evaluator code.
Parameters Returns
---------- -------
application: Application BaseMCOCommunicator
The envisage application instance An instance of the communicator
model: BaseMCOModel
The model to associate to the optimizer, instantiated through
create_model()
""" """
...@@ -32,6 +32,11 @@ class BaseMCOCommunicator(ABCHasStrictTraits): ...@@ -32,6 +32,11 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
Must return a single DataSourceParameters object, containing Must return a single DataSourceParameters object, containing
the parameters as passed by the MCO. the parameters as passed by the MCO.
Parameters
----------
model: BaseMCOModel
The model of the optimizer, instantiated through create_model()
Returns Returns
------- -------
DataSourceParameters DataSourceParameters
...@@ -48,6 +53,9 @@ class BaseMCOCommunicator(ABCHasStrictTraits): ...@@ -48,6 +53,9 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
Parameters Parameters
---------- ----------
model: BaseMCOModel
The model of the optimizer, instantiated through create_model()
kpi_results: List(KPICalculatorResult) kpi_results: List(KPICalculatorResult)
A list of KPI calculator results, one per each KPI calculator. A list of KPI calculator results, one per each KPI calculator.
""" """
...@@ -3,8 +3,10 @@ from envisage.plugin import Plugin ...@@ -3,8 +3,10 @@ from envisage.plugin import Plugin
class IMCOBundle(Interface): class IMCOBundle(Interface):
"""Interface for the MultiCriteria Optimizer bundle. """Interface for the BaseMCOBundle.
You should not need it, as its main use is for envisage support. You should not need it, as its main use is for envisage support.
Refer to BaseMCOBundle for documentation
""" """
id = String() id = String()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment