Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
e6f6d6b
feat: bump flame-sdk version
antidodo Aug 7, 2025
2ccf992
feat: bump flame-sdk version
antidodo Aug 28, 2025
78e09fe
feat: bump flame-sdk version
antidodo Aug 28, 2025
9aa9c85
feat: bump flame-sdk version
antidodo Aug 28, 2025
f1d0ede
feat: bump flame-sdk version
antidodo Aug 28, 2025
1743b72
feat: bump flame-sdk version
antidodo Aug 29, 2025
34c613a
feat: bump flame-sdk version
antidodo Sep 18, 2025
e440841
feat: bump flame-sdk version
antidodo Sep 22, 2025
e3161f0
feat: bump flame-sdk version
antidodo Sep 22, 2025
94a84b6
feat: bump flame-sdk version
antidodo Sep 23, 2025
19d73ca
feat: bump flame-sdk version
antidodo Sep 23, 2025
998249f
feat: bump flame-sdk version
antidodo Sep 23, 2025
c9d52f6
feat: bump flame-sdk version
antidodo Sep 23, 2025
3d19717
feat: bump flame-sdk version
antidodo Sep 23, 2025
01f00d4
feat: bump flame-sdk version
antidodo Sep 24, 2025
87d0f44
feat: bump flame-sdk version
antidodo Sep 24, 2025
32d1d1c
feat: bump flame-sdk version
antidodo Sep 25, 2025
fc4fbf4
feat: bump flame-sdk version
antidodo Sep 29, 2025
4b3f86d
feat: bump flame-sdk version
antidodo Sep 29, 2025
bc75289
feat: bump flame-sdk version
antidodo Oct 17, 2025
1e0cd40
feat: bump flame-sdk version
antidodo Oct 17, 2025
9e7905e
feat: bump flame-sdk version
antidodo Oct 17, 2025
0a66d16
feat: bump flame-sdk version
Nightknight3000 Oct 30, 2025
38880d6
feat: bump flame-sdk version
Nightknight3000 Oct 31, 2025
95e78e5
test: empty commit
Nightknight3000 Nov 3, 2025
a6babd9
feat: bump flame-sdk version
Nightknight3000 Nov 6, 2025
1650326
feat: bump flame-sdk version
Nightknight3000 Nov 6, 2025
a71cde6
feat: bump flame-sdk version
Nightknight3000 Nov 6, 2025
57799d7
feat: bump flame-sdk version
Nightknight3000 Nov 6, 2025
c07cd24
refactor: fix typos in comments
Nightknight3000 Nov 19, 2025
48cf411
Update README with project title and description
antidodo Nov 24, 2025
546e158
feat: add mock classes for testing and update aggregator/analyzer ini…
antidodo Dec 16, 2025
48c362a
feat: enhance logging functionality with new log types and update log…
antidodo Dec 16, 2025
039bcc2
feat: add StarModelTester class and enhance test node functionality
antidodo Dec 18, 2025
8c36373
feat: update dependencies and enhance StarModel logging for test mode
antidodo Jan 13, 2026
fc26140
Merge branch 'main' into local_mock_test
Nightknight3000 Jan 13, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
# python-sdk-patterns

Abstractions on top of the Python SDK for Flame
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions flame/star/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
from flame.star.star_model import StarModel
from flame.star.analyzer_client import Analyzer as StarAnalyzer
from flame.star.aggregator_client import Aggregator as StarAggregator
from flame.star.star_model_tester import StarModelTester
23 changes: 12 additions & 11 deletions flame/star/aggregator_client.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
from abc import abstractmethod
from typing import Any, Optional
from typing import Any, Optional, Union

from flamesdk import FlameCoreSDK
from flame.star.node_base_client import Node
from flame.utils.mock_flame_core import MockFlameCoreSDK


class Aggregator(Node):

def __init__(self, flame: FlameCoreSDK) -> None:
if flame.config.node_role != 'aggregator':
raise ValueError(f'Attempted to initialize aggregator node with mismatching configuration '
f'(expected: node_role="aggregator", received="{flame.config.node_role}").')
def __init__(self, flame: Union[FlameCoreSDK, MockFlameCoreSDK]) -> None:
super().__init__(flame)
if self.role != 'aggregator':
raise ValueError(f'Attempted to initialize aggregator node with mismatching configuration '
f'(expected: node_role="aggregator", received="{self.role}").')

