Skip to content

Commit

Permalink
Fix options reading from XML and change data reading for looping
Browse files Browse the repository at this point in the history
  • Loading branch information
sevisal committed Oct 5, 2023
1 parent 8b5471f commit 9eea132
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 13 deletions.
8 changes: 4 additions & 4 deletions src/vai_lab/Core/vai_lab_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@ def load_config_file(self, filename: Union[str,List,Tuple]):
self._xml_handler.load_XML(filedir)
self._initialised = True

def _load_data(self, module = 'Initialiser') -> None:
def _load_data(self, specs, module = 'Initialiser') -> None:
"""Loads data from XML file into Data object"""
init_data_fn = self._xml_handler.data_to_load(module)
init_data_fn = self._xml_handler.data_to_load(modules=specs, module=module)
if module not in self.data.keys():
self.data[module] = Data()
if isinstance(init_data_fn, str):
Expand All @@ -66,7 +66,7 @@ def _execute_module(self, specs):
mod: ModuleInterface = import_module(globals(), specs["module_type"]).__call__()
mod._debug = self._debug
mod.set_avail_plugins(self._avail_plugins)
self._load_data(specs["name"])
self._load_data(specs, specs["name"])
mod.set_data_in(self.data[specs["name"]])
mod.set_options(specs)
print("\t"*self.loop_level
Expand Down Expand Up @@ -185,7 +185,7 @@ def run(self):
self._initialise_with_gui()
print("Running pipeline...")
if len(self._xml_handler.loaded_modules) > 0:
self._load_data()
self._load_data(self._xml_handler.loaded_modules)

self._init_status(self._xml_handler.loaded_modules)
self._execute(self._xml_handler.loaded_modules)
Expand Down
26 changes: 17 additions & 9 deletions src/vai_lab/Data/xml_handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,9 +200,10 @@ def _load_options(self, element: ET.Element, parent: dict) -> None:
"""
for child in element:
if child.text is not None:
val = self._parse_text_to_list(child)
val = (val[0] if len(val) == 1 else val)
parent["options"][child.tag] = val
try:
parent["options"][child.tag] = literal_eval(child.text.strip())
except Exception as exc:
parent["options"][child.tag] = child.text.strip()

for key in child.attrib:
if key == "val":
Expand Down Expand Up @@ -718,10 +719,15 @@ def append_pipeline_loop(self,

xml_parent_element.append(new_loop)

def _get_data_structure(self, module) -> Dict[str, Any]:
data_struct = self._find_dict_with_key_val_pair(
self.loaded_modules[module],
"class", "data")
def _get_data_structure(self, modules, module) -> Dict[str, Any]:
try:
data_struct = self._find_dict_with_key_val_pair(
modules[module],
"class", "data")
except Exception as exc:
data_struct = self._find_dict_with_key_val_pair(
modules,
"class", "data")

assert len(data_struct) < 2, \
"Multiple data with same ID, please check XML"
Expand All @@ -734,8 +740,10 @@ def _get_data_structure(self, module) -> Dict[str, Any]:
return out

#@property
def data_to_load(self, module='Initialiser') -> Dict[str, str]:
return self._get_data_structure(module)["to_load"]
def data_to_load(self, modules=False, module='Initialiser') -> Dict[str, str]:
if not modules:
modules = self.loaded_modules
return self._get_data_structure(modules, module)["to_load"]


# Use case examples:
Expand Down

0 comments on commit 9eea132

Please sign in to comment.