Skip to content

Commit

Permalink
renamed PersistentOperationChecker -> SystemOperationChecker
Browse files Browse the repository at this point in the history
  • Loading branch information
lane-neuro committed Jun 25, 2024
1 parent b241bab commit c52d937
Show file tree
Hide file tree
Showing 13 changed files with 37 additions and 43 deletions.
1 change: 0 additions & 1 deletion research_analytics_suite/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,3 @@
__emails__ = 'justlane@uw.edu'
__status__ = 'Prototype'

#DEBUG = True and "DEBUG" in os.environ["DEBUG"]
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ async def save_engine(self, instance_path):
os.makedirs(data_path, exist_ok=True)
data_file_path = os.path.join(data_path, f"{self.data_name}.joblib")

self._logger.info(f"Saving instance to {engine_path}")
self._logger.info(f"Saving engine to {engine_path}")

# Save data
async with aiofiles.open(data_file_path, 'w') as data_file:
Expand All @@ -198,7 +198,7 @@ async def save_engine(self, instance_path):
async with aiofiles.open(os.path.join(f"{engine_path}", 'engine_state.joblib'), 'w') as state_file:
await state_file.write(json.dumps(engine_state))

self._logger.info(f"Instance saved to {instance_path}")
self._logger.info(f"Engine saved to {instance_path}")

@staticmethod
async def load_engine(instance_path, engine_id):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ async def display_slot_in_gui(self, collection_id, slot):
slot_group_tag = f"slot_group_{collection_id}_{slot.memory_id}"
if not dpg.does_item_exist(slot_group_tag):
with dpg.group(tag=slot_group_tag, parent=f"collection_group_{collection_id}", horizontal=True):
dpg.add_text(f"Slot: {slot.name} (ID: {slot.memory_id})", parent=slot_group_tag)
dpg.add_text(f"Slot: {slot.name} (ID: {slot.memory_id[:4]})", parent=slot_group_tag)
await self.update_variables_in_gui(collection_id, slot)

async def update_variables_in_gui(self, collection_id, slot):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
from research_analytics_suite.operation_manager.control.OperationControl import OperationControl
from research_analytics_suite.operation_manager.operations.core.BaseOperation import BaseOperation
from research_analytics_suite.utils.CustomLogger import CustomLogger
from research_analytics_suite.utils.UserInputManager import UserInputManager
from research_analytics_suite.operation_manager.management.UserInputManager import UserInputManager


class ConsoleDialog:
Expand Down
1 change: 0 additions & 1 deletion research_analytics_suite/operation_manager/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
from .nodes import *
from .chains import *
from .control import *
from .lifecycle import *
from .management import *
from .execution import *
from .task import *
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,11 @@
import asyncio

from research_analytics_suite.operation_manager.execution.OperationExecutor import OperationExecutor
from research_analytics_suite.operation_manager.lifecycle.OperationLifecycleManager import OperationLifecycleManager
from research_analytics_suite.operation_manager.management.OperationLifecycleManager import OperationLifecycleManager
from research_analytics_suite.operation_manager.management.OperationManager import OperationManager
from research_analytics_suite.operation_manager.management.OperationSequencer import OperationSequencer
from research_analytics_suite.operation_manager.management.OperationStatusChecker import OperationStatusChecker
from research_analytics_suite.operation_manager.management.PersistentOperationChecker import PersistentOperationChecker
from research_analytics_suite.operation_manager.management.SystemOperationChecker import SystemOperationChecker
from research_analytics_suite.operation_manager.task.TaskCreator import TaskCreator
from research_analytics_suite.operation_manager.task.TaskMonitor import TaskMonitor
from research_analytics_suite.utils.CustomLogger import CustomLogger
Expand Down Expand Up @@ -58,7 +58,7 @@ def __init__(self, sleep_time: float = 0.15):
self.operation_executor = None
self.operation_status_checker = None
self.user_input_manager = None
self.persistent_operation_checker = None
self.system_op_checker = None
self.lifecycle_manager = None

self._initialized = False
Expand Down Expand Up @@ -88,16 +88,15 @@ async def initialize(self):
self.operation_executor = OperationExecutor(sequencer=self.sequencer, task_creator=self.task_creator)
self.operation_status_checker = OperationStatusChecker(sequencer=self.sequencer)

from research_analytics_suite.utils.UserInputManager import UserInputManager
from research_analytics_suite.operation_manager.management.UserInputManager import UserInputManager
self.user_input_manager = UserInputManager()
self.persistent_operation_checker = PersistentOperationChecker(operation_manager=self.operation_manager,
sequencer=self.sequencer,
task_creator=self.task_creator)
self.system_op_checker = SystemOperationChecker(sequencer=self.sequencer,
task_creator=self.task_creator)
self.lifecycle_manager = OperationLifecycleManager(sequencer=self.sequencer,
operation_manager=self.operation_manager,
executor=self.operation_executor,
task_monitor=self.task_monitor,
persistent_op_checker=self.persistent_operation_checker)
system_op_checker=self.system_op_checker)
self._initialized = True
self._logger.info("OperationControl.initialize: OperationControl initialized.")

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class OperationLifecycleManager:
"""Manages the lifecycle of operations."""

