示例#1
0
def test_project_subgraph(arrow_modern_graph):
    graph = arrow_modern_graph

    sub_graph = graph.project(vertices={}, edges={})
    assert sub_graph.schema.vertex_labels == []
    assert sub_graph.schema.edge_labels == []
    with pytest.raises(
        RuntimeError,
        match="Failed to project to simple graph as no vertex exists in this graph",
    ):
        graphscope.wcc(sub_graph)

    # project a sub_graph only contain person nodes
    sub_graph = graph.project(vertices={"person": None}, edges={})
    assert sub_graph.schema.vertex_labels == ["person"]
    assert sub_graph.schema.edge_labels == []
    with pytest.raises(
        RuntimeError,
        match="Failed to project to simple graph as no edge exists in this graph",
    ):
        graphscope.wcc(sub_graph)

    graph = graph.project(
        vertices={"person": None, "software": ["name", "id"]},
        edges={"created": ["eid", "weight"], "knows": None},
    )
    assert graph.schema.vertex_labels == ["person", "software"]
    assert graph.schema.edge_labels == ["knows", "created"]
    assert [p.id for p in graph.schema.get_vertex_properties("person")] == [0, 1, 2]
    assert [p.id for p in graph.schema.get_vertex_properties("software")] == [0, 2]
    assert [p.id for p in graph.schema.get_edge_properties("created")] == [0, 1]
    assert [p.id for p in graph.schema.get_edge_properties("knows")] == [0, 1]

    graph = graph.project(edges={"knows": ["eid"]}, vertices={"person": None})

    assert graph.schema.vertex_labels == ["person"]
    assert graph.schema.edge_labels == ["knows"]
    assert [p.id for p in graph.schema.get_vertex_properties("person")] == [0, 1, 2]
    assert [p.id for p in graph.schema.get_edge_properties("knows")] == [0]

    with pytest.raises(ValueError, match="weight not exist in properties"):
        graph = graph.project(edges={"knows": ["weight"]}, vertices={"person": []})

    graph = graph.project(edges={"knows": []}, vertices={"person": []})
    assert not graph.schema.get_vertex_properties("person")
    assert not graph.schema.get_edge_properties("knows")

    ret = graphscope.wcc(graph)
    graph = graph.add_column(ret, {"cc": "r"})
    assert len(graph.schema.get_vertex_properties("person")) == 1
    assert graph.schema.get_vertex_properties("person")[0].name == "cc"
示例#2
0
def test_add_column(ldbc_graph, arrow_modern_graph):
    ldbc = ldbc_graph
    modern = arrow_modern_graph

    sub_graph_1 = ldbc.project(vertices={"person": []}, edges={"knows": ["eid"]})
    sub_graph_2 = ldbc.project(
        vertices={"person": None, "tag": None}, edges={"hasInterest": None}
    )
    sub_graph_3 = ldbc.project(
        vertices={"tag": None, "tagclass": None}, edges={"hasType": None}
    )
    sub_graph_4 = modern.project(vertices={"person": []}, edges={"knows": ["eid"]})

    ret = graphscope.wcc(sub_graph_1)

    # the ret can add to the graph queried on
    g1 = sub_graph_1.add_column(ret, selector={"cc": "r"})
    assert g1.schema.get_vertex_properties("person")[0].id == 8
    assert g1.schema.get_vertex_properties("person")[0].name == "cc"
    # the ret can add to the origin graph
    g2 = ldbc.add_column(ret, selector={"cc": "r"})
    assert g2.schema.get_vertex_properties("person")[8].id == 8
    assert g2.schema.get_vertex_properties("person")[8].name == "cc"
    # the ret can add to the graph tha contain the same vertex label with sub_graph_1
    g3 = sub_graph_2.add_column(ret, selector={"cc": "r"})
    assert g3.schema.get_vertex_properties("person")[8].id == 8
    assert g3.schema.get_vertex_properties("person")[8].name == "cc"
    # the ret can not add to sub_graph_3
    with pytest.raises(AnalyticalEngineInternalError):
        g4 = sub_graph_3.add_column(ret, selector={"cc": "r"})
        print(g4.schema)
    # the ret can not add to sub_graph_4
    with pytest.raises(AnalyticalEngineInternalError):
        g5 = sub_graph_4.add_column(ret, selector={"cc": "r"})
        print(g4.schema)
