Skip to main content

DeepQuantum for quantum computing

Project description

DeepQuantum

DeepQuantum logo

docs PyPI PyPI - Python Version License Downloads Downloads

DeepQuantum is a platform that integrates artificial intelligence (AI) and quantum computing (QC). It is an efficient programming framework designed for quantum machine learning and photonic quantum computing. By 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. This makes it ideal for developers to quickly get started and explore the field in depth. It also serves as a valuable learning platform for quantum computing enthusiasts.

Key Features

DeepQuantum architecture

  • AI-Enhanced Quantum Computing Framework: Seamlessly integrated with PyTorch, it utilizes technologies such as automatic differentiation, vectorized parallelism, and GPU acceleration for efficiency. It facilitates the easy construction of hybrid quantum-classical models, enabling end-to-end training and inference.
  • User-Friendly API Design: The API is designed to be simple and intuitive, making it easy to initialize quantum neural networks and providing flexibility in data encoding.
  • Photonic Quantum Computing Simulation: The Photonic module includes Fock, Gaussian and Bosonic backends, catering to different simulation needs in photonic quantum computing. It comes with built-in optimizers to support on-chip training of photonic quantum circuits.
  • Large-Scale Quantum Circuit Simulation: Based on tensor networks, it enables the simulation of 100+ qubits on a laptop, leading the industry in both simulation efficiency and scale.
  • Advanced Architecture for Cutting-Edge Algorithm Exploration: The 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.

Installation

Before installing DeepQuantum, we recommend first manually installing PyTorch 2. If the latest version of PyTorch is not compatible with your CUDA version, manually install a compatible PyTorch 2 version.

The PyTorch installation instructions currently recommend:

  1. Install Miniconda or Anaconda.
  2. Setup conda environment. For example, run conda create -n <ENV_NAME> python=3.10 and conda activate <ENV_NAME>.
  3. Install PyTorch following the PyTorch installation instructions. Currently, this suggests running conda install pytorch -c pytorch.

If you want to customize your installation, please follow the PyTorch installation instructions to build from source.

To install DeepQuantum with pip, run

pip install deepquantum
# or for developers
pip install deepquantum[dev]
# or use tsinghua source
pip install deepquantum -i https://pypi.tuna.tsinghua.edu.cn/simple

Alternatively, to install DeepQuantum from source, run

git clone https://github.com/TuringQ/deepquantum.git
cd deepquantum
pip install -e .
# or use tsinghua source
pip install -e . -i https://pypi.tuna.tsinghua.edu.cn/simple

Getting Started

To begin, please start with the tutorials (CN) on basics and photonic basics.

Below are some minimal demos to help you get started.

  • Quantum circuit
import deepquantum as dq
cir = dq.QubitCircuit(2)
cir.h(0)
cir.cnot(0, 1)
cir.rx(1, 0.2)
cir.observable(0)
print(cir())
print(cir.expectation())
  • Quantum circuit based on matrix product state

You can simply set mps=True in QubitCircuit and adjust the bond dimension chi to control the complexity.

cir = dq.QubitCircuit(2, mps=True, chi=4)
cir.h(0)
cir.cnot(0, 1)
cir.rx(1, 0.2)
cir.observable(0)
print(cir())
print(cir.expectation())
  • Photonic quantum circuit with the Fock backend, based on Fock basis state
cir = dq.QumodeCircuit(2, [1,1])
cir.dc([0,1])
cir.ps(0, 0.1)
cir.bs([0,1], [0.2,0.3])
print(cir())
print(cir.measure())
  • Photonic quantum circuit with the Fock backend, based on Fock state tensor
cir = dq.QumodeCircuit(2, [(1, [1,1])], basis=False)
cir.dc([0,1])
cir.ps(0, 0.1)
cir.bs([0,1], [0.2,0.3])
print(cir())
print(cir.measure())
  • Photonic quantum circuit with the Gaussian backend
cir = dq.QumodeCircuit(2, 'vac', cutoff=10, backend='gaussian')
cir.s(0, 0.1)
cir.d(1, 0.1)
cir.bs([0,1], [0.2,0.3])
print(cir())
print(cir.measure())
print(cir.photon_number_mean_var(wires=0))
print(cir.measure_homodyne(wires=1))
  • Photonic quantum circuit with the Bosonic backend
cir = dq.QumodeCircuit(2, 'vac', backend='bosonic')
cir.cat(0, 0.5, 0.0)
cir.gkp(1, 0.5, 0.5)
cir.bs([0,1], [0.2,0.3])
print(cir())
print(cir.photon_number_mean_var(wires=0))
print(cir.measure_homodyne(wires=1))
  • Pattern of measurement-based quantum computation
