def drawInstructionGraph(instructions):
    import networkx as nx
    import matplotlib.pyplot as plt

    print "drawing graph with ", len(instructions)

    g = nx.DiGraph()

    def sizeForNode(i):
        if i.isRootInstruction():
            return 500
        else:
            return 100

    edgesToDraw = set()
    nodesToDraw = set()
    nodeColors = {}
    nodeSizes = {}

    def setNodeProps(i):
        if i.getTypedJumpTarget() is not None:
            nodeColors[i] = 'blue'
        elif i.getInstructionGroup().needsInterrupt(i):
            nodeColors[i] = 'green'
        if i.instructionBody.isJump():
            nodeSizes[i] = 100
        if i not in instructions:
            nodeColors[i] = 'red'
            nodeSizes[i] = 100


    def addEdge(i1, i2):
        clusteringWeight = .01
        edgeWeight = .05

        nodesToDraw.add(i1)
        nodesToDraw.add(i2)
        edgesToDraw.add((i1,i2))

        addRoots = i2 in instructions

        g.add_node(i1)
        g.add_node(i2)
        g.add_edge(i1, i2, weight = edgeWeight)

        if addRoots:
            g.add_node(i1.rootInstruction())
            g.add_node(i2.rootInstruction())

            g.add_edge(i1.rootInstruction(), i2.rootInstruction(), weight = 1.0)

            g.add_edge(i1, i1.rootInstruction(), weight = clusteringWeight)
            g.add_edge(i1.rootInstruction(), i1, weight = clusteringWeight)

            g.add_edge(i2, i2.rootInstruction(), weight = clusteringWeight)
            g.add_edge(i2.rootInstruction(), i2, weight = clusteringWeight)

        setNodeProps(i1)
        setNodeProps(i2)



    for i in instructions:
        for ix in range(i.flowsToCount()):
            flowsTo = i.flowsTo(ix)
            addEdge(
                i,
                flowsTo
                )

    pos = nx.spectral_layout(g)

    nx.draw_networkx_nodes(
        g,
        pos,
        nodelist = [n for n in g.nodes() if n in nodesToDraw],
        with_labels=False,
        node_size = [nodeSizes[n] if nodeSizes in n else 300 for n in g.nodes()],
        node_color = [nodeColors[n] if n in nodeColors else 'white' for n in g.nodes()],
        alpha = .5
        )

    nx.draw_networkx_edges(
        g,
        pos,
        edgelist = [e for e in g.edges() if e in edgesToDraw],
        alpha = .5
        )
    plt.show()
dataset/ETHPy150Open ufora/ufora/ufora/FORA/Interpreter/InstructionGraph.py/drawInstructionGraph/swapped operands of `in`