🧬 tox21_hybrid_quantum_model
A research pipeline building and validating a multi-task GNN-quantum architecture for toxicity prediction on the Tox21 dataset (12 simultaneous toxicity endpoints), tested against a parameter-matched classical control across multiple random seeds.
📋 Overview
This project builds a graph neural network (GNN) encoder that learns molecular representations directly from atomic and bond structure, feeding into an 8-qubit variational quantum circuit with 12 independent task heads. It is evaluated against a parameter-matched classical control and validated across multiple random seeds — the same statistical discipline expected of published QML benchmarking work.
🏗️ Architecture
- Stabilized GNN encoder — converts molecular graphs (atom features + adjacency matrix) into continuous latent vectors, replacing fixed Morgan fingerprints with learned structural representations.
- 8-qubit variational quantum circuit —
AngleEmbeddingfollowed by 4 layers ofRY/RZrotations andCNOTentangling gates. - Multi-head decoders — 12 isolated classical heads, one per toxicity task, to prevent negative transfer between unrelated assays.
- Training — weighted BCE loss, masked loss for missing per-task
labels, early stopping, gradient clipping,
ReduceLROnPlateau.
📊 Results
Multi-task GNN-quantum model (12 tasks, 3-seed validation)
| Model | Mean AUC (3 seeds) | Std |
|---|---|---|
| 8-qubit quantum-hybrid GNN | 0.6769 | ± 0.0204 |
| Parameter-matched classical GNN control | 0.6545 | ± 0.0262 |
Per-seed breakdown:
| Seed | Classical GNN | Quantum GNN |
|---|---|---|
| 42 | 0.6492 | 0.6487 |
| 101 | 0.6254 | 0.6856 |
| 777 | 0.6889 | 0.6964 |
Quantum led on 2 of 3 seeds and trailed narrowly on the third; the mean across seeds favors quantum, but the per-seed spread is exactly why the gap does not clear the variance threshold below.
Optimal decision threshold (G-mean optimized): 0.4066
The result is consistent with a competitive-but-unconfirmed pattern: the quantum-hybrid model scored higher on average across seeds. To check whether that gap reflects a real effect rather than a favorable split, it was tested against:
- A parameter-matched classical control — a classical block sized to match the quantum layer's trainable parameter count, not a bare linear layer, so the comparison isn't quantum vs. an artificially weak baseline.
- Multi-seed validation — the same experiment re-run across 3 random seeds to separate signal from seed-to-seed noise.
At this qubit count and dataset scale, the observed gap (+0.0224 AUC) sits inside the combined variance of both models' seed distributions. This project reports that plainly rather than rounding it up to a proven advantage — the willingness to run and report that check is part of what this repo is meant to demonstrate.
📁 Repo contents
tox21_hybrid_quantum_model.ipynb # main notebook — full pipeline
README.md
requirements.txt
.gitignore
expert_scaled_multihead_best.pth (trained weights) and
production_metadata_log.json (validation logs) are generated by the
notebook but excluded from version control by .gitignore — see Setup
below to regenerate them locally.
⚙️ Setup
- Clone the repo
pip install -r requirements.txt- Place
tox21.csv.gzin the same folder as the notebook (download here) - Run the notebook in Jupyter or Colab
Running in Colab: the first cell installs rdkit, pennylane, and
pennylane-lightning automatically — no local environment setup needed.
📦 Dependencies
torch>=2.0
pennylane>=0.35
pennylane-lightning
rdkit>=2023.03
scikit-learn
numpy
pandas
matplotlib
🔭 Next steps
- Scaffold-split evaluation (holding out entire molecule families) to test generalization beyond a random train/test split
- Additional seeds / a formal paired significance test to sharpen the confidence interval on the quantum-classical gap
- Evaluation on real quantum hardware rather than simulation
📄 License
MIT
Built With
- jupyter-notebook
Log in or sign up for Devpost to join the conversation.