示例#3
0
def test_app_on_undirected_graph(
    p2p_project_undirected_graph,
    sssp_result,
    pagerank_result,
    bfs_result,
    wcc_result,
    lpa_result,
    triangles_result,
    kshell_result,
):
    # sssp
    ctx1 = sssp(p2p_project_undirected_graph, src=6)
    r1 = (ctx1.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    r1[r1 == 1.7976931348623157e308] = float(
        "inf")  # replace limit<double>::max with inf
    assert np.allclose(r1, sssp_result["undirected"])
    assert np.allclose(
        ctx1.to_dataframe({
            "node": "v.id",
            "r": "r"
        },
                          vertex_range={
                              "begin": 1,
                              "end": 4
                          }).sort_values(by=["node"]).to_numpy(),
        [[1.0, 31.0], [2.0, 39.0], [3.0, 78.0]],
    )
    assert np.allclose(
        sorted(ctx1.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        })),
        [31.0, 39.0, 78.0],
    )

    # pagerank (only work on undirected graph)
    ctx2 = pagerank(p2p_project_undirected_graph, delta=0.85, max_round=10)
    r2 = (ctx2.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    assert np.allclose(r2, pagerank_result["undirected"])
    ctx3 = pagerank(p2p_project_undirected_graph, 0.85, 10)
    r3 = (ctx3.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    assert np.allclose(r3, pagerank_result["undirected"])
    # r4 = pagerank(arrow_project_graph, 10, 0.85) # check max_round=10
    # assert r4 is not None
    ctx5 = pagerank(p2p_project_undirected_graph, "0.85", "10")
    r5 = (ctx5.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    assert np.allclose(r5, pagerank_result["undirected"])
    ctx6 = pagerank(p2p_project_undirected_graph)
    r6 = (ctx6.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    assert np.allclose(r6, pagerank_result["undirected"])
    assert np.allclose(
        ctx6.to_dataframe({
            "node": "v.id",
            "r": "r"
        },
                          vertex_range={
                              "begin": 1,
                              "end": 4
                          }).sort_values(by=["node"]).to_numpy(),
        [
            [1.0, 6.153724343761569e-05],
            [2.0, 9.280361872165397e-05],
            [3.0, 1.643246086005906e-05],
        ],
    )
    assert np.allclose(
        sorted(ctx6.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        })),
        sorted([
            6.153724343761569e-05, 9.280361872165397e-05, 1.643246086005906e-05
        ]),
    )

    # bfs
    ctx7 = bfs(p2p_project_undirected_graph, src=6)
    r7 = (ctx7.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=int))
    assert np.all(r7 == bfs_result["undirected"])
    assert np.all(
        ctx7.to_dataframe(
            {
                "node": "v.id",
                "r": "r"
            }, vertex_range={
                "begin": 1,
                "end": 4
            }).sort_values(by=["node"]).to_numpy() == [[1, 1], [2, 2], [3, 2]])
    assert np.all(
        sorted(ctx7.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        })) == [1, 2, 2])

    # wcc
    ctx8 = wcc(p2p_project_undirected_graph)
    r8 = (ctx8.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=int))
    assert np.all(r8 == wcc_result)
    assert np.all(
        ctx8.to_dataframe(
            {
                "node": "v.id",
                "r": "r"
            }, vertex_range={
                "begin": 1,
                "end": 4
            }).sort_values(by=["node"]).to_numpy() == [[1, 1], [2, 1], [3, 1]])
    assert np.all(
        ctx8.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        }) == [1, 1, 1])

    # lpa
    ctx9 = lpa(p2p_project_undirected_graph, max_round=10)
    r9 = (ctx9.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=int))
    assert np.all(r9 == lpa_result)
    assert np.all(
        ctx9.to_dataframe(
            {
                "node": "v.id",
                "r": "r"
            }, vertex_range={
                "begin": 1,
                "end": 4
            }).sort_values(by=["node"]).to_numpy() == [[1, 1], [2, 2], [3, 2]])
    assert np.all(
        sorted(ctx9.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        })) == [1, 2, 2])

    # kshell
    ctx10 = k_shell(p2p_project_undirected_graph, k=3)
    r10 = (ctx10.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=int))
    assert np.all(r10 == kshell_result)
    assert np.all(
        ctx10.to_dataframe(
            {
                "node": "v.id",
                "r": "r"
            }, vertex_range={
                "begin": 1,
                "end": 4
            }).sort_values(by=["node"]).to_numpy() == [[1, 0], [2, 0], [3, 0]])
    assert np.all(
        ctx10.to_numpy("r", vertex_range={
            "begin": 1,
            "end": 4
        }) == [0, 0, 0])

    # triangles
    ctx_triangles = triangles(p2p_project_undirected_graph)
    ret_triangles = (ctx_triangles.to_dataframe({
        "node": "v.id",
        "r": "r"
    }).sort_values(by=["node"]).to_numpy(dtype=float))
    assert np.allclose(ret_triangles, triangles_result["undirected"])

    # louvain
    ctx10 = louvain(p2p_project_undirected_graph,
                    min_progress=50,
                    progress_tries=2)

    # simple_path
    assert is_simple_path(p2p_project_undirected_graph, [1, 10])
示例#4
0
def test_graph_lifecycle(graphscope_session):
    graph = load_modern_graph(graphscope_session)
    c = graphscope.wcc(graph)
    del graph
    assert c.to_numpy("v.id") is not None
    del c  # should delete c and graph in c++