Skip to content

Commit 30e2b2d

Browse files
committed
REFACT: FunctionalOperation-->FnOp
1 parent 7359fcb commit 30e2b2d

File tree

14 files changed

+110
-116
lines changed

14 files changed

+110
-116
lines changed

CHANGES.rst

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ v9.0.0.dev2 (30 Jun 2020, @ankostis): JSONP; net, evictions & sfxed fixes; conve
183183
when a pipeline fails.
184184

185185
+ DOC(op): table explaining the differences between various dependency attributes of
186-
:class:`.FunctionalOperation`.
186+
:class:`.FnOp`.
187187

188188
.. include:: ../../graphtik/op.py
189189
:start-after: .. dep-attributes-start
@@ -203,7 +203,7 @@ v9.0.0.dev2 (30 Jun 2020, @ankostis): JSONP; net, evictions & sfxed fixes; conve
203203

204204
v8.4.0 (15 May 2020, @ankostis): subclass-able Op, plot edges from south-->north of nodes
205205
=========================================================================================
206-
+ ENH(pipe): nest all Ops (not just FnOps), dropping ``FunctionalOperation``
206+
+ ENH(pipe): nest all Ops (not just FnOps), dropping ``FnOp``
207207
dependency in network code, to **allow for further sub-classing** :class:`Operation`.
208208
+ FIX(pipeline): due to a side-effect on a ``kw`` dictionary, it was mixing the attributes
209209
of earlier operations into later ones while merging them into pipelines.
@@ -343,7 +343,7 @@ NET: fix rescheduled, cancelable sfx, improve compute API
343343
+ ENH(OP): more intuitive API, ``compute()`` may be called with no args,
344344
or a single string as `outputs` param. Operation's ``__call__`` now delegates
345345
to ``compute()`` - to quickly experiment with function, access it from the
346-
operation's :attr:`.FunctionalOperation.fn` attribute
346+
operation's :attr:`.FnOp.fn` attribute
347347

348348
MODIFIERS: modifier combinations, rename sol_sideffects
349349
-------------------------------------------------------
@@ -397,7 +397,7 @@ v7.0.0 (28 Apr 2020, @ankostis): In-solution sideffects, unified OpBuilder, plot
397397

398398
+ BREAK(op): The :func:`.operation` factory function (used to be *class*) now behave
399399
like a regular decorator when `fn` given in the first call, and constructs
400-
the :class:`.FunctionalOperation` without a need to call again the factory.
400+
the :class:`.FnOp` without a need to call again the factory.
401401

402402
Specifically the last empty call at the end ``()`` is not needed (or possible)::
403403

@@ -418,7 +418,7 @@ MODIFIERS: Sideffecteds; arg--> mapped
418418
"cycles":
419419

420420
+ feat(op): introduce ``_fn_needs``, ``op_needs`` & ``op_provides`` on
421-
:class:`.FunctionalOperation`, used when matching Inps/Outs and when pruning
421+
:class:`.FnOp`, used when matching Inps/Outs and when pruning
422422
graph.
423423
+ FEAT(op): print detailed deps when DEBUG enabled.
424424

@@ -760,7 +760,7 @@ Details
760760
+ FIX(NET): keep Solution's insertion order also for PARALLEL executions.
761761

762762
+ FEAT(NET, OP): :term:`reschedule`\d operations with partial outputs;
763-
they must have :attr:`.FunctionalOperation.rescheduled` set to true,
763+
they must have :attr:`.FnOp.rescheduled` set to true,
764764
or else they will fail.
765765

766766
+ FEAT(OP, netop): specify :term:`endurance`/`reschedule` on a per operation basis,
@@ -894,7 +894,7 @@ v4.0.0 (11 Dec 2019, @ankostis): NESTED merge, revert v3.x Unvarying, immutable
894894
+ BREAK/REFACT(OP): simplify hierarchy, make :class:`.Operation` fully abstract,
895895
without name or requirements.
896896

897-
+ enh: make :class:`.FunctionalOperation` IMMUTABLE, by inheriting
897+
+ enh: make :class:`.FnOp` IMMUTABLE, by inheriting
898898
from class:`.namedtuple`.
899899

