Build and troubleshoot TorchDrug 0.2.1 workflows for molecular graphs, property prediction, self-supervised pretraining, molecule generation, retrosynthesis, protein representation learning, and knowledge graph reasoning. Use when code imports torchdrug or needs its datasets, models, tasks, or Engine.
npx skills add https://github.com/K-Dense-AI/scientific-agent-skills --skill torchdrug
Use TorchDrug as a modular PyTorch graph-learning stack:
datasets.* dataset,models.* representation model,tasks.* objective,core.Engine.The current official documentation and latest release are both 0.2.1. Treat
newer Python or PyTorch combinations as unverified rather than silently assuming
compatibility.
Before generating or debugging code, inspect the environment:
python --version
python -c "import torch; print(torch.__version__)"
python -c "import torchdrug; print(torchdrug.__version__)"
The supported matrix for TorchDrug 0.2.1 is:
If the project uses Python 3.11+ or PyTorch 2.1+, create a compatible environment
or explicitly test a source build. Do not present such combinations as supported.
Prefer a dedicated Python 3.10 environment and pin the TorchDrug release:
uv venv --python 3.10
source .venv/bin/activate
uv pip install "torch==2.0.0"
Install torch-scatter and torch-cluster wheels matched to the exact PyTorch
and CUDA pair, following the
official installation page. For a
CPU-only PyTorch 2.0 environment, one reproducible wheel combination is:
uv pip install "torch-scatter==2.1.1" "torch-cluster==1.6.1" \
--find-links "https://data.pyg.org/whl/torch-2.0.0+cpu.html"
uv pip install "torchdrug==0.2.1"
Do not copy a CUDA wheel URL between environments. Match the PyTorch version,
CUDA build, Python ABI, and platform. On Apple Silicon, the official docs require
building torch-scatter and torch-cluster from source; pin reviewed source
revisions and expect CPU execution.
Use the documented ClinTox → GIN → PropertyPrediction → Engine pattern:
import torch
from torchdrug import core, datasets, models, tasks
dataset = datasets.ClinTox("~/molecule-datasets/")
lengths = [int(0.8 * len(dataset)), int(0.1 * len(dataset))]
lengths.append(len(dataset) - sum(lengths))
train_set, valid_set, test_set = torch.utils.data.random_split(dataset, lengths)
model = models.GIN(
input_dim=dataset.node_feature_dim,
hidden_dims=[256, 256, 256, 256],
short_cut=True,
batch_norm=True,
concat_hidden=True,
)
task = tasks.PropertyPrediction(
model,
task=dataset.tasks,
criterion="bce",
metric=("auprc", "auroc"),
)
optimizer = torch.optim.Adam(task.parameters(), lr=1e-3)
solver = core.Engine(
task,
train_set,
valid_set,
test_set,
optimizer,
batch_size=1024,
)
solver.train(num_epoch=100)
solver.evaluate("valid")
Add gpus=[0] only when a supported CUDA device is available. Omit gpus for
CPU execution.
For binary classification, task.predict(batch) returns logits; apply
torch.sigmoid when probabilities are needed. In 0.2.1, normalized regression
predictions are returned on the original target scale, which is a breaking change
from older releases.
datasets.ClinTox, BBBP, Tox21, QM9, or another documentedmolecule dataset.
models.GIN; use edge_input_dim when the selected featureconfiguration supplies edge features.
tasks.PropertyPrediction.models.InfoGraph(gin_model, separate_model=False) wrapped bytasks.Unsupervised.
tasks.AttributeMasking(model, mask_rate=0.15).strict=False before training tasks.PropertyPrediction.
datasets.ZINC250k(..., kekulize=True, atom_feature="symbol").models.RGCN encoder wrapped by tasks.GCPNGeneration.models.GraphAF flows wrapped bytasks.AutoregressiveGeneration.
"qed" and "plogp";criteria are "nll" and/or "ppo".
datasets.USPTO50k views: reaction mode for centeridentification and as_synthon=True for synthon completion.
tasks.CenterIdentification and tasks.SynthonCompletion separately.tasks.Retrosynthesis; do not pass raw modelsdirectly to the end-to-end task.
datasets.FB15k237 → models.RotatE →tasks.KnowledgeGraphCompletion.
models.NeuralLP with fact_ratio=0.75.data.Protein.from_sequence, from_pdb, orfrom_molecule.
models.ESM, ProteinCNN, ProteinResNet,ProteinLSTM, and ProteinBERT; structure encoders include models.GearNet.
protein.residue_graph() convenience method.
site.
atom_feature, bond_feature,residue_feature, and mol_feature; node_feature, edge_feature, and
graph_feature are deprecated aliases in relevant dataset constructors.
Engine preprocess tasks. If composing pre-trained tasks withoutconstructing their solvers, call each task's preprocess() manually.
seed before splitting reaction and synthon datasets.
data.graph_collate or core.Engine;generic PyTorch collation does not know how to pack TorchDrug graphs.
code is passing task options to a model or passing raw models where a composed
task is required.
experimentally valid or synthesizable compounds.
Check Python, PyTorch, torch-scatter, and torch-cluster as one compatibility
set. Most failures are binary-wheel mismatches, unsupported Python versions, or
attempts to use MPS.
Build model dimensions from the loaded dataset:
dataset.node_feature_dimdataset.edge_feature_dimdataset.num_bond_typedataset.num_entity and dataset.num_relation for knowledge graphsDo not hard-code dimensions copied from a different feature configuration.
Pass gpus=[0] to core.Engine for supported CUDA execution. For manual
prediction, collate first and move the entire nested batch with utils.cuda.
Recreate the same model and feature configuration. For pretraining-to-fine-tuning
transfer, load the checkpoint's "model" state with strict=False; for a complete
solver, use solver.save() and solver.load().
Create new skills, modify and improve existing skills, and measure skill performance. Use when users want to create a skill from scratch, edit, or optimize an existing skill, run evals to test a skill, benchmark skill performance with variance analysis, or optimize a skill's description for better triggering accuracy.
Access NCBI GEO for gene expression/genomics data. Search/download microarray and RNA-seq datasets (GSE, GSM, GPL), retrieve SOFT/Matrix files, for transcriptomics and expression analysis.
Bayesian modeling with PyMC. Build hierarchical models, MCMC (NUTS), variational inference, LOO/WAIC comparison, posterior checks, for probabilistic programming and inference.
Multi-objective optimization framework. NSGA-II, NSGA-III, MOEA/D, Pareto fronts, constraint handling, benchmarks (ZDT, DTLZ), for engineering design and optimization problems.
Statistical modeling toolkit. OLS, GLM, logistic, ARIMA, time series, hypothesis tests, diagnostics, AIC/BIC, for rigorous statistical inference and econometric analysis.
Add unsigned integer (uint) type support to PyTorch operators by updating AT_DISPATCH macros. Use when adding support for uint16, uint32, uint64 types to operators, kernels, or when user mentions enabling unsigned types, barebones unsigned types, or uint support.
Convert PyTorch AT_DISPATCH macros to AT_DISPATCH_V2 format in ATen C++ code. Use when porting AT_DISPATCH_ALL_TYPES_AND*, AT_DISPATCH_FLOATING_TYPES*, or other dispatch macros to the new v2 API. For ATen kernel files, CUDA kernels, and native operator implementations.
Write docstrings for PyTorch functions and methods following PyTorch conventions. Use when writing or updating docstrings in PyTorch code.
Take k-dense-ai/torchdrug from the repository into ~/.claude/skills for personal
use, or into .claude/skills inside a project.
The agent identifies a skill by the name field in its header. Two skills with the
same name cannot sit side by side — one of them will be ignored.
The instructions reference pip, uv.
Without those the skill loads but fails at the first command.