{"id":25952411,"url":"https://github.com/junayed-hasan/quantum-machine-learning-qiskit-pytorch","last_synced_at":"2026-03-16T03:32:06.337Z","repository":{"id":225772464,"uuid":"766815525","full_name":"junayed-hasan/Quantum-Machine-Learning-Qiskit-PyTorch","owner":"junayed-hasan","description":"This repository contains codes and tutorials for quantum machine learning using PyTorch and Qiskit. It covers topics such as qiskit basics, deep learning fundamentals, and hybrid quantum-classical models. It also demonstrates how to use TorchQuantum, a PyTorch-based framework for quantum neural networks.","archived":false,"fork":false,"pushed_at":"2025-02-23T01:32:37.000Z","size":762,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-23T02:26:38.191Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/junayed-hasan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null}},"created_at":"2024-03-04T07:16:07.000Z","updated_at":"2025-02-23T01:32:41.000Z","dependencies_parsed_at":"2024-03-04T08:43:46.195Z","dependency_job_id":null,"html_url":"https://github.com/junayed-hasan/Quantum-Machine-Learning-Qiskit-PyTorch","commit_stats":null,"previous_names":["junayed-hasan/quantum-machine-learning-qiskit-pytorch"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning-Qiskit-PyTorch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning-Qiskit-PyTorch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning-Qiskit-PyTorch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/junayed-hasan%2FQuantum-Machine-Learning-Qiskit-PyTorch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/junayed-hasan","download_url":"https://codeload.github.com/junayed-hasan/Quantum-Machine-Learning-Qiskit-PyTorch/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241868475,"owners_count":20033822,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-04T14:51:08.946Z","updated_at":"2026-03-16T03:32:01.310Z","avatar_url":"https://github.com/junayed-hasan.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bridging Classical and Quantum Machine Learning \n\n[![arXiv](https://img.shields.io/badge/arXiv-2311.13810-b31b1b.svg)](https://arxiv.org/abs/2311.13810)\n\nWelcome to **Bridging Classical and Quantum Machine Learning**, a repository that combines **Qiskit basics** with **PyTorch-based** quantum–classical hybrid experiments. This project introduces how to leverage knowledge distillation to transfer capabilities from classical neural networks to resource-constrained quantum neural networks. In addition, the repository provides **Qiskit** fundamentals through the `Qiskit Basics.ipynb` notebook to help you get started with quantum computing concepts and simulations.\n\n---\n\n## Table of Contents\n\n1. [Motivation](#motivation)  \n2. [Architecture and Approach](#architecture-and-approach)  \n   - [Knowledge Distillation Method](#knowledge-distillation-method)  \n   - [Dimensionality Techniques](#dimensionality-techniques)  \n3. [Qiskit Basics](#qiskit-basics)  \n4. [Project Structure](#project-structure)  \n5. [Installation and Setup](#installation-and-setup)  \n6. [Usage](#usage)  \n7. [Experiments](#experiments)  \n   - [MNIST](#mnist)  \n   - [FashionMNIST](#fashionmnist)  \n8. [Results](#results)  \n9. [Citation](#citation)  \n10. [License](#license)  \n\n---\n\n## Motivation\n\nQuantum neural networks (QNNs) promise a new frontier in machine learning, potentially surpassing classical models when they have a similar number of parameters. However, challenges such as limited qubit availability, decoherence, and hardware noise make large-scale training of quantum models difficult. \n\nThis project addresses these obstacles by **transferring knowledge** from large, well-trained **classical** neural networks to **quantum** student models. Through knowledge distillation, we bypass the requirement of training large quantum networks, making it more feasible to reap the benefits of quantum computing for tasks like image classification.\n\n---\n\n## Architecture and Approach\n\n### Knowledge Distillation Method\n\nIn our paper, “Bridging Classical and Quantum Machine Learning: Knowledge Transfer From Classical to Quantum Neural Networks Using Knowledge Distillation,” we show how a **frozen classical CNN** (teacher) transfers knowledge to a **smaller quantum network** (student). Below is a high-level diagram illustrating the overall training scheme:\n\n![Quantum-Classical Knowledge Distillation Architecture](ss1.png)\n\nWe compare our **classical-to-quantum** knowledge distillation approach to (1) classical-to-classical and (2) quantum-to-quantum distillation methods:\n\n![Motivation and Different Distillation Strategies](ss2.png)\n\n1. **Teacher Model (Classical, Frozen)**  \n   - Typically a large CNN (e.g., LeNet, AlexNet).  \n2. **Student Model (Quantum, Trainable)**  \n   - A QNN with significantly fewer trainable parameters.  \n3. **Distillation Loss**  \n   - Minimizes KL divergence between teacher’s and student’s output logits.\n\n### Dimensionality Techniques\n\nBecause quantum circuits can only handle a limited number of qubits, we must **reduce input dimensionality** before encoding data into a quantum circuit. We experiment with several strategies:\n\n![Dimensionality Reduction for Quantum Processing](ss3.png)\n\n1. **Fully Connected (Flatten + FC):**  \n   - Flatten the image, project to \\(2^Q\\) features for \\(Q\\) qubits.  \n2. **Average/Max Pooling:**  \n   - Divide the image into \\(2^Q\\) regions and pool values.  \n3. **Center Crop:**  \n   - Crop the central \\(N \\times N\\) patch with \\(N^2 = 2^Q\\).  \n4. **PCA:**  \n   - Use Principal Component Analysis to extract \\(2^Q\\) components.\n\nBelow is an example of the **error rates** for different dimensionality strategies across MNIST, FashionMNIST, and CIFAR10 for 4-qubit and 8-qubit QNNs:\n\n![Error Comparison of Methods](ss4.png)\n\n---\n\n## Qiskit Basics\n\nAlongside our quantum–classical experiments, this repository includes a Jupyter notebook named **`Qiskit Basics.ipynb`**, where you can learn:\n\n- How to create quantum circuits using Qiskit  \n- Fundamental quantum operations (gates, measurements)  \n- Running quantum circuits on simulators  \n- (Optionally) deploying circuits on real quantum hardware\n\nThis serves as a gentle introduction to quantum computing concepts that underpin the experiments in the **student** QNN.\n\n---\n\n## Project Structure\n\n```\n.\n├── Qiskit Basics.ipynb                # Fundamentals of Qiskit\n├── MNIST Experiments\n│   ├── Teachers                       # Classical CNN teacher notebooks\n│   ├── Baseline students             # Quantum students without distillation\n│   └── Distillation on students      # Quantum students with knowledge distillation\n├── FashionMNIST Experiments\n│   ├── Teachers\n│   ├── Baseline students\n│   └── Distillation on students\n├── ss1.png                            # Architecture diagram\n├── ss2.png                            # Motivation \u0026 method comparison diagram\n├── ss3.png                            # Dimensionality reduction methods\n├── ss4.png                            # Error comparison chart\n└── README.md                          # You are here!\n```\n\n---\n\n## Installation and Setup\n\nTo run the experiments and Qiskit tutorials, you need:\n\n- **Python 3.7 or higher**\n- **PyTorch 1.8 or higher**\n- **Qiskit 0.25 or higher**  \n- **TorchQuantum 0.1.0 or higher**\n- **Jupyter Notebook or Jupyter Lab**\n\n### Quick Installation\n\n```bash\npip install torch            # For PyTorch\npip install qiskit           # For Qiskit\npip install torchquantum     # For TorchQuantum\npip install jupyter          # For notebooks\n```\n\n### Optional: Virtual Environment\n\nIt’s recommended to use a virtual environment:\n```bash\npython -m venv venv\nsource venv/bin/activate  # or venv\\Scripts\\activate on Windows\n```\nThen proceed with the installations within your virtual environment.\n\n---\n\n## Usage\n\n1. **Clone the Repository**  \n   ```bash\n   git clone https://github.com/your_username/quantum-machine-learning.git\n   cd quantum-machine-learning\n   ```\n\n2. **Launch Jupyter**  \n   ```bash\n   jupyter notebook  # or jupyter lab\n   ```\n3. **Open Notebooks**  \n   - `Qiskit Basics.ipynb` (to learn essential quantum operations).  \n   - `MNIST Experiments` or `FashionMNIST Experiments` notebooks (for classical teacher training, baseline quantum models, and knowledge-distilled quantum models).\n\nIf you prefer **Google Colab**, simply upload the notebooks and select the appropriate runtime.\n\n---\n\n## Experiments\n\n### MNIST\n\n1. **Teachers**  \n   - Train classical CNNs (LeNet, etc.) on MNIST.  \n2. **Baseline Students**  \n   - Train quantum models without using distillation.  \n3. **Distillation on Students**  \n   - Transfer knowledge from the frozen classical teacher to the quantum student.\n\n### FashionMNIST\n\nFollow the same process as MNIST but with FashionMNIST data:\n1. **Teachers**  \n2. **Baseline Students**  \n3. **Distillation on Students**  \n\nThese steps highlight how knowledge distillation improves QNN accuracy across different datasets.\n\n---\n\n## Results\n\n- **MNIST**: Average quantum model accuracy improves by **0.80%** with distillation.  \n- **FashionMNIST**: Average quantum model accuracy improves by **5.40%** with distillation.  \n- **CIFAR10** (in some ablation studies): Also shows enhancement, although absolute performance is more challenging due to dataset complexity.\n\nRefer to the **Error Comparison** chart (`ss4.png`) for a visual summary of various dimensionality reduction strategies and 4-qubit/8-qubit experiments.\n\n---\n\n## Citation\n\nIf you find this repository useful in your research, please consider citing our work:\n\n```bibtex\n@article{hasan2023bridging,\n  title={Bridging Classical and Quantum Machine Learning: Knowledge Transfer From Classical to Quantum Neural Networks Using Knowledge Distillation},\n  author={Hasan, Mohammad Junayed and Mahdy, MRC},\n  journal={arXiv preprint arXiv:2311.13810},\n  year={2023}\n}\n```\n\n---\n\n## License\n\nThis project is licensed under the **MIT License**. See the [LICENSE](LICENSE) file for details.  \n\n**Happy Quantum Coding!** If you have any questions or suggestions, feel free to open an issue or submit a pull request.\n\n\u0026copy; 2025 [Mohammad Junayed Hasan](https://www.linkedin.com/in/mjhasan21/)  \n\n---\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning-qiskit-pytorch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning-qiskit-pytorch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjunayed-hasan%2Fquantum-machine-learning-qiskit-pytorch/lists"}