Skip to content

Commit

Permalink
[ruff] Fix first line doc-strings [5/n] (pyg-team#8334)
Browse files Browse the repository at this point in the history
  • Loading branch information
rusty1s authored Nov 6, 2023
1 parent 62b386f commit 855773d
Show file tree
Hide file tree
Showing 134 changed files with 258 additions and 201 deletions.
4 changes: 2 additions & 2 deletions examples/contrib/pgm_explainer_graph_classification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""This is an example of using the PGM explainer algorithm
on a graph classification task
"""This is an example of using the PGM explainer algorithm on a graph
classification task.
"""
import os.path as osp

Expand Down
4 changes: 2 additions & 2 deletions examples/contrib/pgm_explainer_node_classification.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""This is an example of using the PGM explainer algorithm
on a node classification task
"""This is an example of using the PGM explainer algorithm on a node
classification task.
"""
import os.path as osp

Expand Down
5 changes: 2 additions & 3 deletions examples/equilibrium_median.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
r"""Replicates the experiment from `"Deep Graph Infomax"
<https://arxiv.org/abs/1809.10341>`_ to try and teach
`EquilibriumAggregation` to learn to take the median of
a set of numbers
<https://arxiv.org/abs/1809.10341>`_ to try and teach `EquilibriumAggregation`
to learn to take the median of a set of numbers.
This example converges slowly to being able to predict the
median similar to what is observed in the paper.
Expand Down
4 changes: 3 additions & 1 deletion examples/multi_gpu/multinode_multigpu_papers100m_gcn.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""To run:
"""Multi-node multi-GPU example on ogbn-papers100m.
To run:
srun -l -N<num_nodes> --ntasks-per-node=<ngpu_per_node> \
--container-name=cont --container-image=<image_url> \
--container-mounts=/ogb-papers100m/:/workspace/dataset
Expand Down
5 changes: 2 additions & 3 deletions examples/randlanet_classification.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""An adaptation of RandLA-Net to the classification task, which was not
addressed in the paper:
RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds
Reference: https://arxiv.org/abs/1911.11236
addressed in the `"RandLA-Net: Efficient Semantic Segmentation of Large-Scale
Point Clouds" <https://arxiv.org/abs/1911.11236>`_ paper.
"""
import os.path as osp

Expand Down
6 changes: 3 additions & 3 deletions examples/randlanet_segmentation.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""An implementation of RandLA-Net based on the paper:
RandLA-Net: Efficient Semantic Segmentation of Large-Scale Point Clouds
Reference: https://arxiv.org/abs/1911.11236
"""An implementation of RandLA-Net based on the `"RandLA-Net: Efficient
Semantic Segmentation of Large-Scale Point Clouds"
<https://arxiv.org/abs/1911.11236>`_ paper.
"""
import os.path as osp

Expand Down
2 changes: 1 addition & 1 deletion graphgym/custom_graphgym/head/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

@register_head('head')
class ExampleNodeHead(nn.Module):
"""Head of GNN, node prediction"""
r"""Head of GNN for node prediction."""
def __init__(self, dim_in, dim_out):
super().__init__()
self.layer_post_mp = nn.Linear(dim_in, dim_out, bias=True)
Expand Down
8 changes: 2 additions & 6 deletions graphgym/custom_graphgym/layer/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
# take 'batch' as input and 'batch' as output
@register_layer('exampleconv1')
class ExampleConv1(MessagePassing):
r"""Example GNN layer
"""
r"""Example GNN layer."""
def __init__(self, in_channels, out_channels, bias=True, **kwargs):
super().__init__(aggr=cfg.gnn.agg, **kwargs)

Expand Down Expand Up @@ -57,9 +55,7 @@ def update(self, aggr_out):
# Example 2: First define a PyG format Conv layer
# Then wrap it to become GraphGym format
class ExampleConv2Layer(MessagePassing):
r"""Example GNN layer
"""
r"""Example GNN layer."""
def __init__(self, in_channels, out_channels, bias=True, **kwargs):
super().__init__(aggr=cfg.gnn.agg, **kwargs)

Expand Down
2 changes: 1 addition & 1 deletion graphgym/custom_graphgym/stage/example.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def GNNLayer(dim_in, dim_out, has_act=True):

@register_stage('example')
class GNNStackStage(nn.Module):
"""Simple Stage that stack GNN layers"""
r"""Simple stage that stacks GNN layers."""
def __init__(self, dim_in, dim_out, num_layers):
super().__init__()
for i in range(num_layers):
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,6 @@ ignore = [
"D107", # TODO: Don't ignore "Missing docstring in __init__"
"D200", # Ignore "One-line docstring should fit on one line"
"D205", # Ignore "1 blank line required between summary line and description"
"D415", # Ignore "First line should end with a period, question mark, or exclamation point"

]
src = ["torch_geometric"]
Expand Down
4 changes: 3 additions & 1 deletion torch_geometric/config_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,9 @@ def to_dataclass(
strict: bool = False,
) -> Any:
r"""Converts the input arguments of a given class :obj:`cls` to a
:obj:`dataclass` schema, *e.g.*,
:obj:`dataclass` schema.
For example,
.. code-block:: python
Expand Down
4 changes: 2 additions & 2 deletions torch_geometric/contrib/nn/models/rbcd_attack.py
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,7 @@ def _forward_and_gradient(self, x: Tensor, labels: Tensor,
def _get_modified_adj(self, edge_index: Tensor, edge_weight: Tensor,
block_edge_index: Tensor,
block_edge_weight: Tensor) -> Tuple[Tensor, Tensor]:
"""Merges adjacency matrix with current block (incl. weights)"""
"""Merges adjacency matrix with current block (incl. weights)."""
if self.is_undirected:
block_edge_index, block_edge_weight = to_undirected(
block_edge_index, block_edge_weight, num_nodes=self.num_nodes,
Expand Down Expand Up @@ -539,7 +539,7 @@ def _linear_to_full_idx(n: int, lin_idx: Tensor) -> Tensor:
def _margin_loss(score: Tensor, labels: Tensor,
idx_mask: Optional[Tensor] = None,
reduce: Optional[str] = None) -> Tensor:
r"""Margin loss between true score and highest non-target score:
r"""Margin loss between true score and highest non-target score.
.. math::
m = - s_{y} + max_{y' \ne y} s_{y'}
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/data/database.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ def maybe_cast_to_tensor_info(value: Any) -> Union[Any, TensorInfo]:

class Database(ABC):
r"""Base class for inserting and retrieving data from a database.
A database acts as a persisted, out-of-memory and index-based key/value
store for tensor and custom data:
Expand Down
29 changes: 20 additions & 9 deletions torch_geometric/data/feature_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ def __init__(self, store: 'FeatureStore', attr: TensorAttr):
def __getattr__(self, key: Any) -> Union['AttrView', FeatureTensorType]:
r"""Sets the first unset field of the backing :class:`TensorAttr`
object to the attribute.
This allows for :class:`AttrView` to be indexed by different values of
attributes, in order.
In particular, for a feature store that we want to index by
Expand Down Expand Up @@ -159,6 +160,7 @@ def __getattr__(self, key: Any) -> Union['AttrView', FeatureTensorType]:
def __getitem__(self, key: Any) -> Union['AttrView', FeatureTensorType]:
r"""Sets the first unset field of the backing :class:`TensorAttr`
object to the attribute via indexing.
This allows for :class:`AttrView` to be indexed by different values of
attributes, in order.
In particular, for a feature store that we want to index by
Expand All @@ -176,9 +178,12 @@ def __getitem__(self, key: Any) -> Union['AttrView', FeatureTensorType]:

def __setattr__(self, key: str, value: Any):
r"""Supports attribute assignment to the backing :class:`TensorAttr` of
an :class:`AttrView`. This allows for :class:`AttrView` objects to set
their backing attribute values. In particular, the following operation
sets the :obj:`index` of an :class:`AttrView`:
an :class:`AttrView`.
This allows for :class:`AttrView` objects to set their backing
attribute values.
In particular, the following operation sets the :obj:`index` of an
:class:`AttrView`:
.. code-block:: python
Expand All @@ -194,9 +199,12 @@ def __setattr__(self, key: str, value: Any):

def __setitem__(self, key: str, value: Any):
r"""Supports attribute assignment to the backing :class:`TensorAttr` of
an :class:`AttrView` via indexing. This allows for :class:`AttrView`
objects to set their backing attribute values. In particular, the
following operation sets the `index` of an :class:`AttrView`:
an :class:`AttrView` via indexing.
This allows for :class:`AttrView` objects to set their backing
attribute values.
In particular, the following operation sets the `index` of an
:class:`AttrView`:
.. code-block:: python
Expand All @@ -209,9 +217,11 @@ def __setitem__(self, key: str, value: Any):

def __call__(self) -> FeatureTensorType:
r"""Supports :class:`AttrView` as a callable to force retrieval from
the currently specified attributes. In particular, this passes the
current :class:`TensorAttr` object to a GET call, regardless of whether
all attributes have been specified. It returns the result of this call.
the currently specified attributes.
In particular, this passes the current :class:`TensorAttr` object to a
GET call, regardless of whether all attributes have been specified.
It returns the result of this call.
In particular, the following operation returns a tensor by performing a
GET operation on the backing feature store:
Expand Down Expand Up @@ -487,6 +497,7 @@ def __setitem__(self, key: TensorAttr, value: FeatureTensorType):

def __getitem__(self, key: TensorAttr) -> Any:
r"""Supports pythonic indexing into the :class:`FeatureStore`.
In particular, the following rules are followed for indexing:
* A fully-specified :obj:`key` will produce a tensor output.
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/data/hypergraph_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

class HyperGraphData(Data):
r"""A data object describing a hypergraph.
The data object can hold node-level, link-level and graph-level attributes.
This object differs from a standard :obj:`~torch_geometric.data.Data`
object by having hyperedges, i.e. edges that connect more
Expand Down
6 changes: 5 additions & 1 deletion torch_geometric/data/storage.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,7 @@ def record_stream(self, stream: torch.cuda.Stream, *args: str):


class NodeStorage(BaseStorage):
r"""A storage for node-level information."""
@property
def _key(self) -> NodeType:
key = self.__dict__.get('_key', None)
Expand Down Expand Up @@ -412,7 +413,9 @@ def node_attrs(self) -> List[str]:


class EdgeStorage(BaseStorage):
r"""We support multiple ways to store edge connectivity in a
r"""A storage for edge-level information.
We support multiple ways to store edge connectivity in a
:class:`EdgeStorage` object:
* :obj:`edge_index`: A :class:`torch.LongTensor` holding edge indices in
Expand Down Expand Up @@ -624,6 +627,7 @@ def is_bipartite(self) -> bool:


class GlobalStorage(NodeStorage, EdgeStorage):
r"""A storage for both node-level and edge-level information."""
@property
def _key(self) -> Any:
return None
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/datasets/ba_multi_shapes.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BAMultiShapesDataset(InMemoryDataset):
evaluating explainabilty algorithms, as described in the
`"Global Explainability of GNNs via Logic Combination of Learned Concepts"
<https://arxiv.org/abs/2210.07147>`_ paper.
Given three atomic motifs, namely House (H), Wheel (W), and Grid (G),
:class:`~torch_geometric.datasets.BAMultiShapesDataset` contains 1,000
graphs where each graph is obtained by attaching the motifs to a random
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/datasets/ged_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
class GEDDataset(InMemoryDataset):
r"""The GED datasets from the `"Graph Edit Distance Computation via Graph
Neural Networks" <https://arxiv.org/abs/1808.05689>`_ paper.
GEDs can be accessed via the global attributes :obj:`ged` and
:obj:`norm_ged` for all train/train graph pairs and all train/test graph
pairs:
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/distributed/partition.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class Partitioner:
r"""Partition the graph structure and its features of a
:class:`~torch_geometric.data.Data` or
:class:`~torch_geometric.data.HeteroData` object.
Partitioned data output will be structured like this:
**Homogeneous graphs:**
Expand Down
4 changes: 2 additions & 2 deletions torch_geometric/distributed/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class NodeDict:
r"""Class used during heterogeneous sampling:
1) The nodes to serve as source nodes in the next layer
2) The nodes with duplicates that are further needed to create COO output
3) The output nodes without duplicates
3) The output nodes without duplicates.
"""
src: Dict[NodeType, Tensor] = field(default_factory=dict)
with_dupl: Dict[NodeType, Tensor] = field(default_factory=dict)
Expand All @@ -30,7 +30,7 @@ class BatchDict:
layer
2) The subgraph IDs with duplicates that are further needed to create COO
output
3) The output subgraph IDs without duplicates
3) The output subgraph IDs without duplicates.
"""
src: Dict[NodeType, Tensor] = field(default_factory=dict)
with_duple: Dict[NodeType, Tensor] = field(default_factory=dict)
Expand Down
1 change: 1 addition & 0 deletions torch_geometric/explain/algorithm/pg_explainer.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
class PGExplainer(ExplainerAlgorithm):
r"""The PGExplainer model from the `"Parameterized Explainer for Graph
Neural Network" <https://arxiv.org/abs/2011.04573>`_ paper.
Internally, it utilizes a neural network to identify subgraph structures
that play a crucial role in the predictions made by a GNN.
Importantly, the :class:`PGExplainer` needs to be trained via
Expand Down
2 changes: 1 addition & 1 deletion torch_geometric/explain/metric/fidelity.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def characterization_score(
) -> Tensor:
r"""Returns the componentwise characterization score as described in the
`"GraphFramEx: Towards Systematic Evaluation of Explainability Methods for
Graph Neural Networks" <https://arxiv.org/abs/2206.09677>`_ paper:
Graph Neural Networks" <https://arxiv.org/abs/2206.09677>`_ paper.
.. math::
\textrm{charact} = \frac{w_{+} + w_{-}}{\frac{w_{+}}{\textrm{fid}_{+}} +
Expand Down
22 changes: 12 additions & 10 deletions torch_geometric/graphgym/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@

def set_cfg(cfg):
r"""This function sets the default config value.
1) Note that for an experiment, only part of the arguments will be used
The remaining unused arguments won't affect anything.
So feel free to register any argument in graphgym.contrib.config
2) We support *at most* two levels of configs, e.g., cfg.dataset.name
The remaining unused arguments won't affect anything.
So feel free to register any argument in graphgym.contrib.config
2) We support *at most* two levels of configs, *e.g.*,
:obj:`cfg.dataset.name`.
:return: configuration use by the experiment.
:return: Configuration use by the experiment.
"""
if cfg is None:
return cfg
Expand Down Expand Up @@ -449,7 +451,7 @@ def set_cfg(cfg):


def assert_cfg(cfg):
r"""Checks config values, do necessary post processing to the configs"""
r"""Checks config values, do necessary post processing to the configs."""
if cfg.dataset.task not in ['node', 'edge', 'graph', 'link_pred']:
raise ValueError(f"Task '{cfg.dataset.task}' not supported. Must be "
f"one of node, edge, graph, link_pred")
Expand All @@ -476,7 +478,7 @@ def assert_cfg(cfg):

def dump_cfg(cfg):
r"""Dumps the config to the output directory specified in
:obj:`cfg.out_dir`
:obj:`cfg.out_dir`.
Args:
cfg (CfgNode): Configuration node
Expand All @@ -488,7 +490,7 @@ def dump_cfg(cfg):