pattern = dq.Pattern(2)
# Hadamard gate on qubit 1
pattern.n(2)
pattern.e(1, 2)
pattern.m(1)
pattern.x(2, domain=1)
# CNOT
pattern.n([3,4])
pattern.e(2, 3)
pattern.e(0, 3)
pattern.e(3, 4)
pattern.m(2)
pattern.m(3)
pattern.x(4, domain=3)
pattern.z(4, domain=2)
pattern.z(0, domain=2)
print(abs(pattern().full_state))
  • Transpile quantum circuit to MBQC pattern
cir = dq.QubitCircuit(2)
cir.h(0)
cir.cnot(0, 1)
cir.rx(1, 0.2)
pattern = cir.pattern()
print(cir())
print(pattern().full_state)
print(cir() / pattern().full_state)
  • Distributed simulation of quantum circuit
import torch
# OMP_NUM_THREADS=2 torchrun --nproc_per_node=4 main.py
backend = 'gloo' # for CPU
# torchrun --nproc_per_node=4 main.py
backend = 'nccl' # for GPU
rank, world_size, local_rank = dq.setup_distributed(backend)
data = torch.arange(4, dtype=torch.float, requires_grad=True)
cir = dq.DistributedQubitCircuit(4)
cir.rylayer(encode=True)
cir.cnot_ring()
cir.observable(0)
cir.observable(1, 'x')
if backend == 'nccl':
    data = data.to(f'cuda:{local_rank}')
    cir.to(f'cuda:{local_rank}')
state = cir(data).amps
result = cir.measure(with_prob=True)
exp = cir.expectation().sum()
exp.backward()
if rank == 0:
    print(state)
    print(result)
    print(exp)
    print(data.grad)
dq.cleanup_distributed()
  • Distributed simulation of photonic quantum circuit
# OMP_NUM_THREADS=2 torchrun --nproc_per_node=4 main.py
backend = 'gloo' # for CPU
# torchrun --nproc_per_node=4 main.py
backend = 'nccl' # for GPU
rank, world_size, local_rank = dq.setup_distributed(backend)
nmode = 4
cutoff = 4
data = torch.arange(14, dtype=torch.float) / 10
cir = dq.DistributedQumodeCircuit(nmode, [0] * nmode, cutoff)
for i in range(nmode):
    cir.s(i, encode=True)
for i in range(nmode - 1):
    cir.bs([i, i + 1], encode=True)
if backend == 'nccl':
    data = data.to(f'cuda:{local_rank}')
    cir.to(f'cuda:{local_rank}')
state = cir(data).amps
result = cir.measure(with_prob=True)
if rank == 0:
    print(state)
    print(result)
dq.cleanup_distributed()

License

DeepQuantum is open source, released under the Apache License, Version 2.0.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

deepquantum-4.3.0.tar.gz (203.1 kB view details)

Uploaded Source

Built Distribution

deepquantum-4.3.0-py3-none-any.whl (209.0 kB view details)

Uploaded Python 3

File details

Details for the file deepquantum-4.3.0.tar.gz.

File metadata

  • Download URL: deepquantum-4.3.0.tar.gz
  • Upload date:
  • Size: 203.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for deepquantum-4.3.0.tar.gz
Algorithm Hash digest
SHA256 304debae48cbe8ff543406120bc0f390d1b45e692bb2250664964f3f0aab5d29
MD5 2a939a5af8639785dc99914427321c21
BLAKE2b-256 768878ba36dddc7f4aad4f02d6e371482b4e48ac6cf5c7145413c24be5843aad

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepquantum-4.3.0.tar.gz:

Publisher: publish-to-pypi-github-release.yml on TuringQ/deepquantum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file deepquantum-4.3.0-py3-none-any.whl.

File metadata

  • Download URL: deepquantum-4.3.0-py3-none-any.whl
  • Upload date:
  • Size: 209.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for deepquantum-4.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 783675b25fc447a97a0f838a6d57b549c60a6ea83100c7007c2327d65ee7a2bb
MD5 c0e67c7e4e91610323e64ec4fef5b310
BLAKE2b-256 2a500c2038b80592f4a40f5685f8e1da8aac0f62798ad136ff1ea7f4325b7e9b

See more details on using hashes here.

Provenance

The following attestation bundles were made for deepquantum-4.3.0-py3-none-any.whl:

Publisher: publish-to-pypi-github-release.yml on TuringQ/deepquantum

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page