Unverified Commit f6fa920d authored by Rhett Ying's avatar Rhett Ying Committed by GitHub
Browse files

[GraphBolt] Add functional name into docstring (#6739)

parent 06dc1dc4
...@@ -104,6 +104,8 @@ class CopyTo(IterDataPipe): ...@@ -104,6 +104,8 @@ class CopyTo(IterDataPipe):
"""DataPipe that transfers each element yielded from the previous DataPipe """DataPipe that transfers each element yielded from the previous DataPipe
to the given device. to the given device.
Functional name: :obj:`copy_to`.
This is equivalent to This is equivalent to
.. code:: python .. code:: python
......
...@@ -16,17 +16,9 @@ __all__ = [ ...@@ -16,17 +16,9 @@ __all__ = [
@functional_datapipe("fetch_feature") @functional_datapipe("fetch_feature")
class FeatureFetcher(MiniBatchTransformer): class FeatureFetcher(MiniBatchTransformer):
"""A feature fetcher used to fetch features for node/edge in graphbolt.""" """A feature fetcher used to fetch features for node/edge in graphbolt.
def __init__( Functional name: :obj:`fetch_feature`.
self,
datapipe,
feature_store,
node_feature_keys=None,
edge_feature_keys=None,
):
"""
Initlization for a feature fetcher.
Parameters Parameters
---------- ----------
...@@ -48,6 +40,14 @@ class FeatureFetcher(MiniBatchTransformer): ...@@ -48,6 +40,14 @@ class FeatureFetcher(MiniBatchTransformer):
following the format 'str:str:str', and the values are lists of following the format 'str:str:str', and the values are lists of
feature names. feature names.
""" """
def __init__(
self,
datapipe,
feature_store,
node_feature_keys=None,
edge_feature_keys=None,
):
super().__init__(datapipe, self._read) super().__init__(datapipe, self._read)
self.feature_store = feature_store self.feature_store = feature_store
self.node_feature_keys = node_feature_keys self.node_feature_keys = node_feature_keys
......
...@@ -15,6 +15,8 @@ __all__ = ["InSubgraphSampler"] ...@@ -15,6 +15,8 @@ __all__ = ["InSubgraphSampler"]
class InSubgraphSampler(SubgraphSampler): class InSubgraphSampler(SubgraphSampler):
"""Sample the subgraph induced on the inbound edges of the given nodes. """Sample the subgraph induced on the inbound edges of the given nodes.
Functional name: :obj:`sample_in_subgraph`.
In-subgraph sampler is responsible for sampling a subgraph from given data, In-subgraph sampler is responsible for sampling a subgraph from given data,
returning an induced subgraph along with compacted information. returning an induced subgraph along with compacted information.
......
...@@ -20,6 +20,8 @@ __all__ = ["NeighborSampler", "LayerNeighborSampler"] ...@@ -20,6 +20,8 @@ __all__ = ["NeighborSampler", "LayerNeighborSampler"]
class NeighborSampler(SubgraphSampler): class NeighborSampler(SubgraphSampler):
"""Sample neighbor edges from a graph and return a subgraph. """Sample neighbor edges from a graph and return a subgraph.
Functional name: :obj:`sample_neighbor`.
Neighbor sampler is responsible for sampling a subgraph from given data. It Neighbor sampler is responsible for sampling a subgraph from given data. It
returns an induced subgraph along with compacted information. In the returns an induced subgraph along with compacted information. In the
context of a node classification task, the neighbor sampler directly context of a node classification task, the neighbor sampler directly
...@@ -183,6 +185,8 @@ class NeighborSampler(SubgraphSampler): ...@@ -183,6 +185,8 @@ class NeighborSampler(SubgraphSampler):
class LayerNeighborSampler(NeighborSampler): class LayerNeighborSampler(NeighborSampler):
"""Sample layer neighbor edges from a graph and return a subgraph. """Sample layer neighbor edges from a graph and return a subgraph.
Functional name: :obj:`sample_layer_neighbor`.
Sampler that builds computational dependency of node representations via Sampler that builds computational dependency of node representations via
labor sampling for multilayer GNN from the NeurIPS 2023 paper labor sampling for multilayer GNN from the NeurIPS 2023 paper
`Layer-Neighbor Sampling -- Defusing Neighborhood Explosion in GNNs `Layer-Neighbor Sampling -- Defusing Neighborhood Explosion in GNNs
......
...@@ -12,6 +12,8 @@ class UniformNegativeSampler(NegativeSampler): ...@@ -12,6 +12,8 @@ class UniformNegativeSampler(NegativeSampler):
"""Sample negative destination nodes for each source node based on a uniform """Sample negative destination nodes for each source node based on a uniform
distribution. distribution.
Functional name: :obj:`sample_uniform_negative`.
It's important to note that the term 'negative' refers to false negatives, It's important to note that the term 'negative' refers to false negatives,
indicating that the sampled pairs are not ensured to be absent in the graph. indicating that the sampled pairs are not ensured to be absent in the graph.
For each edge ``(u, v)``, it is supposed to generate `negative_ratio` pairs For each edge ``(u, v)``, it is supposed to generate `negative_ratio` pairs
......
...@@ -14,15 +14,10 @@ __all__ = [ ...@@ -14,15 +14,10 @@ __all__ = [
@functional_datapipe("transform") @functional_datapipe("transform")
class MiniBatchTransformer(Mapper): class MiniBatchTransformer(Mapper):
"""A mini-batch transformer used to manipulate mini-batch""" """A mini-batch transformer used to manipulate mini-batch.
Functional name: :obj:`transform`.
def __init__(
self,
datapipe,
transformer,
):
"""
Initlization for a subgraph transformer.
Parameters Parameters
---------- ----------
datapipe : DataPipe datapipe : DataPipe
...@@ -31,6 +26,12 @@ class MiniBatchTransformer(Mapper): ...@@ -31,6 +26,12 @@ class MiniBatchTransformer(Mapper):
The function applied to each minibatch which is responsible for The function applied to each minibatch which is responsible for
transforming the minibatch. transforming the minibatch.
""" """
def __init__(
self,
datapipe,
transformer,
):
super().__init__(datapipe, self._transformer) super().__init__(datapipe, self._transformer)
self.transformer = transformer self.transformer = transformer
...@@ -44,17 +45,18 @@ class MiniBatchTransformer(Mapper): ...@@ -44,17 +45,18 @@ class MiniBatchTransformer(Mapper):
@functional_datapipe("to_dgl") @functional_datapipe("to_dgl")
class DGLMiniBatchConverter(Mapper): class DGLMiniBatchConverter(Mapper):
"""Convert a graphbolt mini-batch to a dgl mini-batch.""" """Convert a graphbolt mini-batch to a dgl mini-batch.
Functional name: :obj:`to_dgl`.
def __init__(
self,
datapipe,
):
"""
Initlization for a subgraph transformer.
Parameters Parameters
---------- ----------
datapipe : DataPipe datapipe : DataPipe
The datapipe. The datapipe.
""" """
def __init__(
self,
datapipe,
):
super().__init__(datapipe, MiniBatch.to_dgl) super().__init__(datapipe, MiniBatch.to_dgl)
...@@ -16,15 +16,8 @@ class NegativeSampler(MiniBatchTransformer): ...@@ -16,15 +16,8 @@ class NegativeSampler(MiniBatchTransformer):
""" """
A negative sampler used to generate negative samples and return A negative sampler used to generate negative samples and return
a mix of positive and negative samples. a mix of positive and negative samples.
"""
def __init__( Functional name: :obj:`sample_negative`.
self,
datapipe,
negative_ratio,
):
"""
Initlization for a negative sampler.
Parameters Parameters
---------- ----------
...@@ -33,6 +26,12 @@ class NegativeSampler(MiniBatchTransformer): ...@@ -33,6 +26,12 @@ class NegativeSampler(MiniBatchTransformer):
negative_ratio : int negative_ratio : int
The proportion of negative samples to positive samples. The proportion of negative samples to positive samples.
""" """
def __init__(
self,
datapipe,
negative_ratio,
):
super().__init__(datapipe, self._sample) super().__init__(datapipe, self._sample)
assert negative_ratio > 0, "Negative_ratio should be positive Integer." assert negative_ratio > 0, "Negative_ratio should be positive Integer."
self.negative_ratio = negative_ratio self.negative_ratio = negative_ratio
......
...@@ -17,20 +17,20 @@ __all__ = [ ...@@ -17,20 +17,20 @@ __all__ = [
@functional_datapipe("sample_subgraph") @functional_datapipe("sample_subgraph")
class SubgraphSampler(MiniBatchTransformer): class SubgraphSampler(MiniBatchTransformer):
"""A subgraph sampler used to sample a subgraph from a given set of nodes """A subgraph sampler used to sample a subgraph from a given set of nodes
from a larger graph.""" from a larger graph.
def __init__( Functional name: :obj:`sample_subgraph`.
self,
datapipe,
):
"""
Initlization for a subgraph sampler.
Parameters Parameters
---------- ----------
datapipe : DataPipe datapipe : DataPipe
The datapipe. The datapipe.
""" """
def __init__(
self,
datapipe,
):
super().__init__(datapipe, self._sample) super().__init__(datapipe, self._sample)
def _sample(self, minibatch): def _sample(self, minibatch):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment