diff --git a/onair/src/reasoning/agent.py b/onair/src/reasoning/agent.py index 9b83a5ee..69dd9954 100644 --- a/onair/src/reasoning/agent.py +++ b/onair/src/reasoning/agent.py @@ -13,6 +13,7 @@ """ from ..ai_components.learners_interface import LearnersInterface from ..ai_components.planners_interface import PlannersInterface +from ..reasoning.complex_reasoning_interface import ComplexReasoningInterface from ..reasoning.diagnosis import Diagnosis class Agent: @@ -24,6 +25,7 @@ def __init__(self, vehicle, plugin_list): # AI Interfaces self.learning_systems = LearnersInterface(self.vehicle_rep.get_headers(),plugin_list) self.planning_systems = PlannersInterface(self.vehicle_rep.get_headers(),plugin_list) + self.complex_reasoning_systems = ComplexReasoningInterface(self.vehicle_rep.get_headers(),plugin_list) # Markov Assumption holds def reason(self, frame): @@ -37,6 +39,9 @@ def reason(self, frame): self.learning_systems.check_for_salient_event() self.planning_systems.check_for_salient_event() + # NOT YET COMPLETE + self.complex_reasoning_systems.update(frame, self.learning_systems.check_for_salient_event()) + def diagnose(self, time_step): """ Grab the mnemonics from the """ learning_system_results = self.learning_systems.render_reasoning() diff --git a/onair/src/reasoning/complex_reasoning_interface.py b/onair/src/reasoning/complex_reasoning_interface.py new file mode 100644 index 00000000..75dd5aa6 --- /dev/null +++ b/onair/src/reasoning/complex_reasoning_interface.py @@ -0,0 +1,39 @@ +# GSC-19165-1, "The On-Board Artificial Intelligence Research (OnAIR) Platform" +# +# Copyright © 2023 United States Government as represented by the Administrator of +# the National Aeronautics and Space Administration. No copyright is claimed in the +# United States under Title 17, U.S. Code. All Other Rights Reserved. +# +# Licensed under the NASA Open Source Agreement version 1.3 +# See "NOSA GSC-19165-1 OnAIR.pdf" + +""" +Reasoning interface class for managing all complex custom reasoning components +""" +import importlib.util + +from ..util.data_conversion import * + +class ComplexReasoningInterface: + def __init__(self, headers, _reasoning_plugins={}): + assert(len(headers)>0), 'Headers are required' + self.headers = headers + self.reasoning_constructs = [] + for module_name in list(_reasoning_plugins.keys()): + spec = importlib.util.spec_from_file_location(module_name, _reasoning_plugins[module_name]) + module = importlib.util.module_from_spec(spec) + spec.loader.exec_module(module) + self.reasoning_constructs.append(module.Plugin(module_name,headers)) + + def update(self, low_level_data, high_level_data): + for plugin in self.reasoning_constructs: + plugin.update(low_level_data,high_level_data) + + def check_for_salient_event(self): + pass + + def render_reasoning(self): + intelligent_outcomes = {} + for plugin in self.reasoning_constructs: + intelligent_outcomes[plugin.component_name] = plugin.render_reasoning() + return intelligent_outcomes diff --git a/onair/src/reasoning/reasoning_plugin_abstract/core.py b/onair/src/reasoning/reasoning_plugin_abstract/core.py index 45cd372f..e949d6e0 100644 --- a/onair/src/reasoning/reasoning_plugin_abstract/core.py +++ b/onair/src/reasoning/reasoning_plugin_abstract/core.py @@ -25,7 +25,7 @@ def __init__(self, _name, _headers): self.headers = _headers @abstractmethod - def update(self, frame=[], high_level_info=[]): + def update(self, low_level_data=[], high_level_data={}): """ Given streamed data point and other sources of high-level info, system should update internally