You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/source/operations.rst
+37-14Lines changed: 37 additions & 14 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,25 +1,36 @@
1
1
Operations
2
2
==========
3
3
4
-
At a high level, an operation is a node in a computation graph. Graphtik uses an ``operation`` class to represent these computations.
4
+
At a high level, an operation is a node in a computation graph.
5
+
Graphtik uses an :class:`.Operation` class to abstractly represent these computations.
6
+
The class specifies the *requirments* for a function to participate
7
+
in a computation graph; those are its input-data **needs**, and the output-data
8
+
it **provides**.
5
9
6
-
The ``operation`` class
7
-
-----------------------
10
+
The :class:`FunctionalOperation` provides a lightweight wrapper
11
+
around an arbitrary function to define those specifications.
8
12
9
-
The ``operation`` class specifies an operation in a computation graph, including its input data dependencies as well as the output data it provides. It provides a lightweight wrapper around an arbitrary function to make these specifications.
13
+
.. autoclass:: graphtik.op.Operation
14
+
:members: compute
15
+
:noindex:
10
16
11
-
There are many ways to instantiate an ``operation``, and we'll get into more detail on these later. First off, though, here's the specification for the ``operation`` class:
17
+
There is a better way to instantiate an ``FunctionalOperation`` than simply constructing it,
18
+
and we'll get to it later.
19
+
First off, though, here's the specifications for the `operation` classes:
12
20
13
-
.. autoclass:: graphtik.operation
14
-
:members: __init__, __call__
21
+
.. autoclass:: graphtik.op.FunctionalOperation
22
+
:members: __init__, __call__, compute
15
23
:member-order: bysource
16
24
:special-members:
25
+
:noindex:
17
26
18
27
19
28
Operations are just functions
20
29
------------------------------
21
30
22
-
At the heart of each ``operation`` is just a function, any arbitrary function. Indeed, you can instantiate an ``operation`` with a function and then call it just like the original function, e.g.::
31
+
At the heart of each ``operation`` is just a function, any arbitrary function.
32
+
Indeed, you can instantiate an ``operation`` with a function and then call it
33
+
just like the original function, e.g.::
23
34
24
35
>>> from operator import add
25
36
>>> from graphtik import operation
@@ -33,13 +44,24 @@ At the heart of each ``operation`` is just a function, any arbitrary function.
33
44
Specifying graph structure: ``provides`` and ``needs``
Of course, each ``operation`` is more than just a function. It is a node in a computation graph, depending on other nodes in the graph for input data and supplying output data that may be used by other nodes in the graph (or as a graph output). This graph structure is specified via the ``provides`` and ``needs`` arguments to the ``operation`` constructor. Specifically:
47
+
Of course, each ``operation`` is more than just a function.
48
+
It is a node in a computation graph, depending on other nodes in the graph for input data and
49
+
supplying output data that may be used by other nodes in the graph (or as a graph output).
50
+
This graph structure is specified via the ``provides`` and ``needs`` arguments
51
+
to the ``operation`` constructor. Specifically:
37
52
38
-
* ``provides``: this argument names the outputs (i.e. the returned values) of a given ``operation``. If multiple outputs are specified by ``provides``, then the return value of the function comprising the ``operation`` must return an iterable.
53
+
* ``provides``: this argument names the outputs (i.e. the returned values) of a given ``operation``.
54
+
If multiple outputs are specified by ``provides``, then the return value of the function
55
+
comprising the ``operation`` must return an iterable.
39
56
40
-
* ``needs``: this argument names data that is needed as input by a given ``operation``. Each piece of data named in needs may either be provided by another ``operation`` in the same graph (i.e. specified in the ``provides`` argument of that ``operation``), or it may be specified as a named input to a graph computation (more on graph computations :ref:`here <graph-computations>`).
57
+
* ``needs``: this argument names data that is needed as input by a given ``operation``.
58
+
Each piece of data named in needs may either be provided by another ``operation``
59
+
in the same graph (i.e. specified in the ``provides`` argument of that ``operation``),
60
+
or it may be specified as a named input to a graph computation
61
+
(more on graph computations :ref:`here <graph-computations>`).
41
62
42
-
When many operations are composed into a computation graph (see :ref:`graph-composition` for more on that), Graphtik matches up the values in their ``needs`` and ``provides`` to form the edges of that graph.
63
+
When many operations are composed into a computation graph (see :ref:`graph-composition` for more on that),
64
+
Graphtik matches up the values in their ``needs`` and ``provides`` to form the edges of that graph.
43
65
44
66
Let's look again at the operations from the script in :ref:`quick-start`, for example::
45
67
@@ -142,8 +164,9 @@ by creating an operation "builder pattern"::
142
164
Modifiers on ``operation`` inputs and outputs
143
165
---------------------------------------------
144
166
145
-
Certain modifiers are available to apply to input or output values in ``needs`` and ``provides``, for example to designate an optional input. These modifiers are available in the ``graphtik.modifiers`` module:
146
-
167
+
Certain modifiers are available to apply to input or output values in ``needs`` and ``provides``,
168
+
for example, to designate optional inputs, or "ghost" sideffects inputs & outputs.
169
+
These modifiers are available in the ``graphtik.modifiers`` module:
0 commit comments