This repository hosts an Advanced Quantum Machine Learning (QML) project designed for rigorous comparative analysis and reproducible research. It implements and benchmarks two leading NISQ-era paradigms:
Hybrid Variational Quantum Classifier (VQC): A trainable quantum-classical hybrid model optimized end-to-end using PyTorch and PennyLane.
Quantum Kernel Support Vector Machine (QSVM): A kernel-based model utilizing quantum feature maps from PennyLane and Qiskit, interfaced with a classical SVM from scikit-learn.
Status: Active Research & Development / Reproducible Benchmarking Framework
Primary Goal: To provide a statistically grounded, open-source comparison of VQC and QSVM stability and performance on binary classification tasks, emphasizing reproducibility and cross-platform execution.
| Component | Library/Framework | Description |
|---|---|---|
| VQC Training/Evaluation | PyTorch, PennyLane | Backpropagation and quantum differentiation |
| QSVM Training/Evaluation | PennyLane, Qiskit, Scikit-learn | Quantum kernel computation & classification |
| CLI Interface & Logging | Typer, Rich | Clean command execution and formatted logs |
| Configuration Management | PyYAML | Configurable experiment parameters |
| Numerical Processing | NumPy | Data preprocessing |
- Architecture:
HybridVariationalClassifier(inmodels.py) combines a quantum layer implemented withpennylane.QNodeand classical layers viatorch.nn.Module. - Ansatz:
build_variational_circuit(inqnn_layers.py) implements a configurable Hardware-Efficient Ansatz. - Optimization:
train_variational_model(intraining.py) usestorch.optim.Adam. - Execution:
evaluate_vqc(inevaluation.py) computes final metrics on the test set.
- Architecture:
QuantumKernelClassifier(inmodels.py) integratesqml.kernelswithsklearn.svm.SVC. - Feature Map:
build_kernel_qnode(inqnn_layers.py) defines theZZFeatureMap. - Execution:
evaluate_kernel(inevaluation.py) computes final metrics on the test set.
- Provides
trainandevaluatecommands for both models (vqc,kernel). - Integrates Typer for the CLI and
seed.pyfor global seed configuration.
- Author: Ahmad Rasidi
- Email: [email protected]
- GitHub: https://github.com/rasidi3112
License: MIT License
qml_app/
├─ config/
│ └─ default.yaml
├─ qml_app/
│ ├─ __init__.py
│ ├─ config.py
│ ├─ data.py
│ ├─ evaluation.py
│ ├─ main.py
│ ├─ models.py
│ ├─ qnn_layers.py
│ ├─ training.py
│ └─ utils/
│ ├─ __init__.py
│ ├─ config_utils.py
│ ├─ logging_utils.py
│ └─ seed.py
└─ requirements.txt
git clone https://github.com/rasidi3112/Quantum-Machine-Learning.git
cd Quantum-Machine-LearningmacOS / Linux:
python -m venv .venv
source .venv/bin/activateWindows:
python -m venv .venv
.venv\Scripts\activatepip install --upgrade pip
pip install -r requirements.txta. Hybrid Variational Quantum Classifier (VQC)
python -m qml_app.main train --model vqc --config config/default.yamlb. Quantum Kernel SVM (QSVM)
python -m qml_app.main train --model kernel --config config/default.yamlTip: Modify
config/default.yamlto change datasets, qubits, layers, batch size, etc.
python -m qml_app.main evaluate --model vqc --config config/default.yaml
python -m qml_app.main evaluate --model kernel --config config/default.yamlEvaluation results, including metrics and confusion matrices, are saved in artifacts/.
Device Selection:
- Apple M1/M2 →
device: mps - NVIDIA GPU →
device: cuda - CPU-only →
device: cpu
Shots:
shots=nullfor analytic/simulated mode (fast, ideal for CPU)shots=1024or higher for realistic sampling on quantum hardware
Artifacts: Check artifacts/ for trained models, metrics, ROC curves, and confusion matrices.
Note: Adjust
--deviceflag inconfig/default.yamlfor CPU or GPU.
Kernel folder:
# Convert or preprocess data with convert.py
python3 artifacts/kernel/convert.py
# Run custom scripts
python3 artifacts/kernel/script.pyVQC folder:
# Convert PyTorch model to JSON format
python3 artifacts/vqc/convert_pt_to_json.pyGenerate boxplots for VQC and QSVM results:
python generate_boxplots.py





