def test_bottleneck_circuit(): # out = bottleneck(a + b, c + d, e) F1 = CircuitSpec("F1", ['a', 'b', 'c', 'd', 'e', 'out'], dict(add1 = lib.Add, add2 = lib.Add, neck = lib.Bottleneck(3) ), [('a', 'add1.a'), ('b', 'add1.b'), ('c', 'add2.a'), ('d', 'add2.b'), ('add1.out', 'neck.i0'), ('add2.out', 'neck.i1'), ('e', 'neck.i2'), ('neck.out', 'out')]) results = xgate_iter(F1, dict(a = [10, 77], b = [20], c = [30], d = [40], e = [50, 90]), ['out']) # should be [50, 30, 70, 90] or [50, 70, 30, 90], since e=50 # arrives first and e=90 arrives last print(results) # but we don't care all that much about the order assert set(results['out']) == {30, 50, 70, 90}
def test_xgate_iter(): results = xgate_iter(lib.Add, dict(a = [1, 20, 300, 4000, 50000, 600000], b = [6, 50, 400, 3000, 20000, 100000]), ['out', 'error']) print(results) assert results['out'] == [7, 70, 700, 7000, 70000, 700000] assert results['error'] == [VOID] * 6
def test_bottleneck(): results = xgate_iter(lib.Bottleneck(5), dict(i0 = [10], i1 = [20], i2 = [30], i3 = [40], i4 = [50]), ['out']) assert set(results['out']) == {10, 20, 30, 40, 50}
def test_either_once(): results = xgate_iter(lib.EitherOnce(2), dict(i0 = [10, 20, 30, 40], i1 = [100, 200, 300]), ['o0', 'o1']) print(results) # Only one output will ever pass. Typically it'll be o0 here, but # it's also correct if it is o1. assert (results == dict(o0 = [10], o1 = [VOID]) or results == dict(o0 = [VOID], o1 = [100]))
def test_either_once_circuit(): m = [] # out = either(trace(trace(trace(a))), trace(b)) F1 = CircuitSpec("F1", ['a', 'b', 'o0', 'o1'], dict(eith = lib.EitherOnce(2), tracea = TracerGate(m), traceb = TracerGate(m), traceX1 = TracerGate(m), traceX2 = TracerGate(m) ), [('a', 'tracea.x'), ('b', 'traceb.x'), ('tracea.out', 'traceX1.x'), ('traceX1.out', 'traceX2.x'), ('traceX2.out', 'eith.i0'), ('traceb.out', 'eith.i1'), ('eith.o0', 'o0'), ('eith.o1', 'o1')]) results = xgate_iter(F1, dict(a = [10, 20], b = [30]), ['o0', 'o1']) print(results) print(m) # Only one output will ever pass. Since the path to i0 is longer # than the path to i1, i1 should get in before, eith and traceX1 # should be evaluated at the same time, and then the evaluation of # traceX2 should not occur, because the request on i0 is removed. assert (results == dict(o0 = [VOID], o1 = [30])) assert sorted(m) == [10, 10, 30]