Skip to content

Commit 6c0e15c

Browse files
committed
REVERT(yahoo#20, 94b7291): not asking edges for OPTIONALs ...
but still annotate edges with optional edge data-attribute. Reverted bc Operation must not know its network, to belong to more than one. Also the `Operation.net` contradicted `NetwotkOperation.net`; the later indeed is the network it wraps (not the net it is part of).
1 parent ddf9b59 commit 6c0e15c

File tree

5 files changed

+6
-17
lines changed

5 files changed

+6
-17
lines changed

CHANGES.rst

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Network:
2121
The end result is that operations in the graph that do not have all inputs satisfied,
2222
they are skipped (in v1.2.4 they crashed).
2323

24-
Also started annotating edges with optionals, to make proper use of the underlying
25-
``networkx`` graph.
24+
Also started annotating edges with optional/sideffects, to make proper use of
25+
the underlying ``networkx`` graph.
2626

2727
|v130-flowchart|
2828

@@ -109,6 +109,8 @@ Chore & Docs:
109109
- enh(:gh:`30`): added "API reference' chapter.
110110
- drop(build): ``sphinx_rtd_theme`` library is the default theme for Sphinx now.
111111
- enh(build): Add ``test`` *pip extras*.
112+
- sound: https://www.youtube.com/watch?v=-527VazA4IQ,
113+
https://www.youtube.com/watch?v=8J182LRi8sU&t=43s
112114

113115

114116

graphkit/base.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,6 @@ class Operation(object):
3535
specific application.
3636
"""
3737

38-
#: Owning :class:`~.network.Network`, set when added in a network.
39-
#: Needed by `_compute()` to detect *optional needs* from edge-attributes.
40-
net = None
41-
4238
def __init__(self, **kwargs):
4339
"""
4440
Create a new layer instance.

graphkit/functional.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,21 +14,18 @@ def __init__(self, **kwargs):
1414
Operation.__init__(self, **kwargs)
1515

1616
def _compute(self, named_inputs, outputs=None):
17-
assert self.net
18-
1917
inputs = [
2018
named_inputs[n]
2119
for n in self.needs
22-
if "optional" not in self.net.graph.get_edge_data(n, self)
23-
and not isinstance(n, sideffect)
20+
if not isinstance(n, optional) and not isinstance(n, sideffect)
2421
]
2522

2623
# Find any optional inputs in named_inputs. Get only the ones that
2724
# are present there, no extra `None`s.
2825
optionals = {
2926
n: named_inputs[n]
3027
for n in self.needs
31-
if "optional" in self.net.graph.get_edge_data(n, self) and n in named_inputs
28+
if isinstance(n, optional) and n in named_inputs
3229
}
3330

3431
# Combine params and optionals into one big glob of keyword arguments.

graphkit/network.py

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,10 +184,6 @@ def add_op(self, operation):
184184

185185
self._cached_plans = {}
186186

187-
# functionalOperations don't have that set.
188-
if not operation.net:
189-
operation.net = self
190-
191187
# add nodes and edges to graph describing the data needs for this layer
192188
for n in operation.needs:
193189
if isinstance(n, optional):

test/test_graphkit.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,6 @@ def mul_op1(a, b):
6161
def pow_op1(a, exponent=2):
6262
return [math.pow(a, y) for y in range(1, exponent + 1)]
6363

64-
# `_compute()` needs a` nx-DiGraph in op's `net` attribute.
65-
compose("mock graph")(pow_op1)
6664
assert pow_op1._compute({"sum_ab": 2}, ["sum_ab_p2"]) == {"sum_ab_p2": 4.0}
6765

6866
# Partial operation that is bound at a later time

0 commit comments

Comments
 (0)