DeepGraphLearning / torchdrug

A powerful and flexible machine learning platform for drug discovery
https://torchdrug.ai/
Apache License 2.0
1.43k stars 199 forks source link

RuntimeError: General Union types are not currently supported #177

Open OrangeCat7777777 opened 1 year ago

OrangeCat7777777 commented 1 year ago

I'm trying to run the "Property Prediction" tutorial (https://torchdrug.ai/docs/tutorials/property_prediction.html), but I encounter the following error:

Traceback (most recent call last):
  File "/mnt/petrelfs/weili/test.py", line 9, in <module>
    from torchdrug import core, models, tasks, utils
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torchdrug/models/__init__.py", line 1, in <module>
    from .chebnet import ChebyshevConvolutionalNetwork
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torchdrug/models/chebnet.py", line 6, in <module>
    from torchdrug import core, layers
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torchdrug/layers/__init__.py", line 11, in <module>
    from .geometry import GraphConstruction, SpatialLineGraph
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torchdrug/layers/geometry/__init__.py", line 2, in <module>
    from .function import BondEdge, KNNEdge, SpatialEdge, SequentialEdge, AlphaCarbonNode, \
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torchdrug/layers/geometry/function.py", line 3, in <module>
    from torch_cluster import knn_graph, radius_graph
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torch_cluster/__init__.py", line 45, in <module>
    from .rw import random_walk  # noqa
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torch_cluster/rw.py", line 8, in <module>
    def random_walk(
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torch/jit/_script.py", line 989, in script
    fn = torch._C._jit_script_compile(
RuntimeError: 
General Union types are not currently supported. Only Union[T, NoneType] (i.e. Optional[T]) is supported.:
  File "/mnt/petrelfs/weili/anaconda3/envs/torchdrug/lib/python3.9/site-packages/torch_cluster/rw.py", line 18
    num_nodes: Optional[int] = None,
    return_edge_indices: bool = False,
) -> Union[Tensor, Tuple[Tensor, Tensor]]:
     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ <--- HERE
    """Samples random walks of length :obj:`walk_length` from all node indices
    in :obj:`start` in the graph given by :obj:`(row, col)` as described in the

My environment:

cudatoolkit               11.1.1
pytorch                   1.8.1
torch-cluster             1.6.1             
torch-scatter             2.1.1
torchdrug                 0.2.0.post1
KiddoZhu commented 1 year ago

Hi! This looks like an issue caused by torch-cluster, not torchdrug. For pytorch 1.8.1, torch-cluster 1.6.0 works on my side. Maybe you can try this version.

horacehht commented 1 year ago

My environment:

cudatoolkit               11.1.1
pytorch                   1.8.0
torch-cluster             1.6.0             
torch-scatter             2.1.1
torchdrug                 0.2.1

pip install torch-cluster==1.6.0 really works for me. But solving this problem, I have encountered this error.

AttributeError: module 'torchdrug.layers' has no attribute 'MLP'

The code is from the tutorials, the part of "Define a Graph Neural Network for Classification" It really confuses me that when I import torchdrug.layers and get the attribute MLP, no problems occured.

2023.7.31 reply: When I restart the jupyter kernel, the problem just goes away.

RanBoWen commented 9 months ago

great! it is work for me!