Ext
penvm.ext.workers
A Worker is a convenience tool to help parcel out the work to the network of machines. The steps are:
- partition the problem space
- spawn the work to the network
- collect the results
- process the results
- combine (consolidate) the results into one
- return the final result
Workers may be tailored to suit specific needs. This is espectially required for the paritition and combine steps, where both implementations cannot be known in advance.
ExecWorker
Bases: Worker
Worker to call executable.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 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 620 621 622 623 624 625 626 627 |
|
__init__(cwd, network, nworkers=None, auto_collect=True, text=True, env=None)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
cwd |
str
|
Working directory to use. |
required |
network |
Network
|
See Worker.init. |
required |
nworkers |
Union[int, None]
|
See Worker.init. |
None
|
auto_collect |
bool
|
See Worker.init. |
True
|
text |
bool
|
Work in text mode. |
True
|
env |
dict
|
Environment variable settings. |
None
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 |
|
call_one(idx, session, *args, **kwargs)
Call one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
str
|
|
()
|
args |
List[Any]
|
|
()
|
See Worker.call_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 |
|
collect_one(idx, session)
Collect one result.
Extract information from the payload:
status
: Response status.returncode
: Return code from execution.stderr
: Stderr output.stdout
: Stdout output.
See Worker.collect_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 |
|
InputExecWorker
Bases: InputMixin
, ExecWorker
Combined penvm.ext.workers.InputMixin and penvm.ext.workers.ExecWorker.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
835 836 837 838 839 |
|
InputMixin
Mixin to partition the problem space into an input-defined number of partitions.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 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 487 488 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 530 531 532 533 534 535 |
|
combine(results)
Return dictionary with results given under respective partition index.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
List[Any]
|
Collected results. |
required |
Returns:
Type | Description |
---|---|
Dict[int, Any]
|
Combined results. |
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 |
|
partition(*args, **kwargs)
Partition input stream.
Other Parameters:
Name | Type | Description |
---|---|---|
`_` |
dict
|
Input directives. |
`*` |
Any
|
All others for the call. |
Keyword Input Directives:
Name | Type | Description |
---|---|---|
`fieldsname` |
str
|
Name of fields list referenced with
|
`file` |
file
|
Input stream. |
`fsep` |
str
|
Field separator. Defaults to whitespace. |
`data` |
str | bytes
|
Input data. |
`rsep` |
str
|
Record separator. Defaults to newline. |
`striprsep` |
bool
|
Strip record separator. Defaults to
|
`transform` |
str
|
Python code to transform data fields
(accessible via list named |
Yields:
Type | Description |
---|---|
Tuple[List, Dict]
|
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 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 530 531 532 533 534 535 |
|
InputPythonCodeWorker
Bases: InputMixin
, PythonCodeWorker
Combined penvm.ext.workers.InputMixin and penvm.ext.workers.PythonCodeWorker.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
842 843 844 845 846 |
|
MirrorExecWorker
Bases: MirrorMixin
, ExecWorker
Combined penvm.ext.workers.MirrorMixin and penvm.ext.workers.ExecWorker.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
856 857 858 859 860 |
|
MirrorMixin
Mixin to provide mirror support for Worker.
All workers are given the same parameters to use (see
partition
).
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
combine(results)
Return dictionary with results given under respective machine id keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
List[Any]
|
Collected results. |
required |
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
Combined results. |
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
|
partition(*args, **kwargs)
Same args and kwargs (untouched) for each.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments. |
()
|
**kwargs |
Dict
|
Keyword arguments. |
{}
|
Yields:
Type | Description |
---|---|
Tuple[List, Dict]
|
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 |
|
MirrorOpWorker
Bases: MirrorMixin
, OpWorker
Combined penvm.ext.workers.MirrorMixin and penvm.ext.workers.OpWorker.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
849 850 851 852 853 |
|
MirrorPythonCodeWorker
Bases: MirrorMixin
, PythonCodeWorker
Combined penvm.ext.workers.MirrorMixin and penvm.ext.workers.PythonCodeWorker.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
863 864 865 866 867 |
|
OpWorker
Bases: Worker
Worker to call an op.
Note
auto_collect
is False
by default because of the
nature of operations (many do not send responses.)
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
__init__(kernelname, network, nworkers=None, auto_collect=False)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
kernelname |
str
|
Name of kernel to use. |
required |
network |
Network
|
See Worker.init. |
required |
nworkers |
Union[int, None]
|
See Worker.init. |
None
|
auto_collect |
bool
|
See Worker.init. |
False
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 |
|
call_one(idx, session, *args, **kwargs)
Call one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
str
|
|
()
|
args |
List[Any]
|
|
()
|
See Worker.call_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 |
|
collect_one(idx, session)
Collect one result.
See Worker.collect_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 |
|
PartitionByFunctionWorker
Bases: Worker
No partitioning is done, but the args
is extended with
nworkers
and index
. This is suitable for cases in which the
receiving function does the partition based on nworkers
and the
index
.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 |
|
PythonCodeWorker
Bases: Worker
Worker to call Python code.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
|
__init__(fallback, code, network, nworkers=None, auto_collect=True)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fallback |
str
|
Fallback function/method to call. |
required |
code |
str
|
Python code to run. |
required |
network |
Network
|
See Worker.init. |
required |
nworkers |
Union[int, None]
|
See Worker.init. |
None
|
auto_collect |
bool
|
See Worker.init. |
True
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 |
|
call_one(idx, session, *args, **kwargs)
Call one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
args |
str
|
|
()
|
args |
List[Any]
|
|
()
|
kwargs |
Dict
|
Keyword arguments to call function with. |
{}
|
See Worker.call_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 |
|
collect_one(idx, session)
Collect one result.
Extract information from the payload:
-status
: Execution status.return-value
: Function return value.
See Worker.collect_one.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 |
|
run(*args, **kwargs)
Run fallback or worker run.
See Worker.run.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 |
|
use_fallback(*args, **kwargs)
Call fallback by default, if available.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
804 805 806 807 808 809 810 |
|
wrun(fnname)
Wrap run call to provide fnname
with args
and kwargs
.
This allows for the function name to not have to be in the
args
and better mirror what may have been the original call
signature.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
fnname |
str
|
Function name to call. |
required |
Returns:
Type | Description |
---|---|
Callable
|
Wrapped function call. |
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 |
|
Worker
Bases: BaseObject
Base, mostly abstract, class.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
48 49 50 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 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 |
|
machines: List[Machine]
property
Return the machines available for use, subject to the number of workers.
Returns:
Type | Description |
---|---|
List[Machine]
|
List of machines available for use. |
nworkers: int
property
Return the number of workers to use.
Returns:
Type | Description |
---|---|
int
|
Number of workers to use. |
__init__(network, nworkers=None, auto_collect=True)
Initialize.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
network |
Network
|
Network object. |
required |
nworkers |
Union[int, None]
|
(Maximum) Number of workers to run with. |
None
|
auto_collect |
bool
|
Collect response objects. |
True
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.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 |
|
call_one(idx, session, *args, **kwargs)
Call one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Call index. |
required |
session |
Session
|
Session for call. |
required |
*args |
List
|
Positional arguments for call. |
()
|
**kwargs |
Dict
|
Keyword arguments for call. |
{}
|
Note
Override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
|
clean(sessions)
Clean/release all sessions.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sessions |
List[Session]
|
List of sessions to clean. |
required |
Note
Do not override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 |
|
collect(sessions)
Collect all results.
Results are collected using Worker.collect_one.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
sessions |
List[Session]
|
List of sessions to collect for. |
required |
Returns:
Type | Description |
---|---|
List[Any]
|
Results from calls. |
Note
Do not override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 |
|
collect_one(idx, session)
Collect one result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Collect index. |
required |
session |
Session
|
Session to collect for. |
required |
Returns:
Type | Description |
---|---|
Any
|
Collected result. |
Note
Override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 |
|
combine(results)
Combine all results into one and return it.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
List[Any]
|
Collected results. |
required |
Returns:
Type | Description |
---|---|
Any
|
Combined results. |
Note
Override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 |
|
disable()
Disable worker.
Will use fallback if available.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
185 186 187 188 189 190 |
|
enable()
Enable worker.
Will not force use of fallback.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
192 193 194 195 196 197 |
|
partition(*args, **kwargs)
Partition problem space. Yield for each.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments for call. |
()
|
**kwargs |
Dict
|
Keyword arguments for call. |
{}
|
Yields:
Type | Description |
---|---|
Tuple[List, Dict]
|
|
Note
Override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 |
|
process(results)
Process and return all results.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
results |
List[Any]
|
Collected results. |
required |
Returns:
Type | Description |
---|---|
List[Any]
|
Results unchanged. |
Note
Override as needed.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 |
|
run(*args, **kwargs)
Run work across network and return result.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments. |
()
|
**kwargs |
Dict
|
Keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Any
|
Final result. |
Note
Do not override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 |
|
spawn(*args, **kwargs)
Spawn partitioned work across machines.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments. |
()
|
**kwargs |
Dict
|
Keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
List[Session]
|
List of sessions used. |
Note
Do not override.
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 |
|
test(*args, **kwargs)
Test run.
No actual calls or processing are made.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments. |
()
|
**kwargs |
Dict
|
Keyword arguments. |
{}
|
Yields:
Type | Description |
---|---|
Tuple[List, Dict]
|
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
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 |
|
transform(*args, **kwargs)
Transform args and kwargs after partitioning and prior to running.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
*args |
List
|
Positional arguments. |
()
|
**kwargs |
Dict
|
Keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Tuple[List, Dict]
|
|
Source code in penvm/src/ext/penvm/ext/workers/__init__.py
363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 |
|