def test_complete_nx_to_gs(self):
        # multi-propery, node propery and edge propty both aligned
        nodes = [
            (0, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (1, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
            (2, {"vp1": 1, "vp2": "v", "vp3": 3.14}),
        ]
        edges = [
            (0, 1, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (0, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
            (1, 2, {"ep1": 1, "ep2": "e", "ep3": 3.14}),
        ]
        nx_g = self.NXGraph(dist=True)
        nx_g.update(edges, nodes)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # node property aliged, edge not aliged
        nx_g2 = nx_g.copy()
        nx_g2.add_edge(0, 1, ep4="new propery")
        gs_g2 = g(nx_g2)
        self.assert_convert_success(gs_g2, nx_g2)

        # edge property aliged, node not aliged
        nx_g3 = nx_g.copy()
        nx_g3.add_node(2, vp4="new propery")
        gs_g3 = g(nx_g3)
        self.assert_convert_success(gs_g3, nx_g3)

        # both not aliged
        nx_g4 = nx_g.copy()
        nx_g4.add_edge(0, 1, ep4="new propery")
        nx_g4.add_node(2, vp4="new propery")
        gs_g4 = g(nx_g4)
        self.assert_convert_success(gs_g4, nx_g4)
Beispiel #2
0
    def test_nx_to_gs_after_modify(self):
        nx_g = self.NXGraph()
        nodes = [
            (0, {
                "vp1": 1,
                "vp2": "v",
                "vp3": 3.14
            }),
            (1, {
                "vp1": 1,
                "vp2": "v",
                "vp3": 3.14
            }),
            (2, {
                "vp1": 1,
                "vp2": "v",
                "vp3": 3.14
            }),
        ]
        # add nodes
        nx_g.add_nodes_from(nodes)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # add_edges
        edges = [
            (0, 1, {
                "ep1": 1,
                "ep2": "e",
                "ep3": 3.14
            }),
            (0, 2, {
                "ep1": 1,
                "ep2": "e",
                "ep3": 3.14
            }),
            (1, 2, {
                "ep1": 1,
                "ep2": "e",
                "ep3": 3.14
            }),
        ]
        nx_g.add_edges_from(edges)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # remove edge
        nx_g.remove_edge(0, 1)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # remove node
        nx_g.remove_node(0)
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)

        # clear
        nx_g.clear()
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)
 def test_error_on_view_to_gs(self):
     nx_g = self.NXGraph(dist=True)
     nx_g._graph = None  # graph view always has a _graph attribute
     nx_g._is_client_view = False
     with pytest.raises(TypeError,
                        match="graph view can not convert to gs graph"):
         gs_g = g(nx_g)
    def test_nx_to_gs_remove_nodes(self):
        nx_g = self.NXGraph(dist=True)
        nx_g.add_nodes_from(range(10))  # all nodes are int
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)  # success

        nx_g.add_node("str_node")  # add a str node
        with pytest.raises(
            RuntimeError,
            match="The vertex type is not consistent <class 'int'> vs <class 'str'>, can not convert it to arrow graph",
        ):
            gs_g = g(nx_g)  # mixing oid type, failed

        nx_g.remove_node("str_node")  # remove str node, all nodes are int again
        gs_g = g(nx_g)
        self.assert_convert_success(gs_g, nx_g)  # success
 def test_error_on_mixing_node_nx_to_gs(self):
     nx_g = self.NXGraph(dist=True)
     nx_g.add_node(0, weight=1.23)
     nx_g.add_node("zakky", foo="node")
     with pytest.raises(
         RuntimeError,
         match="The vertex type is not consistent <class 'int'> vs <class 'str'>, can not convert it to arrow graph",
     ):
         gs_g = g(nx_g)
 def test_int_node_nx_to_gs(self):
     nx_g = self.NXGraph(dist=True)
     nx_g.add_nodes_from(range(10), foo="star")
     nx_g.add_edges_from(
         [(0, 1), (1, 2), (2, 3), (3, 4), (4, 5), (5, 6), (6, 7), (7, 8), (8, 9)],
         weight=3.14,
     )
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Beispiel #7
0
    def setup_class(cls):
        cls.NXGraph = nx.Graph

        data_dir = os.path.expandvars("${GS_TEST_DIR}/ldbc_sample")
        cls.single_label_g = ldbc_sample_single_label(data_dir, False)
        cls.multi_label_g = ldbc_sample_multi_labels(data_dir, False)
        cls.duplicated_oid_g = ldbc_sample_with_duplicated_oid(data_dir, False)

        # FIXME: this is tricky way to create a str gs graph
        les_g = nx.les_miserables_graph()
        cls.str_oid_g = g(les_g)
    def test_multiple_sessions(self):
        sess2 = graphscope.session(cluster_type="hosts", num_workers=1)
        nx2 = sess2.nx()
        gs_g = self.single_label_g

        if self.NXGraph is nx.Graph:
            gs_g2 = ldbc_sample_single_label_with_sess(sess2, self.data_dir,
                                                       False)
        else:
            gs_g2 = ldbc_sample_single_label_with_sess(sess2, self.data_dir,
                                                       True)
        assert gs_g.session_id != gs_g2.session_id

        nx_g = self.NXGraph(gs_g, dist=True)
        if nx_g.is_directed():
            nx_g2 = nx2.DiGraph(gs_g2, dist=True)
        else:
            nx_g2 = nx2.Graph(gs_g2, dist=True)
        self.assert_convert_success(gs_g2, nx_g2)
        assert nx_g.session_id == gs_g.session_id
        assert nx_g2.session_id == gs_g2.session_id

        # copies
        cg1 = nx_g2.copy()
        assert cg1.session_id == nx_g2.session_id
        dg1 = nx_g2.to_directed()
        assert dg1.session_id == nx_g2.session_id
        dg2 = nx_g2.to_directed(as_view=True)
        assert dg2.session_id == nx_g2.session_id

        # subgraph
        sg1 = nx_g2.subgraph([274877907301, 274877907299])
        assert sg1.session_id == nx_g2.session_id
        sg2 = nx_g2.edge_subgraph([(274877907301, 274877907299)])
        assert sg2.session_id == nx_g2.session_id

        # error raise if gs graph and nx graph not in the same session.
        with pytest.raises(
                RuntimeError,
                match=
                "graphscope graph and networkx graph not in the same session.",
        ):
            tmp = self.NXGraph(gs_g2)
        with pytest.raises(
                RuntimeError,
                match=
                "networkx graph and graphscope graph not in the same session.",
        ):
            tmp = g(nx_g2)
            print(tmp.session_id, nx_g2.session_id)

        sess2.close()
Beispiel #9
0
 def test_empty_gs_to_nx(self):
     empty_nx = self.NXGraph()
     empty_gs_graph = g(empty_nx)
     nx_g = self.NXGraph(empty_gs_graph)
     self.assert_convert_success(empty_gs_graph, nx_g)
Beispiel #10
0
 def test_str_node_nx_to_gs(self):
     nx_g = nx.les_miserables_graph()
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Beispiel #11
0
 def test_simple_nx_to_gs(self):
     nx_g = nx.complete_graph(10, create_using=self.NXGraph)
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Beispiel #12
0
 def test_only_contains_nodes_nx_to_gs(self):
     nx_g = self.NXGraph()
     nx_g.add_nodes_from(range(100), type="node")
     gs_g = g(nx_g)
     self.assert_convert_success(gs_g, nx_g)
Beispiel #13
0
 def test_empty_nx_to_gs(self):
     empty_nx_g = self.NXGraph()
     gs_g = g(empty_nx_g)
     self.assert_convert_success(gs_g, empty_nx_g)
 def test_empty_gs_to_nx(self):
     empty_nx = self.NXGraph(dist=True)
     empty_gs_graph = g(empty_nx)
     G = self.NXGraph(empty_gs_graph)
     self.assert_convert_success(empty_gs_graph, G)