Example #1
0
  def test_1hop_with_neighbor_missing(self):
    """ Test case for sample 1 hop neighbor with strategy of edge_weight.
    Some of src_ids have no neighbor.
    """
    expand_factor = 6
    ids = self._seed_node1_ids_with_nbr_missing
    nbr_s = self.g.neighbor_sampler(self._edge1_type,
                                    expand_factor=expand_factor,
                                    strategy="edge_weight")
    nbrs = nbr_s.get(ids)
    edges = nbrs.layer_edges(1)
    nodes = nbrs.layer_nodes(1)

    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids,
                                   default_dst_id=self._default_dst_id)
    utils.check_edge_type(edges,
                          src_type=self._node1_type,
                          dst_type=self._node2_type,
                          edge_type=self._edge1_type)
    utils.check_edge_shape(edges, ids.size * expand_factor)
    utils.check_not_exist_edge_attrs(
        edges, default_int_attr=self._default_int_attr,
        default_float_attr=self._default_float_attr,
        default_string_attr=self._default_string_attr,)
    utils.check_not_exist_edge_labels(edges)

    utils.check_equal(nodes.ids, edges.dst_ids)
    utils.check_node_ids(nodes, [self._default_dst_id])
    utils.check_node_type(nodes, node_type=self._node2_type)
    utils.check_node_shape(nodes, ids.size * expand_factor)
    utils.check_not_exist_node_weights(nodes)
    utils.check_not_exist_node_labels(nodes)
    def test_1hop_using_gsl(self):
        """ Using gsl api.
    """
        gl.set_eager_mode(True)
        expand_factor = 6
        ids = self._seed_node1_ids
        nbrs = self.g.V(self._node1_type, feed=ids) \
          .outE(self._edge1_type).sample(expand_factor).by("in_degree") \
          .inV().emit()

        edges = nbrs[1]
        nodes = nbrs[2]

        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node2_range,
                                       expected_src_ids=ids)
        utils.check_edge_type(edges,
                              src_type=self._node1_type,
                              dst_type=self._node2_type,
                              edge_type=self._edge1_type)
        utils.check_edge_shape(edges, ids.size * expand_factor)
        utils.check_edge_attrs(edges)
        utils.check_edge_labels(edges)

        utils.check_equal(nodes.ids, edges.dst_ids)
        utils.check_node_ids(nodes, self._node2_ids)
        utils.check_node_type(nodes, node_type=self._node2_type)
        utils.check_node_shape(nodes, ids.size * expand_factor)
        utils.check_node_weights(nodes)
        utils.check_node_labels(nodes)
Example #3
0
  def test_1hop(self):
    """ Test case for sample 1 hop neighbor with strategy of edge_weight.
    All the src_ids have neighbors.
    """
    expand_factor = 6
    ids = self._seed_node1_ids
    nbr_s = self.g.neighbor_sampler(self._edge1_type,
                                    expand_factor=expand_factor,
                                    strategy="edge_weight")
    nbrs = nbr_s.get(ids)
    edges = nbrs.layer_edges(1)
    nodes = nbrs.layer_nodes(1)

    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids)
    utils.check_edge_type(edges,
                          src_type=self._node1_type,
                          dst_type=self._node2_type,
                          edge_type=self._edge1_type)
    utils.check_edge_shape(edges, ids.size * expand_factor)
    utils.check_edge_attrs(edges)
    utils.check_edge_labels(edges)

    utils.check_equal(nodes.ids, edges.dst_ids)
    utils.check_node_ids(nodes, self._node2_ids)
    utils.check_node_type(nodes, node_type=self._node2_type)
    utils.check_node_shape(nodes, ids.size * expand_factor)
    utils.check_node_weights(nodes)
    utils.check_node_labels(nodes)
  def test_1hop_using_gsl(self):
    """ Test case for sample 1 hop neighbor.
    hetegerous graph with edge attrs, without edge weight.
    """
    gl.set_eager_mode(True)
    expand_factor = 6
    ids = self._seed_node1_ids
    nbrs = self.g.V(self._node1_type, feed=ids) \
      .outE(self._edge1_type).sample(expand_factor).by("edge_weight") \
      .inV().emit()

    edges = nbrs[1]
    nodes = nbrs[2]

    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids)
    utils.check_edge_type(edges,
                          src_type=self._node1_type,
                          dst_type=self._node2_type,
                          edge_type=self._edge1_type)
    utils.check_edge_shape(edges, ids.size * expand_factor)
    utils.check_edge_attrs(edges)
    utils.check_edge_labels(edges)

    utils.check_equal(nodes.ids, edges.dst_ids)
    utils.check_node_ids(nodes, self._node2_ids)
    utils.check_node_type(nodes, node_type=self._node2_type)
    utils.check_node_shape(nodes, ids.size * expand_factor)
    utils.check_node_weights(nodes)
    utils.check_node_labels(nodes)
