{"id":37080438,"url":"https://github.com/turingq/deepquantum","last_synced_at":"2026-04-24T15:01:32.073Z","repository":{"id":245308917,"uuid":"817413864","full_name":"TuringQ/deepquantum","owner":"TuringQ","description":"DeepQuantum for quantum computing","archived":false,"fork":false,"pushed_at":"2026-04-24T12:58:37.000Z","size":11596,"stargazers_count":75,"open_issues_count":4,"forks_count":17,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-04-24T13:31:03.402Z","etag":null,"topics":["photonic-quantum-computing","pytorch","quantum-computing","quantum-machine-learning"],"latest_commit_sha":null,"homepage":"https://deepquantum.turingq.com/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/TuringQ.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2024-06-19T16:48:45.000Z","updated_at":"2026-04-24T11:38:35.000Z","dependencies_parsed_at":"2024-07-18T07:00:51.219Z","dependency_job_id":"f332b511-1f68-486f-8f17-e0659ffbd309","html_url":"https://github.com/TuringQ/deepquantum","commit_stats":null,"previous_names":["turingq/deepquantum"],"tags_count":35,"template":false,"template_full_name":null,"purl":"pkg:github/TuringQ/deepquantum","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuringQ%2Fdeepquantum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuringQ%2Fdeepquantum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuringQ%2Fdeepquantum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuringQ%2Fdeepquantum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TuringQ","download_url":"https://codeload.github.com/TuringQ/deepquantum/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TuringQ%2Fdeepquantum/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":32228437,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-24T13:21:15.438Z","status":"ssl_error","status_checked_at":"2026-04-24T13:21:15.005Z","response_time":64,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["photonic-quantum-computing","pytorch","quantum-computing","quantum-machine-learning"],"created_at":"2026-01-14T09:45:53.801Z","updated_at":"2026-04-24T15:01:32.066Z","avatar_url":"https://github.com/TuringQ.png","language":"Jupyter Notebook","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DeepQuantum\n\n![DeepQuantum logo](docs/source/_static/assets/logo_light_v1.png)\n\n[![docs](https://img.shields.io/badge/docs-link-blue.svg)](https://dqapi.turingq.com/)\n[![PyPI](https://img.shields.io/pypi/v/deepquantum.svg?logo=pypi)](https://pypi.org/project/deepquantum/)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/deepquantum)\n[![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg?logo=apache)](./LICENSE)\n[![Downloads](https://img.shields.io/pypi/dm/deepquantum.svg)](https://pypi.org/project/deepquantum/)\n[![Downloads](https://static.pepy.tech/badge/deepquantum)](https://pepy.tech/project/deepquantum)\n\nDeepQuantum is a platform that integrates artificial intelligence (AI) and quantum computing (QC).\nIt is an efficient programming framework designed for quantum machine learning and photonic quantum computing.\nBy leveraging the PyTorch deep learning platform for QC, DeepQuantum provides a powerful and easy-to-use tool for creating and simulating quantum circuits and photonic quantum circuits.\nThis makes it ideal for developers to quickly get started and explore the field in depth.\nIt also serves as a valuable learning platform for quantum computing enthusiasts.\n\n# Key Features\n\n![DeepQuantum architecture](docs/source/_static/assets/architecture.png)\n\n- **AI-Enhanced Quantum Computing Framework**:\nSeamlessly integrated with PyTorch, it utilizes technologies such as automatic differentiation, vectorized parallelism, and GPU acceleration for efficiency.\nIt facilitates the easy construction of hybrid quantum-classical models, enabling end-to-end training and inference.\n- **User-Friendly API Design**:\nThe API is designed to be simple and intuitive, making it easy to initialize quantum neural networks and providing flexibility in data encoding.\n- **Photonic Quantum Computing Simulation**:\nThe Photonic module includes Fock, Gaussian and Bosonic backends, catering to different simulation needs in photonic quantum computing.\nIt comes with built-in optimizers to support on-chip training of photonic quantum circuits.\n- **Large-Scale Quantum Circuit Simulation**:\nLeveraging tensor network techniques, DeepQuantum enables approximate simulation of circuits with over 100 qubits on a single laptop.\nThrough a distributed parallel architecture and PyTorch's native communication protocol, it efficiently utilizes multi-node, multi-GPU computational power to boost large-scale quantum simulations.\nThese capabilities allow DeepQuantum to deliver industry-leading performance in both simulation scale and efficiency.\n- **Advanced Architecture for Cutting-Edge Algorithm Exploration**:\nThe first framework to support algorithm design and mapping for time-domain-multiplexed photonic quantum circuits, and the first to realize closed-loop integration of quantum circuits, photonic quantum circuits, and MBQC, enabling robust support for both specialized and universal photonic quantum algorithm design.\n\n# Installation\n\n## 1. Prerequisites (PyTorch)\n\nDeepQuantum requires **PyTorch 2**.\nWe recommend installing it manually first to ensure compatibility with your system and CUDA version.\n\n0. **(Optional)** Install [uv](https://docs.astral.sh/uv/getting-started/installation/).\nWe strongly recommend using `uv` instead of standard `pip` for lightning-fast package installations.\n1. Install [Miniconda](https://www.anaconda.com/docs/getting-started/miniconda/main) or [Anaconda](https://www.anaconda.com/docs/getting-started/main).\n2. Create and activate a conda environment.\nFor example, run `conda create -n \u003cENV_NAME\u003e python=3.12` and `conda activate \u003cENV_NAME\u003e`.\n3. Install PyTorch following the [official instructions](https://pytorch.org/get-started/locally/).\nFor example, run `pip install torch` or `uv pip install torch`.\n\n*(Tip: Avoid using `conda install` with `uv`)*\n\n## 2. Install DeepQuantum\n\n### For Users (Stable Version)\n\nTo install DeepQuantum with `uv` or standard `pip`, run\n\n```bash\nuv pip install deepquantum\n\n# Or use a mirror site for faster download\nuv pip install deepquantum -i https://pypi.tuna.tsinghua.edu.cn/simple\n\n# Fallback for standard pip\npip install deepquantum\n```\n\n### For Developers (Source Installation)\n\nIf you intend to contribute to DeepQuantum or run unit tests, **we strongly recommend installing from source**.\n\n\u003e **Note on Dependencies**: `strawberryfields` and `thewalrus` on PyPI are outdated and may have compatibility issues with modern environments.\nFor development, our project is configured to automatically pull their latest GitHub `master` branches.\n\n#### Option A: Using `uv` (Recommended)\n\nSince you have `uv` installed, it will automatically handle the Git branch overrides defined in our `pyproject.toml`.\n\n```bash\ngit clone https://github.com/TuringQ/deepquantum.git\ncd deepquantum\n\nuv pip install -e \".[dev]\"\n\n# Or use a mirror site for faster download\nuv pip install -e \".[dev]\" -i https://pypi.tuna.tsinghua.edu.cn/simple\n```\n\n#### Option B: Using standard `pip`\n\nIf you prefer not to use `uv`, you must use our `requirements-dev.txt` to explicitly enforce the necessary Git overrides.\n\n```bash\ngit clone https://github.com/TuringQ/deepquantum.git\ncd deepquantum\n\npip install -e .\npip install -r requirements-dev.txt\n\n# Or use a mirror site for faster download\npip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple\npip install -r requirements-dev.txt -i https://pypi.tuna.tsinghua.edu.cn/simple\n```\n\n# Getting Started\n\nTo begin, please start with the tutorials (CN) on [basics](./tutorials/basics.ipynb) and [photonic basics](./tutorials/photonic_basics.ipynb).\n\nBelow are some minimal examples to help you get started.\n\n- Quantum circuit\n\n```python\nimport deepquantum as dq\n\ncir = dq.QubitCircuit(2)\ncir.h(0)\ncir.cnot(0, 1)\ncir.rx(1, 0.2)\ncir.observable(0)\nprint(cir())\nprint(cir.expectation())\n```\n\n- Quantum circuit based on matrix product state\n\nYou can simply set `mps=True` in `QubitCircuit` and adjust the bond dimension `chi` to control the complexity.\n\n```python\ncir = dq.QubitCircuit(2, mps=True, chi=4)\ncir.h(0)\ncir.cnot(0, 1)\ncir.rx(1, 0.2)\ncir.observable(0)\nprint(cir())\nprint(cir.expectation())\n```\n\n- Photonic quantum circuit with the Fock backend, based on Fock basis state\n\n```python\ncir = dq.QumodeCircuit(2, [1, 1])\ncir.dc([0, 1])\ncir.ps(0, 0.1)\ncir.bs([0, 1], [0.2, 0.3])\nprint(cir())\nprint(cir.measure())\n```\n\n- Photonic quantum circuit with the Fock backend, based on Fock state tensor\n\n```python\ncir = dq.QumodeCircuit(2, [(1, [1, 1])], basis=False)\ncir.dc([0, 1])\ncir.ps(0, 0.1)\ncir.bs([0, 1], [0.2, 0.3])\nprint(cir())\nprint(cir.measure())\n```\n\n- Photonic quantum circuit with the Gaussian backend\n\n```python\ncir = dq.QumodeCircuit(2, 'vac', cutoff=10, backend='gaussian')\ncir.s(0, 0.1)\ncir.d(1, 0.1)\ncir.bs([0, 1], [0.2, 0.3])\nprint(cir())\nprint(cir.measure())\nprint(cir.photon_number_mean_var(wires=0))\nprint(cir.measure_homodyne(wires=1))\n```\n\n- Photonic quantum circuit with the Bosonic backend\n\n```python\ncir = dq.QumodeCircuit(2, 'vac', backend='bosonic')\ncir.cat(0, 0.5, 0.0)\ncir.gkp(1, 0.5, 0.5)\ncir.bs([0, 1], [0.2, 0.3])\nprint(cir())\nprint(cir.photon_number_mean_var(wires=0))\nprint(cir.measure_homodyne(wires=1))\n```\n\n- Pattern of measurement-based quantum computation\n\n```python\npattern = dq.Pattern(2)\n# Hadamard gate on qubit 1\npattern.n(2)\npattern.e(1, 2)\npattern.m(1)\npattern.x(2, domain=1)\n# CNOT\npattern.n([3, 4])\npattern.e(2, 3)\npattern.e(0, 3)\npattern.e(3, 4)\npattern.m(2)\npattern.m(3)\npattern.x(4, domain=3)\npattern.z(4, domain=2)\npattern.z(0, domain=2)\nprint(abs(pattern().full_state))\n```\n\n- Transpile quantum circuit to MBQC pattern\n\n```python\ncir = dq.QubitCircuit(2)\ncir.h(0)\ncir.cnot(0, 1)\ncir.rx(1, 0.2)\npattern = cir.pattern()\nprint(cir())\nprint(pattern().full_state)\nprint(cir() / pattern().full_state)\n```\n\n- Distributed simulation of quantum circuit\n\n```python\nimport torch\n\n# OMP_NUM_THREADS=2 torchrun --nproc_per_node=4 main.py\nbackend = 'gloo'  # for CPU\n# torchrun --nproc_per_node=4 main.py\nbackend = 'nccl'  # for GPU\nrank, world_size, local_rank = dq.setup_distributed(backend)\nif backend == 'nccl':\n    device = f'cuda:{local_rank}'\nelif backend == 'gloo':\n    device = 'cpu'\ndata = torch.arange(4, dtype=torch.float, device=device, requires_grad=True)\ncir = dq.DistributedQubitCircuit(4)\ncir.rylayer(encode=True)\ncir.cnot_ring()\ncir.observable(0)\ncir.observable(1, 'x')\nif backend == 'nccl':\n    cir.to(f'cuda:{local_rank}')\nstate = cir(data).amps\nresult = cir.measure(with_prob=True)\nexp = cir.expectation().sum()\nexp.backward()\nif rank == 0:\n    print(state)\n    print(result)\n    print(exp)\n    print(data.grad)\ndq.cleanup_distributed()\n```\n\n- Distributed simulation of photonic quantum circuit\n\n```python\n# OMP_NUM_THREADS=2 torchrun --nproc_per_node=4 main.py\nbackend = 'gloo'  # for CPU\n# torchrun --nproc_per_node=4 main.py\nbackend = 'nccl'  # for GPU\nrank, world_size, local_rank = dq.setup_distributed(backend)\nnmode = 4\ncutoff = 4\ndata = torch.arange(14, dtype=torch.float) / 10\ncir = dq.DistributedQumodeCircuit(nmode, [0] * nmode, cutoff)\nfor i in range(nmode):\n    cir.s(i, encode=True)\nfor i in range(nmode - 1):\n    cir.bs([i, i + 1], encode=True)\nif backend == 'nccl':\n    data = data.to(f'cuda:{local_rank}')\n    cir.to(f'cuda:{local_rank}')\nstate = cir(data).amps\nresult = cir.measure(with_prob=True)\nif rank == 0:\n    print(state)\n    print(result)\ndq.cleanup_distributed()\n```\n\n# Contributing\n\nWe welcome contributions from the community!\nTo maintain high code quality and consistent style, we use a modern development workflow.\n\n[![Ruff](https://img.shields.io/endpoint?url=https://raw.githubusercontent.com/astral-sh/ruff/main/assets/badge/v2.json)](https://github.com/astral-sh/ruff)\n[![Jupytext](https://img.shields.io/badge/jupytext-enabled-blue)](https://github.com/mwouts/jupytext)\n[![pre-commit](https://img.shields.io/badge/pre--commit-enabled-brightgreen?logo=pre-commit)](https://github.com/pre-commit/pre-commit)\n\nPlease refer to our **[CONTRIBUTING.md](./CONTRIBUTING.md)** for detailed instructions on:\n- **Linting \u0026 Formatting**: Our coding standards using Ruff.\n- **Notebook Management**: How we sync `.ipynb` and `.py` files using Jupytext.\n- **Pull Request Process**: How to link issues and submit your changes.\n\nBefore your first commit, remember to run `pre-commit install` in your local environment.\n\n# Citation\n\nIf you use DeepQuantum in your research, please cite [our paper](https://arxiv.org/abs/2512.18995):\n\n```bibtex\n@article{he2025deepquantum,\n  title={DeepQuantum: A PyTorch-based Software Platform for Quantum Machine Learning and Photonic Quantum Computing},\n  author={He, Jun-Jie and Hu, Ke-Ming and Zhu, Yu-Ze and Yan, Guan-Ju and Liang, Shu-Yi and Zhao, Xiang and Wang, Ding and Guo, Fei-Xiang and Lan, Ze-Feng and Shang, Xiao-Wen and others},\n  journal={arXiv preprint arXiv:2512.18995},\n  year={2025}\n}\n```\n\n# Star History\n\n[![Stargazers over time](https://starchart.cc/TuringQ/deepquantum.svg?variant=adaptive)](https://starchart.cc/TuringQ/deepquantum)\n\n# License\n\nDeepQuantum is open source, released under the Apache License, Version 2.0.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturingq%2Fdeepquantum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fturingq%2Fdeepquantum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fturingq%2Fdeepquantum/lists"}