900900
+ refact(net): consider as netop `needs` also intermediate data nodes.
@@ -999,7 +999,7 @@ v2.2.0 (20 Nov 2019, @ankostis): enhance OPERATIONS & restruct their modules
999999
+ BREAK(op): drop unused `Operation._after_init()` pickle-hook; use `dill` instead.
10001000
+ refact(op): convert :meth:`Operation._validate()` into a function,
10011001
to be called by clients wishing to automate operation construction.
1002-
+ refact(op): replace ``**kwargs`` with named-args in class:`FunctionalOperation`,
1002+
+ refact(op): replace ``**kwargs`` with named-args in class:`FnOp`,
10031003
because it allowed too wide args, and offered no help to the user.
10041004
+ REFACT(configs): privatize ``network._execution_configs``; expose more
10051005
config-methods from base package.

docs/source/arch.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ Architecture
3636

3737
.. autosummary::
3838

39-
graphtik.op.FunctionalOperation
39+
graphtik.op.FnOp
4040
graphtik.pipeline.Pipeline
4141
graphtik.planning.Network
4242
graphtik.execution.ExecutionPlan
@@ -56,7 +56,7 @@ Architecture
5656
<dependency>`.
5757

5858
.. Tip::
59-
- Use :func:`.operation` factory to construct :class:`.FunctionalOperation`
59+
- Use :func:`.operation` factory to construct :class:`.FnOp`
6060
instances (a.k.a. operations).
6161
- Use :func:`.compose()` factory to build :class:`.Pipeline`
6262
instances (a.k.a. pipelines).
@@ -160,7 +160,7 @@ Architecture
160160
This layering is disabled if a `jsonp` `dependency` exists in the `network`,
161161
assuming that :func:`.set_layered_solution` `configurations` has not been
162162
called with a ``True/False``, nor has the respective parameter been given
163-
to methods :meth:`~.FunctionalOperation.compute()`/:meth:`~.ExecutionPlan.execute()`.
163+
to methods :meth:`~.FnOp.compute()`/:meth:`~.ExecutionPlan.execute()`.
164164

165165
.. hint::
166166

@@ -257,7 +257,7 @@ Architecture
257257

258258
operation
259259
Either the abstract notion of an action with specified `needs` and `provides`,
260-
*dependencies*, or the concrete wrapper :class:`.FunctionalOperation` for
260+
*dependencies*, or the concrete wrapper :class:`.FnOp` for
261261
(any :func:`callable`), that feeds on `inputs` and update `outputs`,
262262
from/to `solution`, or given-by/returned-to the user by a `pipeline`.
263263

@@ -269,7 +269,7 @@ Architecture
269269
The (possibly `hierarchical <subdoc>`) name of a `solution` value an `operation` `needs` or `provides`.
270270

271271
- *Dependencies* are declared during `composition`, when building
272-
:class:`.FunctionalOperation` instances.
272+
:class:`.FnOp` instances.
273273
*Operations* are then interlinked together, by matching the *needs* & *provides*
274274
of all *operations* contained in a `pipeline`.
275275

@@ -328,14 +328,14 @@ Architecture
328328
default identity function
329329
The default function if none given to an `operation` that conveys `needs` to `provides`.
330330

331-
For this to happen when :meth:`.FunctionalOperation.compute()` is called,
331+
For this to happen when :meth:`.FnOp.compute()` is called,
332332
an operation *name* must have been given AND the number of `provides` must match
333333
that of the number of `needs`.
334334

335335
:seealso: :ref:`conveyor-function` & :func:`.identity_function()`.
336336

337337
returns dictionary
338-
When an `operation` is marked with :attr:`FunctionalOperation.returns_dict` flag,
338+
When an `operation` is marked with :attr:`FnOp.returns_dict` flag,
339339
the underlying function is not expected to return `fn_provides` as a sequence
340340
but as a dictionary; hence, no "zipping" of function-results --> `fn_provides`
341341
takes place.
@@ -487,7 +487,7 @@ Architecture
487487
The partial `pruning` of the `solution`'s dag during `execution`.
488488
It happens when any of these 2 conditions apply:
489489

490-
- an `operation` is marked with the :attr:`.FunctionalOperation.rescheduled`
490+
- an `operation` is marked with the :attr:`.FnOp.rescheduled`
491491
attribute, which means that its underlying *callable* may produce
492492
only a subset of its `provides` (*partial outputs*);
493493
- `endurance` is enabled, either globally (in the `configurations`), or
@@ -505,7 +505,7 @@ Architecture
505505
endured
506506
Keep executing as many `operation`\s as possible, even if some of them fail.
507507
Endurance for an operation is enabled if :func:`.set_endure_operations()`
508-
is true globally in the `configurations` or if :attr:`.FunctionalOperation.endured`
508+
is true globally in the `configurations` or if :attr:`.FnOp.endured`
509509
is true.
510510

511511
You may interrogate :attr:`.Solution.executed` to discover the status
@@ -563,7 +563,7 @@ Architecture
563563

564564
plottable
565565
Objects that can plot their graph network, such as those inheriting :class:`.Plottable`,
566-
(:class:`.FunctionalOperation`, :class:`.Pipeline`, :class:`.Network`,
566+
(:class:`.FnOp`, :class:`.Pipeline`, :class:`.Network`,
567567
:class:`.ExecutionPlan`, :class:`.Solution`) or a |pydot.Dot|_ instance
568568
(the result of the :meth:`.Plottable.plot()` method).
569569

docs/source/operations.rst

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ to retrofitting existing *functions* unaware of all these, into :term:`operation
2424