Example #5
0
  def test_1hop(self):
    """ Sample one hop of neighbors.
    """
    expand_factor = 6
    ids = self._seed_node1_ids
    nbr_s = self.g.neighbor_sampler(self._edge1_type,
                                    expand_factor=expand_factor,
                                    strategy="random")
    nbrs = nbr_s.get(ids)
    edges = nbrs.layer_edges(1)
    nodes = nbrs.layer_nodes(1)

    print(edges.src_nodes.get_out_degrees(self._edge1_type))

    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids)
    utils.check_edge_type(edges,
                          src_type=self._node1_type,
                          dst_type=self._node2_type,
                          edge_type=self._edge1_type)
    utils.check_edge_shape(edges, ids.size * expand_factor)
    utils.check_edge_attrs(edges)
    utils.check_edge_labels(edges)

    utils.check_equal(nodes.ids, edges.dst_ids)
    utils.check_node_ids(nodes, self._node2_ids)
    utils.check_node_type(nodes, node_type=self._node2_type)
    utils.check_node_shape(nodes, ids.size * expand_factor)
    utils.check_node_weights(nodes)
    utils.check_node_labels(nodes)
    def test_2hop_using_gsl_with_undirected_edge(self):
        """ Using gsl api and sample neighbor on undirected edges
    whose source node and dst node has defferent type.
    """
        gl.set_eager_mode(True)
        expand_factor = [3, 2]
        ids = self._seed_node1_ids
        nbrs = self.g.V(self._node1_type, feed=ids) \
          .outE(self._edge1_type).sample(expand_factor[0]).by("random") \
          .inV() \
          .inE(self._edge1_type).sample(expand_factor[1]).by("random") \
          .inV().emit()

        edges1 = nbrs[1]
        nodes1 = nbrs[2]
        edges2 = nbrs[3]
        nodes2 = nbrs[4]

        utils.check_fixed_edge_dst_ids(edges1,
                                       dst_range=self._node2_range,
                                       expected_src_ids=ids)

        utils.check_edge_type(edges1, self._node1_type, self._node2_type,
                              self._edge1_type)
        utils.check_edge_type(edges2, self._node2_type, self._node1_type,
                              self._edge1_type + "_reverse")
        utils.check_node_type(nodes1, self._node2_type)
        utils.check_node_type(nodes2, self._node1_type)
        utils.check_node_ids(nodes2, self._node1_ids)
