Pipeline
Pipeline
Components orchestration engine.
Builds a graph of components and orchestrates their execution according to the execution graph.
Source code in canals/pipeline/pipeline.py
40 41 42 43 44 45 46 47 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 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 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 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 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 536 537 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 628 629 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 |
|
__eq__(other)
Equal pipelines share every metadata, node and edge, but they're not required to use the same node instances: this allows pipeline saved and then loaded back to be equal to themselves.
Source code in canals/pipeline/pipeline.py
__init__(metadata=None, max_loops_allowed=100, debug_path=Path('.canals_debug/'))
Creates the Pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
metadata |
Optional[Dict[str, Any]]
|
arbitrary dictionary to store metadata about this pipeline. Make sure all the values contained in
this dictionary can be serialized and deserialized if you wish to save this pipeline to file with
|
None
|
max_loops_allowed |
int
|
how many times the pipeline can run the same node before throwing an exception. |
100
|
debug_path |
Union[Path, str]
|
when debug is enabled in |
Path('.canals_debug/')
|
Source code in canals/pipeline/pipeline.py
add_component(name, instance)
Create a component for the given component. Components are not connected to anything by default:
use Pipeline.connect()
to connect components together.
Component names must be unique, but component instances can be reused if needed.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the component. |
required |
instance |
Component
|
the component instance. |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ValueError
|
if a component with the same name already exists |
PipelineValidationError
|
if the given instance is not a Canals component |
Source code in canals/pipeline/pipeline.py
connect(connect_from, connect_to)
Connects two components together. All components to connect must exist in the pipeline. If connecting to an component that has several output connections, specify the inputs and output names as 'component_name.connections_name'.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
connect_from |
str
|
the component that delivers the value. This can be either just a component name or can be
in the format |
required |
connect_to |
str
|
the component that receives the value. This can be either just a component name or can be
in the format |
required |
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
PipelineConnectError
|
if the two components cannot be connected (for example if one of the components is not present in the pipeline, or the connections don't match by type, and so on). |
Source code in canals/pipeline/pipeline.py
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 |
|
draw(path, engine='mermaid-image')
Draws the pipeline. Requires either graphviz
as a system dependency, or an internet connection for Mermaid.
Run pip install canals[graphviz]
or pip install canals[mermaid]
to install missing dependencies.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
Path
|
where to save the diagram. |
required |
engine |
RenderingEngines
|
which format to save the graph as. Accepts 'graphviz', 'mermaid-text', 'mermaid-image'. Default is 'mermaid-image'. |
'mermaid-image'
|
Returns:
Type | Description |
---|---|
None
|
None |
Raises:
Type | Description |
---|---|
ImportError
|
if |
HTTPConnectionError
|
(and similar) if the internet connection is down or other connection issues. |
Source code in canals/pipeline/pipeline.py
from_dict(data, **kwargs)
classmethod
Creates a Pipeline instance from a dictionary.
A sample data
dictionary could be formatted like so:
{
"metadata": {"test": "test"},
"max_loops_allowed": 100,
"components": {
"add_two": {
"type": "AddFixedValue",
"init_parameters": {"add": 2},
},
"add_default": {
"type": "AddFixedValue",
"init_parameters": {"add": 1},
},
"double": {
"type": "Double",
},
},
"connections": [
{"sender": "add_two.result", "receiver": "double.value"},
{"sender": "double.value", "receiver": "add_default.value"},
],
}
Supported kwargs:
components
: a dictionary of {name: instance} to reuse instances of components instead of creating new ones.
Source code in canals/pipeline/pipeline.py
get_component(name)
Returns an instance of a component.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
name |
str
|
the name of the component |
required |
Returns:
Type | Description |
---|---|
Component
|
The instance of that component. |
Raises:
Type | Description |
---|---|
ValueError
|
if a component with that name is not present in the pipeline. |
Source code in canals/pipeline/pipeline.py
inputs()
Returns a dictionary containing the inputs of a pipeline. Each key in the dictionary corresponds to a component name, and its value is another dictionary that describes the input sockets of that component, including their types and whether they are optional.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, Any]]
|
A dictionary where each key is a pipeline component name and each value is a dictionary of |
Dict[str, Dict[str, Any]]
|
inputs sockets of that component. |
Source code in canals/pipeline/pipeline.py
outputs()
Returns a dictionary containing the outputs of a pipeline. Each key in the dictionary corresponds to a component name, and its value is another dictionary that describes the output sockets of that component.
Returns:
Type | Description |
---|---|
Dict[str, Dict[str, Any]]
|
A dictionary where each key is a pipeline component name and each value is a dictionary of |
Dict[str, Dict[str, Any]]
|
output sockets of that component. |
Source code in canals/pipeline/pipeline.py
run(data, debug=False)
Runs the pipeline.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
Dict[str, Any]
|
the inputs to give to the input components of the Pipeline. |
required |
debug |
bool
|
whether to collect and return debug information. |
False
|
Returns:
Type | Description |
---|---|
Dict[str, Any]
|
A dictionary with the outputs of the output components of the Pipeline. |
Raises:
Type | Description |
---|---|
PipelineRuntimeError
|
if the any of the components fail or return unexpected output. |
Source code in canals/pipeline/pipeline.py
419 420 421 422 423 424 425 426 427 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 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 |
|
to_dict()
Returns this Pipeline instance as a dictionary. This is meant to be an intermediate representation but it can be also used to save a pipeline to file.
Source code in canals/pipeline/pipeline.py
warm_up()
Make sure all nodes are warm.
It's the node's responsibility to make sure this method can be called at every Pipeline.run()
without re-initializing everything.
Source code in canals/pipeline/pipeline.py
validate_pipeline_input(graph, input_values)
Make sure the pipeline is properly built and that the input received makes sense. Returns the input values, validated and updated at need.