Skip to content

Commit c1fa639

Browse files
committed
DOC(pipes): discern term Combine vs Merge; ...
discovered that the voice is sometimes too personal.
1 parent f6ee21b commit c1fa639

File tree

1 file changed

+28
-19
lines changed

1 file changed

+28
-19
lines changed

docs/source/pipelines.rst

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,16 @@ the ``PIL.Image`` if you have it and skip providing the image data string.
128128

129129
Extending pipelines
130130
-------------------
131+
Sometimes we have existing computation graph(s) to which we want to append
132+
operations or other pipelines.
131133

132-
Sometimes you will have an existing computation graph to which you want to add operations.
133-
This is simple, since ``compose`` can compose whole graphs along with individual ``operation`` instances.
134-
For example, if we have ``graph`` as above, we can add another operation to it
135-
to create a new graph:
134+
Combining
135+
^^^^^^^^^
136+
This is simple, since ``compose()`` can *combine* whole pipelines along with
137+
individual operations and pipelines.
138+
139+
For example, if we have the above ``graph``, we can add another operation to it
140+
and create a new graph:
136141

137142
>>> # Add another subtraction operation to the graph.
138143
>>> bigger_graph = compose("bigger_graph",
@@ -143,6 +148,9 @@ to create a new graph:
143148
.. graphtik::
144149
:graphvar: bigger_graph
145150

151+
Notice that the original pipeline is preserved intact in an "isolated" cluster,
152+
and its operations have been prefixed by the name of that pipeline.
153+
146154
Run the graph and print the output:
147155

148156
>>> sol = bigger_graph.compute({'a': 2, 'b': 5, 'c': 5},
@@ -154,25 +162,20 @@ Run the graph and print the output:
154162
.. graphtik::
155163

156164
.. tip::
157-
We had to plot with ``clusters=True`` so that we prevent :term:`plan`
158-
from inserting the "pruned" cluster (see :attr:`.PlotArgs.clusters`).
159-
165+
We had to plot with ``clusters=True`` so that we prevent the :term:`plan`
166+
to insert the "after pruning" cluster (see :attr:`.PlotArgs.clusters`).
160167

161-
Merging pipelines
162-
^^^^^^^^^^^^^^^^^
163168

164-
Sometimes you will have two computation graphs---perhaps ones that share operations---you want to combine into one.
165-
In the simple case, where the graphs don't share operations or where you don't care
166-
whether a duplicated operation is run multiple (redundant) times,
167-
you can just do something like this:
169+
Merging
170+
^^^^^^^
168171

169-
.. code-block::
172+
Sometimes we have computation graphs -- perhaps ones that share operations --
173+
and we want to *merge* them into one.
170174

171-
combined_graph = compose("combined_graph", graph1, graph2)
175+
This is doable with ``compose(..., merge=True))``.
176+
Any identically-named operations are consolidate into a single node, where
177+
the operation added later in the call (further to the right) wins.
172178

173-
However, if you want to combine graphs that share operations and don't want to pay the price
174-
of running redundant computations, you can set the ``merge`` parameter of ``compose()`` to ``True``.
175-
This will consolidate redundant ``operation`` nodes (based on ``name``) into a single node.
176179
For example, let's say we have ``graphop``, as in the examples above, along with this graph:
177180

178181
>>> another_graph = compose("another_graph",
@@ -204,12 +207,18 @@ We can merge :graphtik:`graphop` and :graphtik:`another_graph` like so, avoiding
204207

205208
As always, we can run computations with this graph by simply calling it:
206209

207-
>>> sol = merged_graph.compute({'a': 2, 'b': 5, 'c': 5}, outputs=["cab"])
210+
>>> sol = merged_graph.compute({"a": 2, "b": 5, "c": 5}, outputs=["cab"])
208211
>>> sol
209212
{'cab': 50}
210213

211214
.. graphtik::
212215

216+
.. seealso::
217+
Consult these test-cases from the full sources of the project:
218+
219+
- :file:`test/test_graphtik.py:test_network_simple_merge()`
220+
- :file:`test/test_graphtik.py:test_network_deep_merge()`
221+
213222

214223
Advanced pipelines
215224
------------------

0 commit comments

Comments
 (0)