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

Adding data value

parent be9184f6
No related branches found
No related tags found
1 merge request!68Introduced data value object
from .base_extension_plugin import BaseExtensionPlugin # noqa
from .ids import bundle_id, plugin_id # noqa
from .core.data_value import DataValue # noqa
from .data_sources.base_data_source_model import BaseDataSourceModel # noqa
from .data_sources.data_source_result import DataSourceResult # noqa
......
from traits.api import HasStrictTraits, Any, String
class DataValue(HasStrictTraits):
"""Contains the parameters as passed from the MCO."""
#: The CUBA types associated to the values
type = String()
#: The user-defined names associated to the values.
name = String()
#: The values as a single array.
value = Any()
def __str__(self):
return """
{} {} : {}
""".format(str(self.type),
str(self.name),
str(self.value))
......@@ -31,13 +31,13 @@ class CoreEvaluationDriver(BaseCoreDriver):
mco_bundle = mco_model.bundle
mco_communicator = mco_bundle.create_communicator()
parameters = mco_communicator.receive_from_mco(mco_model)
mco_data_values = mco_communicator.receive_from_mco(mco_model)
ds_results = []
for ds_model in workflow.data_sources:
ds_bundle = ds_model.bundle
data_source = ds_bundle.create_data_source()
ds_results.append(data_source.run(ds_model, parameters))
ds_results.append(data_source.run(ds_model, mco_data_values))
kpi_results = []
for kpic_model in workflow.kpi_calculators:
......
import csv
import numpy
from force_bdss.api import BaseDataSource
from force_bdss.api import DataSourceResult
from force_bdss.api import BaseDataSource, DataValue
class CSVExtractorDataSource(BaseDataSource):
......@@ -13,13 +11,12 @@ class CSVExtractorDataSource(BaseDataSource):
continue
if rowindex == model.row:
return DataSourceResult(
originator=self,
value_types=[model.cuba_type],
values=numpy.array(
parameters.values[0]+float(
row[model.column])).reshape(1, 1)
)
return [
DataValue(
type=model.cuba_type,
value=float(row[model.column])
)
]
return None
return None
import sys
import numpy
from force_bdss.api import DataSourceParameters, BaseMCOCommunicator
from force_bdss.api import (
BaseMCOCommunicator,
DataValue)
class DummyDakotaCommunicator(BaseMCOCommunicator):
......@@ -11,11 +12,10 @@ class DummyDakotaCommunicator(BaseMCOCommunicator):
value_names = [p.value_name for p in model.parameters]
value_types = [p.value_type for p in model.parameters]
return DataSourceParameters(
value_names=value_names,
value_types=value_types,
values=numpy.array(values)
)
return [
DataValue(type=type_, name=name, value=value)
for type_, name, value in zip(
value_types, value_names, values)]
def send_to_mco(self, model, kpi_results):
data = " ".join(
......
from force_bdss.api import BaseDataSource, DataSourceResult
from force_bdss.api import BaseDataSource
class DummyDataSource(BaseDataSource):
def run(self, model, parameters):
print(parameters)
return DataSourceResult(
originator=self,
value_names=parameters.value_names,
value_types=parameters.value_types,
values=parameters.values.reshape(
parameters.values.shape + (1,)))
return parameters
from force_bdss.api import BaseKPICalculator, KPICalculatorResult, bundle_id
from force_bdss.api import BaseKPICalculator, bundle_id
class DummyKPICalculator(BaseKPICalculator):
id = bundle_id("enthought", "dummy_kpi_calculator")
def run(self, model, data_source_results):
res = KPICalculatorResult(
originator=self,
value_names=data_source_results[0].value_names,
value_types=data_source_results[0].value_types,
values=data_source_results[0].values.reshape(
data_source_results[0].values.shape[:-1]))
return res
return data_source_results
import numpy
from force_bdss.api import BaseKPICalculator
from force_bdss.api import KPICalculatorResult
from force_bdss.api import BaseKPICalculator, DataValue
class KPIAdderCalculator(BaseKPICalculator):
def run(self, model, data_source_results):
sum = 0.0
for res in data_source_results:
try:
value_idx = res.value_types.index(model.cuba_type_in)
except ValueError:
continue
for ds_res in data_source_results:
for res in ds_res:
if res.type != model.cuba_type_in:
continue
sum += res.values[value_idx].sum()
sum += res.value
return KPICalculatorResult(
originator=self,
value_types=[model.cuba_type_out],
values=numpy.array([sum])
)
return [
DataValue(
type=model.cuba_type_out,
value=sum
)]
......@@ -29,8 +29,8 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
The conversion is specific to the format of the communication
between the MCO and its evaluator program.
Must return a single DataSourceParameters object, containing
the parameters as passed by the MCO.
Must return a list of DataValue objects, containing the data passed
by the MCO.
Parameters
----------
......@@ -39,9 +39,8 @@ class BaseMCOCommunicator(ABCHasStrictTraits):
Returns
-------
DataSourceParameters
An instance of the DataSourceParameters with the appropriate
information filled in.
List(DataValue)
A list of the DataValues with the appropriate information filled in
"""
@abc.abstractmethod
......
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