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

Prototype that works

parent 799a4fd1
No related branches found
No related tags found
1 merge request!45Added support for MCO named parameters.
This commit is part of merge request !45. Comments created here will be created in the context of that merge request.
......@@ -8,12 +8,15 @@ class DummyDakotaCommunicator(BaseMCOCommunicator):
def receive_from_mco(self):
data = sys.stdin.read()
values = list(map(float, data.split()))
value_names = [p.name for p in self.model.parameters]
value_types = [p.value_type for p in self.model.parameters]
return DataSourceParameters(
value_types=["DUMMY"]*len(values),
value_names=value_names,
value_types=value_types,
values=numpy.array(values)
)
def send_to_mco(self, kpi_results):
data = " ".join(
[" ".join(list(map(str, r.values.tolist()))) for r in kpi_results]
......
......@@ -14,17 +14,16 @@ def rotated_range(start, stop, starting_value):
return list(d)
class DakotaOptimizer(BaseMultiCriteriaOptimizer):
class DummyDakotaOptimizer(BaseMultiCriteriaOptimizer):
def run(self):
parameters = self.model.parameters
values = []
for p in parameters:
values.append(
rotated_range(p.lower_bound,
p.upper_bound,
p.initial_value)
rotated_range(int(p.lower_bound),
int(p.upper_bound),
int(p.initial_value))
)
value_iterator = itertools.product(*values)
......
......@@ -5,9 +5,12 @@ class DummyKPICalculator(BaseKPICalculator):
id = bundle_id("enthought", "dummy_kpi_calculator")
def run(self, data_source_results):
return KPICalculatorResult(
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]))
print(res)
return res
......@@ -3,6 +3,7 @@ import logging
from traits.api import HasStrictTraits, Instance
from ..workspecs.mco_parameters import RangedMCOParameter
from ..workspecs.workflow import Workflow
from ..bundle_registry_plugin import BundleRegistryPlugin
......@@ -115,8 +116,11 @@ class WorkflowReader(HasStrictTraits):
mco_id = mco_data["id"]
mco_bundle = registry.mco_bundle_by_id(mco_id)
return mco_bundle.create_model(
model = mco_bundle.create_model(
wf_data["multi_criteria_optimizer"]["model_data"])
model.parameters = self._extract_mco_parameters(
wf_data["multi_criteria_optimizer"]["parameters"])
return model
def _extract_data_sources(self, wf_data):
"""Extracts the data sources from the workflow dictionary data.
......@@ -166,3 +170,7 @@ class WorkflowReader(HasStrictTraits):
kpic_bundle.create_model(kpic_entry["model_data"]))
return kpi_calculators
def _extract_mco_parameters(self, parameters_data):
return [RangedMCOParameter(**d) for d in parameters_data]
......@@ -10,3 +10,32 @@ class KPICalculatorResult(HasTraits):
values = Array(shape=(None, ))
accuracy = ArrayOrNone(shape=(None, ))
quality = ArrayOrNone(shape=(None, ))
def __str__(self):
return """
DataSourceResults
originator:
{}
value_names:
{}
value_types:
{}
values:
{}
Accuracy:
{}
Quality:
{}
""".format(
self.originator,
self.value_names,
self.value_types,
self.values,
self.accuracy,
self.quality)
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