-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
24 allow for dynamic plugins #36
Changes from 6 commits
508325f
12a85c2
d4e195c
e8ca351
5b2e9d1
e5cfee4
87f8fad
fcbd9ab
532ce3c
d91a21e
266c512
f4006d2
35650c5
6eb773d
a794f99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,17 +10,22 @@ | |
""" | ||
Data driven learning class for managing all data driven AI components | ||
""" | ||
import importlib | ||
import importlib.util | ||
|
||
from ..util.data_conversion import * | ||
|
||
class DataDrivenLearning: | ||
def __init__(self, headers, _ai_plugins:list=[]): | ||
def __init__(self, headers, _ai_plugins={}): | ||
assert(len(headers)>0) | ||
self.headers = headers | ||
self.ai_constructs = [ | ||
importlib.import_module('onair.src.data_driven_components.' + plugin_name + '.' + f'{plugin_name}_plugin').Plugin(plugin_name, headers) for plugin_name in _ai_plugins | ||
] | ||
self.ai_constructs = [] | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. assertion here, or earlier. Also, I'd remove this empty space. |
||
for module_name in list(_ai_plugins.keys()): | ||
spec = importlib.util.spec_from_file_location(module_name, _ai_plugins[module_name]) | ||
module = importlib.util.module_from_spec(spec) | ||
spec.loader.exec_module(module) | ||
self.ai_constructs.append(module.Plugin(module_name,headers)) | ||
|
||
|
||
def update(self, curr_data, status): | ||
input_data = curr_data | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,9 +15,9 @@ | |
from ..reasoning.diagnosis import Diagnosis | ||
|
||
class Agent: | ||
def __init__(self, vehicle): | ||
def __init__(self, plugin_list, vehicle): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd swap the order (most significant to least significant) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, follows the instantiation order |
||
self.vehicle_rep = vehicle | ||
self.learning_systems = DataDrivenLearning(self.vehicle_rep.get_headers()) | ||
self.learning_systems = DataDrivenLearning(self.vehicle_rep.get_headers(),plugin_list) | ||
self.mission_status = self.vehicle_rep.get_status() | ||
self.bayesian_status = self.vehicle_rep.get_bayesian_status() | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
import shutil | ||
from distutils.dir_util import copy_tree | ||
from time import gmtime, strftime | ||
import ast | ||
|
||
from ...data_handling.time_synchronizer import TimeSynchronizer | ||
from ..run_scripts.sim import Simulator | ||
|
@@ -49,6 +50,9 @@ def __init__(self, config_file='', run_name='', save_flag=False): | |
self.sim_name = '' | ||
self.processedSimData = None | ||
self.sim = None | ||
|
||
# Init plugins | ||
self.plugin_list = [''] | ||
|
||
self.save_flag = save_flag | ||
self.save_name = run_name | ||
|
@@ -94,6 +98,8 @@ def parse_configs(self, config_filepath): | |
self.benchmarkIndices = config['DEFAULT']['BenchmarkIndices'] | ||
except: | ||
pass | ||
## Sort Data: Plugins | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. is sorting happening? I think this function turns a string into list (with extra processing of tokens , beyond pythons built in "list()"). |
||
self.plugin_list = ast.literal_eval(config['DEFAULT']['PluginList']) | ||
|
||
def parse_data(self, parser_name, parser_file_name, dataFilePath, metadataFilePath, subsystems_breakdown=False): | ||
parser = importlib.import_module('onair.data_handling.parsers.' + parser_file_name) | ||
|
@@ -104,7 +110,7 @@ def parse_data(self, parser_name, parser_file_name, dataFilePath, metadataFilePa | |
self.processedSimData = TimeSynchronizer(*parsed_data.get_sim_data()) | ||
|
||
def setup_sim(self): | ||
self.sim = Simulator(self.sim_name, self.processedSimData, self.SBN_Flag) | ||
self.sim = Simulator(self.sim_name, self.processedSimData, self.plugin_list, self.SBN_Flag) | ||
try: | ||
fls = ast.literal_eval(self.benchmarkFiles) | ||
fp = os.path.dirname(os.path.realpath(__file__)) + '/../..' + self.benchmarkFilePath | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -25,7 +25,7 @@ | |
DIAGNOSIS_INTERVAL = 100 | ||
|
||
class Simulator: | ||
def __init__(self, simType, parsedData, SBN_Flag): | ||
def __init__(self, simType, parsedData, plugin_list, SBN_Flag): | ||
self.simulator = simType | ||
vehicle = VehicleRepresentation(*parsedData.get_vehicle_metadata()) | ||
|
||
|
@@ -39,7 +39,7 @@ def __init__(self, simType, parsedData, SBN_Flag): | |
|
||
else: | ||
self.simData = DataSource(parsedData.get_sim_data()) | ||
self.agent = Agent(vehicle) | ||
self.agent = Agent(plugin_list,vehicle) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. swap |
||
|
||
def run_sim(self, IO_Flag=False, dev_flag=False, viz_flag = True): | ||
if IO_Flag == True: print_sim_header() | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .generic_plugin import Plugin |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# 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" | ||
|
||
import numpy as np | ||
from onair.src.data_driven_components.ai_plugin_abstract.core import AIPlugIn | ||
|
||
class Plugin(AIPlugIn): | ||
def apriori_training(self,batch_data=[]): | ||
""" | ||
Given data, system should learn any priors necessary for realtime diagnosis. | ||
""" | ||
pass | ||
|
||
def update(self,frame=[]): | ||
""" | ||
Given streamed data point, system should update internally | ||
""" | ||
pass | ||
|
||
def render_reasoning(self): | ||
""" | ||
System should return its diagnosis | ||
""" | ||
pass |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
from .kalman_plugin import Plugin |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we have an area where we can put an assertion statement?