From 7180514fc6c2c6b84ff03ea47385765d0fd0b5d3 Mon Sep 17 00:00:00 2001 From: Stefano Borini <sborini@enthought.com> Date: Fri, 21 Jul 2017 16:43:34 +0100 Subject: [PATCH] Restoring old dummy dakota optimizer --- .../dummy_mco/dakota/dakota_communicator.py | 16 +++++----------- .../dummy_mco/dakota/dakota_model.py | 1 + .../dummy_mco/dakota/dakota_optimizer.py | 4 +--- force_bdss/tests/fixtures/test_csv.json | 1 + 4 files changed, 8 insertions(+), 14 deletions(-) diff --git a/force_bdss/core_plugins/dummy_mco/dakota/dakota_communicator.py b/force_bdss/core_plugins/dummy_mco/dakota/dakota_communicator.py index 1b81684..37aa364 100644 --- a/force_bdss/core_plugins/dummy_mco/dakota/dakota_communicator.py +++ b/force_bdss/core_plugins/dummy_mco/dakota/dakota_communicator.py @@ -8,20 +8,14 @@ class DakotaCommunicator(BaseMCOCommunicator): def receive_from_mco(self): data = sys.stdin.read() values = list(map(float, data.split())) - parameters = self.model.parameters - if len(values) != len(parameters): - raise ValueError( - "The passed information length is {}, but the model " - "specifies {} values.".format( - len(values), len(parameters) - )) - - value_types = [p.type for p in parameters] - value_names = [p.name for p in parameters] + value_types = self.model.value_types + if len(values) != len(value_types): + raise ValueError("Length of provided data differs from the number " + "of expected types. {} {}".format(values, + value_types)) return DataSourceParameters( - value_names=value_names, value_types=value_types, values=numpy.array(values) ) diff --git a/force_bdss/core_plugins/dummy_mco/dakota/dakota_model.py b/force_bdss/core_plugins/dummy_mco/dakota/dakota_model.py index 5ff9571..b4c081a 100644 --- a/force_bdss/core_plugins/dummy_mco/dakota/dakota_model.py +++ b/force_bdss/core_plugins/dummy_mco/dakota/dakota_model.py @@ -1,4 +1,5 @@ from traits.api import List, String + from force_bdss.api import BaseMCOModel diff --git a/force_bdss/core_plugins/dummy_mco/dakota/dakota_optimizer.py b/force_bdss/core_plugins/dummy_mco/dakota/dakota_optimizer.py index 0f845ec..6b607cf 100644 --- a/force_bdss/core_plugins/dummy_mco/dakota/dakota_optimizer.py +++ b/force_bdss/core_plugins/dummy_mco/dakota/dakota_optimizer.py @@ -5,7 +5,7 @@ import sys from force_bdss.api import BaseMultiCriteriaOptimizer -class DummyDakotaOptimizer(BaseMultiCriteriaOptimizer): +class DakotaOptimizer(BaseMultiCriteriaOptimizer): def run(self): print("Running dakota optimizer") for initial_value in range(10): @@ -18,5 +18,3 @@ class DummyDakotaOptimizer(BaseMultiCriteriaOptimizer): out = ps.communicate("{}".format(initial_value).encode("utf-8")) print("{}: {}".format(initial_value, out[0].decode("utf-8"))) - - diff --git a/force_bdss/tests/fixtures/test_csv.json b/force_bdss/tests/fixtures/test_csv.json index f061c10..1c15b0f 100644 --- a/force_bdss/tests/fixtures/test_csv.json +++ b/force_bdss/tests/fixtures/test_csv.json @@ -4,6 +4,7 @@ "multi_criteria_optimizer": { "id": "force.bdss.bundles.enthought.dakota", "model_data": { + "value_types": ["DUMMY"] } }, "data_sources": [ -- GitLab