API Reference — Composition Core¶
The Operator / Sequential / Graph composition algebra lives in the
carrier-agnostic pipekit
framework and is re-exported at geotoolz.* (and pipekit.*) for
convenience. The only geotoolz-specific addition on this page is
ModelOp, which lives at geoops.learn.
For the model behind these primitives, read the Concepts page first.
Base¶
pipekit_ops.Operator
¶
Bases: ConfigMixin
Base class for pipekit operators.
Subclasses implement _apply(self, *args, **kwargs). The base
class dispatches __call__ to either _apply (eager) or
Node construction (symbolic) based on whether any positional
argument is a graph node.
Attributes:
| Name | Type | Description |
|---|---|---|
forbid_in_yaml |
bool
|
|
_terminal |
bool
|
|
backends |
tuple[str, ...] | None
|
The array backends the operator runs on ( |
traceable |
bool
|
|
Example
Define and compose::
class Scale(Operator):
def __init__(self, factor: float) -> None:
self.factor = factor
def _apply(self, x):
return x * self.factor
pipe = Scale(0.5) | Scale(2.0) # Sequential([Scale(0.5), Scale(2.0)])
assert pipe(10.0) == 10.0
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
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 | |
state: dict[str, Any]
property
¶
Return a JSON-serialisable state record for this operator.
__call__(*args: Any, **kwargs: Any) -> Any
¶
Dispatch eager vs symbolic on positional arguments.
If any positional argument is a Node (which Input subclasses),
all positional args must be Nodes and the call returns a new
Node recording this operator and its parents. Otherwise the
call routes to _apply. Subclasses override _apply, not
__call__.
Raises:
| Type | Description |
|---|---|
BackendError
|
|
TypeError
|
if graph-construction mode is triggered (at
least one |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
__or__(other: Operator) -> Sequential
¶
op1 | op2 returns Sequential([op1, op2]), flattening on the right.
a | (b | c) produces a single three-element Sequential.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
compute_output_signature(input_signature: Any) -> Any
¶
Return the signature of this operator's output given an input signature.
Default is passthrough — most carrier-agnostic operators preserve
shape and dtype. Subclasses that reshape / reduce / retype override.
Returning None signals "this operator does not track shape"
(carriers without named dimensions); Sequential.summary and
Graph.summary show ? for it, and every later step in a
Sequential is unknown too.
Handed a carrier instead of a signature, the default reads the
carrier's Signature through its registered adapter
(pipekit_ops.carriers.signature_of), so Sequential.summary can
start from data.
The annotation is Any rather than Signature | None so domain
libraries can thread their own signature types.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
from_config(config: dict[str, Any]) -> Self
classmethod
¶
Build an operator from its decoded get_config() record.
The default calls cls(**config), which is right for every
operator whose config keys are its constructor's arguments.
Operators whose config is not a constructor call (Graph,
whose config is a topology) override this.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
The config with nested operators already rebuilt. |
required |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
from_state(state: dict[str, Any]) -> Operator
classmethod
¶
Reconstruct an operator, and any operators nested in it, from state.
Resolves classes among cls and all its transitive subclasses,
so Operator.from_state(state) resolves any imported subclass;
nothing is imported. Config values are rebuilt recursively: a
nested state record becomes an operator, an
{"exception": "module.Name"} record becomes that (already
imported) exception class, lists and dicts are rebuilt item by
item, and JSON primitives pass through. The class's
from_config then builds the operator.
Raises:
| Type | Description |
|---|---|
ValueError
|
if a state record is malformed. |
TypeError
|
if a class isn't a loaded |
RuntimeError
|
if any class in the tree is marked
|
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
pipekit_ops.ConfigMixin
¶
Auto-derive get_config() from __init__ parameter names.
Reads inspect.signature(type(self).__init__), then for each
declared parameter name looks up the matching instance attribute on
self. The discipline: store __init__ kwargs as attributes of the
same name (the geotoolz / xr_toolz convention).
Opt-out: set __config_mixin_auto__ = False to disable
auto-derivation entirely (subclasses then must override
get_config themselves).
Exclude: set __config_exclude__ = ("field_a",) to skip specific
parameters (useful for runtime-only state).
Subclasses can override get_config directly when auto-derivation
isn't appropriate (e.g. Sequential whose config is a list of
nested operators, not constructor parameters).
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
get_config()
¶
Return a JSON-serialisable dict of constructor args.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_operator.py
Linear composition¶
pipekit_ops.Sequential
¶
Bases: Operator
Apply a list of operators in order, threading the output of each into the next.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operators
|
list[Operator]
|
A list of |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
if any element is not an |
Example
Basic::
pipe = Sequential([Scale(0.5), Scale(2.0)])
assert pipe(10.0) == 10.0
Slice into a sub-pipeline::
head = pipe[:1] # Sequential([Scale(0.5)])
Index a single step::
first = pipe[0] # Scale(0.5)
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
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 | |
is_stateful: bool
property
¶
True if any contained operator is a StatefulOperator.
Such a pipeline is called as pipe(carrier, state) and returns
(carrier, state), so it can step a pipekit-cycle cycle.
__getitem__(key: int | slice) -> Operator | Sequential
¶
Index or slice into the underlying operator list.
pipe[0] returns the first operator. pipe[1:3] returns a
new Sequential containing the slice.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
__or__(other: Operator) -> Sequential
¶
Append on the right; flatten nested Sequentials.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
compute_output_signature(input_signature: Any) -> Any
¶
Thread the signature through every operator in order.
A registered carrier is read as its Signature first.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
describe(indent: int = 0) -> str
¶
Return an indented-tree pretty-print of the pipeline.
Recurses into nested Sequential / Graph operators. Useful
for notebook exploration; not parsed.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
summary(input_signature: Any = None) -> str
¶
Render a Keras-style summary table.
Threads input_signature through compute_output_signature;
a registered carrier is read as its Signature first. If any
operator returns None (does not track shape), the summary
still lists the operator but shows ? for its output
signature. With input_signature=None, only operator names
and types are shown.
The return type is str rather than printing directly so the
caller decides where it goes (notebook, log, file).
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_sequential.py
Graphs¶
pipekit_ops.Input
¶
Bases: Node
A named entry point into a Graph.
Operator.__call__ recognises Node (and any subclass, including
Input) as graph-construction mode. Graph._apply supplies the
value at run-time from the caller's kwargs / positional args.
Subclassing Node (master plan Report 2.A.3, "xr_toolz shape")
lets the topological sort treat all vertices uniformly with one
special case: "this node has no operator — source it from the
caller's inputs".
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
pipekit_ops.Node
¶
A vertex in a Graph.
Created automatically by Operator.__call__ when any positional
argument is a Node (or Input, which subclasses Node). Carries
the operator and its parent vertices. Compared by identity so the
id(...)-keyed evaluation cache during topological sort works.
Raises:
| Type | Description |
|---|---|
TypeError
|
if any element of |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
pipekit_ops.Graph
¶
Bases: Operator
A symbolic operator graph with multiple inputs and outputs.
Construction is implicit — calling operators on Input / Node
instances builds the graph; Graph(inputs=..., outputs=...)
wraps the result. _apply(**inputs) evaluates in topological
order.
Inherits from Operator so a Graph satisfies the same interface
as any other operator. Operator.__call__ dispatches keyword
args straight through to Graph._apply; positional args are bound
to declared Inputs in declaration order.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
inputs
|
dict[str, Input]
|
Map of |
required |
outputs
|
dict[str, Node]
|
Map of |
required |
State
A graph that contains a stateful node (a StatefulOperator, or
a Sequential / Graph that contains one) threads a carry state
the way Sequential does: call it as
graph(a=..., b=..., state=s) and it returns
(outputs, state). The state passes through the stateful nodes
in topological order (the order describe lists); stateless
nodes ignore it. Inside a stateful Sequential the graph receives
(carrier, state) positionally, like any stateful step.
Raises:
| Type | Description |
|---|---|
ValueError
|
if the graph contains a cycle, if an |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
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 | |
compute_output_signature(input_signature: Any) -> Any
¶
None: a graph returns a dict of outputs, not one carrier.
Use output_signatures for each output's signature, and
summary for the whole table.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
describe() -> str
¶
Return a short topology description.
Lists inputs, internal nodes (in topological order), and outputs. Useful for notebook exploration.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
from_config(config: dict[str, Any]) -> Self
classmethod
¶
Rebuild a graph from the topology get_config records.
Re-creates each Input, then calls each node's operator on its
parents in the recorded order, which wires the nodes exactly as
they were; an operator shared by several nodes stays one object.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
dict[str, Any]
|
A |
required |
Raises:
| Type | Description |
|---|---|
ValueError
|
if a reference names an undeclared input or a node that comes later in the order. |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
get_config() -> dict[str, Any]
¶
The whole topology: inputs, operators, nodes and outputs.
Every node is recorded, upstream ones included, so two graphs
that differ anywhere have different configs (and so different
state records and content hashes). The record::
{
"inputs": ["image", "reference"],
"operators": [<state>, ...],
"nodes": [{"operator": 0, "parents": [{"input": "image"}]}, ...],
"outputs": {"ndvi": {"node": 0}, "raw": {"input": "image"}},
}
operators lists each distinct operator once, by identity, in
first-use order, so an operator shared by several nodes is not
duplicated. nodes is in topological order; a parent or an
output refers either to a declared input by name or to an
earlier node by index.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
output_signatures(input_signatures: Any) -> dict[str, Any]
¶
Each output's signature, propagated node by node without data.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_signatures
|
Any
|
|
required |
Returns:
| Type | Description |
|---|---|
``{output name
|
Signature | None} |
dict[str, Any]
|
operator does not track shape, or where a multi-input node's |
dict[str, Any]
|
inputs disagree (see |
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
summary(input_signatures: Any = None) -> str
¶
A Keras-style table of the nodes, their input and output signatures.
Nodes are listed in topological order. Signatures propagate
through each node's compute_output_signature; a node with
several inputs gets its operator's signature for them only when
they all agree (an elementwise join), and ? otherwise, since
compute_output_signature takes one input. The outputs follow.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
input_signatures
|
Any
|
As for |
None
|
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/core/_graph.py
pipekit_ops.Fanout
¶
Bases: Operator
Apply each named operator to the same input; return a dict of outputs.
The dict-keyed companion to juxt. Each operator runs on the same
carrier; the results are collected under their keys.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
branches
|
dict[str, Operator]
|
Mapping from output name to |
required |
Raises:
| Type | Description |
|---|---|
TypeError
|
if any branch isn't an |
ValueError
|
if |
Example::
rgb = Fanout({
"red": SelectBand(0),
"green": SelectBand(1),
"blue": SelectBand(2),
})
out = rgb(image)
# {"red": ..., "green": ..., "blue": ...}
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_combine.py
compute_output_signature(input_signature: Any) -> Any
¶
Inference¶
geoops.learn.ModelOp
¶
Bases: Operator
Wrap any callable as an Operator.
Materialises the GeoArray to a plain np.ndarray (via
np.asarray) before handing it to the model — frameworks that
strip the subclass (torch, JAX, sklearn) don't care, and frameworks
that preserve it (numpy proper) still see something sensible.
Output contract: the model's return value is passed through as-is
and never rewrapped into the input carrier -- a GeoArray input
yields whatever the model returns (an np.ndarray, a torch tensor,
...) without transform / crs / fill_value. Rewrap
it yourself, or use :class:SklearnOp, which restores the grid for
per-pixel estimators.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
model
|
Any
|
Any object that can be called as |
required |
method
|
str
|
Method name to invoke on |
'__call__'
|
batch_size
|
int | None
|
If set, split the input along axis 0 into chunks of this size, call the model once per chunk, concatenate the results along axis 0. Useful when the model can't fit the whole input in GPU memory. |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
At construction, when |
Note
forbid_in_yaml = True — the model is a runtime object and
won't round-trip to YAML. Users typically pin a model artifact
(state-dict + class config) themselves.
Examples:
A scikit-learn estimator sees the raw array, so feed it the
(n_samples, n_features) table it was fit on; for per-pixel
prediction on a (C, H, W) scene use :class:SklearnOp,
which flattens the pixels and restores the grid::
op = ModelOp(model=rf_clf, method="predict")
labels = op(features) # features: (n_samples, n_features)
Batched inference with a torch model::
op = ModelOp(model=unet_model, batch_size=8)
preds = op(chips_gt) # iterates 8 chips at a time
Source code in packages/geotoolz-ops/src/geoops/learn/_src/operators.py
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 | |
Observers — identity with side effects¶
pipekit_ops.Tap
¶
Bases: Operator
Fire a callback on the carrier; return the carrier unchanged.
Distinct from Sink only by naming convention — Tap is for
observation (logging, metrics, breakpoint hooks); Sink is for
persistence. Both pass the carrier through; both carry
forbid_in_yaml = True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[[Any], Any]
|
Callable invoked with the carrier. Its return value is ignored. |
required |
name
|
str | None
|
Optional name for |
None
|
Example::
log = Tap(lambda x: print(getattr(x, "shape", x)), name="log_shape")
pipe = Scale(2.0) | log | AddConst(1.0)
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/observe/_observers.py
pipekit_ops.Snapshot
¶
Controller that captures intermediate carriers by name.
Not an Operator itself. Call .at(key) to obtain a per-step
operator that stores the carrier under that key.
Attributes:
| Name | Type | Description |
|---|---|---|
captures |
dict[str, Any]
|
Dict |
Example::
snap = Snapshot()
pipe = snap.at("pre") | Scale(2.0) | snap.at("post") | AddConst(1.0)
pipe(3.0)
snap.captures
# {"after_scale": 3.0, "after_add": 6.0}
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/observe/_observers.py
pipekit_ops.ShapeTrace
¶
Bases: Operator
Log shape / dtype of each carrier passing through.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
printer
|
Callable[[str], None]
|
Callable invoked with the formatted line. Defaults to
the built-in |
print
|
mode
|
str
|
|
'every'
|
label
|
str | None
|
Optional prefix for the printed line (useful when
multiple |
None
|
extra
|
Callable[[Any], str | None] | None
|
Optional callable |
None
|
Example::
trace = ShapeTrace(mode="diff_only", label="post-resample")
pipe = Resample() | trace | NDVI()
# print the coordinate system too
ShapeTrace(extra=lambda gt: f"crs={gt.crs}")
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/observe/_observers.py
Control flow¶
pipekit_ops.Branch
¶
Bases: Operator
Binary conditional: run if_true or if_false based on a predicate.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
predicate
|
Callable[..., bool]
|
Callable |
required |
if_true
|
Operator
|
|
required |
if_false
|
Operator | None
|
|
None
|
Example::
clean_if_dirty = Branch(
predicate=has_nans,
if_true=GapFill(),
if_false=Identity(),
)
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_control.py
compute_output_signature(input_signature: Any) -> Any
¶
The signature both branches agree on (else None).
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_control.py
pipekit_ops.Switch
¶
Bases: Operator
Multi-way dispatch on key(carrier).
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
key
|
Callable[..., Hashable]
|
Callable |
required |
cases
|
dict[Hashable, Operator]
|
Mapping from key-value to |
required |
default
|
Operator | None
|
|
None
|
Example::
by_sensor = Switch(
key=lambda gt: gt.attrs["sensor"],
cases={
"sentinel-2": Sentinel2Pipeline(),
"landsat-8": Landsat8Pipeline(),
},
default=Identity(),
)
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_control.py
compute_output_signature(input_signature: Any) -> Any
¶
The signature every case and the default agree on (else None).
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_control.py
Building blocks¶
pipekit_ops.Identity
¶
Bases: Operator
Explicit no-op. Returns its input unchanged.
Used as the default value for slots that need an Operator but
where "do nothing" is the right behaviour — Branch.if_false,
Switch.default, training-mode-off augmentation, etc.
Example::
Branch(predicate=is_clean, if_true=Identity(), if_false=Despeckle())
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_blocks.py
pipekit_ops.Const
¶
Bases: Operator
Return a fixed value, ignoring any input.
Useful for test fixtures, Switch default cases that should emit a
sentinel, and golden values used in Try fallbacks.
Example::
zero = Const(0.0)
assert zero() == 0.0
assert zero("anything") == 0.0
The value should be JSON-primitive for round-trip via from_state.
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_blocks.py
pipekit_ops.Lambda
¶
Bases: Operator
Wrap an arbitrary callable as an Operator.
The escape hatch for one-off operations that don't warrant a named
subclass. Carries forbid_in_yaml = True because the wrapped
callable typically captures closure state that doesn't survive
JSON / YAML round-trip.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
fn
|
Callable[..., Any]
|
The callable to wrap. Receives the carrier and any extra
positional / keyword arguments forwarded through |
required |
name
|
str | None
|
Optional name for |
None
|
Example::
twice = Lambda(lambda x: x * 2, name="double")
assert twice(3) == 6
Source code in .venv/lib/python3.12/site-packages/pipekit_ops/operators/_blocks.py
pipekit_ops.Sink
¶
Bases: Operator
Apply a side-effecting write and pass the input through unchanged.
The canonical checkpointing primitive: log, persist, broadcast, etc.
The return value of write_fn is discarded; the original input
flows on.
Sink is not marked _terminal because it returns the
carrier — a Sequential can continue past it. For operators that
legitimately return None (write-to-disk, render-and-exit),
define a subclass with _terminal = True and put it at the end.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
write_fn
|
Callable[..., Any]
|
Callable that consumes the carrier for side effects. Its return value is ignored. |
required |
name
|
str | None
|
Optional name for |
None
|
Raises:
| Type | Description |
|---|---|
TypeError
|
If the carrier is a JAX tracer, for example inside
|
Example::
log = Sink(lambda gt: print(gt.shape), name="log_shape")
pipe = Scale(2.0) | log | AddConst(1.0)
# log fires between Scale and AddConst; the carrier is untouched