Repository: pyg-team/pytorch_geometric

Issue:
`get_num_hops` incorrectly counts "multi-hop" layers
### 🐛 Describe the bug

Hello, this is very minor and maybe not a bug per se. The `torch_geometric.util.get_num_hops` counts the number of MessagePassing layers as a sort of proxy for the number of hops covered by a model.
However, there's at least one MessagePassing layer (`ChebConv`) that aggregates info from multiple hops.  There may be a couple others, it looks like MixHopConv will also aggregate multiple hops if `p > 1`. 

TL;DR, in my opinion, `get_num_hops` returns a slightly misleading number for layers like ChebConv. Even if it's hard and/or impossible to accurately get the hops for arbitrary models, I would expect this function to be "correct" for individual layers :shrug:

Maybe a suitable fix is just to update the docstring to explain it's counting the MessagePassing layers, not doing something super fancy?

```python
import torch
import torch_geometric
from torch_geometric.utils import get_num_hops, to_undirected

# define a graph that has 5 edges
# 0 <-> 1 <-> 2 <-> 3 <-> 4 <-> 5
# only node 0 has a non-zero feature.
x = torch.Tensor([1, 0, 0, 0, 0, 0]).unsqueeze(1)
edge_index = to_undirected(torch.Tensor([
        [0, 1, 2, 3, 4],
        [1, 2, 3, 4, 5]
])).to(torch.int64)
edge_weight = torch.ones(edge_index.size(1))

# make a model with 1 layer with filter size of K=3
model = torch_geometric.nn.conv.ChebConv(1, 1, K=3)
x = model(x, edge_index, edge_weight)

# the number of nonzero nodes now matches K - 1
print('get_num_hops: ', get_num_hops(model))
print('actual hops: ', torch.count_nonzero(x).item() - 1)
```

```
get_num_hops:  1
actual hops:  2
```

### Versions

