Repository: pyg-team/pytorch_geometric
Pull request #7062 (2023-03-28 10:27:51)

Drop `torch_sparse` dependency in tests (11/n)

codecov[bot]: ## [Codecov](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/7062?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) Report
> Merging [#7062](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/7062?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (9fefd82) into [master](https://codecov.io/gh/pyg-team/pytorch_geometric/commit/833ac54d2ef1ae9a98edd79ea825d6dee26c4def?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) (833ac54) will **not change** coverage.
> The diff coverage is `n/a`.

```diff
@@           Coverage Diff           @@
##           master    #7062   +/-   ##
=======================================
  Coverage   91.43%   91.43%           
=======================================
  Files         436      436           
  Lines       23828    23828           
=======================================
  Hits        21788    21788           
  Misses       2040     2040           
```


| [Impacted Files](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/7062?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team) | Coverage Δ | |
|---|---|---|
| [torch\_geometric/typing.py](https://codecov.io/gh/pyg-team/pytorch_geometric/pull/7062?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team#diff-dG9yY2hfZ2VvbWV0cmljL3R5cGluZy5weQ==) | `100.00% <ø> (ø)` | |

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pyg-team)


Patch:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ab6051e61..d8bf4ab8e 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -7,7 +7,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
 
 ### Added
 
-- Added support for `jittable` without `torch_sparse` being installed ([#7061](https://github.com/pyg-team/pytorch_geometric/pull/7061))
+- Added support for `torch.jit.script` within `MessagePassing` layers without `torch_sparse` being installed ([#7061](https://github.com/pyg-team/pytorch_geometric/pull/7061), [#7062](https://github.com/pyg-team/pytorch_geometric/pull/7062))
 - Added unbatching logic for `torch.sparse` tensors ([#7037](https://github.com/pyg-team/pytorch_geometric/pull/7037))
 - Added the `RotatE` KGE model ([#7026](https://github.com/pyg-team/pytorch_geometric/pull/7026))
 
diff --git a/torch_geometric/typing.py b/torch_geometric/typing.py
index e7379e7c8..81c2316c5 100644
--- a/torch_geometric/typing.py
+++ b/torch_geometric/typing.py
@@ -73,6 +73,13 @@ except (ImportError, OSError) as e:
         def is_cuda(self) -> bool:
             raise ImportError("'SparseTensor' requires 'torch-sparse'")
 
+        def has_value(self) -> bool:
+            raise ImportError("'SparseTensor' requires 'torch-sparse'")
+
+        def fill_value(self, fill_value: float,
+                       dtype: Optional[torch.dtype] = None) -> 'SparseTensor':
+            raise ImportError("'SparseTensor' requires 'torch-sparse'")
+
         def coo(self) -> Tuple[Tensor, Tensor, Optional[Tensor]]:
             raise ImportError("'SparseTensor' requires 'torch-sparse'")
 
@@ -91,6 +98,19 @@ except (ImportError, OSError) as e:
                    reduce: str = "sum") -> Tensor:
             raise ImportError("'matmul' requires 'torch-sparse'")
 
+        @staticmethod
+        def sum(src: SparseTensor, dim: Optional[int] = None) -> Tensor:
+            raise ImportError("'sum' requires 'torch-sparse'")
+
+        @staticmethod
+        def mul(src: SparseTensor, other: Tensor) -> SparseTensor:
+            raise ImportError("'mul' requires 'torch-sparse'")
+
+        @staticmethod
+        def fill_diag(src: SparseTensor, fill_value: float,
+                      k: int = 0) -> SparseTensor:
+            raise ImportError("'fill_diag' requires 'torch-sparse'")
+
 
 # Types for accessing data ####################################################
 


Test patch:
diff --git a/.github/workflows/latest_testing.yml b/.github/workflows/latest_testing.yml
index 5a28fe1dc..224f68748 100644
--- a/.github/workflows/latest_testing.yml
+++ b/.github/workflows/latest_testing.yml
@@ -62,6 +62,7 @@ jobs:
           pytest test/utils/
           pytest test/visualization/
           pytest test/nn/aggr
+          pytest test/nn/conv/test_message_passing.py
           # pytest test/nn/conv
           pytest test/nn/dense
           pytest test/nn/functional
@@ -70,6 +71,4 @@ jobs:
           pytest test/nn/norm
           pytest test/nn/pool
           pytest test/nn/unpool
-          pytest test/nn/test_compile_basic.py test/nn/test_compile_conv.py test/nn/test_compile_dynamic.py test/nn/test_data_parallel.py test/nn/test_encoding.py test/nn/test_inits.py test/nn/test_model_hub.py test/nn/test_model_summary.py test/nn/test_module_dict.py test/nn/test_parameter_dict.py test/nn/test_reshape.py test/nn/test_resolver.py
-          # pytest test/nn/test_sequential.py
-          pytest test/nn/test_to_fixed_size_transformer.py test/nn/test_to_hetero_module.py test/nn/test_to_hetero_transformer.py test/nn/test_to_hetero_with_bases_transformer.py
+          pytest test/nn/test_compile_basic.py test/nn/test_compile_conv.py test/nn/test_compile_dynamic.py test/nn/test_data_parallel.py test/nn/test_encoding.py test/nn/test_inits.py test/nn/test_model_hub.py test/nn/test_model_summary.py test/nn/test_module_dict.py test/nn/test_parameter_dict.py test/nn/test_reshape.py test/nn/test_resolver.py test/nn/test_sequential.py test/nn/test_to_fixed_size_transformer.py test/nn/test_to_hetero_module.py test/nn/test_to_hetero_transformer.py test/nn/test_to_hetero_with_bases_transformer.py
diff --git a/test/nn/test_sequential.py b/test/nn/test_sequential.py
index 4d8db76fd..086e194c3 100644
--- a/test/nn/test_sequential.py
+++ b/test/nn/test_sequential.py
@@ -4,6 +4,7 @@ import torch
 import torch.fx
 from torch.nn import Dropout, Linear, ReLU
 
+import torch_geometric.typing
 from torch_geometric.nn import (
     GCNConv,
     JumpingKnowledge,
@@ -67,7 +68,6 @@ def test_sequential():
 def test_sequential_jittable():
     x = torch.randn(4, 16)
     edge_index = torch.tensor([[0, 0, 0, 1, 2, 3], [1, 2, 3, 0, 0, 0]])
-    adj_t = SparseTensor(row=edge_index[0], col=edge_index[1]).t()
 
     model = Sequential('x: Tensor, edge_index: Tensor', [
         (GCNConv(16, 64).jittable(), 'x, edge_index -> x'),
@@ -78,14 +78,17 @@ def test_sequential_jittable():
     ])
     torch.jit.script(model)(x, edge_index)
 
-    model = Sequential('x: Tensor, edge_index: SparseTensor', [
-        (GCNConv(16, 64).jittable(), 'x, edge_index -> x'),
-        ReLU(inplace=True),
-        (GCNConv(64, 64).jittable(), 'x, edge_index -> x'),
-        ReLU(inplace=True),
-        Linear(64, 7),
-    ])
-    torch.jit.script(model)(x, adj_t)
+    if torch_geometric.typing.WITH_TORCH_SPARSE:
+        adj_t = SparseTensor.from_edge_index(edge_index).t()
+
+        model = Sequential('x: Tensor, edge_index: SparseTensor', [
+            (GCNConv(16, 64).jittable(), 'x, edge_index -> x'),
+            ReLU(inplace=True),
+            (GCNConv(64, 64).jittable(), 'x, edge_index -> x'),
+            ReLU(inplace=True),
+            Linear(64, 7),
+        ])
+        torch.jit.script(model)(x, adj_t)
 
 
 def symbolic_trace(module):