Example #1
0
File: bfs.py Project: pamvc/katana
def bfs_sync_pg(graph: PropertyGraph, source, property_name):
    next_level_number = 0

    curr_level = InsertBag[np.uint64]()
    next_level = InsertBag[np.uint64]()

    timer = StatTimer("BFS Property Graph Numba: " + property_name)
    timer.start()
    distance = np.empty((len(graph), ), dtype=np.uint32)
    initialize(graph, source, distance)
    next_level.push(source)
    while not next_level.empty():
        curr_level.swap(next_level)
        next_level.clear()
        next_level_number += 1
        do_all(
            curr_level,
            bfs_sync_operator_pg(graph, next_level, next_level_number,
                                 distance),
            steal=True,
            loop_name="bfs_sync_pg",
        )
    timer.stop()

    graph.add_node_property(pyarrow.table({property_name: distance}))
Example #2
0
def cc_push_topo(graph: PropertyGraph, property_name):
    print("Executing Push algo\n")
    num_nodes = graph.num_nodes()

    timer = StatTimer("CC: Property Graph Numba: " + property_name)
    timer.start()
    # Stores the component id assignment
    comp_current = np.empty((num_nodes,), dtype=np.uint32)
    comp_old = np.empty((num_nodes,), dtype=np.uint32)

    # Initialize
    do_all(
        range(num_nodes),
        initialize_cc_push_operator(graph, comp_current, comp_old),
        steal=True,
        loop_name="initialize_cc_push",
    )

    # Execute while component ids are updated
    changed = GReduceLogicalOr()
    changed.update(True)
    while changed.reduce():
        changed.reset()
        do_all(
            range(num_nodes),
            cc_push_topo_operator(graph, changed, comp_current, comp_old),
            steal=True,
            loop_name="cc_push_topo",
        )

    timer.stop()
    # Add the component assignment as a new property to the property graph
    graph.add_node_property(pyarrow.table({property_name: comp_current}))
Example #3
0
 def bind(self, args, unbound_argument_types):
     arg_types = tuple(typeof(v) for v in args)
     with _compilation_timer, StatTimer("Compilation", self.__qualname__):
         inst = self._generate(arg_types, unbound_argument_types)
         env = PointerPair()
         env_ptr = ctypes.addressof(env)
         env_struct = inst.Environment(*args)
         inst.store_struct(env_struct, env_ptr)
         return Closure(
             inst.wrapper,
             env,
             self._return_type,
             unbound_argument_types,
             captured=(env_struct, args),
             name=self.__name__,
             qualname=self.__qualname__,
         )
Example #4
0
def pagerank_pull_sync_residual(graph: PropertyGraph, maxIterations, tolerance, property_name):
    num_nodes = graph.num_nodes()

    rank = LargeArray[float](num_nodes, AllocationPolicy.INTERLEAVED)
    nout = LargeArray[np.uint64](num_nodes, AllocationPolicy.INTERLEAVED)
    delta = LargeArray[float](num_nodes, AllocationPolicy.INTERLEAVED)
    residual = LargeArray[float](num_nodes, AllocationPolicy.INTERLEAVED)

    # Initialize
    do_all(
        range(num_nodes),
        initialize_residual_operator(rank.as_numpy(), nout.as_numpy(), delta.as_numpy(), residual.as_numpy(),),
        steal=True,
        loop_name="initialize_pagerank_pull_residual",
    )

    # Compute out-degree for each node
    do_all(
        range(num_nodes), compute_out_deg_operator(graph, nout.as_numpy()), steal=True, loop_name="Compute_out_degree",
    )

    print("Out-degree of 0: ", nout[0])

    changed = GReduceLogicalOr(True)
    iterations = 0
    timer = StatTimer("Pagerank: Property Graph Numba: " + property_name)
    timer.start()
    while iterations < maxIterations and changed.reduce():
        print("Iter: ", iterations, "\n")
        changed.reset()
        iterations += 1
        do_all(
            range(num_nodes),
            compute_pagerank_pull_delta_operator(
                rank.as_numpy(), nout.as_numpy(), delta.as_numpy(), residual.as_numpy(), tolerance, changed,
            ),
            steal=True,
            loop_name="pagerank_delta",
        )

        do_all(
            range(num_nodes),
            compute_pagerank_pull_residual_operator(graph, delta.as_numpy(), residual.as_numpy()),
            steal=True,
            loop_name="pagerank",
        )

    timer.stop()
    # Add the ranks as a new property to the property graph
    graph.add_node_property(pyarrow.table({property_name: rank}))
