コード例 #1
0
ファイル: graph.py プロジェクト: siyuan0322/GraphScope
 def _construct_op_of_empty_graph(self):
     config = {}
     config[types_pb2.ARROW_PROPERTY_DEFINITION] = attr_value_pb2.AttrValue()
     config[types_pb2.DIRECTED] = utils.b_to_attr(self._directed)
     config[types_pb2.GENERATE_EID] = utils.b_to_attr(self._generate_eid)
     config[types_pb2.OID_TYPE] = utils.s_to_attr(self._oid_type)
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(False)
     return dag_utils.create_graph(
         self.session_id, graph_def_pb2.ARROW_PROPERTY, inputs=None, attrs=config
     )
コード例 #2
0
ファイル: graph.py プロジェクト: MrAladdin/GraphScope
 def _from_vineyard_name(self, vineyard_name):
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(True)
     config[types_pb2.VINEYARD_NAME] = utils.s_to_attr(str(vineyard_name))
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = utils.s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     return dag_utils.create_graph(self.session_id,
                                   types_pb2.ARROW_PROPERTY,
                                   attrs=config)
コード例 #3
0
ファイル: graph.py プロジェクト: zjureel/GraphScope-1
 def _from_vineyard_id(self, vineyard_id):
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = b_to_attr(True)
     config[types_pb2.VINEYARD_ID] = i_to_attr(vineyard_id)
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = s_to_attr("uint64_t")
     op = create_graph(self._session_id, types_pb2.ARROW_PROPERTY, attrs=config)
     graph_def = op.eval()
     return graph_def
コード例 #4
0
ファイル: graph.py プロジェクト: siyuan0322/GraphScope
 def _construct_op_from_vineyard_id(self, vineyard_id):
     assert self._session is not None
     config = {}
     config[types_pb2.IS_FROM_VINEYARD_ID] = utils.b_to_attr(True)
     config[types_pb2.VINEYARD_ID] = utils.i_to_attr(int(vineyard_id))
     # FIXME(hetao) hardcode oid/vid type for codegen, when loading from vineyard
     #
     # the metadata should be retrived from vineyard
     config[types_pb2.OID_TYPE] = utils.s_to_attr("int64_t")
     config[types_pb2.VID_TYPE] = utils.s_to_attr("uint64_t")
     return dag_utils.create_graph(
         self.session_id, graph_def_pb2.ARROW_PROPERTY, attrs=config
     )
コード例 #5
0
ファイル: misc.py プロジェクト: lidongze0629/GraphScope
def init_empty_graph_in_engine(graph, directed, distributed=True):
    """initialize an empty graph in grape_engine with the graph metadata.

    Parameters:
    -----------
    graph: the graph instance in python.
    graph_type: the graph type of graph (IMMUTABLE, ARROW, DYNAMIC).

    """
    op = dag_utils.create_graph(
        graph.session.session_id,
        graph_type=graph._graph_type,
        directed=directed,
        distributed=distributed,
        efile="",
        vfile="",
    )
    graph._op = op
    graph_def = op.eval(leaf=False)
    return graph_def
コード例 #6
0
def empty_graph_in_engine(graph, directed):
    """create empty graph in grape_engine with the graph metadata.

    Parameters:
    -----------
    graph: the graph instance in python.
    graph_type: the graph type of graph (IMMUTABLE, ARROW, DYNAMIC).
    nx_graph_type: the networkx graph type of graph (Graph, DiGraph, MultiGraph, MultiDiGraph).

    """
    sess = get_session_by_handle(graph._session_id)
    op = dag_utils.create_graph(
        sess.session_id,
        graph_type=graph._graph_type,
        directed=directed,
        efile="",
        vfile="",
    )
    graph_def = sess.run(op)
    return graph_def
コード例 #7
0
ファイル: graph.py プロジェクト: MrAladdin/GraphScope
    def _construct_graph(self,
                         vertices,
                         edges,
                         v_labels,
                         e_labels,
                         e_relations,
                         mutation_func=None):
        """Construct graph.
           1. Construct a graph from scratch.
              If the vertices and edges is empty, return a empty graph.
           2. Construct a graph from existed builded graph.
              If the vertices and edges is empty, return a copied graph.

        Args:
            vertices ([type]): [description]
            edges ([type]): [description]
            v_labels ([type]): [description]
            e_labels ([type]): [description]
            e_relations ([type]): [description]
            mutation_func ([type], optional): [description]. Defaults to None.

        Returns:
            [type]: [description]
        """
        config = graph_utils.assemble_op_config(
            vertices.values(),
            edges.values(),
            self._oid_type,
            self._directed,
            self._generate_eid,
        )

        # edge case.
        if not vertices and not edges:
            if mutation_func:
                # Rely on `self._key`
                return Graph(self._session, self)
            else:
                return Graph(
                    self._session,
                    None,
                    self._oid_type,
                    self._directed,
                    self._generate_eid,
                )
        if mutation_func:
            op = mutation_func(self, attrs=config)
        else:
            op = dag_utils.create_graph(self.session_id,
                                        types_pb2.ARROW_PROPERTY,
                                        attrs=config)

        graph = Graph(self._session, op, self._oid_type, self._directed,
                      self._generate_eid)
        graph._unsealed_vertices = vertices
        graph._unsealed_edges = edges
        graph._v_labels = v_labels
        graph._e_labels = e_labels
        graph._e_relationships = e_relations
        # propage info about whether is a loaded graph.
        # graph._key = self._key
        if mutation_func:
            graph._base_graph = self._base_graph or self
        return graph
