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

Basic functionality

parent 9a843095
No related branches found
No related tags found
1 merge request!162Provide ability to run a single data source and check its results [WIP]
...@@ -8,7 +8,7 @@ from envisage.api import Application ...@@ -8,7 +8,7 @@ from envisage.api import Application
from envisage.core_plugin import CorePlugin from envisage.core_plugin import CorePlugin
from traits.api import Unicode, Bool, Either from traits.api import Unicode, Bool, Either
from force_bdss.core_run_datasource_driver import CoreRunDataSourceDriver from force_bdss.core_run_data_source_driver import CoreRunDataSourceDriver
from .factory_registry_plugin import FactoryRegistryPlugin from .factory_registry_plugin import FactoryRegistryPlugin
from .core_evaluation_driver import CoreEvaluationDriver from .core_evaluation_driver import CoreEvaluationDriver
from .core_mco_driver import CoreMCODriver from .core_mco_driver import CoreMCODriver
...@@ -41,7 +41,7 @@ class BDSSApplication(Application): ...@@ -41,7 +41,7 @@ class BDSSApplication(Application):
plugins = [CorePlugin(), FactoryRegistryPlugin()] plugins = [CorePlugin(), FactoryRegistryPlugin()]
if self.run_datasource: if self.run_data_source:
plugins.append(CoreRunDataSourceDriver( plugins.append(CoreRunDataSourceDriver(
run_data_source=run_data_source run_data_source=run_data_source
)) ))
......
...@@ -3,6 +3,7 @@ import logging ...@@ -3,6 +3,7 @@ import logging
from traits.api import on_trait_change, Unicode from traits.api import on_trait_change, Unicode
from force_bdss.core.data_value import DataValue
from force_bdss.ids import InternalPluginID from force_bdss.ids import InternalPluginID
from .base_core_driver import BaseCoreDriver from .base_core_driver import BaseCoreDriver
...@@ -24,8 +25,14 @@ class CoreRunDataSourceDriver(BaseCoreDriver): ...@@ -24,8 +25,14 @@ class CoreRunDataSourceDriver(BaseCoreDriver):
log.exception("Unable to open workflow file.") log.exception("Unable to open workflow file.")
sys.exit(1) sys.exit(1)
model = _find_data_source_model(workflow, self.run_data_source)
'''factory = model.factory if model is None:
raise RuntimeError(
"Unable to find model information for data "
"source with id {}".format(self.run_data_source))
factory = model.factory
try: try:
data_source = factory.create_data_source() data_source = factory.create_data_source()
except Exception: except Exception:
...@@ -37,32 +44,48 @@ class CoreRunDataSourceDriver(BaseCoreDriver): ...@@ -37,32 +44,48 @@ class CoreRunDataSourceDriver(BaseCoreDriver):
factory.plugin.id)) factory.plugin.id))
raise raise
# Get the slots for this data source. These must be matched to
# the appropriate values in the environment data values.
# Matching is by position.
in_slots, out_slots = data_source.slots(model) in_slots, out_slots = data_source.slots(model)
# Binding performs the extraction of the specified data values print("DataSource: {}".format(factory.id))
# satisfying the above input slots from the environment data values
# considering what the user specified in terms of names (which is print("Input Slots:")
# in the model input slot info for slot in in_slots:
# The resulting data are the ones picked by name from the print(" {}: {}".format(slot.type, slot.description))
# environment data values, and in the appropriate ordering as
# needed by the input slots. print("Output Slots:")
passed_data_values = _bind_data_values( for slot in out_slots:
environment_data_values, print(" {}: {}".format(slot.type, slot.description))
model.input_slot_info,
in_slots) values = []
# execute data source, passing only relevant data values. if len(in_slots) > 0:
log.info("Evaluating for Data Source {}".format( print("Input values for input slots, separated by spaces:")
factory.name)) line = sys.stdin.readline().strip()
log.info("Passed values:") if len(line) == 0:
for idx, dv in enumerate(passed_data_values): raise RuntimeError(
log.info("{}: {}".format(idx, dv)) "Specified input is empty. Please provide values.")
try:
values = [float(x) for x in line.strip().split(' ')]
except ValueError:
raise RuntimeError(
"Unable to convert values to floating point number. "
"Please check your input.")
if len(values) != len(in_slots):
raise RuntimeError(
"The number of specified values did not match the number "
"of slots.")
# transfer the values to datavalue instances, matching then with the
# appropriate type from the in_slot.
data_values = [
DataValue(type=slot.type, value=value)
for slot, value in zip(in_slots, values)
]
try: try:
res = data_source.run(model, passed_data_values) res = data_source.run(model, data_values)
except Exception: except Exception:
log.exception( log.exception(
"Evaluation could not be performed. " "Evaluation could not be performed. "
...@@ -128,12 +151,20 @@ class CoreRunDataSourceDriver(BaseCoreDriver): ...@@ -128,12 +151,20 @@ class CoreRunDataSourceDriver(BaseCoreDriver):
for dv, output_slot_info in zip(res, model.output_slot_info): for dv, output_slot_info in zip(res, model.output_slot_info):
dv.name = output_slot_info.name dv.name = output_slot_info.name
# If the name was not specified, simply discard the value, print("Result:")
# because apparently the user is not interested in it.
res = [r for r in res if r.name != ""]
results.extend(res)
log.info("Returned values:")
for idx, dv in enumerate(res): for idx, dv in enumerate(res):
log.info("{}: {}".format(idx, dv)) print(" {}: {}".format(idx, dv))
'''
def _find_data_source_model(workflow, data_source_id):
"""Finds the data source model on the workflow by data source id.
The match looks if the passed id is contained in the full id, so a
substring will also suffice.
"""
for layer in workflow.execution_layers:
for data_source_model in layer.data_sources:
if data_source_id in data_source_model.factory.id:
return data_source_model
return None
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