```
PyTorch version: 2.0.1
Is debug build: False
CUDA used to build PyTorch: 11.7
ROCM used to build PyTorch: N/A

OS: Rocky Linux release 8.8 (Green Obsidian) (x86_64)
GCC version: (GCC) 8.5.0 20210514 (Red Hat 8.5.0-18)
Clang version: Could not collect
CMake version: version 3.27.5
Libc version: glibc-2.28

Python version: 3.9.18 (main, Sep 11 2023, 13:41:44)  [GCC 11.2.0] (64-bit runtime)
Python platform: Linux-4.18.0-477.15.1.el8_8.x86_64-x86_64-with-glibc2.28
Is CUDA available: False
CUDA runtime version: No CUDA
CUDA_MODULE_LOADING set to: N/A
GPU models and configuration: No CUDA
Nvidia driver version: No CUDA
cuDNN version: No CUDA
HIP runtime version: N/A
MIOpen runtime version: N/A
Is XNNPACK available: True

CPU:
Architecture:        x86_64
CPU op-mode(s):      32-bit, 64-bit
Byte Order:          Little Endian
CPU(s):              40
On-line CPU(s) list: 0-39
Thread(s) per core:  1
Core(s) per socket:  20
Socket(s):           2
NUMA node(s):        2
Vendor ID:           GenuineIntel
CPU family:          6
Model:               85
Model name:          Intel(R) Xeon(R) Gold 6148 CPU @ 2.40GHz
Stepping:            4
CPU MHz:             2400.000
BogoMIPS:            4800.00
L1d cache:           32K
L1i cache:           32K
L2 cache:            1024K
L3 cache:            28160K
NUMA node0 CPU(s):   0-19
NUMA node1 CPU(s):   20-39
Flags:               fpu vme de pse tsc msr pae mce cx8 apic sep mtrr pge mca cmov pat pse36 clflush dts acpi mmx fxsr sse sse2 ss ht tm pbe syscall nx pdpe1gb rdtscp lm constant_tsc art arch_perfmon pebs bts rep_good nopl xtopology nonstop_tsc cpuid aperfmperf pni pclmulqdq dtes64 monitor ds_cpl smx est tm2 ssse3 sdbg fma cx16 xtpr pdcm pcid dca sse4_1 sse4_2 x2apic movbe popcnt tsc_deadline_timer aes xsave avx f16c rdrand lahf_lm abm 3dnowprefetch cpuid_fault epb cat_l3 cdp_l3 invpcid_single pti intel_ppin ssbd mba ibrs ibpb stibp fsgsbase tsc_adjust bmi1 hle avx2 smep bmi2 erms invpcid rtm cqm mpx rdt_a avx512f avx512dq rdseed adx smap clflushopt clwb intel_pt avx512cd avx512bw avx512vl xsaveopt xsavec xgetbv1 xsaves cqm_llc cqm_occup_llc cqm_mbm_total cqm_mbm_local dtherm ida arat pln pts pku ospke md_clear flush_l1d

Versions of relevant libraries:
[pip3] configmypy==0.1.0
[pip3] numpy==1.25.2
[pip3] tensorly-torch==0.4.0
[pip3] torch==1.13.1
[pip3] torch-cluster==1.6.1
[pip3] torch-geometric==2.3.1
[pip3] torch-scatter==2.1.1
[pip3] torch-sparse==0.6.18
[pip3] torchdeq==0.1.0
[pip3] torchvision==0.15.2
[pip3] triton==2.0.0
[conda] blas                      1.0                         mkl
[conda] mkl                       2023.2.0                 pypi_0    pypi
[conda] mkl-service               2.4.0            py39h5eee18b_1
[conda] mkl_fft                   1.3.8            py39h5eee18b_0
[conda] mkl_random                1.2.4            py39hdb19cb5_0
[conda] numpy                     1.25.2           py39h5f9d8c6_0
[conda] numpy-base                1.25.2           py39hb5e798b_0
[conda] pyg                       2.3.1           py39_torch_2.0.0_cu117    pyg
[conda] pytorch                   2.0.1           py3.9_cuda11.7_cudnn8.5.0_0    pytorch
[conda] pytorch-cluster           1.6.1           py39_torch_2.0.0_cu117    pyg
[conda] pytorch-cuda              11.7                 h778d358_5    pytorch
[conda] pytorch-mutex             1.0                        cuda    pytorch
[conda] pytorch-scatter           2.1.1           py39_torch_2.0.0_cu117    pyg
[conda] pytorch-sparse            0.6.18          py39_torch_2.0.0_cu117    pyg
[conda] tensorly-torch            0.4.0                    pypi_0    pypi
[conda] torchdeq                  0.1.0                    pypi_0    pypi
[conda] torchtriton               2.0.0                      py39    pytorch
[conda] torchvision               0.15.2               py39_cu117    pytorch
```


Discussion:
Since I assume `get_num_hops` is not called every batch iteration in most cases, we could possibly do something fancy without any performance concerns, but I'm not sure if there's a robust way to count the number of hops.

As a quick fix, we can update the docs as you suggest :)

Resolving patch:
diff --git a/torch_geometric/utils/_subgraph.py b/torch_geometric/utils/_subgraph.py
--- a/torch_geometric/utils/_subgraph.py
+++ b/torch_geometric/utils/_subgraph.py
@@ -14,6 +14,14 @@ def get_num_hops(model: torch.nn.Module) -> int:
     r"""Returns the number of hops the model is aggregating information
     from.
 
+    .. note::
+
+        This function counts the number of message passing layers as an
+        approximation of the total number of hops covered by the model.
+        Its output may not necessarily correct in case message passing layers
+        perform multi-hop aggregation, *e.g.*, as in
+        :class:`~torch_geometric.nn.conv.ChebConv`.
+
     Example:
         >>> class GNN(torch.nn.Module):
         ...     def __init__(self):


Test patch: