Skip to main content

QuAIRKit is a Python research toolbox for developing quantum computing, quantum information, and quantum machine learning algorithms.

Project description

QuAIRKit

QuAIRKit is a Python research framework for quantum computing, quantum information, and quantum machine learning algorithm development. It focuses on flexible design, real-time simulation and rapid verification of quantum and classical algorithms.

Installation

The minimum Python environment for QuAIRKit is 3.8. We recommend installing QuAIRKit with Python 3.10.

conda create -n quair python=3.10
conda activate quair
conda install jupyter notebook

We recommend the following way of installing QuAIRKit with pip,

pip install quairkit

or download all the files and finish the installation locally,

git clone https://github.com/QuAIR/QuAIRKit
cd QuAIRKit
pip install -e .

Features

Batch computation

QuAIRKit supports batch computations for quantum circuit simulations, state measurement and quantum information processing. It is easy to use and can be customized for different quantum (machine learning) algorithms.

Below is an example of batch computation for quantum circuit simulation. Here a zero state is passed through four different quantum circuits, and compared with the target state.

import quairkit as qkit
from quairkit.database import *
from quairkit.qinfo import *

target_state = zero_state(1)
unitary_data = pauli_group(1)

cir = qkit.Circuit(1)
cir.oracle(unitary_data, 0)
cir.ry(param=[0, 1, 2, 3])

print(state_fidelity(cir(), target_state)) # zero-state input by default
tensor([1.0000, 0.4794, 0.8415, 0.0707])

Above output is equivalent to

\left|\bra{0} R_z(0)\,I \ket{0} \right|,\,\,
\left|\bra{0} R_z(1)\,X \ket{0} \right|,\,\,
\left|\bra{0} R_z(2)\,Y \ket{0} \right|,\,\,
\left|\bra{0} R_z(3)\,Z \ket{0} \right|

Qudit computation

QuAIRKit also supports batch computations for quantum circuit simulations and most of the quantum information processing tools in qudit quantum computing. Note that qudit computation can be used with batch computation, as shown below

# claim three systems, with 1 qubit and 1 qutrit
cir = qkit.Circuit(2, system_dim=[2, 3])

# apply the Heisenberg-Weyl operators on all systems
cir.oracle(heisenberg_weyl(6), [0, 1])

# apply the H gate on the first system, controlled by the second system
cir.control_oracle(h(), [1, 0])

# trace out the qutrit system and get the qubit state
traced_state = cir().trace(1)

print('The 6th and 7th state for the batched qubit state is', traced_state[5:7])
The 6th and 7th state for the batched qubit state is 
---------------------------------------------------
 Backend: density_matrix
 System dimension: [2]
 System sequence: [0]
 Batch size: [2]

 # 0:
[[1.+0.j 0.+0.j]
 [0.+0.j 0.+0.j]]
 # 1:
[[0.5+0.j 0.5+0.j]
 [0.5+0.j 0.5+0.j]]
---------------------------------------------------

Fast construction

QuAIRKit provides a fast and flexible way to construct quantum circuits, by self-managing the parameters. All parameters would be created randomly if not specified. QuAIRKit also supports built-in layer ansatzes, such as complex_entangled_layer.

cir = qkit.Circuit(3)

cir.h() # apply Hadamard gate on all qubits
cir.complex_entangled_layer(depth=3) # apply complex entangled layers of depth 3
cir.universal_three_qubits() # apply universal three-qubit gate with random parameters

qkit.Circuit is a child class of torch.nn.Module, so you can access its parameters and other attributes directly, or use it as a layer in a hybrid neural network.

Implicit transition

If you want to perform noise simulation or mixed-state-related tools, there is no need to specify the backend, or import other libraries. Just call the function, and QuAIRKit will transit the backend for you.

cir = qkit.Circuit(3)

cir.complex_entangled_layer(depth=3)
print(cir().backend)

# partial transpose on the first two qubits
print(cir().transpose([0, 1]).backend)

cir.depolarizing(prob=0.1)
print(cir().backend)
state_vector
density_matrix
density_matrix

Global setup

QuAIRKit provides global setup functions to set the default data type, device and random seed.

qkit.set_dtype('complex128') # default data type is complex64
qkit.set_device('cuda') # make sure CUDA is setup with torch
qkit.set_seed(73) # set seeds for all random number generators

Overall Structure

QuAIRKit provides the following functionalities,

  • Quantum neural network algorithm simulation
  • Quantum circuit simulation & visualization
  • Quantum channel simulation
  • Quantum algorithm/information tools

Modules

quairkit: QuAIRKit source code

  • database: module of useful matrices & sets
  • loss: module of quantum loss functions
  • qinfo: library of quantum algorithms & information tools
  • circuit: quantum circuit interface

Tutorials

Acknowledgement

We appreciate the kind support from the Sourcery AI that greatly enhances the coding & review quality of the QuAIRKit project.

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

quairkit-0.2.0.tar.gz (108.8 kB view details)

Uploaded Source

Built Distribution

quairkit-0.2.0-py3-none-any.whl (144.8 kB view details)

Uploaded Python 3

File details

Details for the file quairkit-0.2.0.tar.gz.

File metadata

  • Download URL: quairkit-0.2.0.tar.gz
  • Upload date:
  • Size: 108.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for quairkit-0.2.0.tar.gz
Algorithm Hash digest
SHA256 65212d2aefd6a25243926b107e16edf74bdef4b8d80235b065c20e2117a3345b
MD5 790f120f7f43c10d1e810ec1b48c47ab
BLAKE2b-256 1718770676fcc0a768eb8c0fde1f664f81c293edd5cd5d56674b2836fc70e198

See more details on using hashes here.

File details

Details for the file quairkit-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: quairkit-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 144.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.15

File hashes

Hashes for quairkit-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 18787271e50816f0ce78bd3e6a490f8b8c31e2d5ebd3c12808027fc4683fa14a
MD5 548481b1b2fccfc60f9c53f6b1e3de86
BLAKE2b-256 5d497229b62fe37ea77b52118dd922a3486a59681cba60294241d55051fd2506

See more details on using hashes here.

Supported by

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