Esempio n. 1
0
def test_border_cases():
    s1 = graphscope.session(cluster_type="hosts")
    s2 = graphscope.session(cluster_type="hosts")
    s3 = graphscope.session(cluster_type="hosts")

    s1.as_default()
    assert graphscope.get_default_session() == s1

    g3 = load_p2p_network(s3)
    pg3 = g3.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})

    with pytest.raises(
            ValueError,
            match=
            "A default session is already active. You must explicitly call Session.close().",
    ):
        s2.as_default()

    s1.close()

    s2.as_default()
    assert graphscope.get_default_session() == s2
    s2.close()

    s3.as_default()
    assert graphscope.get_default_session() == s3
    sssp = graphscope.sssp(pg3, src=4)  # ok, g3 belong to s3
    s3.close()
Esempio n. 2
0
def test_graph_to_dataframe(sess):
    g = load_p2p_network(sess)
    pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    c = graphscope.sssp(pg, 20)
    ctx_out_df = c.to_dataframe({"result": "r"})
    g2 = g.add_column(c, {"result_0": "r"})
    graph_out_df = g2.to_dataframe({"result": "v:host.result_0"})
    r = sess.run([ctx_out_df, graph_out_df])
    assert r[0].equals(r[1])
Esempio n. 3
0
def test_graph_to_numpy(sess):
    g = load_p2p_network(sess)
    pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    c = graphscope.sssp(pg, 20)
    ctx_out_np = c.to_numpy("r")
    g2 = g.add_column(c, {"result_0": "r"})
    graph_out_np = g2.to_numpy("v:host.result_0")
    r = sess.run([ctx_out_np, graph_out_np])
    assert np.all(r[0] == r[1])
Esempio n. 4
0
def test_error_selector_context(sess):
    # vertex data context
    g = load_p2p_network(sess)
    pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    c = graphscope.sssp(pg, 20)
    with pytest.raises(SyntaxError, match="Invalid selector"):
        r = c.to_dataframe({"id": "v.ID"})
    with pytest.raises(ValueError, match="selector of to_dataframe must be a dict"):
        r = c.to_dataframe("id")
Esempio n. 5
0
def test_add_column(sess):
    g = load_p2p_network(sess)
    pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    c = graphscope.sssp(pg, 20)
    g1 = g.add_column(c, {
        "id_col": "v.id",
        "data_col": "v.data",
        "result_col": "r"
    })
    sess.run(g1)
Esempio n. 6
0
def test_simulate_eager(sess):
    g1_node = load_p2p_network(sess)
    g1 = sess.run(g1_node)
    pg_node = g1.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    pg = sess.run(pg_node)
    c_node = graphscope.sssp(pg, 20)
    c = sess.run(c_node)
    g2_node = g1.add_column(
        c, {"id_col": "v.id", "data_col": "v.data", "result_col": "r"}
    )
    g2 = sess.run(g2_node)
Esempio n. 7
0
def test_context(sess):
    g = load_p2p_network(sess)
    pg = g.project(vertices={"host": ["id"]}, edges={"connect": ["dist"]})
    c = graphscope.sssp(pg, 20)
    r1 = c.to_numpy("r")
    r2 = c.to_dataframe({"id": "v.id", "result": "r"})
    r3 = c.to_vineyard_tensor("r")
    r4 = c.to_vineyard_dataframe({"id": "v.id", "data": "v.data", "result": "r"})
    r = sess.run([r1, r2, r3, r4])
    assert r[0].shape == (62586,)
    assert r[1].shape == (62586, 2)
    assert r[2] is not None
    assert r[3] is not None
Esempio n. 8
0
def test_unload(graphscope_session):
    g = load_p2p_network(graphscope_session)
    assert g.loaded()
    assert g.vineyard_id is not None
    g.unload()

    assert not g.loaded()

    # unload twice
    g.unload()

    with pytest.raises(RuntimeError, match="The graph is not loaded"):
        pg = g.project(vertices={"host": []}, edges={"connect": []})
        pg._project_to_simple()
    with pytest.raises(AssertionError):
        g2 = graphscope_session.g(g)
Esempio n. 9
0
def run_app(
    vdataType: str,
    edataType: str,
    app_type: str,
    directed: bool,
    jar_path: str,
    java_app_class: str,
    param_str,
):
    sess = graphscope.session(cluster_type="hosts", num_workers=1)
    graph = sess.g(directed=directed)
    graph = load_p2p_network(sess)

    if "simple" in app_type:
        graph = graph.project(vertices={"host": ['id']},
                              edges={"connect": ["dist"]})
    app = JavaApp(full_jar_path=jar_path, java_app_class=java_app_class)
    exec("ctx=app(graph, {})".format(param_str))
    logger.info("Successfully verify app: {}".format(java_app_class))
Esempio n. 10
0
def test_unload(graphscope_session):
    g = load_p2p_network(graphscope_session)
    assert g.loaded()
    assert g.vineyard_id is not None
    del g