flgo.simulator.base
BasicSimulator
Bases: AbstractSimulator
Simulate the system heterogeneity with the client state machine.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
object |
list
|
a list of objects in the federated scenario |
required |
Source code in flgo\simulator\base.py
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 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
dropped_clients
property
Return the dropped clients
idle_clients
property
Return ideal clients
offline_clients
property
Return offline clients
selected_clients
property
Return the selected clients
working_clients
property
Return working clients
flush()
Flush the client state machine as time goes by
Source code in flgo\simulator\base.py
382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 |
|
get_client_with_state(state='idle')
Get clients according to their states.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
state |
str
|
the state in ['offline', 'idle', 'selected', 'working', 'dropped'] |
'idle'
|
Returns:
Type | Description |
---|---|
a list of clients whose states are state |
Source code in flgo\simulator\base.py
246 247 248 249 250 251 252 253 254 255 256 |
|
get_clients(client_ids=None)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_ids |
list
|
a list of client ids |
None
|
Returns:
Name | Type | Description |
---|---|---|
res |
list
|
a list of client object |
Source code in flgo\simulator\base.py
300 301 302 303 304 305 306 307 308 |
|
get_variable(client_ids, varname)
Get the simulator-private variables of the clients in client_ids according to varname
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_ids |
list
|
a list of clients' ids |
required |
varname |
str
|
the name of the simulator-private variable |
required |
Returns:
Type | Description |
---|---|
the simulator-private variables of the clients in client_ids |
Source code in flgo\simulator\base.py
335 336 337 338 339 340 341 342 343 344 345 346 347 348 |
|
reset_client_counter(client_ids=[])
Reset the clients' counter
Source code in flgo\simulator\base.py
293 294 295 296 297 298 |
|
set_client_dropped_counter(client_ids=[])
Set the dropped_counter
Source code in flgo\simulator\base.py
286 287 288 289 290 291 |
|
set_client_latency_counter(client_ids=[])
Set the latency_counter
Source code in flgo\simulator\base.py
279 280 281 282 283 284 |
|
set_client_state(client_ids, state)
Set the states of clients in client_ids to the state
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_ids |
list
|
a list of clients' ids |
required |
state |
str
|
the state in ['offline', 'idle', 'selected', 'working', 'dropped'] |
required |
Returns:
Type | Description |
---|---|
a list of clients whose states are state |
Source code in flgo\simulator\base.py
258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 |
|
set_variable(client_ids, varname, values)
Set the simulator-private variables of the clients in client_ids to values
Parameters:
Name | Type | Description | Default |
---|---|---|---|
client_ids |
list
|
a list of clients' ids |
required |
varname |
str
|
the name of the simulator-private variable |
required |
values |
list
|
a list of things |
required |
Source code in flgo\simulator\base.py
350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 |
|
update_client_availability(*args, **kwargs)
API to update client availability every time unit
Source code in flgo\simulator\base.py
366 367 368 |
|
update_client_completeness(client_ids, *args, **kwargs)
API to update client completeness every time unit
Source code in flgo\simulator\base.py
374 375 376 |
|
update_client_connectivity(client_ids, *args, **kwargs)
API to update client connectivity every time unit
Source code in flgo\simulator\base.py
370 371 372 |
|
update_client_responsiveness(client_ids, *args, **kwargs)
API to update client responsiveness every time unit
Source code in flgo\simulator\base.py
378 379 380 |
|
ElemClock
Simulate the clock by the timestamp of each Element
Source code in flgo\simulator\base.py
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 |
|
current_time
property
Return the current time
Elem
Element with a timestamp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
element |
required | |
time |
int
|
the timestamp |
required |
Source code in flgo\simulator\base.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
|
clear()
Clear the queue
Source code in flgo\simulator\base.py
177 178 179 180 181 182 |
|
conditionally_clear(f)
Clear elements if f(element) is False
Parameters:
Name | Type | Description | Default |
---|---|---|---|
f |
function
|
a function that receives element and returns bool variable |
required |
Source code in flgo\simulator\base.py
184 185 186 187 188 189 190 191 192 193 194 195 |
|
empty()
Return whether the queue is empty
Source code in flgo\simulator\base.py
197 198 199 |
|
get()
Get an element from the queue
Returns:
Type | Description |
---|---|
the element in the nearest coming time |
Source code in flgo\simulator\base.py
125 126 127 128 129 130 131 132 133 |
|
get_sofar()
Get elements from the queue until now
Returns:
Type | Description |
---|---|
a list of elements whose timestamps is no larger than the current time |
Source code in flgo\simulator\base.py
155 156 157 158 159 160 161 162 |
|
get_until(t)
Get elements from the queue until time t
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
int
|
time |
required |
Returns:
Type | Description |
---|---|
a list of elements whose timestamps is no larger than t |
Source code in flgo\simulator\base.py
135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 |
|
gets()
Get all the elements in the queue
Returns:
Type | Description |
---|---|
a list of elements in the queue |
Source code in flgo\simulator\base.py
164 165 166 167 168 169 170 171 172 173 174 175 |
|
put(x, time)
Put an element into the time queue with timestamp
Parameters:
Name | Type | Description | Default |
---|---|---|---|
x |
element |
required | |
time |
int
|
the timestamp |
required |
Source code in flgo\simulator\base.py
115 116 117 118 119 120 121 122 123 |
|
register_simulator(simulator)
Set self.simulator=simulator
Source code in flgo\simulator\base.py
206 207 208 |
|
set_time(t)
Set time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
t |
int
|
time |
required |
Source code in flgo\simulator\base.py
105 106 107 108 109 110 111 112 113 |
|
step(delta_t=1)
Step delta_t units of the virtual time
Parameters:
Name | Type | Description | Default |
---|---|---|---|
delta_t |
int
|
the delta of time |
1
|
Source code in flgo\simulator\base.py
92 93 94 95 96 97 98 99 100 101 102 103 |
|
PriorityQueue
Priority Queue
Source code in flgo\simulator\base.py
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
|
empty()
Return whether the queue is empty
Source code in flgo\simulator\base.py
21 22 23 |
|
get()
Get item from the queue
Source code in flgo\simulator\base.py
29 30 31 |
|
put(item)
Put item into the queue
Source code in flgo\simulator\base.py
25 26 27 |
|
size()
The size of the queue
Source code in flgo\simulator\base.py
17 18 19 |
|
seed_generator(seed=0)
Return an integer as the seed
Source code in flgo\simulator\base.py
42 43 44 45 46 |
|
size_of_package(package)
Compute the size of the package
Parameters:
Name | Type | Description | Default |
---|---|---|---|
package |
dict
|
the pacakge |
required |
Returns:
Name | Type | Description |
---|---|---|
size |
int
|
the size of the package |
Source code in flgo\simulator\base.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
|
with_availability(sample)
The decorator for sampling with client availability
Example:
>>> import flgo.algorithm.fedbase
>>> import flgo.simulator.base as ss
>>> class Server(flgo.algorithm.fedbase.BasicServer):
... @ss.with_availability
... def sample(self):
... ...
Source code in flgo\simulator\base.py
428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 |
|
with_clock(communicate)
The decorator to simulate the scene where there is a virtual global clock
Example:
>>> import flgo.algorithm.fedbase
>>> import flgo.simulator.base as ss
>>> class Server(flgo.algorithm.fedbase.BasicServer):
... @ss.with_clock
... def communicate(self,...):
... ...
Source code in flgo\simulator\base.py
555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 |
|
with_completeness(train)
The decorator to simulate the scene where the clients may upload incomplete model updates
Example:
>>> import flgo.algorithm.fedbase
>>> import flgo.simulator.base as ss
>>> class Client(flgo.algorithm.fedbase.BasicClient):
... @ss.with_completeness
... def train(self,...):
... ...
Source code in flgo\simulator\base.py
532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 |
|
with_dropout(communicate)
The decorator for communicating to simulate the scene where clients may drop out
Example:
>>> import flgo.algorithm.fedbase
>>> import flgo.simulator.base as ss
>>> class Server(flgo.algorithm.fedbase.BasicServer):
... @ss.with_dropout
... def communicate(self,...):
... ...
Source code in flgo\simulator\base.py
462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 |
|
with_latency(communicate_with)
The decorator to simulate the scene where there are network latencies during communication
Example:
>>> import flgo.algorithm.fedbase
>>> import flgo.simulator.base as ss
>>> class Server(flgo.algorithm.fedbase.BasicServer):
... @ss.with_latency
... def communicate_with(self,...):
... ...
Source code in flgo\simulator\base.py
489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 |
|