|
a/README.md |
|
b/README.md |
1 |
[](https://torchdrug.ai/) |
1 |
|
2 |
<h1 align="center"> |
|
|
3 |
with |
|
|
4 |
<a href="https://torchprotein.ai/"> |
|
|
5 |
<img src="asset/torchprotein_logo_tight.svg" alt="TorchProtein" style="height:26px" /> |
|
|
6 |
</a> |
|
|
7 |
</h1> |
|
|
8 |
|
|
|
9 |
[](https://colab.research.google.com/drive/1Tbnr1Fog_YjkqU1MOhcVLuxqZ4DC-c8-#forceEdit=true&sandboxMode=true) |
2 |
[](https://colab.research.google.com/drive/1Tbnr1Fog_YjkqU1MOhcVLuxqZ4DC-c8-#forceEdit=true&sandboxMode=true)
|
10 |
[](https://github.com/DeepGraphLearning/torchdrug/blob/master/CONTRIBUTING.md) |
3 |
[](https://github.com/DeepGraphLearning/torchdrug/blob/master/CONTRIBUTING.md)
|
11 |
[](https://github.com/DeepGraphLearning/torchdrug/blob/master/LICENSE) |
4 |
[](https://github.com/DeepGraphLearning/torchdrug/blob/master/LICENSE)
|
12 |
[](https://pypi.org/project/torchdrug/) |
5 |
[](https://pypi.org/project/torchdrug/)
|
13 |
[](https://twitter.com/DrugTorch) |
6 |
[](https://twitter.com/DrugTorch) |
14 |
|
7 |
|
15 |
[Docs] | [Tutorials] | [Benchmarks] | [Papers Implemented] |
8 |
[Docs] | [Tutorials] | [Benchmarks] | [Papers Implemented] |
16 |
|
9 |
|
17 |
[Docs]: https://deepgraphlearning.github.io/torchdrug-site/docs |
10 |
[Docs]: https://deepgraphlearning.github.io/torchdrug-site/docs
|
18 |
[Tutorials]: https://deepgraphlearning.github.io/torchdrug-site/docs/tutorials |
11 |
[Tutorials]: https://deepgraphlearning.github.io/torchdrug-site/docs/tutorials
|
19 |
[Benchmarks]: https://deepgraphlearning.github.io/torchdrug-site/docs/benchmark |
12 |
[Benchmarks]: https://deepgraphlearning.github.io/torchdrug-site/docs/benchmark
|
20 |
[Papers Implemented]: https://deepgraphlearning.github.io/torchdrug-site/docs/paper |
13 |
[Papers Implemented]: https://deepgraphlearning.github.io/torchdrug-site/docs/paper |
21 |
|
14 |
|
22 |
TorchDrug is a [PyTorch]-based machine learning toolbox designed for several purposes. |
15 |
TorchDrug is a [PyTorch]-based machine learning toolbox designed for several purposes. |
23 |
|
16 |
|
24 |
- Easy implementation of graph operations in a PyTorchic style with GPU support |
17 |
- Easy implementation of graph operations in a PyTorchic style with GPU support
|
25 |
- Being friendly to practitioners with minimal knowledge about drug discovery |
18 |
- Being friendly to practitioners with minimal knowledge about drug discovery
|
26 |
- Rapid prototyping of machine learning research |
19 |
- Rapid prototyping of machine learning research |
27 |
|
20 |
|
28 |
[PyTorch]: https://pytorch.org/ |
21 |
[PyTorch]: https://pytorch.org/ |
29 |
|
22 |
|
30 |
Installation |
23 |
Installation
|
31 |
------------ |
24 |
------------ |
32 |
|
25 |
|
33 |
TorchDrug can be installed on either Linux, Windows or macOS. It is compatible with |
26 |
TorchDrug can be installed on either Linux, Windows or macOS. It is compatible with
|
34 |
3.7 <= Python <= 3.10 and PyTorch >= 1.8.0. |
27 |
3.7 <= Python <= 3.10 and PyTorch >= 1.8.0. |
35 |
|
28 |
|
36 |
### From Conda ### |
29 |
### From Conda ### |
37 |
|
30 |
|
38 |
```bash |
31 |
```bash
|
39 |
conda install torchdrug -c milagraph -c conda-forge -c pytorch -c pyg |
32 |
conda install torchdrug -c milagraph -c conda-forge -c pytorch -c pyg
|
40 |
``` |
33 |
``` |
41 |
|
34 |
|
42 |
### From Pip ### |
35 |
### From Pip ### |
43 |
|
36 |
|
44 |
```bash |
37 |
```bash
|
45 |
pip install torch==1.9.0 |
38 |
pip install torch==1.9.0
|
46 |
pip install torch-scatter torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html |
39 |
pip install torch-scatter torch-cluster -f https://pytorch-geometric.com/whl/torch-1.9.0+cu102.html
|
47 |
pip install torchdrug |
40 |
pip install torchdrug
|
48 |
``` |
41 |
``` |
49 |
|
42 |
|
50 |
To install `torch-scatter` for other PyTorch or CUDA versions, please see the |
43 |
To install `torch-scatter` for other PyTorch or CUDA versions, please see the
|
51 |
instructions in https://github.com/rusty1s/pytorch_scatter |
44 |
instructions in https://github.com/rusty1s/pytorch_scatter |
52 |
|
45 |
|
53 |
### From Source ### |
46 |
### From Source ### |
54 |
|
47 |
|
55 |
```bash |
48 |
```bash
|
56 |
git clone https://github.com/DeepGraphLearning/torchdrug |
49 |
git clone https://github.com/DeepGraphLearning/torchdrug
|
57 |
cd torchdrug |
50 |
cd torchdrug
|
58 |
pip install -r requirements.txt |
51 |
pip install -r requirements.txt
|
59 |
python setup.py install |
52 |
python setup.py install
|
60 |
``` |
53 |
``` |
61 |
|
54 |
|
62 |
### Windows (PowerShell) ### |
55 |
### Windows (PowerShell) ### |
63 |
|
56 |
|
64 |
We need to first install the build tools for Visual Studio. We then install the |
57 |
We need to first install the build tools for Visual Studio. We then install the
|
65 |
following modules in PowerShell. |
58 |
following modules in PowerShell. |
66 |
|
59 |
|
67 |
```powershell |
60 |
```powershell
|
68 |
Install-Module Pscx -AllowClobber |
61 |
Install-Module Pscx -AllowClobber
|
69 |
Install-Module VSSetup |
62 |
Install-Module VSSetup
|
70 |
``` |
63 |
``` |
71 |
|
64 |
|
72 |
Initialize Visual Studio in PowerShell with the following commands. We may setup |
65 |
Initialize Visual Studio in PowerShell with the following commands. We may setup
|
73 |
this for all PowerShell sessions by writing it to the PowerShell profile. Change |
66 |
this for all PowerShell sessions by writing it to the PowerShell profile. Change
|
74 |
the library path according to your own case. |
67 |
the library path according to your own case. |
75 |
|
68 |
|
76 |
```powershell |
69 |
```powershell
|
77 |
Import-VisualStudioVars -Architecture x64 |
70 |
Import-VisualStudioVars -Architecture x64
|
78 |
$env:LIB += ";C:\Program Files\Python37\libs" |
71 |
$env:LIB += ";C:\Program Files\Python37\libs"
|
79 |
``` |
72 |
``` |
80 |
|
73 |
|
81 |
### Apple Silicon (M1/M2 Chips) ### |
74 |
### Apple Silicon (M1/M2 Chips) ### |
82 |
|
75 |
|
83 |
We need PyTorch >= 1.13 to run TorchDrug on Apple silicon. For `torch-scatter` and |
76 |
We need PyTorch >= 1.13 to run TorchDrug on Apple silicon. For `torch-scatter` and
|
84 |
`torch-cluster`, they can be compiled from their sources. Note TorchDrug doesn't |
77 |
`torch-cluster`, they can be compiled from their sources. Note TorchDrug doesn't
|
85 |
support `mps` devices. |
78 |
support `mps` devices. |
86 |
|
79 |
|
87 |
```bash |
80 |
```bash
|
88 |
pip install torch==1.13.0 |
81 |
pip install torch==1.13.0
|
89 |
pip install git+https://github.com/rusty1s/pytorch_scatter.git |
82 |
pip install git+https://github.com/rusty1s/pytorch_scatter.git
|
90 |
pip install git+https://github.com/rusty1s/pytorch_cluster.git |
83 |
pip install git+https://github.com/rusty1s/pytorch_cluster.git
|
91 |
pip install torchdrug |
84 |
pip install torchdrug
|
92 |
``` |
85 |
``` |
93 |
|
86 |
|
94 |
Quick Start |
87 |
Quick Start
|
95 |
----------- |
88 |
----------- |
96 |
|
89 |
|
97 |
TorchDrug is designed for humans and focused on graph structured data. |
90 |
TorchDrug is designed for humans and focused on graph structured data.
|
98 |
It enables easy implementation of graph operations in machine learning models. |
91 |
It enables easy implementation of graph operations in machine learning models.
|
99 |
All the operations in TorchDrug are backed by [PyTorch] framework, and support GPU |
92 |
All the operations in TorchDrug are backed by [PyTorch] framework, and support GPU
|
100 |
acceleration and auto differentiation. |
93 |
acceleration and auto differentiation. |
101 |
|
94 |
|
102 |
```python |
95 |
```python
|
103 |
from torchdrug import data |
96 |
from torchdrug import data |
104 |
|
97 |
|
105 |
edge_list = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]] |
98 |
edge_list = [[0, 1], [1, 2], [2, 3], [3, 4], [4, 5], [5, 0]]
|
106 |
graph = data.Graph(edge_list, num_node=6) |
99 |
graph = data.Graph(edge_list, num_node=6)
|
107 |
graph = graph.cuda() |
100 |
graph = graph.cuda()
|
108 |
# the subgraph induced by nodes 2, 3 & 4 |
101 |
# the subgraph induced by nodes 2, 3 & 4
|
109 |
subgraph = graph.subgraph([2, 3, 4]) |
102 |
subgraph = graph.subgraph([2, 3, 4])
|
110 |
``` |
103 |
``` |
111 |
|
104 |
|
112 |
Molecules are also supported in TorchDrug. You can get the desired molecule |
105 |
Molecules are also supported in TorchDrug. You can get the desired molecule
|
113 |
properties without any domain knowledge. |
106 |
properties without any domain knowledge. |
114 |
|
107 |
|
115 |
```python |
108 |
```python
|
116 |
mol = data.Molecule.from_smiles("CCOC(=O)N", atom_feature="default", bond_feature="default") |
109 |
mol = data.Molecule.from_smiles("CCOC(=O)N", atom_feature="default", bond_feature="default")
|
117 |
print(mol.node_feature) |
110 |
print(mol.node_feature)
|
118 |
print(mol.atom_type) |
111 |
print(mol.atom_type)
|
119 |
print(mol.to_scaffold()) |
112 |
print(mol.to_scaffold())
|
120 |
``` |
113 |
``` |
121 |
|
114 |
|
122 |
You may also register custom node, edge or graph attributes. They will be |
115 |
You may also register custom node, edge or graph attributes. They will be
|
123 |
automatically processed during indexing operations. |
116 |
automatically processed during indexing operations. |
124 |
|
117 |
|
125 |
```python |
118 |
```python
|
126 |
with mol.edge(): |
119 |
with mol.edge():
|
127 |
mol.is_CC_bond = (mol.edge_list[:, :2] == td.CARBON).all(dim=-1) |
120 |
mol.is_CC_bond = (mol.edge_list[:, :2] == td.CARBON).all(dim=-1)
|
128 |
sub_mol = mol.subgraph(mol.atom_type != td.NITROGEN) |
121 |
sub_mol = mol.subgraph(mol.atom_type != td.NITROGEN)
|
129 |
print(sub_mol.is_CC_bond) |
122 |
print(sub_mol.is_CC_bond)
|
130 |
``` |
123 |
``` |
131 |
|
124 |
|
132 |
TorchDrug provides a wide range of common datasets and building blocks for drug |
125 |
TorchDrug provides a wide range of common datasets and building blocks for drug
|
133 |
discovery. With minimal code, you can apply standard models to solve your own |
126 |
discovery. With minimal code, you can apply standard models to solve your own
|
134 |
problem. |
127 |
problem. |
135 |
|
128 |
|
136 |
```python |
129 |
```python
|
137 |
import torch |
130 |
import torch
|
138 |
from torchdrug import datasets |
131 |
from torchdrug import datasets |
139 |
|
132 |
|
140 |
dataset = datasets.Tox21() |
133 |
dataset = datasets.Tox21()
|
141 |
dataset[0].visualize() |
134 |
dataset[0].visualize()
|
142 |
lengths = [int(0.8 * len(dataset)), int(0.1 * len(dataset))] |
135 |
lengths = [int(0.8 * len(dataset)), int(0.1 * len(dataset))]
|
143 |
lengths += [len(dataset) - sum(lengths)] |
136 |
lengths += [len(dataset) - sum(lengths)]
|
144 |
train_set, valid_set, test_set = torch.utils.data.random_split(dataset, lengths) |
137 |
train_set, valid_set, test_set = torch.utils.data.random_split(dataset, lengths)
|
145 |
``` |
138 |
``` |
146 |
|
139 |
|
147 |
```python |
140 |
```python
|
148 |
from torchdrug import models, tasks |
141 |
from torchdrug import models, tasks |
149 |
|
142 |
|
150 |
model = models.GIN(dataset.node_feature_dim, hidden_dims=[256, 256, 256, 256]) |
143 |
model = models.GIN(dataset.node_feature_dim, hidden_dims=[256, 256, 256, 256])
|
151 |
task = tasks.PropertyPrediction(model, task=dataset.tasks) |
144 |
task = tasks.PropertyPrediction(model, task=dataset.tasks)
|
152 |
``` |
145 |
``` |
153 |
|
146 |
|
154 |
Training and inference are accelerated by multiple CPUs or GPUs. |
147 |
Training and inference are accelerated by multiple CPUs or GPUs.
|
155 |
This can be seamlessly switched in TorchDrug by just a line of code. |
148 |
This can be seamlessly switched in TorchDrug by just a line of code.
|
156 |
```python |
149 |
```python
|
157 |
from torchdrug import core |
150 |
from torchdrug import core |
158 |
|
151 |
|
159 |
# Single CPU / Multiple CPUs / Distributed CPUs |
152 |
# Single CPU / Multiple CPUs / Distributed CPUs
|
160 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer) |
153 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer)
|
161 |
# Single GPU |
154 |
# Single GPU
|
162 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0]) |
155 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0])
|
163 |
# Multiple GPUs |
156 |
# Multiple GPUs
|
164 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3]) |
157 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3])
|
165 |
# Distributed GPUs |
158 |
# Distributed GPUs
|
166 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3, 0, 1, 2, 3]) |
159 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, gpus=[0, 1, 2, 3, 0, 1, 2, 3])
|
167 |
``` |
160 |
``` |
168 |
|
161 |
|
169 |
Experiments can be easily tracked and managed through [Weights & Biases platform]. |
162 |
Experiments can be easily tracked and managed through [Weights & Biases platform].
|
170 |
```python |
163 |
```python
|
171 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, logger="wandb") |
164 |
solver = core.Engine(task, train_set, valid_set, test_set, optimizer, logger="wandb")
|
172 |
``` |
165 |
``` |
173 |
|
166 |
|
174 |
[Weights & Biases platform]: https://wandb.ai/ |
167 |
[Weights & Biases platform]: https://wandb.ai/ |
175 |
|
168 |
|
176 |
Contributing |
169 |
Contributing
|
177 |
------------ |
170 |
------------ |
178 |
|
171 |
|
179 |
Everyone is welcome to contribute to the development of TorchDrug. |
172 |
Everyone is welcome to contribute to the development of TorchDrug.
|
180 |
Please refer to [contributing guidelines](CONTRIBUTING.md) for more details. |
173 |
Please refer to [contributing guidelines](CONTRIBUTING.md) for more details. |
181 |
|
174 |
|
182 |
License |
175 |
License
|
183 |
------- |
176 |
------- |
184 |
|
177 |
|
185 |
TorchDrug is released under [Apache-2.0 License](LICENSE). |
178 |
TorchDrug is released under [Apache-2.0 License](LICENSE).
|