Пример #1
0
def main():
    import argparse

    import katana.local

    katana.local.initialize()

    parser = argparse.ArgumentParser()
    parser.add_argument("--startNode", type=int, default=0)
    parser.add_argument("--propertyName", type=str, default="NewProperty")
    parser.add_argument("--edgeWeightProperty", type=str, required=True)
    parser.add_argument("--shift", type=int, default=6)
    parser.add_argument("--reportNode", type=int, default=1)
    parser.add_argument("--noverify", action="store_true", default=False)
    parser.add_argument("--threads", "-t", type=int, default=1)
    parser.add_argument("input", type=str)
    args = parser.parse_args()

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

    graph = Graph(args.input)

    sssp(graph, args.startNode, args.edgeWeightProperty, args.shift,
         args.propertyName)

    print("Node {}: {}".format(
        args.reportNode,
        graph.get_node_property(args.propertyName)[args.reportNode]))

    if not args.noverify:
        numNodeProperties = len(graph.loaded_node_schema())
        newPropertyID = numNodeProperties - 1
        verify_sssp(graph, args.startNode, newPropertyID)
Пример #2
0
def main():
    import argparse

    import katana.local

    katana.local.initialize()

    parser = argparse.ArgumentParser()
    parser.add_argument("--algoType", type=str, default="push")
    parser.add_argument("--propertyName", type=str, default="NewProperty")
    parser.add_argument("--reportNode", type=int, default=1)
    parser.add_argument("--noverify", action="store_true", default=False)
    parser.add_argument("--threads", "-t", type=int, default=1)
    parser.add_argument("input", type=str)
    args = parser.parse_args()

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

    graph = Graph(args.input)

    if args.algoType == "push":
        cc_push_topo(graph, args.propertyName)
    else:
        cc_pull_topo(graph, args.propertyName)

    print("Node {}: {}".format(
        args.reportNode,
        graph.get_node_property(args.propertyName)[args.reportNode]))

    if not args.noverify:
        numNodeProperties = len(graph.loaded_node_schema())
        newPropertyID = numNodeProperties - 1
        verify_cc(graph, newPropertyID)
Пример #3
0
def main():
    import argparse

    import katana.local
    from katana import set_active_threads

    katana.local.initialize()

    parser = argparse.ArgumentParser()
    parser.add_argument("--startNode", type=int, default=0)
    parser.add_argument("--propertyName", type=str, default="NewProperty")
    parser.add_argument("--reportNode", type=int, default=1)
    parser.add_argument("--noverify", action="store_true", default=False)
    parser.add_argument("--threads", "-t", type=int, default=1)
    parser.add_argument("input", type=str)

    args = parser.parse_args()

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

    graph = Graph(args.input)

    bfs_sync_pg(graph, args.startNode, args.propertyName)

    print("Node {}: {}".format(
        args.reportNode,
        graph.get_node_property(args.propertyName)[args.reportNode]))

    if not args.noverify:
        newPropertyID = graph.loaded_node_schema()[-1].name
        verify_bfs(graph, args.startNode, newPropertyID)
Пример #4
0
def test_write(graph):
    with TemporaryDirectory() as tmpdir:
        graph.write(tmpdir)
        del graph
        graph = Graph(tmpdir)
    assert graph.num_nodes() == 29946
    assert graph.num_edges() == 43072
    assert len(graph.loaded_node_schema()) == 17
    assert len(graph.loaded_edge_schema()) == 3
Пример #5
0
def test_commit(graph):
    with TemporaryDirectory() as tmpdir:
        graph.path = tmpdir
        graph.write()
        del graph
        graph = Graph(tmpdir)
    assert graph.num_nodes() == 29092
    assert graph.num_edges() == 39283
    assert len(graph.loaded_node_schema()) == 17
    assert len(graph.loaded_edge_schema()) == 3
Пример #6
0
def test_bfs(graph: Graph):
    start_node = 0
    property_name = "NewProp"

    bfs_sync_pg(graph, start_node, property_name)

    num_node_properties = len(graph.loaded_node_schema())
    new_property_id = num_node_properties - 1
    verify_bfs(graph, start_node, new_property_id)

    stats = BfsStatistics(graph, property_name)
    assert stats.n_reached_nodes == 3
Пример #7
0
def test_betweenness_centrality_level(graph: Graph):
    property_name = "NewProp"

    betweenness_centrality(graph, property_name, 16,
                           BetweennessCentralityPlan.level())

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    stats = BetweennessCentralityStatistics(graph, property_name)

    assert stats.min_centrality == 0
    assert stats.max_centrality == approx(7.0)
    assert stats.average_centrality == approx(0.000534295046236366)
Пример #8
0
def test_pagerank(graph: Graph):
    property_name = "NewProp"

    pagerank(graph, property_name)

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    pagerank_assert_valid(graph, property_name)

    stats = PagerankStatistics(graph, property_name)

    assert stats.min_rank == approx(0.1499999761581421)
    assert stats.max_rank == approx(1347.884765625, abs=0.06)
    assert stats.average_rank == approx(0.5215466022491455, abs=0.001)
Пример #9
0
def test_busy_wait(graph: Graph):
    set_busy_wait()
    property_name = "NewProp"
    start_node = 0

    bfs(graph, start_node, property_name)

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    assert graph.get_node_property(property_name)[start_node].as_py() == 0

    bfs_assert_valid(graph, start_node, property_name)

    BfsStatistics(graph, property_name)

    # Verify with numba implementation of verifier as well
    verify_bfs(graph, start_node, new_property_id)
    set_busy_wait(0)
Пример #10
0
def test_sssp(graph: Graph):
    property_name = "NewProp"
    weight_name = "workFrom"
    start_node = 0

    sssp(graph, start_node, weight_name, property_name)

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    assert graph.get_node_property(property_name)[start_node].as_py() == 0

    sssp_assert_valid(graph, start_node, weight_name, property_name)

    stats = SsspStatistics(graph, property_name)

    print(stats)
    assert stats.max_distance == 0.0

    # Verify with numba implementation of verifier
    verify_sssp(graph, start_node, new_property_id)
Пример #11
0
def test_jaccard(graph: Graph):
    property_name = "NewProp"
    compare_node = 0

    jaccard(graph, compare_node, property_name)

    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name

    jaccard_assert_valid(graph, compare_node, property_name)

    stats = JaccardStatistics(graph, compare_node, property_name)

    assert stats.max_similarity == approx(1)
    assert stats.min_similarity == approx(0)
    assert stats.average_similarity == approx(0.000552534)

    similarities: np.ndarray = graph.get_node_property(
        property_name).to_numpy()
    assert similarities[compare_node] == 1
    assert similarities[1917] == approx(0.0)
    assert similarities[2812] == approx(0.0)
Пример #12
0
def check_schema(graph: Graph, property_name):
    node_schema: Schema = graph.loaded_node_schema()
    num_node_properties = len(node_schema)
    new_property_id = num_node_properties - 1
    assert node_schema.names[new_property_id] == property_name