Exemple #1
0
def test_02():
    """Simple test of the graph plotter"""
    g = Graph()
    n1 = g.add_node('node1')
    n2 = g.add_node('node2')
    n3 = g.add_node('node3')
    g._wrap_fcns(toucher, printer)

    out1 = n1._add_output('o1')
    out2 = n1._add_output('o2')

    _, out3 = n2._add_pair('i1', 'o1')
    n2._add_input('i2')

    _, final = n3._add_pair('i1', 'o1')

    (out1, out2) >> n2
    out3 >> n3

    d = GraphDot(g)
    d.savegraph('output/test2_00.png')

    final.data
    d = GraphDot(g)
    d.savegraph('output/test2_01.png')
Exemple #2
0
def test_08():
    g = Graph()
    n1 = g.add_node('node1')
    n2 = g.add_node('node2')
    n3 = g.add_node('node3')
    g._wrap_fcns(toucher, printer)

    out1 = n1._add_output('o1')
    out2 = n1._add_output('o2')

    _, out3 = n2._add_pair('i1', 'o1')
    n2._add_input('i2')

    _, final = n3._add_pair('i1', 'o1')

    (out1, out2) >> n2
    out3 >> n3

    print()
    final.data

    print('Taint n2')
    n2.taint()
    final.data

    print('Taint n3')
    n3.taint()
    final.data
Exemple #3
0
def test_00():
    """Create four nodes: sum up three of them, multiply the result by the fourth
    Use Graph methods to build the graph
    """
    graph = Graph()
    in1 = graph.add_node('n1', nodeclass=Array)
    in2 = graph.add_node('n2', nodeclass=Array)
    in3 = graph.add_node('n3', nodeclass=Array)
    in4 = graph.add_node('n4', nodeclass=Array)
    s = graph.add_node('add', nodeclass=Adder)
    m = graph.add_node('mul', nodeclass=Multiplier)

    (in1, in2, in3) >> s
    (in4, s) >> m

    graph._wrap_fcns(dataprinter, printer)

    result = m.outputs.result.data
    printl(result)

    savegraph(graph, 'output/decorators_graph_00.pdf')
Exemple #4
0
def test_02a():
    """Simple test of the graph plotter"""
    g = Graph()
    n1 = g.add_node('node1')
    n2 = g.add_node('node2')
    n3 = g.add_node('node3')
    n4 = g.add_node('node4')
    g._wrap_fcns(toucher, printer)

    out1 = n1._add_output('o1')

    in2, out2 = n2._add_pair('i1', 'o1')
    in3, out3 = n3._add_pair('i1', 'o1')
    in4, out4 = n4._add_pair('i1', 'o1')

    out1.repeat() >> (in2, in3, in4)

    d = GraphDot(g)
    d.savegraph('output/test2a_00.png')

    print(out4.data)
    d = GraphDot(g)
    d.savegraph('output/test2a_01.png')
Exemple #5
0
def test_07():
    g = Graph()
    n1 = g.add_node('node1')
    n2 = g.add_node('node2')
    g._wrap_fcns(toucher, printer)

    out1 = n1._add_output('o1')
    out2 = n1._add_output('o2')

    _, final = n2._add_pair('i1', 'o1')
    n2._add_input('i2')

    (out1, out2) >> n2

    final.data
Exemple #6
0
def test_graph_big_01():
    """Create a graph of nodes and test evaluation features"""
    g = Graph()
    label = None

    def plot(suffix=''):
        global counter
        d = GraphDot(g)
        newlabel = label and label + suffix or suffix
        if newlabel is not None:
            d.set_label(newlabel)
        d.savegraph('output/test_graph_big_{:03d}.png'.format(counter))
        counter += 1

    def plotter(fcn, node, inputs, outputs):
        plot('[start evaluating {}]'.format(node.name))
        fcn(node, inputs, outputs)
        plot('[done evaluating {}]'.format(node.name))

    A1 = g.add_node('A1')
    A2 = g.add_node('A2', auto_freeze=True, label='{name}|frozen')
    A3 = g.add_node('A3', immediate=True, label='{name}|immediate')
    B = g.add_node('B')
    C1 = g.add_node('C1')
    C2 = g.add_node('C2')
    D = g.add_node('D')
    E = g.add_node('E')
    F = g.add_node('F')
    H = g.add_node('H')
    P = g.add_node('P', immediate=True, label='{name}|immediate')

    g._wrap_fcns(toucher, printer, plotter)

    A1._add_output('o1')
    A2._add_output('o1')
    P._add_output('o1')
    A3._add_pair('i1', 'o1')
    B._add_pair(('i1', 'i2', 'i3', 'i4'), ('o1', 'o2'))
    C1._add_output('o1')
    C2._add_output('o1')
    D._add_pair('i1', 'o1')
    D._add_pair('i2', 'o2')
    H._add_pair('i1', 'o1')
    _, other = F._add_pair('i1', 'o1')
    _, final = E._add_pair('i1', 'o1')

    (A1, A2, (P >> A3), D[:1]) >> B >> (E, H)
    ((C1, C2) >> D[:, 1]) >> F

    g.print()

    label = 'Initial graph state.'
    plot()

    label = 'Read E...'
    plot()
    plot()
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Taint D.'
    plot()
    plot()
    plot()
    D.taint()
    plot()
    label = 'Read F...'
    other.data
    label = 'Done reading F.'
    plot()

    label = 'Read E...'
    plot()
    plot()
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Taint A2.'
    plot()
    plot()
    plot()
    A2.taint()
    plot()
    label = 'Read E...'
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Unfreeze A2 (tainted).'
    plot()
    plot()
    plot()
    A2.unfreeze()
    plot()
    label = 'Read E...'
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Unfreeze A2 (not tainted).'
    plot()
    plot()
    plot()
    A2.unfreeze()
    plot()
    label = 'Read E...'
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Taint P'
    plot()
    plot()
    plot()
    P.taint()
    plot()
    label = 'Read E...'
    plot()
    final.data
    label = 'Done reading E.'
    plot()

    label = 'Invalidate P'
    plot()
    plot()
    plot()
    P.invalid = True
    plot()

    label = 'Validate P'
    plot()
    plot()
    plot()
    P.invalid = False
    plot()
    label = 'Read E...'
    plot()
    final.data
    label = 'Done reading E.'
    plot()