def test_00():
    array >> adder
    (array, adder) >> multiplier

    graph._wrap_fcns(dataprinter, printer)

    result = multiplier.outputs[0].data
    printl(result)

    savegraph(graph, 'output/decorators_static_graph_00.pdf')
Ejemplo n.º 2
0
    def init(self):
        """Initialize configuration chain"""
        print('Initialize analysis chain')

        self.FileList >> self.InitAnalyzers >> self.SetupCuts >> self.AnalyzeStage1 >> self.AnalyzeSingles
        self.FileList >> self.CurrentFileIteration >> self.ParseFilename >> self.AnalyzeStage1
        self.CurrentFileIteration >> self.ReadInputFile >> self.AnalyzeStage1
        self.FileList >> self.FindCommonRoot >> self.CreateOutputFile >> self.AnalyzeStage1
        (self.CurrentFileIteration,
         self.ParseFilename) >> self.CreateOutputFile

        # self.graph._wrap_fcns(before_printer)
        # self.AnalyzeStage1._unwrap_fcn()
        self.FileList.taint(True)

        if self.opts.graph:
            savegraph(self.graph, self.opts.graph[0], rankdir='TB')
Ejemplo n.º 3
0
def test_01():
    """Create four nodes: sum up three of them, multiply the result by the fourth
    Use graph context to create the graph.
    Use one-line code for connecting the nodes
    """
    with Graph() as graph:
        initials = [Array(name) for name in ['n1', 'n2', 'n3', 'n4']]
        s = Adder('add')
        m = Multiplier('mul')

    (initials[3], (initials[:3] >> s)) >> m

    graph._wrap_fcns(dataprinter, printer)

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

    savegraph(graph, 'output/decorators_graph_01.pdf')
Ejemplo n.º 4
0
def test_02():
    """Create four nodes: sum up three of them, multiply the result by the fourth
    Use graph context to create the graph.
    Use one-line code for connecting the nodes.
    Use NodeInstance decorator to convert functions directly to node instances.
    """
    with Graph() as graph:
        initials = [Array(name) for name in ['n1', 'n2', 'n3', 'n4']]

        @NodeInstance(
            name='add',
            class_kwargs=dict(missing_input_handler=MissingInputAddOne(
                output_fmt='result')))
        def s(node, inputs, outputs):
            out = None
            for input in inputs:
                if out is None:
                    out = outputs[0].data = input.data
                else:
                    out += input.data

        @NodeInstance(
            name='mul',
            class_kwargs=dict(missing_input_handler=MissingInputAddOne(
                output_fmt='result')))
        def m(node, inputs, outputs):
            out = None
            for input in inputs:
                if out is None:
                    out = outputs[0].data = input.data
                else:
                    out *= input.data

    (initials[3], (initials[:3] >> s)) >> m

    graph._wrap_fcns(dataprinter, printer)

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

    savegraph(graph, 'output/decorators_graph_02.pdf')
Ejemplo n.º 5
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')
Ejemplo n.º 6
0
    """Adds all the inputs together"""
    out = None
    for input in inputs:
        if out is None:
            out=outputs[0].data = input.data.copy()
        else:
            out+=input.data

@NodeClass(missing_input_handler=MissingInputAddOne(output_fmt='result'))
def Multiplier(node, inputs, outputs):
    """Multiplies all the inputs together"""
    out = None
    for input in inputs:
        if out is None:
            out = outputs[0].data = input.data.copy()
        else:
            out*=input.data

# The actual code
with Graph() as graph:
    (in1, in2, in3, in4) = [Array(name) for name in ['n1', 'n2', 'n3', 'n4']]
    s = Adder('add')
    m = Multiplier('mul')

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

print('Result is:', m.outputs.result.data)
savegraph(graph, 'example/dagflow_example.png')

Ejemplo n.º 7
0
    def run(self):
        self.AnalyzeSingles.touch()

        if len(self.opts.graph) > 1:
            savegraph(self.graph, self.opts.graph[1], rankdir='TB')