fluke
¶
The fluke
module is the entry module of the fluke
framework. Here are defined generic
classes used by the other modules.
Submodules
This module contains (as submodules) the implementation of several the federated learning algorithms. |
|
This module contains the data utilities for |
|
This module contains the classes for the communication between the clients and the server. |
|
The module |
|
This module contains the definition of the evaluation classes used to perform the evaluation of the model client-side and server-side. |
|
This module contains the definition of several neural networks used in state-of-the-art federated learning papers. |
|
The module |
|
This module contains utility functions and classes used in |
Classes included in fluke
A dictionary that can be accessed with dot notation recursively. |
|
This metaclass is used to create singleton classes. |
|
Global settings for |
|
Subject class for the observer pattern. |
Classes¶
class fluke.DDict
- class fluke.DDict(*args: dict, **kwargs: dict[str, Any])[source]¶
Bases:
dict
A dictionary that can be accessed with dot notation recursively.
Example
1d = DDict(a=1, b=2, c={'d': 3, 'e': 4}) 2print(d.a) # 1 3print(d.b) # 2 4print(d.c.d) # 3 5print(d.c.e) # 4
- exclude(*keys: str)[source]¶
Create a new
DDict
excluding the specified keys.- Parameters:
*keys – The keys to be excluded.
- Returns:
The new DDict.
- Return type:
Example
1d = DDict(a=1, b=2, c=3) 2e = d.exclude('b', 'c') 3print(e) # {'a': 1}
- update(*args: dict, **kwargs: dict[str, Any])[source]¶
Update the
DDict
with the specified key-value pairs.- Parameters:
*args (dict) – Dictionary with the key-value pairs.
**kwargs – The key-value pairs.
Example
1d = DDict(a=1) 2print(d) # {'a': 1} 3d.update(b=2, c=3) 4print(d) # {'a': 1, 'b': 2, 'c': 3}
metaclass fluke.Singleton
- class fluke.Singleton[source]¶
Bases:
type
This metaclass is used to create singleton classes. A singleton class is a class that can have only one instance. If the instance does not exist, it is created; otherwise, the existing instance is returned.
Example
1class MyClass(metaclass=Singleton): 2 pass 3a = MyClass() 4b = MyClass() 5print(a is b) # True
class fluke.GlobalSettings
- class fluke.GlobalSettings(*args, **kwargs: dict[str, Any])[source]¶
Bases:
object
Global settings for
fluke
. This class is a singleton that holds the global settings forfluke
. The settings include:The device (
"cpu"
,"cuda[:N]"
,"auto"
,"mps"
);The
seed
for reproducibility;The evaluation configuration;
The progress bars for the federated learning process, clients and the server;
The live renderer, which is used to render the progress bars.
- auto_device() device [source]¶
Set device to
cuda
ormps
if available, otherwisecpu
.- Returns:
The device.
- Return type:
torch.device
- get_device() device [source]¶
Get the current device.
- Returns:
The device.
- Return type:
torch.device
- get_eval_cfg() DDict [source]¶
Get the evaluation configuration.
- Returns:
The evaluation configuration.
- Return type:
- get_live_renderer() Live [source]¶
Get the live renderer. The live renderer is used to render the progress bars.
- Returns:
The live renderer.
- Return type:
Live
- get_progress_bar(progress_type: str) Progress [source]¶
Get the progress bar. The possible progress bar types are:
FL
: The progress bar for the federated learning process.clients
: The progress bar for the clients.server
: The progress bar for the server.
- Parameters:
progress_type (str) – The type of progress bar.
- Returns:
The progress bar.
- Return type:
Progress
- Raises:
ValueError – If the progress bar type is invalid.
- set_device(device: str) device [source]¶
Set the device. The device can be
cpu
,auto
,mps
,cuda
orcuda:N
, whereN
is the GPU index.- Parameters:
device (str) – The device as string.
- Returns:
The selected device as torch.device.
- Return type:
torch.device
- set_eval_cfg(cfg: DDict) None [source]¶
Set the evaluation configuration.
- Parameters:
cfg (DDict) – The evaluation configuration.
interface fluke.ObserverSubject
- class fluke.ObserverSubject[source]¶
Bases:
object
Subject class for the observer pattern. The subject is the class that is observed and thus it holds the observers.
Example
1class MySubject(ObserverSubject): 2 def __init__(self): 3 super().__init__() 4 self._data = 0 5 6 @property 7 def data(self): 8 return self._data 9 10 @data.setter 11 def data(self, value): 12 self._data = value 13 self.notify() 14 15class MyObserver: 16 def __init__(self, subject): 17 subject.attach(self) 18 19 def update(self): 20 print("Data changed.") 21 22subject = MySubject() 23observer = MyObserver(subject) 24subject.data = 1 # "Data changed."