Skip to content

autora.experimentalist.pipeline

Provides tools to chain functions used to create experiment sequences.

Pipe

Bases: Protocol

Takes in an _ExperimentalSequence and modifies it before returning it.

Source code in autora/experimentalist/pipeline.py
32
33
34
35
36
37
@runtime_checkable
class Pipe(Protocol):
    """Takes in an _ExperimentalSequence and modifies it before returning it."""

    def __call__(self, ex: _ExperimentalSequence) -> _ExperimentalSequence:
        ...

Pipeline

Processes ("pipelines") a series of ExperimentalSequences through a pipeline.

Examples:

A pipeline which filters even values 0 to 9:

>>> p = Pipeline(
... [("is_even", lambda values: filter(lambda i: i % 2 == 0, values))]  # a "pipe" function
... )
>>> list(p(range(10)))
[0, 2, 4, 6, 8]

A pipeline which filters for square, odd numbers:

>>> from math import sqrt
>>> p = Pipeline([
... ("is_odd", lambda values: filter(lambda i: i % 2 != 0, values)),
... ("is_sqrt", lambda values: filter(lambda i: sqrt(i) % 1 == 0., values))
... ])
>>> list(p(range(100)))
[1, 9, 25, 49, 81]
>>> from itertools import product
>>> Pipeline([("pool", lambda: product(range(5), ["a", "b"]))])
Pipeline(steps=[('pool', <function <lambda> at 0x...>)], params={})
>>> Pipeline([
... ("pool", lambda: product(range(5), ["a", "b"])),
... ("filter", lambda values: filter(lambda i: i[0] % 2 == 0, values))
... ])
Pipeline(steps=[('pool', <function <lambda> at 0x...>),         ('filter', <function <lambda> at 0x...>)],         params={})
>>> pipeline = Pipeline([
... ("pool", lambda maximum: product(range(maximum), ["a", "b"])),
... ("filter", lambda values, divisor: filter(lambda i: i[0] % divisor == 0, values))
... ] ,
... params = {"pool": {"maximum":5}, "filter": {"divisor": 2}})
>>> pipeline
Pipeline(steps=[('pool', <function <lambda> at 0x...>),         ('filter', <function <lambda> at 0x...>)],         params={'pool': {'maximum': 5}, 'filter': {'divisor': 2}})
>>> list(pipeline.run())
[(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]
>>> pipeline.params = {"pool": {"maximum":7}, "filter": {"divisor": 3}}
>>> list(pipeline())
[(0, 'a'), (0, 'b'), (3, 'a'), (3, 'b'), (6, 'a'), (6, 'b')]
>>> pipeline.params = {"pool": {"maximum":7}}
>>> list(pipeline())
Traceback (most recent call last):
...
TypeError: <lambda>() missing 1 required positional argument: 'divisor'
Source code in autora/experimentalist/pipeline.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
class Pipeline:
    """
    Processes ("pipelines") a series of ExperimentalSequences through a pipeline.

    Examples:
        A pipeline which filters even values 0 to 9:
        >>> p = Pipeline(
        ... [("is_even", lambda values: filter(lambda i: i % 2 == 0, values))]  # a "pipe" function
        ... )
        >>> list(p(range(10)))
        [0, 2, 4, 6, 8]

        A pipeline which filters for square, odd numbers:
        >>> from math import sqrt
        >>> p = Pipeline([
        ... ("is_odd", lambda values: filter(lambda i: i % 2 != 0, values)),
        ... ("is_sqrt", lambda values: filter(lambda i: sqrt(i) % 1 == 0., values))
        ... ])
        >>> list(p(range(100)))
        [1, 9, 25, 49, 81]


        >>> from itertools import product
        >>> Pipeline([("pool", lambda: product(range(5), ["a", "b"]))]) # doctest: +ELLIPSIS
        Pipeline(steps=[('pool', <function <lambda> at 0x...>)], params={})

        >>> Pipeline([
        ... ("pool", lambda: product(range(5), ["a", "b"])),
        ... ("filter", lambda values: filter(lambda i: i[0] % 2 == 0, values))
        ... ]) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('pool', <function <lambda> at 0x...>), \
        ('filter', <function <lambda> at 0x...>)], \
        params={})

        >>> pipeline = Pipeline([
        ... ("pool", lambda maximum: product(range(maximum), ["a", "b"])),
        ... ("filter", lambda values, divisor: filter(lambda i: i[0] % divisor == 0, values))
        ... ] ,
        ... params = {"pool": {"maximum":5}, "filter": {"divisor": 2}})
        >>> pipeline # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('pool', <function <lambda> at 0x...>), \
        ('filter', <function <lambda> at 0x...>)], \
        params={'pool': {'maximum': 5}, 'filter': {'divisor': 2}})
        >>> list(pipeline.run())
        [(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]

        >>> pipeline.params = {"pool": {"maximum":7}, "filter": {"divisor": 3}}
        >>> list(pipeline())
        [(0, 'a'), (0, 'b'), (3, 'a'), (3, 'b'), (6, 'a'), (6, 'b')]

        >>> pipeline.params = {"pool": {"maximum":7}}
        >>> list(pipeline()) # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        TypeError: <lambda>() missing 1 required positional argument: 'divisor'


    """

    def __init__(
        self,
        steps: Optional[Sequence[_StepType]] = None,
        params: Optional[Dict[str, Any]] = None,
    ):
        """Initialize the pipeline with a series of Pipe objects."""
        if steps is None:
            steps = list()
        self.steps = steps

        if params is None:
            params = dict()
        self.params = params

    def __repr__(self):
        return f"{self.__class__.__name__}(steps={self.steps}, params={self.params})"

    def __call__(
        self,
        ex: Optional[_ExperimentalSequence] = None,
        **params,
    ) -> _ExperimentalSequence:
        """Successively pass the input values through the Pipe."""

        # Initialize the parameters objects.
        merged_params = self._merge_params_with_self_params(params)

        try:
            # Check we have steps to use
            assert len(self.steps) > 0
        except AssertionError:
            # If the pipeline doesn't have any steps...
            if ex is not None:
                # ...the output is the input
                return ex
            elif ex is None:
                # ... unless the input was None, in which case it's an emtpy list
                return []

        # Make an iterator from the steps, so that we can be sure to only go through them once
        # (Otherwise if we handle the "pool" as a special case, we have to track our starting point)
        pipes_iterator = iter(self.steps)

        # Initialize our results object
        if ex is None:
            # ... there's no input, so presumably the first element in the steps is a pool
            # which should generate our initial values.
            name, pool = next(pipes_iterator)
            if isinstance(pool, Pool):
                # Here, the pool is a Pool callable, which we can pass parameters.
                all_params_for_pool = merged_params.get(name, dict())
                results = [pool(**all_params_for_pool)]
            elif isinstance(pool, Iterable):
                # Otherwise, the pool should be an iterable which we can just use as is.
                results = [pool]

        else:
            # ... there's some input, so we can use that as the initial value
            results = [ex]

        # Run the successive steps over the last result
        for name, pipe in pipes_iterator:
            assert isinstance(pipe, Pipe)
            all_params_for_pipe = merged_params.get(name, dict())
            results.append(pipe(results[-1], **all_params_for_pipe))

        return results[-1]

    def _merge_params_with_self_params(self, params):
        pipeline_params = _parse_params_to_nested_dict(
            self.params, divider=PARAM_DIVIDER
        )
        call_params = _parse_params_to_nested_dict(params, divider=PARAM_DIVIDER)
        merged_params = _merge_dicts(pipeline_params, call_params)
        return merged_params

    run = __call__

__call__(ex=None, **params)

Successively pass the input values through the Pipe.

Source code in autora/experimentalist/pipeline.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
def __call__(
    self,
    ex: Optional[_ExperimentalSequence] = None,
    **params,
) -> _ExperimentalSequence:
    """Successively pass the input values through the Pipe."""

    # Initialize the parameters objects.
    merged_params = self._merge_params_with_self_params(params)

    try:
        # Check we have steps to use
        assert len(self.steps) > 0
    except AssertionError:
        # If the pipeline doesn't have any steps...
        if ex is not None:
            # ...the output is the input
            return ex
        elif ex is None:
            # ... unless the input was None, in which case it's an emtpy list
            return []

    # Make an iterator from the steps, so that we can be sure to only go through them once
    # (Otherwise if we handle the "pool" as a special case, we have to track our starting point)
    pipes_iterator = iter(self.steps)

    # Initialize our results object
    if ex is None:
        # ... there's no input, so presumably the first element in the steps is a pool
        # which should generate our initial values.
        name, pool = next(pipes_iterator)
        if isinstance(pool, Pool):
            # Here, the pool is a Pool callable, which we can pass parameters.
            all_params_for_pool = merged_params.get(name, dict())
            results = [pool(**all_params_for_pool)]
        elif isinstance(pool, Iterable):
            # Otherwise, the pool should be an iterable which we can just use as is.
            results = [pool]

    else:
        # ... there's some input, so we can use that as the initial value
        results = [ex]

    # Run the successive steps over the last result
    for name, pipe in pipes_iterator:
        assert isinstance(pipe, Pipe)
        all_params_for_pipe = merged_params.get(name, dict())
        results.append(pipe(results[-1], **all_params_for_pipe))

    return results[-1]

__init__(steps=None, params=None)

Initialize the pipeline with a series of Pipe objects.

Source code in autora/experimentalist/pipeline.py
107
108
109
110
111
112
113
114
115
116
117
118
119
def __init__(
    self,
    steps: Optional[Sequence[_StepType]] = None,
    params: Optional[Dict[str, Any]] = None,
):
    """Initialize the pipeline with a series of Pipe objects."""
    if steps is None:
        steps = list()
    self.steps = steps

    if params is None:
        params = dict()
    self.params = params

PipelineUnion

Bases: Pipeline

Run several Pipes in parallel and concatenate all their results.

Examples:

You can use the ParallelPipeline to parallelize a group of poolers:

>>> union_pipeline_0 = PipelineUnion([
...      ("pool_1", make_pipeline([range(5)])),
...      ("pool_2", make_pipeline([range(25, 30)])),
...     ]
... )
>>> list(union_pipeline_0.run())
[0, 1, 2, 3, 4, 25, 26, 27, 28, 29]
>>> union_pipeline_1 = PipelineUnion([
...      ("pool_1", range(5)),
...      ("pool_2", range(25, 30)),
...     ]
... )
>>> list(union_pipeline_1.run())
[0, 1, 2, 3, 4, 25, 26, 27, 28, 29]

You can use the ParallelPipeline to parallelize a group of pipes – each of which gets the same input.

>>> pipeline_with_embedded_union = Pipeline([
...      ("pool", range(22)),
...      ("filters",  PipelineUnion([
...          ("div_5_filter", lambda x: filter(lambda i: i % 5 == 0, x)),
...          ("div_7_filter", lambda x: filter(lambda i: i % 7 == 0, x))
...         ]))
... ])
>>> list(pipeline_with_embedded_union.run())
[0, 5, 10, 15, 20, 0, 7, 14, 21]
Source code in autora/experimentalist/pipeline.py
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
class PipelineUnion(Pipeline):
    """
    Run several Pipes in parallel and concatenate all their results.

    Examples:
        You can use the ParallelPipeline to parallelize a group of poolers:
        >>> union_pipeline_0 = PipelineUnion([
        ...      ("pool_1", make_pipeline([range(5)])),
        ...      ("pool_2", make_pipeline([range(25, 30)])),
        ...     ]
        ... )
        >>> list(union_pipeline_0.run())
        [0, 1, 2, 3, 4, 25, 26, 27, 28, 29]

        >>> union_pipeline_1 = PipelineUnion([
        ...      ("pool_1", range(5)),
        ...      ("pool_2", range(25, 30)),
        ...     ]
        ... )
        >>> list(union_pipeline_1.run())
        [0, 1, 2, 3, 4, 25, 26, 27, 28, 29]

        You can use the ParallelPipeline to parallelize a group of pipes – each of which gets
        the same input.
        >>> pipeline_with_embedded_union = Pipeline([
        ...      ("pool", range(22)),
        ...      ("filters",  PipelineUnion([
        ...          ("div_5_filter", lambda x: filter(lambda i: i % 5 == 0, x)),
        ...          ("div_7_filter", lambda x: filter(lambda i: i % 7 == 0, x))
        ...         ]))
        ... ])
        >>> list(pipeline_with_embedded_union.run())
        [0, 5, 10, 15, 20, 0, 7, 14, 21]

    """

    def __call__(
        self,
        ex: Optional[_ExperimentalSequence] = None,
        **params,
    ) -> _ExperimentalSequence:
        """Pass the input values in parallel through the steps."""

        # Initialize the parameters objects.
        merged_params = self._merge_params_with_self_params(params)

        results = []

        # Run the parallel steps over the input
        for name, pipe in self.steps:
            all_params_for_step = merged_params.get(name, dict())
            if ex is None:
                if isinstance(pipe, Pool):
                    results.append(pipe(**all_params_for_step))
                elif isinstance(pipe, Iterable):
                    results.append(pipe)
                else:
                    raise NotImplementedError(
                        f"{pipe=} cannot be used in the PipelineUnion"
                    )
            else:
                assert isinstance(
                    pipe, Pipe
                ), f"{pipe=} is incompatible with the Pipe interface"
                results.append(pipe(ex, **all_params_for_step))

        union_results = chain.from_iterable(results)

        return union_results

    run = __call__

__call__(ex=None, **params)

Pass the input values in parallel through the steps.

Source code in autora/experimentalist/pipeline.py
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
def __call__(
    self,
    ex: Optional[_ExperimentalSequence] = None,
    **params,
) -> _ExperimentalSequence:
    """Pass the input values in parallel through the steps."""

    # Initialize the parameters objects.
    merged_params = self._merge_params_with_self_params(params)

    results = []

    # Run the parallel steps over the input
    for name, pipe in self.steps:
        all_params_for_step = merged_params.get(name, dict())
        if ex is None:
            if isinstance(pipe, Pool):
                results.append(pipe(**all_params_for_step))
            elif isinstance(pipe, Iterable):
                results.append(pipe)
            else:
                raise NotImplementedError(
                    f"{pipe=} cannot be used in the PipelineUnion"
                )
        else:
            assert isinstance(
                pipe, Pipe
            ), f"{pipe=} is incompatible with the Pipe interface"
            results.append(pipe(ex, **all_params_for_step))

    union_results = chain.from_iterable(results)

    return union_results

Pool

Bases: Protocol

Creates an experimental sequence from scratch.

Source code in autora/experimentalist/pipeline.py
24
25
26
27
28
29
@runtime_checkable
class Pool(Protocol):
    """Creates an experimental sequence from scratch."""

    def __call__(self) -> _ExperimentalSequence:
        ...

make_pipeline(steps=None, params=None, kind='serial')

A factory function to make pipeline objects.

The pipe objects' names will be set to the lowercase of their types, plus an index starting from 0 for non-unique names.

Parameters:

Name Type Description Default
steps Optional[Sequence[Union[Pool, Pipe]]]

a sequence of Pipe-compatible objects

None
params Optional[Dict[str, Any]]

a dictionary of parameters passed to each Pipe by its inferred name

None
kind Literal['serial', 'union']

whether the steps should run in "serial", passing data from one to the next, or in "union", where all the steps get the same data and the output is the union of all the results.

'serial'

Returns:

Type Description
Pipeline

A pipeline object

Examples:

You can create pipelines using purely anonymous functions:
>>> from itertools import product
>>> make_pipeline([lambda: product(range(5), ["a", "b"])]) # doctest: +ELLIPSIS
Pipeline(steps=[('<lambda>', <function <lambda> at 0x...>)], params={})

You can create pipelines with normal functions.
>>> def ab_pool(maximum=5): return product(range(maximum), ["a", "b"])
>>> def even_filter(values): return filter(lambda i: i[0] % 2 == 0, values)
>>> make_pipeline([ab_pool, even_filter]) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Pipeline(steps=[('ab_pool', <function ab_pool at 0x...>),         ('even_filter', <function even_filter at 0x...>)], params={})

You can create pipelines with generators as their first elements functions.
>>> ab_pool_gen = product(range(3), ["a", "b"])
>>> pl = make_pipeline([ab_pool_gen, even_filter])
>>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Pipeline(steps=[('step', <itertools.product object at 0x...>),
('even_filter', <function even_filter at 0x...>)], params={})
>>> list(pl.run())
[(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b')]

You can pass parameters into the different steps of the pl using the "params"
argument:
>>> def divisor_filter(x, divisor): return filter(lambda i: i[0] % divisor == 0, x)
>>> pl = make_pipeline([ab_pool, divisor_filter],
... params = {"ab_pool": {"maximum":5}, "divisor_filter": {"divisor": 2}})
>>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Pipeline(steps=[('ab_pool', <function ab_pool at 0x...>),         ('divisor_filter', <function divisor_filter at 0x...>)],         params={'ab_pool': {'maximum': 5}, 'divisor_filter': {'divisor': 2}})

You can evaluate the pipeline means calling its `run` method:
>>> list(pl.run())
[(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]

... or calling it directly:
>>> list(pl())
[(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]

You can update the parameters and evaluate again, giving different results:
>>> pl.params = {"ab_pool": {"maximum": 7}, "divisor_filter": {"divisor": 3}}
>>> list(pl())
[(0, 'a'), (0, 'b'), (3, 'a'), (3, 'b'), (6, 'a'), (6, 'b')]

If the pipeline needs parameters, then removing them will break the pipeline:
>>> pl.params = {}
>>> list(pl()) # doctest: +ELLIPSIS
Traceback (most recent call last):
...
TypeError: divisor_filter() missing 1 required positional argument: 'divisor'

If multiple steps have the same inferred name, then they are given a suffix automatically,
which has to be reflected in the params if used:
>>> pl = make_pipeline([ab_pool, divisor_filter, divisor_filter])
>>> pl.params = {
...     "ab_pool": {"maximum": 22},
...     "divisor_filter_0": {"divisor": 3},
...     "divisor_filter_1": {"divisor": 7}
... }
>>> list(pl())
[(0, 'a'), (0, 'b'), (21, 'a'), (21, 'b')]

You can also use "partial" functions to include Pipes with defaults in the pipeline.
Because the `partial` function doesn't inherit the __name__ of the original function,
these steps are renamed to "step".
>>> from functools import partial
>>> pl = make_pipeline([partial(ab_pool, maximum=100)])
>>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Pipeline(steps=[('step', functools.partial(<function ab_pool at 0x...>, maximum=100))],         params={})

If there are multiple steps with the same name, they get suffixes as usual:
>>> pl = make_pipeline([partial(range, stop=10), partial(divisor_filter, divisor=3)])
>>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
Pipeline(steps=[('step_0', functools.partial(<class 'range'>, stop=10)),         ('step_1', functools.partial(<function divisor_filter at 0x...>, divisor=3))],         params={})

It is possible to create parallel pipelines too:
>>> pl = make_pipeline([range(5), range(10,15)], kind="union")
>>> pl
PipelineUnion(steps=[('step_0', range(0, 5)), ('step_1', range(10, 15))], params={})

>>> list(pl.run())
[0, 1, 2, 3, 4, 10, 11, 12, 13, 14]
Source code in autora/experimentalist/pipeline.py
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
def make_pipeline(
    steps: Optional[Sequence[Union[Pool, Pipe]]] = None,
    params: Optional[Dict[str, Any]] = None,
    kind: Literal["serial", "union"] = "serial",
) -> Pipeline:
    """
    A factory function to make pipeline objects.

    The pipe objects' names will be set to the lowercase of their types, plus an index
    starting from 0 for non-unique names.

    Args:
        steps: a sequence of Pipe-compatible objects
        params: a dictionary of parameters passed to each Pipe by its inferred name
        kind: whether the steps should run in "serial", passing data from one to the next,
            or in "union", where all the steps get the same data and the output is the union
            of all the results.

    Returns:
        A pipeline object

    Examples:

        You can create pipelines using purely anonymous functions:
        >>> from itertools import product
        >>> make_pipeline([lambda: product(range(5), ["a", "b"])]) # doctest: +ELLIPSIS
        Pipeline(steps=[('<lambda>', <function <lambda> at 0x...>)], params={})

        You can create pipelines with normal functions.
        >>> def ab_pool(maximum=5): return product(range(maximum), ["a", "b"])
        >>> def even_filter(values): return filter(lambda i: i[0] % 2 == 0, values)
        >>> make_pipeline([ab_pool, even_filter]) # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('ab_pool', <function ab_pool at 0x...>), \
        ('even_filter', <function even_filter at 0x...>)], params={})

        You can create pipelines with generators as their first elements functions.
        >>> ab_pool_gen = product(range(3), ["a", "b"])
        >>> pl = make_pipeline([ab_pool_gen, even_filter])
        >>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('step', <itertools.product object at 0x...>),
        ('even_filter', <function even_filter at 0x...>)], params={})
        >>> list(pl.run())
        [(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b')]

        You can pass parameters into the different steps of the pl using the "params"
        argument:
        >>> def divisor_filter(x, divisor): return filter(lambda i: i[0] % divisor == 0, x)
        >>> pl = make_pipeline([ab_pool, divisor_filter],
        ... params = {"ab_pool": {"maximum":5}, "divisor_filter": {"divisor": 2}})
        >>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('ab_pool', <function ab_pool at 0x...>), \
        ('divisor_filter', <function divisor_filter at 0x...>)], \
        params={'ab_pool': {'maximum': 5}, 'divisor_filter': {'divisor': 2}})

        You can evaluate the pipeline means calling its `run` method:
        >>> list(pl.run())
        [(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]

        ... or calling it directly:
        >>> list(pl())
        [(0, 'a'), (0, 'b'), (2, 'a'), (2, 'b'), (4, 'a'), (4, 'b')]

        You can update the parameters and evaluate again, giving different results:
        >>> pl.params = {"ab_pool": {"maximum": 7}, "divisor_filter": {"divisor": 3}}
        >>> list(pl())
        [(0, 'a'), (0, 'b'), (3, 'a'), (3, 'b'), (6, 'a'), (6, 'b')]

        If the pipeline needs parameters, then removing them will break the pipeline:
        >>> pl.params = {}
        >>> list(pl()) # doctest: +ELLIPSIS
        Traceback (most recent call last):
        ...
        TypeError: divisor_filter() missing 1 required positional argument: 'divisor'

        If multiple steps have the same inferred name, then they are given a suffix automatically,
        which has to be reflected in the params if used:
        >>> pl = make_pipeline([ab_pool, divisor_filter, divisor_filter])
        >>> pl.params = {
        ...     "ab_pool": {"maximum": 22},
        ...     "divisor_filter_0": {"divisor": 3},
        ...     "divisor_filter_1": {"divisor": 7}
        ... }
        >>> list(pl())
        [(0, 'a'), (0, 'b'), (21, 'a'), (21, 'b')]

        You can also use "partial" functions to include Pipes with defaults in the pipeline.
        Because the `partial` function doesn't inherit the __name__ of the original function,
        these steps are renamed to "step".
        >>> from functools import partial
        >>> pl = make_pipeline([partial(ab_pool, maximum=100)])
        >>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('step', functools.partial(<function ab_pool at 0x...>, maximum=100))], \
        params={})

        If there are multiple steps with the same name, they get suffixes as usual:
        >>> pl = make_pipeline([partial(range, stop=10), partial(divisor_filter, divisor=3)])
        >>> pl # doctest: +ELLIPSIS +NORMALIZE_WHITESPACE
        Pipeline(steps=[('step_0', functools.partial(<class 'range'>, stop=10)), \
        ('step_1', functools.partial(<function divisor_filter at 0x...>, divisor=3))], \
        params={})

        It is possible to create parallel pipelines too:
        >>> pl = make_pipeline([range(5), range(10,15)], kind="union")
        >>> pl
        PipelineUnion(steps=[('step_0', range(0, 5)), ('step_1', range(10, 15))], params={})

        >>> list(pl.run())
        [0, 1, 2, 3, 4, 10, 11, 12, 13, 14]

    """

    if steps is None:
        steps = []
    steps_: List[_StepType] = []
    raw_names_ = [getattr(pipe, "__name__", "step").lower() for pipe in steps]
    names_tally_ = dict([(name, raw_names_.count(name)) for name in set(raw_names_)])
    names_index_ = dict([(name, 0) for name in set(raw_names_)])

    for name, pipe in zip(raw_names_, steps):
        assert isinstance(pipe, get_args(Union[Pipe, Pool, Iterable]))

        if names_tally_[name] > 1:
            current_index_for_this_name = names_index_.get(name, 0)
            name_in_pipeline = f"{name}_{current_index_for_this_name}"
            names_index_[name] += 1
        else:
            name_in_pipeline = name

        steps_.append((name_in_pipeline, pipe))

    if kind == "serial":
        pipeline = Pipeline(steps_, params=params)
    elif kind == "union":
        pipeline = PipelineUnion(steps_, params=params)
    else:
        raise NotImplementedError(f"{kind=} is not implemented")

    return pipeline