Diff of /README.md [000000] .. [36b44b]

Switch to unified view

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