2525
Operations from existing functions
2626
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
27-
The :class:`.FunctionalOperation` provides a concrete lightweight wrapper
27+
The :class:`.FnOp` provides a concrete lightweight wrapper
2828
around any arbitrary function to define and execute within a *pipeline*.
2929
Use the :func:`.operation()` factory to instantiate one:
3030

@@ -35,16 +35,16 @@ Use the :func:`.operation()` factory to instantiate one:
3535
... needs=['a', 'b'],
3636
... provides=['a_plus_b'])
3737
>>> add_op
38-
FunctionalOperation(name='add', needs=['a', 'b'], provides=['a_plus_b'], fn='add')
38+
FnOp(name='add', needs=['a', 'b'], provides=['a_plus_b'], fn='add')
3939

40-
You may still call the original function at :attr:`.FunctionalOperation.fn`,
40+
You may still call the original function at :attr:`.FnOp.fn`,
4141
bypassing thus any operation pre-processing:
4242

4343
>>> add_op.fn(3, 4)
4444
7
4545

4646
But the proper way is to *call the operation* (either directly or by calling the
47-
:meth:`.FunctionalOperation.compute()` method). Notice though that unnamed
47+
:meth:`.FnOp.compute()` method). Notice though that unnamed
4848
positional parameters are not supported:
4949

5050
>>> add_op(a=3, b=4)
@@ -58,7 +58,7 @@ positional parameters are not supported:
5858

5959
Builder pattern
6060
^^^^^^^^^^^^^^^
61-
There are two ways to instantiate a :class:`.FunctionalOperation`\s, each one suitable
61+
There are two ways to instantiate a :class:`.FnOp`\s, each one suitable
6262
for different scenarios.
6363

6464
We've seen that calling manually :func:`.operation()` allows putting into a pipeline
@@ -69,7 +69,7 @@ with similar attributes, e.g. ``needs``:
6969

7070
>>> op_factory = operation(needs=['a'])
7171

72-
Notice that we specified a `fn`, in order to get back a :class:`.FunctionalOperation`
72+
Notice that we specified a `fn`, in order to get back a :class:`.FnOp`
7373
instance (and not a decorator).
7474

7575
>>> from graphtik import operation, compose
@@ -134,8 +134,8 @@ to the :func:`.operation` factory, specifically:
134134

135135
It can be a single string, in which case a 1-element iterable is assumed.
136136

137-
:seealso: :term:`needs`, :term:`modifier`, :attr:`.FunctionalOperation.needs`,
138-
:attr:`.FunctionalOperation.op_needs`, :attr:`.FunctionalOperation._fn_needs`
137+
:seealso: :term:`needs`, :term:`modifier`, :attr:`.FnOp.needs`,
138+
:attr:`.FnOp.op_needs`, :attr:`.FnOp._fn_needs`
139139

