Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Type Hints] NELL PPI MoleculeNet QM7 ZINC #5678

Merged
merged 17 commits into from
Oct 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/).
- Support `in_channels` with `tuple` in `GENConv` for bipartite message passing ([#5627](https://github.com/pyg-team/pytorch_geometric/pull/5627), [#5641](https://github.com/pyg-team/pytorch_geometric/pull/5641))
- Handle cases of not having enough possible negative edges in `RandomLinkSplit` ([#5642](https://github.com/pyg-team/pytorch_geometric/pull/5642))
- Fix `RGCN+pyg-lib` for `LongTensor` input ([#5610](https://github.com/pyg-team/pytorch_geometric/pull/5610))
- Improved type hint support ([#5603](https://github.com/pyg-team/pytorch_geometric/pull/5603), [#5659](https://github.com/pyg-team/pytorch_geometric/pull/5659), [#5664](https://github.com/pyg-team/pytorch_geometric/pull/5664), [#5665](https://github.com/pyg-team/pytorch_geometric/pull/5665), [#5666](https://github.com/pyg-team/pytorch_geometric/pull/5666), [#5667](https://github.com/pyg-team/pytorch_geometric/pull/5667), [#5668](https://github.com/pyg-team/pytorch_geometric/pull/5668), [#5669](https://github.com/pyg-team/pytorch_geometric/pull/5669), [#5673](https://github.com/pyg-team/pytorch_geometric/pull/5673), [#5675](https://github.com/pyg-team/pytorch_geometric/pull/5675), [#5673](https://github.com/pyg-team/pytorch_geometric/pull/5676))
- Improved type hint support ([#5603](https://github.com/pyg-team/pytorch_geometric/pull/5603), [#5659](https://github.com/pyg-team/pytorch_geometric/pull/5659), [#5664](https://github.com/pyg-team/pytorch_geometric/pull/5664), [#5665](https://github.com/pyg-team/pytorch_geometric/pull/5665), [#5666](https://github.com/pyg-team/pytorch_geometric/pull/5666), [#5667](https://github.com/pyg-team/pytorch_geometric/pull/5667), [#5668](https://github.com/pyg-team/pytorch_geometric/pull/5668), [#5669](https://github.com/pyg-team/pytorch_geometric/pull/5669), [#5673](https://github.com/pyg-team/pytorch_geometric/pull/5673), [#5675](https://github.com/pyg-team/pytorch_geometric/pull/5675), [#5673](https://github.com/pyg-team/pytorch_geometric/pull/5676), [#5678](https://github.com/pyg-team/pytorch_geometric/pull/5678))
- Avoid modifying `mode_kwargs` in `MultiAggregation` ([#5601](https://github.com/pyg-team/pytorch_geometric/pull/5601))
- Changed `BatchNorm` to allow for batches of size one during training ([#5530](https://github.com/pyg-team/pytorch_geometric/pull/5530), [#5614](https://github.com/pyg-team/pytorch_geometric/pull/5614))
- Integrated better temporal sampling support by requiring that local neighborhoods are sorted according to time ([#5516](https://github.com/pyg-team/pytorch_geometric/issues/5516), [#5602](https://github.com/pyg-team/pytorch_geometric/issues/5602))
Expand Down
19 changes: 13 additions & 6 deletions torch_geometric/datasets/molecule_net.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import os.path as osp
import re
from typing import Callable, Optional

import torch

Expand Down Expand Up @@ -145,27 +146,33 @@ class MoleculeNet(InMemoryDataset):
slice(1, 3)],
}

def __init__(self, root, name, transform=None, pre_transform=None,
pre_filter=None):
def __init__(
self,
root: str,
name: str,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):
self.name = name.lower()
assert self.name in self.names.keys()
super().__init__(root, transform, pre_transform, pre_filter)
self.data, self.slices = torch.load(self.processed_paths[0])

@property
def raw_dir(self):
def raw_dir(self) -> str:
return osp.join(self.root, self.name, 'raw')

@property
def processed_dir(self):
def processed_dir(self) -> str:
return osp.join(self.root, self.name, 'processed')

@property
def raw_file_names(self):
def raw_file_names(self) -> str:
return f'{self.names[self.name][2]}.csv'

@property
def processed_file_names(self):
def processed_file_names(self) -> str:
return 'data.pt'

def download(self):
Expand Down
12 changes: 9 additions & 3 deletions torch_geometric/datasets/nell.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import os
import os.path as osp
import shutil
from typing import Callable, List, Optional

import torch

Expand Down Expand Up @@ -51,17 +52,22 @@ class NELL(InMemoryDataset):

url = 'http://www.cs.cmu.edu/~zhiliny/data/nell_data.tar.gz'

def __init__(self, root, transform=None, pre_transform=None):
def __init__(
self,
root: str,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
):
super().__init__(root, transform, pre_transform)
self.data, self.slices = torch.load(self.processed_paths[0])

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
names = ['x', 'tx', 'allx', 'y', 'ty', 'ally', 'graph', 'test.index']
return [f'ind.nell.0.001.{name}' for name in names]

@property
def processed_file_names(self):
def processed_file_names(self) -> str:
return 'data.pt'

def download(self):
Expand Down
15 changes: 11 additions & 4 deletions torch_geometric/datasets/ppi.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
import os.path as osp
from itertools import product
from typing import Callable, List, Optional

import numpy as np
import torch
Expand Down Expand Up @@ -59,8 +60,14 @@ class PPI(InMemoryDataset):

url = 'https://data.dgl.ai/dataset/ppi.zip'

def __init__(self, root, split='train', transform=None, pre_transform=None,
pre_filter=None):
def __init__(
self,
root: str,
split: str = 'train',
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):

assert split in ['train', 'val', 'test']

Expand All @@ -74,13 +81,13 @@ def __init__(self, root, split='train', transform=None, pre_transform=None,
self.data, self.slices = torch.load(self.processed_paths[2])

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
splits = ['train', 'valid', 'test']
files = ['feats.npy', 'graph_id.npy', 'graph.json', 'labels.npy']
return [f'{split}_{name}' for split, name in product(splits, files)]

@property
def processed_file_names(self):
def processed_file_names(self) -> str:
return ['train.pt', 'val.pt', 'test.pt']

def download(self):
Expand Down
15 changes: 11 additions & 4 deletions torch_geometric/datasets/qm7.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
from typing import Callable, Optional

import torch

from torch_geometric.data import Data, InMemoryDataset, download_url
Expand Down Expand Up @@ -42,17 +44,22 @@ class QM7b(InMemoryDataset):

url = 'https://deepchemdata.s3-us-west-1.amazonaws.com/datasets/qm7b.mat'

def __init__(self, root, transform=None, pre_transform=None,
pre_filter=None):
def __init__(
self,
root: str,
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):
super().__init__(root, transform, pre_transform, pre_filter)
self.data, self.slices = torch.load(self.processed_paths[0])

@property
def raw_file_names(self):
def raw_file_names(self) -> str:
return 'qm7b.mat'

@property
def processed_file_names(self):
def processed_file_names(self) -> str:
return 'data.pt'

def download(self):
Expand Down
18 changes: 13 additions & 5 deletions torch_geometric/datasets/zinc.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os.path as osp
import pickle
import shutil
from typing import Callable, List, Optional

import torch
from tqdm import tqdm
Expand Down Expand Up @@ -85,28 +86,35 @@ class ZINC(InMemoryDataset):
split_url = ('https://raw.githubusercontent.com/graphdeeplearning/'
'benchmarking-gnns/master/data/molecules/{}.index')

def __init__(self, root, subset=False, split='train', transform=None,
pre_transform=None, pre_filter=None):
def __init__(
self,
root: str,
subset: bool = False,
split: str = 'train',
transform: Optional[Callable] = None,
pre_transform: Optional[Callable] = None,
pre_filter: Optional[Callable] = None,
):
self.subset = subset
assert split in ['train', 'val', 'test']
super().__init__(root, transform, pre_transform, pre_filter)
path = osp.join(self.processed_dir, f'{split}.pt')
self.data, self.slices = torch.load(path)

@property
def raw_file_names(self):
def raw_file_names(self) -> List[str]:
return [
'train.pickle', 'val.pickle', 'test.pickle', 'train.index',
'val.index', 'test.index'
]

@property
def processed_dir(self):
def processed_dir(self) -> str:
name = 'subset' if self.subset else 'full'
return osp.join(self.root, name, 'processed')

@property
def processed_file_names(self):
def processed_file_names(self) -> List[str]:
return ['train.pt', 'val.pt', 'test.pt']

def download(self):
Expand Down