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

Method get

graphlearn/python/sampler/subgraph_sampler.py:56–90  ·  view source on GitHub ↗

Get sampled `SubGraph`. Return: An `SubGraph` object. Raise: `graphlearn.OutOfRangeError`

(self)

Source from the content-addressed store, hash-verified

54 self._node_type = topology.get_src_type(self._nbr_type)
55
56 def get(self):
57 """ Get sampled `SubGraph`.
58
59 Return:
60 An `SubGraph` object.
61 Raise:
62 `graphlearn.OutOfRangeError`
63 """
64 state = self._graph.node_state.get(self._seed_type)
65 req = pywrap.new_subgraph_request(
66 self._seed_type,
67 self._nbr_type,
68 strategy2op(self._strategy, "SubGraphSampler"),
69 self._batch_size,
70 state)
71 res = pywrap.new_subgraph_response()
72
73 status = self._client.sample_subgraph(req, res)
74 if status.ok():
75 node_ids = pywrap.get_node_set(res)
76 row_idx = pywrap.get_row_idx(res)
77 col_idx = pywrap.get_col_idx(res)
78 edge_ids = pywrap.get_edge_set(res)
79 else:
80 if status.code() == errors.OUT_OF_RANGE:
81 if self._client.connect_to_next_server():
82 return self.get()
83 self._graph.node_state.inc(self._seed_type)
84
85 pywrap.del_op_response(res)
86 pywrap.del_op_request(req)
87 errors.raise_exception_on_not_ok_status(status)
88
89 nodes = self._graph.get_nodes(self._node_type, node_ids)
90 return SubGraph(np.stack([row_idx, col_idx], axis=0), nodes, Edges(edge_ids=edge_ids))
91
92
93class RandomNodeSubGraphSampler(SubGraphSampler):

Callers

nothing calls this directly

Calls 9

strategy2opFunction · 0.90
SubGraphClass · 0.90
EdgesClass · 0.90
sample_subgraphMethod · 0.80
codeMethod · 0.80
incMethod · 0.80
okMethod · 0.45
get_nodesMethod · 0.45

Tested by

no test coverage detected