How sovereignedgeeu-cognit/device-runtime-py works
Project Type and Purpose
• This project is a Python SDK designed to enable devices to communicate with the COGNIT platform for task offloading. It provides a high-level abstraction where devices can offload tasks via its built-in state machine.
• The README highlights two key components: the Cognit Frontend Client (for task offloading requests) and the Edge Cluster Frontend (for executing previously offloaded functions).
File Structure
• Top-Level Files: Look at files like LICENSE, README.md, setup.py, and requirements.txt which indicate a standard Python distribution.
• Package Structure: The main package ("cognit") includes submodules for device runtime and models and modules for different clients:
• The "cognit/device_runtime.py" file likely contains the core logic for the state machine managing communication.
• The "cognit/models" and "cognit/modules" directories contain distinct implementations for the Cognit Frontend Client, Edge Cluster Frontend Client, state machine, configuration, logger, and faas_parser.
• Tests and Examples: The separate test folders (with integration and unit tests) provide insight into how the components interact, and the examples directory shows minimal setups and configuration files.
• Documentation: The docs folder, including the state machine docs (device_runtime_sm.md), gives additional insights into how the state machine is designed.
Main Components
• Device Runtime Core:
• This is the central component that encapsulates the state machine (see files like _device_runtime_state_machine.py). It autonomously manages communication states.
• Cognit Frontend Client:
• Found in both the models and modules directories. This client handles task offloading setup requests and maintains policies/dependencies.
• Edge Cluster Frontend Client:
• Also present in both the models and modules directories. This component is responsible for executing offloaded tasks.
• Configuration & Environment:
• The configuration files (e.g., cognit.yml in the test/config directory and example configs) represent how the environment is set up.
• Testing & Examples:
Relationships and Interactions
• The Cognit Frontend Client: For sending function-offloading requests along with requirements, policies, etc.
• The Edge Cluster Frontend Client: For receiving and executing functions offloaded from the device.
• That the state machine in Device Runtime autonomously transitions between various states (e.g., idle, offloading, executing, error handling) and controls which external client (frontend or edge) is engaged at a given moment.
Architectural Patterns and Technologies
• Architectural Pattern: State Machine Pattern—central to the Device Runtime, ensuring that the communication flows and state transitions are managed automatically.
• Modular Design: Clear separation between models (data representations for clients) and modules (actual logic/operations for clients) emphasizes a separation of concerns.
• Python-based Implementation: Based on Python 3.10.6 as specified, with virtual environment setups and package distribution through setup.py.