def __init__(self, sequencer: OperationSequencer, operation_manager, executor: OperationExecutor,
persistent_op_checker, task_monitor: TaskMonitor):
system_op_checker, task_monitor: TaskMonitor):
"""
Initializes the OperationLifecycleManager with the given parameters.
Expand All @@ -39,7 +39,7 @@ def __init__(self, sequencer: OperationSequencer, operation_manager, executor: O
self.sequencer = sequencer
self.operation_manager = operation_manager
self.operation_executor = executor
self.persistent_operation_checker = persistent_op_checker
self.persistent_operation_checker = system_op_checker
self.task_monitor = task_monitor
self._logger = CustomLogger()

Expand Down Expand Up @@ -85,7 +85,7 @@ async def pause_all_operations(self):

async def exec_loop(self):
"""Executes the main loop of the operations manager."""
tasks = [self.persistent_operation_checker.check_persistent_operations(),
tasks = [self.persistent_operation_checker.check_system_operations(),
self.start_all_operations(),
self.operation_executor.execute_ready_operations(),
self.task_monitor.handle_tasks()]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""
PersistentOperationChecker Module.
SystemOperationChecker Module.
This module defines the PersistentOperationChecker class, which is responsible for managing and checking persistent
This module defines the SystemOperationChecker class, which is responsible for managing and checking system
operations within the research analytics suite. It ensures that necessary operations such as ConsoleOperation and
ResourceMonitorOperation are running and adds them to the sequencer if they are not present.
Expand All @@ -14,58 +14,56 @@
Email: justlane@uw.edu
Status: Prototype
"""
from research_analytics_suite.operation_manager.management.OperationManager import OperationManager
from research_analytics_suite.operation_manager.management.OperationSequencer import OperationSequencer
from research_analytics_suite.operation_manager.operations.persistent.ConsoleOperation import ConsoleOperation
from research_analytics_suite.operation_manager.operations.persistent.ResourceMonitorOperation import \
ResourceMonitorOperation
from research_analytics_suite.operation_manager.task.TaskCreator import TaskCreator
from research_analytics_suite.utils.CustomLogger import CustomLogger


class PersistentOperationChecker:
class SystemOperationChecker:
"""
Class to manage and check persistent operations.
This class is responsible for ensuring that necessary persistent operations, such as ConsoleOperation and
This class is responsible for ensuring that necessary system operations, such as ConsoleOperation and
ResourceMonitorOperation, are running within the research analytics suite. If these operations are not
present, it adds them to the operation sequencer.
"""

def __init__(self, operation_manager: OperationManager, sequencer: OperationSequencer,
task_creator: TaskCreator):
def __init__(self, sequencer: OperationSequencer, task_creator: TaskCreator):
"""
Initializes the PersistentOperationChecker with the necessary components.
Initializes the SystemOperationChecker with the necessary components.
Parameters:
- operation_manager (OperationManager): The manager responsible for operations.
- sequencer (OperationSequencer): The sequencer that holds operations to be executed.
- task_creator (TaskCreator): The task creator that handles task generation.
"""
from research_analytics_suite.utils.CustomLogger import CustomLogger
self._logger = CustomLogger()

from research_analytics_suite.operation_manager.control.OperationControl import OperationControl
self._operation_control = OperationControl()
self.op_manager = self._operation_control.operation_manager

self.op_manager = operation_manager
self.sequencer = sequencer
self.task_creator = task_creator
self._logger = CustomLogger()

async def check_persistent_operations(self) -> None:
async def check_system_operations(self) -> None:
"""
Checks for persistent operations and adds them to the sequencer if they are not already present.
This method ensures that a ConsoleOperation is in progress and a ResourceMonitorOperation is running. If these
operations are not present, they are added to the operation sequencer.
"""
if not self._operation_control.console_operation_in_progress:
await self.op_manager.add_operation_if_not_exists(operation_type=ConsoleOperation,
user_input_manager=self._operation_control.user_input_manager,
action=self._operation_control.user_input_manager.process_user_input,
prompt="", concurrent=True,
persistent=True)
await self.op_manager.add_operation_if_not_exists(
operation_type=ConsoleOperation,
user_input_manager=self._operation_control.user_input_manager,
action=self._operation_control.user_input_manager.process_user_input,
prompt="", concurrent=True, persistent=True)
self._operation_control.console_operation_in_progress = True

# Check if a ResourceMonitorOperation is already running
if not any(isinstance(task, ResourceMonitorOperation) for task in self.task_creator.tasks):
await self.op_manager.add_operation_if_not_exists(operation_type=ResourceMonitorOperation,
concurrent=True, persistent=True)
await self.op_manager.add_operation_if_not_exists(
operation_type=ResourceMonitorOperation, concurrent=True, persistent=True)
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,6 @@
from .OperationManager import OperationManager
from .OperationSequencer import OperationSequencer
from .OperationStatusChecker import OperationStatusChecker
from .PersistentOperationChecker import PersistentOperationChecker
from .SystemOperationChecker import SystemOperationChecker
from .UserInputManager import UserInputManager
from .OperationLifecycleManager import OperationLifecycleManager
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ async def action() -> Any:

# Create a restricted execution environment
safe_globals = {"__builtins__": SAFE_BUILTINS}

# noinspection PyTypeChecker
safe_globals.update(SAFE_MODULES)

Expand Down
2 changes: 1 addition & 1 deletion research_analytics_suite/utils/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# utils/__init__.py

from .CustomLogger import CustomLogger
from .UserInputManager import UserInputManager
from .Config import Config

0 comments on commit c52d937

Please sign in to comment.