140140
``provides``
141141
this argument names the list of (positionally ordered) :term:`outputs` data
@@ -148,8 +148,8 @@ to the :func:`.operation` factory, specifically:
148148
If they are more than one, the underlying function must return an iterable
149149
with same number of elements (unless it :term:`returns dictionary`).
150150

151-
:seealso: :term:`provides`, :term:`modifier`, :attr:`.FunctionalOperation.provides`,
152-
:attr:`.FunctionalOperation.op_provides`, :attr:`.FunctionalOperation._fn_provides`
151+
:seealso: :term:`provides`, :term:`modifier`, :attr:`.FnOp.provides`,
152+
:attr:`.FnOp.op_provides`, :attr:`.FnOp._fn_provides`
153153

154154
Declarations of *needs* and *provides* is affected by :term:`modifier`\s like
155155
:func:`.keyword`:

docs/source/pipelines.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,7 @@ are raising errors, if they are marked as :term:`endured`:
261261
... def get_out():
262262
... raise ValueError("Quarantined!")
263263
>>> get_out
264-
FunctionalOperation!(name='get_out', provides=['space', 'time'], fn='get_out')
264+
FnOp!(name='get_out', provides=['space', 'time'], fn='get_out')
265265

266266
Notice the exclamation(``!``) before the parenthesis in the string representation
267267
of the operation.
@@ -325,7 +325,7 @@ actual `provides` delivered:
325325
... else:
326326
... return {"space": "around the block"}
327327
>>> get_out_or_stay_home
328-
FunctionalOperation?(name='get_out_or_stay_home',
328+
FnOp?(name='get_out_or_stay_home',
329329
needs=['quarantine'],
330330
provides=['space', 'time'],
331331
fn{}='get_out_or_stay_home')

docs/source/plotting.rst

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ solution of the last computation, calling methods with arguments like this::
3232

3333
The same :meth:`.Plottable.plot()` method applies also for:
3434

35-
- :class:`.FunctionalOperation`
35+
- :class:`.FnOp`
3636
- :class:`.Pipeline`
3737
- :class:`.Network`
3838
- :class:`.ExecutionPlan`
@@ -251,7 +251,7 @@ Directives
251251
252252
the variable name containing what to render, which it can be:
253253
254-
- an instance of :class:`.Plottable` (such as :class:`.FunctionalOperation`,
254+
- an instance of :class:`.Plottable` (such as :class:`.FnOp`,
255255
:class:`.Pipeline`, :class:`.Network`, :class:`.ExecutionPlan` or
256256
:class:`.Solution`);
257257
@@ -506,21 +506,21 @@ in :term:`parallel`::
506506
DEBUG ... cache-updated key: ((), None, None)
507507
DEBUG === (3C40) Executing pipeline(t), in parallel, on inputs[], according to ExecutionPlan(needs=[], provides=['b'], x2 steps: op1, op2)...
508508
DEBUG +++ (3C40) Parallel batch['op1'] on solution[].
509-
DEBUG +++ (3C40) Executing OpTask(FunctionalOperation|(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>'), sol_keys=[])...
509+
DEBUG +++ (3C40) Executing OpTask(FnOp|(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>'), sol_keys=[])...
510510
INFO graphtik.op.py:534 Results[sfx: 'b'] contained +1 unknown provides[sfx: 'b']
511-
FunctionalOperation|(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>')
511+
FnOp|(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>')
512512
DEBUG ... (3C40) op(op1) completed in 1.406ms.
513513

514514
...
515515

516516
DEBUG === Compiling pipeline(t)...
517517
DEBUG ... cache-hit key: ((), None, None)
518518
DEBUG === (8697) Executing pipeline(t), evicting, on inputs[], according to ExecutionPlan(needs=[], provides=['b'], x3 steps: op1, op2, sfx: 'b')...
519-
DEBUG +++ (8697) Executing OpTask(FunctionalOperation(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>'), sol_keys=[])...
519+
DEBUG +++ (8697) Executing OpTask(FnOp(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>'), sol_keys=[])...
520520
INFO graphtik.op.py:534 Results[sfx: 'b'] contained +1 unknown provides[sfx: 'b']
521-
FunctionalOperation(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>')
521+
FnOp(name='op1', needs=[], provides=[sfx: 'b'], fn{}='<lambda>')
522522
DEBUG ... (8697) op(op1) completed in 0.149ms.
523-
DEBUG +++ (8697) Executing OpTask(FunctionalOperation(name='op2', needs=[sfx: 'b'], provides=['b'], fn='<lambda>'), sol_keys=[sfx: 'b'])...
523+
DEBUG +++ (8697) Executing OpTask(FnOp(name='op2', needs=[sfx: 'b'], provides=['b'], fn='<lambda>'), sol_keys=[sfx: 'b'])...
524524
DEBUG ... (8697) op(op2) completed in 0.08ms.
525525
DEBUG ... (8697) evicting 'sfx: 'b'' from solution[sfx: 'b', 'b'].
526526
DEBUG === (8697) Completed pipeline(t) in 0.229ms.
@@ -562,13 +562,13 @@ with the following properties, as a debug aid:
562562
{'aliases': None,
563563
'args': {'kwargs': {}, 'positional': [None], 'varargs': []},
564564
'network': Network(x3 nodes, x1 ops: screamer),
565-
'operation': FunctionalOperation(name='screamer', needs=['a'], provides=['foo'], fn='scream'),
565+
'operation': FnOp(name='screamer', needs=['a'], provides=['foo'], fn='scream'),
566566
'outputs': None,
567567
'plan': ExecutionPlan(needs=['a'], provides=['foo'], x1 steps: screamer),
568568
'results_fn': None,
569569
'results_op': None,
570570
'solution': {'a': None},
571-
'task': OpTask(FunctionalOperation(name='screamer', needs=['a'], provides=['foo'], fn='scream'), sol_keys=['a'])}
571+
'task': OpTask(FnOp(name='screamer', needs=['a'], provides=['foo'], fn='scream'), sol_keys=['a'])}
572572

573573

574574
In interactive *REPL* console you may use this to get the last raised exception::
@@ -633,7 +633,7 @@ problems with computed values.
633633
Accessing wrapper operation from task-context
634634
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
635635
Alternatively, when the debugger is stopped inside an underlying function,
636-
you may access the wrapper :class:`.FunctionalOperation` and the :class:`.Solution`
636+
you may access the wrapper :class:`.FnOp` and the :class:`.Solution`
637637
through the :data:`graphtik.execution.task_context` context-var.
638638
This is populated with the :class:`._OpTask` instance of the currently executing operation,
639639
as shown in the :mod:`pdb` session printout, below::
@@ -659,7 +659,7 @@ Printing the operation-task gives you a quick overview of the operation and
659659
the available solution keys (but not the values, not to clutter the debugger console)::
660660

661661
(Pdb) p op_task
662-
OpTask(FunctionalOperation(name=..., needs=..., provides=..., fn=...), sol_keys=[...])
662+
OpTask(FnOp(name=..., needs=..., provides=..., fn=...), sol_keys=[...])
663663

664664
Print the wrapper operation::
665665

graphtik/base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -896,7 +896,7 @@ def _rename_graph_names(
896896
all data are extracted 1st from this kw, falling back on the operation's
897897
attributes, and it is modified in-place
898898
899-
For the other 2 params, see :meth:`.FunctionalOperation.withset()`.
899+
For the other 2 params, see :meth:`.FnOp.withset()`.
900900
901901
:raise ValueError:
902902
- if a `renamer` was neither dict nor callable

graphtik/config.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ def _tristate_armed(context_var: ContextVar, enabled):
8888
8989
.. debug-behavior-start
9090
91-
+ :meth:`FunctionalOperation.compute()` raise any matching-needs errors immediately;
91+
+ :meth:`FnOp.compute()` raise any matching-needs errors immediately;
9292
+ net objects print details recursively;
9393
+ plotted SVG diagrams include style-provenance as tooltips;
9494
+ Sphinx extension also saves the original DOT file next to each image

0 commit comments

Comments
 (0)