MCPcopy Create free account
hub / github.com/alibaba/graph-learn / __init__

Method __init__

graphlearn/python/sampler/node_sampler.py:29–83  ·  view source on GitHub ↗

Create a Base NodeSampler.. Args: graph (`Graph` object): The graph which sample from. t (string): type of node or egde. If t is a type of node, then `NodeSampler` will sample from node source. Else if `t` is a type of edge, then `node_from=EDGE_SRC` indicates that

(self,
               graph,
               t,
               batch_size,
               strategy="by_order",
               node_from=pywrap.NodeFrom.NODE,
               mask=utils.Mask.NONE)

Source from the content-addressed store, hash-verified

27 """
28
29 def __init__(self,
30 graph,
31 t,
32 batch_size,
33 strategy="by_order",
34 node_from=pywrap.NodeFrom.NODE,
35 mask=utils.Mask.NONE):
36 """ Create a Base NodeSampler..
37
38 Args:
39 graph (`Graph` object): The graph which sample from.
40 t (string): type of node or egde. If t is a type of node, then
41 `NodeSampler` will sample from node source. Else if `t` is a type
42 of edge, then `node_from=EDGE_SRC` indicates that the nodes will
43 be sampled from edges's source nodes, `node_from=EDGE_DST`
44 indicates that the nodes will be sampled from edges's dst nodes.
45 batch_size (int): How many nodes will be returned for `get()`.
46 strategy (string, Optional): Sampling strategy. "by_order", "random"
47 and "shuffle" are supported.
48 "by_order": get nodes by the order of how the specified node is stored,
49 if all the specified type of nodes are visited,
50 `graphlearn.OutOfRangeError` will be raised.
51 NodeSamplers that process the same node will share the same state.
52 "random": randomly visit nodes, no state will be kept.
53 "shuffle": visit the nodes with shuffling, if all the specified type of
54 nodes are visited, `graphlearn.OutOfRangeError` will be raised.
55 NodeSamplers that process the same node will share the same state.
56 node_from (graphlearn.NODE | graphlearn.EDGE_SRC | graphlearn.EDGE_DST):
57 `graphlearn.NODE`: get node from node data, and `t` must be a node type.
58 `graphlearn.EDGE_SRC`: get node from source node of edge data, and `t`
59 must be an edge type.
60 `graphlearn.EDGE_DST`: get node from destination node of edge data, and
61 `t` must be an edge type.
62 """
63 self._graph = graph
64 self._type = t
65 self._batch_size = batch_size
66 self._strategy = strategy
67 self._client = self._graph.get_client()
68 self._node_from = node_from
69 self._mask = mask
70
71 if self._node_from == pywrap.NodeFrom.NODE:
72 if self._type not in self._graph.get_node_decoders().keys():
73 raise ValueError('Graph has no node type of {}'.format(self._type))
74 self._node_type = self._type
75 else:
76 topology = self._graph.get_topology()
77 src_type = topology.get_src_type(self._type)
78 dst_type = topology.get_dst_type(self._type)
79 self._src_type, self._dst_type = src_type, dst_type
80 if self._node_from == pywrap.NodeFrom.EDGE_SRC:
81 self._node_type = src_type
82 else:
83 self._node_type = dst_type
84
85 def get(self):
86 """ Get batched sampled nodes.

Callers

nothing calls this directly

Calls 6

get_clientMethod · 0.80
get_node_decodersMethod · 0.80
get_topologyMethod · 0.80
get_src_typeMethod · 0.80
get_dst_typeMethod · 0.80
keysMethod · 0.45

Tested by

no test coverage detected