コード例 #8
0
ファイル: graph_utils.py プロジェクト: edgar87/GraphScope
def load_from(
    edges: Union[Mapping[str, Union[LoaderVariants, Sequence, Mapping]],
                 LoaderVariants, Sequence],
    vertices: Union[Mapping[str, Union[LoaderVariants, Sequence, Mapping]],
                    LoaderVariants, Sequence, None, ] = None,
    directed=True,
    oid_type="int64_t",
    generate_eid=True,
) -> Graph:
    """Load a Arrow property graph using a list of vertex/edge specifications.

    - Use Dict of tuples to setup a graph.
        We can use a dict to set vertex and edge configurations,
        which can be used to build graphs.

        Examples:

        .. code:: ipython

            g = graphscope_session.load_from(
                edges={
                    "group": [
                        (
                            "file:///home/admin/group.e",
                            ["group_id", "member_size"],
                            ("leader_student_id", "student"),
                            ("member_student_id", "student"),
                        ),
                        (
                            "file:///home/admin/group_for_teacher_student.e",
                            ["group_id", "group_name", "establish_date"],
                            ("teacher_in_charge_id", "teacher"),
                            ("member_student_id", "student"),
                        ),
                    ]
                },
                vertices={
                    "student": (
                        "file:///home/admin/student.v",
                        ["name", "lesson_nums", "avg_score"],
                        "student_id",
                    ),
                    "teacher": (
                        "file:///home/admin/teacher.v",
                        ["name", "salary", "age"],
                        "teacher_id",
                    ),
                },
            )

        'e' is the label of edges, and 'v' is the label for vertices, edges are stored in the 'both_in_out' format
        edges with label 'e' linking from 'v' to 'v'.

    - Use Dict of dict to setup a graph.
        We can also give each element inside the tuple a meaningful name,
        makes it more understandable.

        Examples:

        .. code:: ipython

            g = graphscope_session.load_from(
                edges={
                    "group": [
                        {
                            "loader": "file:///home/admin/group.e",
                            "properties": ["group_id", "member_size"],
                            "source": ("leader_student_id", "student"),
                            "destination": ("member_student_id", "student"),
                        },
                        {
                            "loader": "file:///home/admin/group_for_teacher_student.e",
                            "properties": ["group_id", "group_name", "establish_date"],
                            "source": ("teacher_in_charge_id", "teacher"),
                            "destination": ("member_student_id", "student"),
                        },
                    ]
                },
                vertices={
                    "student": {
                        "loader": "file:///home/admin/student.v",
                        "properties": ["name", "lesson_nums", "avg_score"],
                        "vid": "student_id",
                    },
                    "teacher": {
                        "loader": "file:///home/admin/teacher.v",
                        "properties": ["name", "salary", "age"],
                        "vid": "teacher_id",
                    },
                },
            )

    Args:
        edges: Edge configuration of the graph
        vertices (optional): Vertices configurations of the graph. Defaults to None.
            If None, we assume all edge's src_label and dst_label are deduced and unambiguous.
        directed (bool, optional): Indicate whether the graph
            should be treated as directed or undirected.
        oid_type (str, optional): ID type of graph. Can be "int64_t" or "string". Defaults to "int64_t".
        generate_eid (bool, optional): Whether to generate a unique edge id for each edge. Generated eid will be placed
            in third column. This feature is for cooperating with interactive engine.
            If you only need to work with analytical engine, set it to False. Defaults to False.
    """

    # Don't import the :code:`nx` in top-level statments to improve the
    # performance of :code:`import graphscope`.
    from graphscope.experimental import nx

    sess = get_default_session()
    if sess is None:
        raise ValueError("No default session found.")
    if isinstance(edges, (Graph, nx.Graph, *VineyardObjectTypes)):
        return Graph(sess.session_id, edges)
    oid_type = utils.normalize_data_type_str(oid_type)
    e_labels = normalize_parameter_edges(edges)
    v_labels = normalize_parameter_vertices(vertices)
    e_labels, v_labels = _sanity_check(e_labels, v_labels)
    config = _get_config(e_labels, v_labels, directed, oid_type, generate_eid)
    op = dag_utils.create_graph(sess.session_id,
                                types_pb2.ARROW_PROPERTY,
                                attrs=config)
    graph_def = sess.run(op)
    graph = Graph(sess.session_id, graph_def)
    return graph