Example #7
0
  def test_1hop_with_neighbor_missing(self):
    """ Sample neighbors for nodes which have no out neighbors,
    and get the default neighbor id.
    """
    expand_factor = 6
    ids = self._seed_node1_ids_with_nbr_missing
    nbr_s = self.g.neighbor_sampler(self._edge1_type,
                                    expand_factor=expand_factor,
                                    strategy="in_degree")
    nbrs = nbr_s.get(ids)
    edges = nbrs.layer_edges(1)
    nodes = nbrs.layer_nodes(1)

    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids,
                                   default_dst_id=self._default_dst_id)
    utils.check_edge_type(edges,
                          src_type=self._node1_type,
                          dst_type=self._node2_type,
                          edge_type=self._edge1_type)
    utils.check_edge_shape(edges, ids.size * expand_factor)
    utils.check_not_exist_edge_attrs(
        edges, default_int_attr=self._default_int_attr,
        default_float_attr=self._default_float_attr,
        default_string_attr=self._default_string_attr,)
    utils.check_not_exist_edge_labels(edges)

    utils.check_equal(nodes.ids, edges.dst_ids)
    utils.check_node_ids(nodes, [self._default_dst_id])
    utils.check_node_type(nodes, node_type=self._node2_type)
    utils.check_node_shape(nodes, ids.size * expand_factor)
    utils.check_not_exist_node_weights(nodes)
    utils.check_not_exist_node_labels(nodes)
    def test_2hop(self):
        """ Sample 2 hops of neighbors.
    """
        gl.set_eager_mode(True)
        expand_factor = [3, 2]
        ids = self._seed_node1_ids
        nbr_s = self.g.neighbor_sampler([self._edge1_type, self._edge2_type],
                                        expand_factor=expand_factor,
                                        strategy="in_degree")
        nbrs = nbr_s.get(ids)
        edges = nbrs.layer_edges(1)
        nodes = nbrs.layer_nodes(1)

        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node2_range,
                                       expected_src_ids=ids)
        utils.check_edge_type(edges,
                              src_type=self._node1_type,
                              dst_type=self._node2_type,
                              edge_type=self._edge1_type)
        utils.check_edge_shape(edges, ids.size * expand_factor[0])
        utils.check_edge_attrs(edges)
        utils.check_edge_labels(edges)

        utils.check_equal(nodes.ids, edges.dst_ids)
        utils.check_node_ids(nodes, self._node2_ids)
        utils.check_node_type(nodes, node_type=self._node2_type)
        utils.check_node_shape(nodes, ids.size * expand_factor[0])
        utils.check_node_weights(nodes)
        utils.check_node_labels(nodes)

        ids = nodes.ids.reshape(-1)
        edges = nbrs.layer_edges(2)
        nodes = nbrs.layer_nodes(2)

        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node1_range,
                                       expected_src_ids=ids)
        utils.check_edge_type(edges,
                              src_type=self._node2_type,
                              dst_type=self._node1_type,
                              edge_type=self._edge2_type)
        utils.check_edge_shape(edges, ids.size * expand_factor[1])
        utils.check_edge_attrs(edges)
        utils.check_edge_weights(edges)

        utils.check_equal(nodes.ids, edges.dst_ids)
        utils.check_node_ids(nodes, self._node1_ids)
        utils.check_node_type(nodes, node_type=self._node1_type)
        utils.check_node_shape(nodes, ids.size * expand_factor[1])
    def test_1hop_with_neighbor_missing(self):
        """ Sample neighbors for nodes which have no out neighbors,
    and get the default neighbor id.
    """
        gl.set_padding_mode(gl.REPLICATE)
        expand_factor = 6
        ids = self._seed_node1_ids_with_nbr_missing
        nbr_s = self.g.neighbor_sampler(self._edge1_type,
                                        expand_factor=expand_factor,
                                        strategy="random_without_replacement")
        nbrs = nbr_s.get(ids)
        edges = nbrs.layer_edges(1)
        nodes = nbrs.layer_nodes(1)

        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node2_range,
                                       expected_src_ids=ids,
                                       default_dst_id=self._default_dst_id)
  def test_2hop_using_gremlin(self):
    """ Using gremlin-like api.
    """
    expand_factor = [3, 2]
    ids = self._seed_node1_ids
    nbrs = self.g.V(self._node1_type, feed=ids) \
      .outE(self._edge1_type).sample(expand_factor[0]).by("random") \
      .inV() \
      .outE(self._edge2_type).sample(expand_factor[1]).by("random") \
      .inV().emit()

    edges = nbrs[1]
    nodes = nbrs[2]
    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids)

    ids = nodes.ids.reshape(-1)
    edges = nbrs[3]
    nodes = nbrs[4]
    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node1_range,
                                   expected_src_ids=ids)
  def test_2hop_using_gsl(self):
    """ Test case for sample 2 hop neighbor with strategy of edge_weight.
    """
    gl.set_eager_mode(True)
    expand_factor = [3, 2]
    ids = self._seed_node1_ids
    nbrs = self.g.V(self._node1_type, feed=ids) \
      .outE(self._edge1_type).sample(expand_factor[0]).by("edge_weight") \
      .inV() \
      .outE(self._edge2_type).sample(expand_factor[1]).by("edge_weight") \
      .inV().emit()

    edges = nbrs[1]
    nodes = nbrs[2]
    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node2_range,
                                   expected_src_ids=ids)

    ids = nodes.ids.reshape(-1)
    edges = nbrs[3]
    nodes = nbrs[4]
    utils.check_fixed_edge_dst_ids(edges, dst_range=self._node1_range,
                                   expected_src_ids=ids)
    def test_2hop_using_gsl(self):
        """ Using gsl api.
    """
        gl.set_eager_mode(True)
        expand_factor = [3, 2]
        ids = self._seed_node1_ids
        nbrs = self.g.V(self._node1_type, feed=ids) \
          .outE(self._edge1_type).sample(expand_factor[0]).by("in_degree") \
          .inV() \
          .outE(self._edge2_type).sample(expand_factor[1]).by("in_degree") \
          .inV().emit()

        edges = nbrs[1]
        nodes = nbrs[2]
        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node2_range,
                                       expected_src_ids=ids)

        ids = nodes.ids.reshape(-1)
        edges = nbrs[3]
        nodes = nbrs[4]
        utils.check_fixed_edge_dst_ids(edges,
                                       dst_range=self._node1_range,
                                       expected_src_ids=ids)