def load_cfg(cfg, args):
r"""Load configurations from file system and command line
r"""Load configurations from file system and command line.
Args:
cfg (CfgNode): Configuration node
Expand All @@ -506,7 +508,7 @@ def makedirs_rm_exist(dir):


def get_fname(fname):
r"""Extract filename from file name path
r"""Extract filename from file name path.
Args:
fname (str): Filename for the yaml format configuration file
Expand All @@ -520,7 +522,7 @@ def get_fname(fname):


def set_out_dir(out_dir, fname):
r"""Create the directory for full experiment run
r"""Create the directory for full experiment run.
Args:
out_dir (str): Directory for output, specified in :obj:`cfg.out_dir`
Expand All @@ -536,7 +538,7 @@ def set_out_dir(out_dir, fname):


def set_run_dir(out_dir):
r"""Create the directory for each random seed experiment run
r"""Create the directory for each random seed experiment run.
Args:
out_dir (str): Directory for output, specified in :obj:`cfg.out_dir`
Expand Down
2 changes: 1 addition & 1 deletion torch_geometric/graphgym/contrib/layer/generalconv.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ def __repr__(self):


class GeneralEdgeConvLayer(MessagePassing):
r"""General GNN layer, with edge features
r"""General GNN layer, with edge features.
"""
def __init__(self, in_channels, out_channels, edge_dim, improved=False,
cached=False, bias=True, **kwargs):
Expand Down
2 changes: 1 addition & 1 deletion torch_geometric/graphgym/init.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@


def init_weights(m):
r"""Performs weight initialization
r"""Performs weight initialization.
Args:
m (nn.Module): PyTorch module
Expand Down
Loading

0 comments on commit 855773d

Please sign in to comment.