Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
ruokolt committed Dec 15, 2023
1 parent e55900b commit a120262
Show file tree
Hide file tree
Showing 17 changed files with 90 additions and 91 deletions.
9 changes: 8 additions & 1 deletion environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@ name: vai-lab-env
channels:
- conda-forge
dependencies:
- python=3.11
- python=3.7
- c-compiler
- pandas
- pillow
- scikit-learn
- ttkwidgets
- opencv
- pybullet
- attrs
- pip
- pip:
- .
11 changes: 1 addition & 10 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,11 @@ classifiers = [
"License :: OSI Approved :: MIT License",
'Programming Language :: Python :: 3.11'
]
requires-python = ">=3.11"
requires-python = ">=3.7"
version = "0.0.dev4"
description = "AI assisted Virtual Laboratory framework."

dependencies = [
"numpy >= 1.20.0",
"pillow >= 9.0.0", # package name of PIL
"pandas >= 1.4.0",
"scikit-learn >= 0.0",
"ttkwidgets >= 0.12.0",
"matplotlib >= 3.5.0",
"opencv-python >= 4.6.0.65",
"pybullet >= 3.2.5",
"attrs >= 23.1.0"
]

[project.optional-dependencies]
Expand Down
7 changes: 3 additions & 4 deletions src/vai_lab/Core/vai_lab_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from vai_lab._import_helper import import_module, rel_to_abs
from vai_lab._plugin_helpers import PluginSpecs
from vai_lab._types import ModuleInterface, PluginSpecsInterface
from vai_lab.GUI.GUI_core import GUI
from vai_lab.Data.Data_core import Data
from vai_lab.Data.xml_handler import XML_handler
Expand All @@ -17,7 +16,7 @@ def __init__(self) -> None:
self.data = {}
self.data['Initialiser'] = Data()
self._xml_handler = XML_handler()
self._avail_plugins: PluginSpecsInterface = PluginSpecs()
self._avail_plugins = PluginSpecs()

