API Reference¶
AppConfig
¶
Bases: BaseImmutableConfig
The master configuration schema for the entire simulation application. Aggregates all sub-configurations and validates cross-domain logical consistency.
Source code in src/afl_sim/config.py
208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 | |
check_batch_size_validity()
¶
Validates that training and evaluation batch sizes do not exceed their respective total dataset sizes.
Returns:
| Name | Type | Description |
|---|---|---|
AppConfig |
AppConfig
|
The validated configuration object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a configured batch size exceeds the available dataset size. |
Source code in src/afl_sim/config.py
check_checkpoint_interval()
¶
Checks if the checkpoint interval exceeds or equals the simulation timeout, warning the user that intermediate checkpoints will not be saved.
Returns:
| Name | Type | Description |
|---|---|---|
AppConfig |
AppConfig
|
The validated configuration object. |
Source code in src/afl_sim/config.py
check_logical_consistency()
¶
Validates that the communication strategy does not request more clients than are available in the simulation pool.
Returns:
| Name | Type | Description |
|---|---|---|
AppConfig |
AppConfig
|
The validated configuration object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If synchronous sample size exceeds total clients. |
Source code in src/afl_sim/config.py
check_model_compatibility()
¶
Validates that the selected model architecture can accept the number of input channels provided by the selected dataset.
Returns:
| Name | Type | Description |
|---|---|---|
AppConfig |
AppConfig
|
The validated configuration object. |
Raises:
| Type | Description |
|---|---|
ValueError
|
If a strict channel mismatch occurs. |
Source code in src/afl_sim/config.py
sanitize_visualization_config()
¶
Disables visualizations automatically if the client count exceeds a readability threshold (150 clients) to prevent resource exhaustion and unreadable plots.
Returns:
| Name | Type | Description |
|---|---|---|
AppConfig |
AppConfig
|
The sanitized configuration object with updated visualization flags. |
Source code in src/afl_sim/config.py
AsyncStrategy
¶
Bases: BaseImmutableConfig
Configuration for asynchronous federated learning strategies.
Source code in src/afl_sim/config.py
agg_target
property
¶
Retrieves the target number of client updates required for a global aggregation.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The configured buffer size limit. |
CheckpointConfig
¶
Bases: BaseImmutableConfig
Configuration for managing state serialization and disk I/O. Controls both interval-based heavy checkpoints and best-model artifacts.
Source code in src/afl_sim/config.py
DataConfig
¶
Bases: BaseImmutableConfig
Configuration for dataset selection and distributed partitioning.
Source code in src/afl_sim/config.py
DatasetType
¶
Bases: StrEnum
Enumeration of supported federated learning datasets.
Attributes:
| Name | Type | Description |
|---|---|---|
MNIST |
str
|
The MNIST dataset of handwritten digits. |
FASHION_MNIST |
str
|
The Fashion-MNIST dataset of clothing articles. |
CIFAR10 |
str
|
The CIFAR-10 dataset of 10 object classes. |
CIFAR100 |
str
|
The CIFAR-100 dataset of 100 object classes. |
Source code in src/afl_sim/enums.py
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 | |
apply_crop_transform
property
¶
Determines whether random cropping should be applied during training.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if random cropping is enabled, False otherwise. |
apply_horizontal_flip_transform
property
¶
Determines whether random horizontal flipping should be applied during training.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if horizontal flipping is enabled, False otherwise. |
image_size
property
¶
Retrieves the pixel height and width of the images (assumes square aspect ratio).
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The image dimension in pixels. |
mean
property
¶
Retrieves the channel-wise mean values for dataset normalization.
Returns:
| Type | Description |
|---|---|
tuple[float] | tuple[float, float, float]
|
tuple[float] | tuple[float, float, float]: A tuple of means for each channel. |
num_channels
property
¶
Retrieves the number of color channels in the dataset images.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
1 for grayscale, 3 for RGB. |
num_classes
property
¶
Retrieves the total number of target classes/labels in the dataset.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The number of classes. |
source
property
¶
Retrieves the source library mapping for the dataset.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The name of the upstream library (e.g., "torchvision"). |
source_name
property
¶
Retrieves the exact dataset class name used by the source library.
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The string identifier for the source dataset class. |
std
property
¶
Retrieves the channel-wise standard deviation values for dataset normalization.
Returns:
| Type | Description |
|---|---|
tuple[float] | tuple[float, float, float]
|
tuple[float] | tuple[float, float, float]: A tuple of standard deviations for each channel. |
test_size
property
¶
Retrieves the total number of samples in the raw evaluation split.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The evaluation dataset size. |
train_size
property
¶
Retrieves the total number of samples in the raw training split.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The training dataset size. |
DefaultDirs
¶
Bases: StrEnum
Enumerates the standardized directories for storing simulation artifacts.
Attributes:
| Name | Type | Description |
|---|---|---|
DATA |
str
|
The default directory for storing generated simulation input data such as raw datasets, data splits and simualtion clocks. Defaults to |
OUTPUTS |
str
|
The default directory for storing execution logs, metrics logs, and runtime metadata. Defaults to |
CHECKPOINTS |
str
|
The default directory for storing resumable simulation and best model checkpoints. Defaults to |
Source code in src/afl_sim/enums.py
DeviceType
¶
Bases: StrEnum
Enumeration of supported hardware accelerator backends.
Attributes:
| Name | Type | Description |
|---|---|---|
CPU |
str
|
Central Processing Unit backend. |
MPS |
str
|
Apple Metal Performance Shaders backend. |
CUDA |
str
|
NVIDIA CUDA backend. |
AUTO |
str
|
Automatically selects the best available backend. |
Source code in src/afl_sim/enums.py
EvaluationConfig
¶
Bases: BaseImmutableConfig
Configuration for the server-side global evaluation process.
Source code in src/afl_sim/config.py
MemStrategyConfig
¶
Bases: BaseImmutableConfig
Configuration defining the memory tracking behavior of clients.
Source code in src/afl_sim/config.py
MemoryType
¶
Bases: StrEnum
Enumeration of client-side memory tracking strategies.
Attributes:
| Name | Type | Description |
|---|---|---|
DISABLED |
str
|
Strategy indicating no memory tracking. |
MODELS |
str
|
Strategy for tracking historical model weights. |
GRADS |
str
|
Strategy for tracking historical gradients. |
Source code in src/afl_sim/enums.py
has_memory
property
¶
Determines if the selected strategy necessitates tracking client-side memory states.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if memory is actively used, False if disabled. |
requires_buffer_reset
property
¶
Determines if the server buffer must be flushed after a global update.
Returns:
| Name | Type | Description |
|---|---|---|
bool |
bool
|
True if the server buffer requires resetting, False if updates are accumulated continuously (e.g., gradient memory). |
ModelConfig
¶
Bases: BaseImmutableConfig
Configuration detailing the target neural network architecture.
Source code in src/afl_sim/config.py
ModelType
¶
Bases: StrEnum
Enumeration of supported neural network architectures.
Attributes:
| Name | Type | Description |
|---|---|---|
LOG_REG |
str
|
Logistic regression architecture. |
CNN |
str
|
Simple Convolutional Neural Network architecture. |
RESNET18 |
str
|
ResNet-18 architecture. |
Source code in src/afl_sim/enums.py
required_channels
property
¶
Determines the strict number of input channels required by the architecture.
Returns:
| Type | Description |
|---|---|
int | None
|
int | None: The required integer channel count, or None if the model dynamically adapts to any input shape. |
OptimizationConfig
¶
Bases: BaseImmutableConfig
Configuration for the local client-side optimization process.
Source code in src/afl_sim/config.py
SimulationConfig
¶
Bases: BaseImmutableConfig
Configuration for the top-level simulation environment and hardware settings.
Source code in src/afl_sim/config.py
SyncStrategy
¶
Bases: BaseImmutableConfig
Configuration for synchronous federated learning strategies.
Source code in src/afl_sim/config.py
agg_target
property
¶
Retrieves the target number of client updates required for a global aggregation.
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
The sample size per synchronous round. |
VisualizationConfig
¶
Bases: BaseImmutableConfig
Configuration for creating and saving data split and client arrival visualizations.
Note: Requires matplotlib to be installed if enabled.
Source code in src/afl_sim/config.py
resume_simulation(output_path, timeout=None)
¶
Resumes an existing simulation from a previously saved output directory.
Restores the configuration, locates the appropriate datasets and checkpoints from the runtime metadata, and continues the simulation loop from the exact global index where it last stopped.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
output_path
|
Path
|
Path to the existing run directory containing |
required |
timeout
|
float | None
|
Optional override for the wall-clock timeout in seconds for this specific session. |
None
|
Raises:
| Type | Description |
|---|---|
FileNotFoundError
|
If the configuration or metadata files cannot be found. |
ValueError
|
If there is an invalid parameter value. |
YAMLError
|
If the YAML configuration is malformed. |
ValidationError
|
If the configuration fails Pydantic validation. |
PermissionError
|
If there are insufficient permissions to read/write directories. |
OSError
|
If a general filesystem error occurs. |
Source code in src/afl_sim/api.py
run_simulation(config, output_dir=DefaultDirs.OUTPUTS, data_dir=DefaultDirs.DATA, checkpoint_dir=DefaultDirs.CHECKPOINTS, learning_rate=None, tag=None, dry_run=False)
¶
Orchestrates and starts a new federated learning simulation.
This function accepts either a path to a YAML configuration file or a pre-instantiated AppConfig object. It creates a timestamped results directory, initializes the data partitions and simulation environment, and begins the run.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
Path | str | AppConfig
|
Path to the YAML configuration file, or an AppConfig instance. |
required |
output_dir
|
Path | str
|
Base directory for all output runs. |
OUTPUTS
|
data_dir
|
Path | str
|
Directory for saving/loading datasets, splits, and clocks. |
DATA
|
checkpoint_dir
|
Path | str
|
Base directory for saving checkpoints. |
CHECKPOINTS
|
learning_rate
|
float | None
|
Optional override for the YAML client learning rate. |
None
|
tag
|
str | None
|
Optional label appended to the run directory name. |
None
|
dry_run
|
bool
|
If True, validates the config and exits without starting. |
False
|
Raises:
| Type | Description |
|---|---|
RuntimeError
|
If a YAML learning rate override is requested without a YAML path. |
TypeError
|
If the provided config is not a Path, string, or AppConfig. |
FileNotFoundError
|
If the configuration file cannot be found. |
ValueError
|
If there is an invalid parameter value. |
YAMLError
|
If the YAML configuration is malformed. |
ValidationError
|
If the configuration fails Pydantic validation. |
PermissionError
|
If there are insufficient permissions to create directories. |
OSError
|
If a general filesystem error occurs. |