def aggregate(self, node_results: list[Any], simple_analysis: bool = True) -> tuple[Any, bool]:
result = self.aggregation_method(node_results)

if not simple_analysis:
if self.latest_result is None:
converged = False
if self.num_iterations != 0:
converged = self.has_converged(result, self.latest_result)
else:
converged = self.has_converged(result, self.latest_result, self.num_iterations)
converged = False
else:
converged = True

Expand All @@ -32,15 +33,15 @@ def aggregate(self, node_results: list[Any], simple_analysis: bool = True) -> tu
@abstractmethod
def aggregation_method(self, analysis_results: list[Any]) -> Any:
"""
This method will be used to aggregate the data. It has to be overridden.
This method will be used to aggregate the data. It has to be overwritten.
:return: aggregated_result
"""
pass

@abstractmethod
def has_converged(self, result: Any, last_result: Optional[Any], num_iterations: int) -> bool:
def has_converged(self, result: Any, last_result: Optional[Any]) -> bool:
"""
This method will be used to check if the aggregator has converged. It has to be overridden.
This method will be used to check if the aggregator has converged. It has to be overwritten.
:return: converged
"""
pass
22 changes: 10 additions & 12 deletions flame/star/analyzer_client.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,31 @@
from abc import abstractmethod
from typing import Any, Optional
from typing import Any, Optional, Union

from flamesdk import FlameCoreSDK
from flame.star.node_base_client import Node
from flame.utils.mock_flame_core import MockFlameCoreSDK


class Analyzer(Node):

def __init__(self, flame: FlameCoreSDK) -> None:
if flame.config.node_role != 'default':
raise ValueError(f'Attempted to initialize analyzer node with mismatching configuration '
f'(expected: node_mode="default", received="{flame.config.node_role}").')
def __init__(self, flame: Union[FlameCoreSDK, MockFlameCoreSDK]) -> None:
super().__init__(flame)
if self.role != 'default':
raise ValueError(f'Attempted to initialize analyzer node with mismatching configuration '
f'(expected: node_mode="default", received="{self.role}").')

def analyze(self,
data: list[Any],
aggregator_results: Optional[str],
simple_analysis: bool = True) -> tuple[Any, bool]:
result = self.analysis_method(data, aggregator_results)
def analyze(self, data: list[Any]) -> Any:
result = self.analysis_method(data, self.latest_result)

self.latest_result = result
self.num_iterations += 1

return self.latest_result, simple_analysis
return self.latest_result

@abstractmethod
def analysis_method(self, data: list[Any], aggregator_results: Optional[Any]) -> Any:
"""
This method will be used to analyze the data. It has to be overridden.
This method will be used to analyze the data. It has to be overwritten.

The parameter data will be formatted like this:
[list element for every registered data source
Expand Down
30 changes: 19 additions & 11 deletions flame/star/node_base_client.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
from typing import Any, Literal, Optional
from enum import Enum

from flamesdk import FlameCoreSDK


class NodeStatus(Enum):
STARTED = "Analysis/Aggregation undergoing"
FINISHED = "Results sent"


class Node:
id: str
role: Literal["default", "aggregator"]
status: str
finished: bool
latest_result: Optional[Any]
partner_node_ids: list[str]
num_iterations: int
Expand All @@ -21,12 +15,26 @@ class Node:
def __init__(self, flame: FlameCoreSDK):
self.flame = flame

self.id = self.flame.config.node_id
self.role = self.flame.config.node_role
self.status = NodeStatus.STARTED.value
self.id = self.flame.get_id()
self.role = self.flame.get_role()
self.finished = False
self.latest_result = None
self.partner_node_ids = self.flame.get_participant_ids()
self.num_iterations: int = 0

def node_finished(self):
self.status = NodeStatus.FINISHED.value
self.finished = True

def set_num_iterations(self, num_iterations: int) -> None:
"""
This method sets the number of iterations completed by the aggregator.
:param num_iterations: Number of iterations to set.
"""
self.num_iterations = num_iterations

def set_latest_result(self, latest_result: Any) -> None:
"""
This method sets the latest result of the aggregator.
:param latest_result: Latest result to set.
"""
self.latest_result = latest_result
Loading