Skip to content

Commit ffee34b

Browse files
committed
refact(net): propertize sol.overwrites
1 parent caa3b94 commit ffee34b

File tree

3 files changed

+26
-18
lines changed

3 files changed

+26
-18
lines changed

docs/source/arch.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,8 @@ Architecture
122122
to get back the given inputs in case of `overwrites`.
123123

124124
overwrites
125-
Values in the `solution` that are written by more than one `operation`\s.
125+
Values in the `solution` that are written by more than one `operation`\s,
126+
accessed by :attr:`Solution.overwrites`:
126127

127128
net
128129
network

graphtik/network.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,12 @@ class Solution(ChainMap, Plotter):
165165
a "virtual" property with executed operations that raised an exception
166166
:ivar canceled:
167167
A sorted set of operations canceled due to upstream failures.
168+
:ivar overwrites:
169+
a "virtual" property to a dictionary with keys the names of values that
170+
exist more than once, and values, all those values in a list, ordered:
171+
172+
- before :meth:`finsihed()`, as computed;
173+
- after :meth:`finsihed()`, in reverse.
168174
:ivar finished:
169175
a flag denoting that this instance cannot acccept more results
170176
(after the :meth:`finished` has been invoked)
@@ -216,13 +222,14 @@ def __delitem__(self, key):
216222
for d in self.maps:
217223
d.pop(key, None)
218224

225+
@property
219226
def overwrites(self) -> Mapping[Any, List]:
220227
"""
221-
Collect items in the maps that exist more than once.
228+
The data in the solution that exist more than once.
222229
223230
:return:
224231
a dictionary with keys only those items that existed in more than one map,
225-
an values, all those values, in the order of given `maps`
232+
and values, all those values, in the order of given `maps`
226233
"""
227234
maps = self.maps
228235
dd = defaultdict(list)

test/test_graphtik.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -457,11 +457,11 @@ def test_pruning_not_overrides_given_intermediate(exemethod):
457457
#
458458
solution = pipeline.compute(inputs, ["asked"])
459459
assert solution == filtdict(exp, "asked")
460-
assert solution.overwrites() == {} # unjust must have been pruned
460+
assert solution.overwrites == {} # unjust must have been pruned
461461

462462
solution = pipeline(**inputs)
463463
assert solution == exp
464-
assert solution.overwrites() == {} # unjust must have been pruned
464+
assert solution.overwrites == {} # unjust must have been pruned
465465

466466

467467
def test_pruning_multiouts_not_override_intermediates1(exemethod):
@@ -488,24 +488,24 @@ def test_pruning_multiouts_not_override_intermediates1(exemethod):
488488
# - on v4.0.0 (overidden, asked) := (5, 11)
489489
solution = pipeline.compute(inp1)
490490
assert solution == exp
491-
assert solution.overwrites() == {"overidden": [5, 1]}
491+
assert solution.overwrites == {"overidden": [5, 1]}
492492

493493
# FAILs
494494
# - on v1.2.4 with KeyError: 'e',
495495
# - on #18(unsatisfied) + #23(ordered-sets) with empty result.
496496
# FIXED on #26
497497
solution = pipeline.compute(inp2, "asked")
498498
assert solution == exp2
499-
assert solution.overwrites() == {}
499+
assert solution.overwrites == {}
500500

501501
## Test OVERWITES
502502
#
503503
solution = pipeline.compute(inp1)
504504
assert solution == exp
505-
assert solution.overwrites() == {"overidden": [5, 1]}
505+
assert solution.overwrites == {"overidden": [5, 1]}
506506

507507
solution = pipeline.compute(inp1, "asked")
508-
assert solution.overwrites() == {}
508+
assert solution.overwrites == {}
509509

510510

511511
@pytest.mark.xfail(
@@ -546,17 +546,17 @@ def test_pruning_multiouts_not_override_intermediates2(exemethod):
546546
#
547547
solution = pipeline.compute(inputs)
548548
assert solution == exp
549-
assert solution.overwrites() == {"overidden": [5, 1]}
549+
assert solution.overwrites == {"overidden": [5, 1]}
550550
# No overwrites when evicted.
551551
#
552552
solution = pipeline.compute(inputs, "asked")
553553
assert solution == filtdict(exp, "asked")
554-
assert solution.overwrites() == {}
554+
assert solution.overwrites == {}
555555
# ... but overrites collected if asked.
556556
#
557557
solution = pipeline.compute(inputs, ["asked", "overidden"])
558558
assert solution == filtdict(exp, "asked", "overidden")
559-
assert solution.overwrites() == {"overidden": [5, 1]}
559+
assert solution.overwrites == {"overidden": [5, 1]}
560560

561561

562562
def test_pruning_with_given_intermediate_and_asked_out(exemethod):
@@ -585,11 +585,11 @@ def test_pruning_with_given_intermediate_and_asked_out(exemethod):
585585
#
586586
solution = pipeline.compute(inps)
587587
assert solution == exp
588-
assert solution.overwrites() == {}
588+
assert solution.overwrites == {}
589589

590590
solution = pipeline.compute(inps, "asked")
591591
assert solution == filtdict(exp, "asked")
592-
assert solution.overwrites() == {}
592+
assert solution.overwrites == {}
593593

594594

595595
def test_same_outputs_operations_order():
@@ -617,17 +617,17 @@ def test_same_outputs_operations_order():
617617
# Notice that `ab` assumed as 2 for `AB` but results in `2`
618618
solution = addsub.compute(inp)
619619
assert solution == {"a": 3, "b": 1, "ab": 2, "AB": 4}
620-
assert solution.overwrites() == {"ab": [2, 4]}
620+
assert solution.overwrites == {"ab": [2, 4]}
621621
solution = addsub.compute(inp, "AB")
622622
assert solution == {"AB": 4}
623-
assert solution.overwrites() == {}
623+
assert solution.overwrites == {}
624624

625625
solution = subadd.compute(inp)
626626
assert solution == {"a": 3, "b": 1, "ab": 4, "AB": 2}
627-
assert solution.overwrites() == {"ab": [4, 2]}
627+
assert solution.overwrites == {"ab": [4, 2]}
628628
solution = subadd.compute(inp, "AB")
629629
assert solution == {"AB": 2}
630-
assert solution.overwrites() == {}
630+
assert solution.overwrites == {}
631631

632632
assert subadd.compute(inp, "AB") == {"AB": 2}
633633
assert len(subadd.last_plan.steps) == 6

0 commit comments

Comments
 (0)