self.loop_level: int = 0
self._initialised: bool = False
Expand All @@ -28,7 +27,7 @@ def _launch(self):
gui_app = GUI()
gui_app._debug = self._debug
gui_app.set_avail_plugins(self._avail_plugins)
gui_app.set_gui_as_startpage()
gui_app.set_gui_as_startpage() # FIXME
gui_output = gui_app.launch()
if not self._debug:
try:
Expand Down Expand Up @@ -63,7 +62,7 @@ def _execute_module(self, specs):
:param specs: dict of module to be executed
"""
mod: ModuleInterface = import_module(globals(), specs["module_type"]).__call__()
mod = import_module(globals(), specs["module_type"]).__call__()
mod._debug = self._debug
mod.set_avail_plugins(self._avail_plugins)
self._load_data(specs, specs["name"])
Expand Down
13 changes: 6 additions & 7 deletions src/vai_lab/DataProcessing/DataProcessing_core.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface, DataProcessingPluginInterface
from pandas import DataFrame
from numpy import array
class DataProcessing(object):
def __init__(self) -> None:
self.output_data: DataInterface
self.output_data

def set_avail_plugins(self, avail_plugins: PluginSpecsInterface) -> None:
def set_avail_plugins(self, avail_plugins) -> None:
self._avail_plugins = avail_plugins

def set_data_in(self, data_in: DataInterface) -> None:
def set_data_in(self, data_in) -> None:
self._data_in = data_in

def _load_plugin(self, data_in: DataInterface) -> None:
def _load_plugin(self, data_in) -> None:
avail_plugins = self._avail_plugins.find_from_readable_name(
self._module_config["plugin"]["plugin_name"])
self.set_data_in(data_in)
self._plugin: DataProcessingPluginInterface = import_plugin_absolute(globals(),
self._plugin = import_plugin_absolute(globals(),
avail_plugins["_PLUGIN_PACKAGE"],
avail_plugins["_PLUGIN_CLASS_NAME"])\
.__call__(self._module_config["plugin"], data_in)
Expand All @@ -40,5 +39,5 @@ def launch(self) -> None:
if len(out) > 0 and (isinstance(out[0], DataFrame) or isinstance(out[0], array)):
self.output_data.data[list(out[1])[0]] = out[0]

def get_result(self) -> DataInterface:
def get_result(self):
return self.output_data
1 change: 0 additions & 1 deletion src/vai_lab/DataProcessing/plugins/normalizer.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from vai_lab._plugin_templates import DataProcessingT
from vai_lab._types import DataInterface

from sklearn.preprocessing import Normalizer as model
import pandas as pd
Expand Down
9 changes: 4 additions & 5 deletions src/vai_lab/DecisionMaking/DecisionMaking_core.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
# -*- coding: utf-8 -*-
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface
class DecisionMaking(object):
def __init__(self):
self.output_data: DataInterface
self.output_data

def set_avail_plugins(self,avail_plugins: PluginSpecsInterface):
def set_avail_plugins(self,avail_plugins):
self._avail_plugins = avail_plugins

def set_data_in(self,data_in: DataInterface):
def set_data_in(self,data_in):
self._data_in = data_in

def _load_plugin(self, data_in: DataInterface):
def _load_plugin(self, data_in):
avail_plugins = self._avail_plugins.find_from_readable_name(self._module_config["plugin"]["plugin_name"])
self.set_data_in(data_in)
self._plugin = import_plugin_absolute(globals(),\
Expand Down
13 changes: 6 additions & 7 deletions src/vai_lab/Environment/Environment_core.py
Original file line number Diff line number Diff line change
@@ -1,21 +1,20 @@
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface, EnvironmentPluginInterface

class Environment(object):
def __init__(self) -> None:
self.output_data: DataInterface
self.output_data

def set_avail_plugins(self, avail_plugins: PluginSpecsInterface) -> None:
def set_avail_plugins(self, avail_plugins) -> None:
self._avail_plugins = avail_plugins

def set_data_in(self, data_in: DataInterface) -> None:
def set_data_in(self, data_in) -> None:
self._data_in = data_in

def _load_plugin(self, data_in: DataInterface) -> None:
def _load_plugin(self, data_in) -> None:
avail_plugins = self._avail_plugins.find_from_readable_name(
self._module_config["plugin"]["plugin_name"])
self.set_data_in(data_in)
self._plugin: EnvironmentPluginInterface = import_plugin_absolute(globals(),
self._plugin = import_plugin_absolute(globals(),
avail_plugins["_PLUGIN_PACKAGE"],
avail_plugins["_PLUGIN_CLASS_NAME"])\
.__call__(self._module_config["plugin"], data_in)
Expand All @@ -33,6 +32,6 @@ def launch(self) -> None:
self._plugin.run_simulation()


def get_result(self) -> DataInterface:
def get_result(self):
# return self.output_data
return self._data_in
17 changes: 8 additions & 9 deletions src/vai_lab/GUI/GUI_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from vai_lab.Data.xml_handler import XML_handler
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import DataInterface, PluginSpecsInterface, DictT
from vai_lab.Data.Data_core import Data

from typing import Any
Expand Down Expand Up @@ -32,13 +31,13 @@ def __init__(self, *args, **kwargs):
self._is_startpage = False
self.output = {}

def set_avail_plugins(self, avail_plugins: PluginSpecsInterface):
def set_avail_plugins(self, avail_plugins):
self._avail_plugins = avail_plugins

def set_data_in(self, data_in: DataInterface):
def set_data_in(self, data_in):
self._data_in = data_in

def set_options(self, module_config: DictT):
def set_options(self, module_config):
"""Send configuration arguments to GUI
:param module_config: dict of settings to congfigure the plugin
Expand All @@ -48,7 +47,7 @@ def set_options(self, module_config: DictT):

def set_gui_as_startpage(self):
self._is_startpage = True
self._load_plugin("main")
self._load_plugin("main") # FIXME
self.xml_handler = XML_handler()
self.xml_handler.new_config_file()

Expand Down Expand Up @@ -78,10 +77,10 @@ def _add_UI_type_to_frames(self, ui_specs):
:param ui_name: name of the UI method being loaded
:type ui_name: str
"""

plugin = import_plugin_absolute(globals(),
ui_specs["_PLUGIN_PACKAGE"],
ui_specs["_PLUGIN_CLASS_NAME"])

ui_specs["_PLUGIN_CLASS_NAME"]) # FIXME
self._desired_ui_types.append(plugin)
self._compare_layer_priority(ui_specs)
if ui_specs["_PLUGIN_MODULE_OPTIONS"]["required_children"] != None:
Expand All @@ -98,9 +97,9 @@ def _load_plugin(self, ui_type: list):
if isinstance(ui_type, list)\
else [ui_type]
for ui in ui_type:
ui_specs = self._avail_plugins.find_from_readable_name(ui)
ui_specs = self._avail_plugins.find_from_readable_name(ui)
try:
self._add_UI_type_to_frames(ui_specs)
self._add_UI_type_to_frames(ui_specs) # FIXME
except ModuleNotFoundError as ex:
from sys import exit
print(ex.msg)
Expand Down
9 changes: 4 additions & 5 deletions src/vai_lab/InputData/InputData_core.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from vai_lab.Data.Data_core import Data
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface

class InputData(Data):
def __init__(self):
Expand All @@ -9,7 +8,7 @@ def __init__(self):
self.plugin_name = None
self.output_data = None

def set_data_in(self, data_in: DataInterface) -> None:
def set_data_in(self, data_in) -> None:
"""Pass existing data from another module to be stored in this class"""
self._data_in = data_in

Expand All @@ -24,14 +23,14 @@ def set_options(self, module_config: dict) -> None:
"""
self._module_config = module_config