Example #5
0
def sssp(graph: PropertyGraph, source, length_property, shift, property_name):
    dists = create_distance_array(graph, source, length_property)
    init_bag = InsertBag[UpdateRequest]()
    init_bag.push((source, 0))

    t = StatTimer("Total SSSP")
    t.start()
    for_each(
        init_bag,
        sssp_operator(graph, dists, graph.get_edge_property(length_property)),
        worklist=OrderedByIntegerMetric(obim_indexer(shift)),
        disable_conflict_detection=True,
        loop_name="SSSP",
    )
    t.stop()
    print("Elapsed time: ", t.get(), "milliseconds.")

    graph.add_node_property(pyarrow.table({property_name: dists}))
Example #6
0
def kcore_async(graph: PropertyGraph, k_core_num, property_name):
    num_nodes = graph.num_nodes()
    initial_worklist = InsertBag[np.uint64]()
    current_degree = LargeArray[np.uint64](num_nodes,
                                           AllocationPolicy.INTERLEAVED)

    timer = StatTimer("Kcore: Property Graph Numba: " + property_name)
    timer.start()

    # Initialize
    do_all(
        range(num_nodes),
        compute_degree_count_operator(graph, current_degree.as_numpy()),
        steal=True,
    )

    # Setup initial worklist
    do_all(
        range(num_nodes),
        setup_initial_worklist_operator(initial_worklist,
                                        current_degree.as_numpy(), k_core_num),
        steal=True,
    )

    # Compute k-core
    for_each(
        initial_worklist,
        compute_async_kcore_operator(graph, current_degree.as_numpy(),
                                     k_core_num),
        steal=True,
        disable_conflict_detection=True,
    )

    timer.stop()
    # Add the ranks as a new property to the property graph
    graph.add_node_property(pyarrow.table({property_name: current_degree}))
Example #7
0
def main():
    import argparse

    parser = argparse.ArgumentParser()
    parser.add_argument("--baseNode", type=int, default=0)
    parser.add_argument("--reportNode", type=int, default=1)
    parser.add_argument("--propertyName", type=str, default="NewProperty")
    parser.add_argument("--threads", "-t", type=int, default=1)
    parser.add_argument("input", type=str)
    args = parser.parse_args()

    print("Using threads:", setActiveThreads(args.threads))

    g = PropertyGraph(args.input)

    timer = StatTimer("Jaccard (Property Graph) Numba")
    timer.start()
    jaccard(g, args.baseNode, args.propertyName)
    timer.stop()
    # del timer

    print("Node {}: {}".format(
        args.reportNode,
        g.get_node_property(args.propertyName)[args.reportNode]))
Example #8
0
import atexit
import ctypes
from functools import wraps

import llvmlite.ir
from numba import types, typeof, njit
from numba.experimental import jitclass
from numba.extending import lower_builtin
from numba.extending import type_callable

from galois.numba_support.galois_compiler import OperatorCompiler, cfunc
from galois.timer import StatTimer

PointerPair = ctypes.c_void_p * 2

_compilation_timer = StatTimer("Compilation", "Galois-Python")
atexit.register(_compilation_timer.finalize)


class Closure:
    """
    A closure containing a native function pointer and the environment needed to invoke it. These closures are
    used by galois to specify operators.
    """

    __slots__ = [
        "_function",
        "_userdata",
        "return_type",
        "unbound_argument_types",
        "_captured",