コード例 #9
0
def load_from(
    edges: Union[Mapping[str, Union[LoaderVariants, Sequence, Mapping]],
                 LoaderVariants, Sequence],
    vertices: Union[Mapping[str, Union[LoaderVariants, Sequence, Mapping]],
                    LoaderVariants, Sequence, None, ] = None,
    directed=True,
    oid_type="int64_t",
    generate_eid=True,
    vformat=None,
    eformat=None,
) -> Graph:
    """Load a Arrow property graph using a list of vertex/edge specifications.

    .. deprecated:: version 0.3
       Use :class:`graphscope.Graph()` instead.

    - Use Dict of tuples to setup a graph.
        We can use a dict to set vertex and edge configurations,
        which can be used to build graphs.

        Examples:

        .. code:: ipython

            g = graphscope_session.load_from(
                edges={
                    "group": [
                        (
                            "file:///home/admin/group.e",
                            ["group_id", "member_size"],
                            ("leader_student_id", "student"),
                            ("member_student_id", "student"),
                        ),
                        (
                            "file:///home/admin/group_for_teacher_student.e",
                            ["group_id", "group_name", "establish_date"],
                            ("teacher_in_charge_id", "teacher"),
                            ("member_student_id", "student"),
                        ),
                    ]
                },
                vertices={
                    "student": (
                        "file:///home/admin/student.v",
                        ["name", "lesson_nums", "avg_score"],
                        "student_id",
                    ),
                    "teacher": (
                        "file:///home/admin/teacher.v",
                        ["name", "salary", "age"],
                        "teacher_id",
                    ),
                },
            )

        'e' is the label of edges, and 'v' is the label for vertices, edges are stored in the 'both_in_out' format
        edges with label 'e' linking from 'v' to 'v'.

    - Use Dict of dict to setup a graph.
        We can also give each element inside the tuple a meaningful name,
        makes it more understandable.

        Examples:

        .. code:: ipython

            g = graphscope_session.load_from(
                edges={
                    "group": [
                        {
                            "loader": "file:///home/admin/group.e",
                            "properties": ["group_id", "member_size"],
                            "source": ("leader_student_id", "student"),
                            "destination": ("member_student_id", "student"),
                        },
                        {
                            "loader": "file:///home/admin/group_for_teacher_student.e",
                            "properties": ["group_id", "group_name", "establish_date"],
                            "source": ("teacher_in_charge_id", "teacher"),
                            "destination": ("member_student_id", "student"),
                        },
                    ]
                },
                vertices={
                    "student": {
                        "loader": "file:///home/admin/student.v",
                        "properties": ["name", "lesson_nums", "avg_score"],
                        "vid": "student_id",
                    },
                    "teacher": {
                        "loader": "file:///home/admin/teacher.v",
                        "properties": ["name", "salary", "age"],
                        "vid": "teacher_id",
                    },
                },
            )

    Args:
        edges: Edge configuration of the graph
        vertices (optional): Vertices configurations of the graph. Defaults to None.
            If None, we assume all edge's src_label and dst_label are deduced and unambiguous.
        directed (bool, optional): Indicate whether the graph
            should be treated as directed or undirected.
        oid_type (str, optional): ID type of graph. Can be "int64_t" or "string". Defaults to "int64_t".
        generate_eid (bool, optional): Whether to generate a unique edge id for each edge. Generated eid will be placed
            in third column. This feature is for cooperating with interactive engine.
            If you only need to work with analytical engine, set it to False. Defaults to False.
    """

    # Don't import the :code:`nx` in top-level statments to improve the
    # performance of :code:`import graphscope`.
    from graphscope import nx

    sess = get_default_session()
    if isinstance(edges, (Graph, nx.Graph, *VineyardObjectTypes)):
        return sess.g(edges)
    oid_type = utils.normalize_data_type_str(oid_type)
    if oid_type not in ("int64_t", "std::string"):
        raise ValueError("oid_type can only be int64_t or string.")
    v_labels = normalize_parameter_vertices(vertices, oid_type, vformat)
    e_labels = normalize_parameter_edges(edges, oid_type, eformat)
    # generate and add a loader op to dag
    loader_op = dag_utils.create_loader(v_labels + e_labels)
    sess.dag.add_op(loader_op)
    # construct create graph op
    config = {
        types_pb2.DIRECTED: utils.b_to_attr(directed),
        types_pb2.OID_TYPE: utils.s_to_attr(oid_type),
        types_pb2.GENERATE_EID: utils.b_to_attr(generate_eid),
        types_pb2.VID_TYPE: utils.s_to_attr("uint64_t"),
        types_pb2.IS_FROM_VINEYARD_ID: utils.b_to_attr(False),
    }
    op = dag_utils.create_graph(sess.session_id,
                                graph_def_pb2.ARROW_PROPERTY,
                                inputs=[loader_op],
                                attrs=config)
    graph = sess.g(op)
    return graph