def set_avail_plugins(self, avail_plugins: PluginSpecsInterface) -> None:
def set_avail_plugins(self, avail_plugins) -> None:
self._avail_plugins = avail_plugins

def _load_plugin(self, data_in: DataInterface) -> None:
def _load_plugin(self, data_in) -> None:
avail_plugins = self._avail_plugins.find_from_readable_name(
self._module_config["plugin"]["plugin_name"])
self.set_data_in(data_in)
self._plugin: PluginSpecsInterface = import_plugin_absolute(globals(),
self._plugin = import_plugin_absolute(globals(),
avail_plugins["_PLUGIN_PACKAGE"],
avail_plugins["_PLUGIN_CLASS_NAME"])\
.__call__(self._module_config["plugin"], data_in)
Expand Down
9 changes: 4 additions & 5 deletions src/vai_lab/Modelling/Modelling_core.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
# -*- coding: utf-8 -*-
from vai_lab._import_helper import import_plugin_absolute
from vai_lab._types import PluginSpecsInterface, DataInterface

class Modelling(object):
def __init__(self):
self.output_data: DataInterface
self.output_data

def set_avail_plugins(self, avail_plugins: PluginSpecsInterface):
def set_avail_plugins(self, avail_plugins):
self._avail_plugins = avail_plugins

def set_data_in(self,data_in: DataInterface):
def set_data_in(self,data_in):
self._data_in = data_in

def _load_plugin(self, data_in: DataInterface):
def _load_plugin(self, data_in):
avail_plugins = self._avail_plugins.find_from_readable_name(self._module_config["plugin"]["plugin_name"])
self.set_data_in(data_in)
self._plugin = import_plugin_absolute(globals(),\
Expand Down
7 changes: 3 additions & 4 deletions src/vai_lab/UserInteraction/plugins/ManualInput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from vai_lab._plugin_templates import UI
from vai_lab._import_helper import get_lib_parent_dir
from vai_lab._types import DictT, DataInterface, GUICoreInterface

import os
import numpy as np
Expand All @@ -25,18 +24,18 @@
class ManualInput(tk.Frame, UI): # type:ignore
"""Method of user interaction for binary or classification data"""

def __init__(self, parent, controller, config: DictT):
def __init__(self, parent, controller, config):
self.parent = parent
super().__init__(parent, bg=self.parent['bg'])
self.controller: GUICoreInterface = controller
self.controller = controller
self.controller.title('Manual Input')

self.dirpath = get_lib_parent_dir()


self.assets_path = os.path.join(self.dirpath, 'utils', 'resources', 'Assets')

self._data_in: DataInterface
self._data_in
self._class_list = None
self._config = config
self.save_path = ''
Expand Down
7 changes: 3 additions & 4 deletions src/vai_lab/UserInteraction/plugins/OptimisationInput.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
from vai_lab._plugin_templates import UI
from vai_lab._import_helper import get_lib_parent_dir
from vai_lab._types import DictT, DataInterface, GUICoreInterface

import os
import numpy as np
Expand All @@ -27,10 +26,10 @@
class OptimisationInput(tk.Frame, UI): # type:ignore
"""Method of user interaction for optimisation problems"""

def __init__(self, parent, controller, config: DictT):
def __init__(self, parent, controller, config):
self.parent = parent
super().__init__(parent, bg=self.parent['bg'])
self.controller: GUICoreInterface = controller
self.controller = controller
self.controller.title('Optimisation Interaction')

self.dirpath = get_lib_parent_dir()
Expand All @@ -44,7 +43,7 @@ def __init__(self, parent, controller, config: DictT):

self.assets_path = os.path.join(self.dirpath, 'utils', 'resources', 'Assets')

self._data_in: DataInterface
self._data_in
self._config = config
self.save_path = ''
self.saved = True
Expand Down
24 changes: 20 additions & 4 deletions src/vai_lab/_import_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,26 @@ def import_plugin(script_config, plugin_name):
return plugin_class

def import_plugin_absolute(script_config,plugin_package,plugin_name):
plugin_list = __import__(plugin_package,
script_config,
{},
[plugin_name])
print("script_config:", script_config)
print()
print("plugin_package:", plugin_package)
print()
print("plugin_name:", plugin_name)

# FIXME
import traceback
try:
plugin_list = __import__(plugin_package,
script_config,
{},
[plugin_name])
except Exception as err:
print("\n\nERROR >>>\n\n")
print(traceback.format_exc())
print("err:", err)
print("\n\n<<< ERROR\n\n")


plugin_class = getattr(plugin_list, plugin_name)
return plugin_class

Expand Down
Loading

0 comments on commit a120262

Please sign in to comment.