Skip to content

Commit

Permalink
update v0.2.0, readme & tutorials
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiZhang-116-4 committed Oct 5, 2024
1 parent 08fdb04 commit 1376d09
Show file tree
Hide file tree
Showing 11 changed files with 654 additions and 549 deletions.
161 changes: 137 additions & 24 deletions quairkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,39 +47,151 @@
cd QuAIRKit
pip install -e .
Functionality
-------------
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.
```python
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
```
```text
tensor([1.0000, 0.4794, 0.8415, 0.0707])
```
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
```python
# 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])
```
```text
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`.
```python
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.
```python
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)
```
```text
state_vector
density_matrix
density_matrix
```
Global setup
------------
QuAIRKit provides global setup functions to set the default data type, device and random seed.
```python
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
`quairkit`: QuAIRKit source code
- ``ansatz``: module of circuit templates
- ``database``: module of useful matrices & sets
- ``operator``: module of quantum operators
- ``qinfo``: library of quantum algorithms & information tools
- ``circuit``: quantum circuit interface
- `database`: module of useful matrices & sets
- `loss`: module of quantum loss functions
- `qinfo`: library of quantum algorithms & information tools
- `circuit`: quantum circuit interface
Tutorials
---------
Check out the tutorial folder on `GitHub <https://github.com/QuAIR/QuAIRKit>`_ for more information.
Relations with Paddle Quantum
-----------------------------
- `Hamiltonian in QuAIRKit <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/Hamiltonian.ipynb>`_
- `Constructing Quantum Circuits in QuAIRKit <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/circuit.ipynb>`_
- `Measuring quantum states in QuAIRKit <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/measure.ipynb>`_
- `Quantum gates and quantum channels <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/operator.ipynb>`_
- `Quantum information tools <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/qinfo.ipynb>`_
- `Manipulation of Quantum States in QuAIRKit <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/state.ipynb>`_
- `Training parameterized quantum circuits <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/introduction/training.ipynb>`_
- `Batch Computation <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/feature/batch.ipynb>`_
- `Neural network setup customization <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/feature/custom.ipynb>`_
- `Introduction to qudit quantum computing <https://github.com/QuAIR/QuAIRKit/tree/v0.2.0/tutorials/feature/qudit.ipynb>`_
`Paddle Quantum <https://github.com/PaddlePaddle/Quantum>`_ is the world's first cloud-integrated
quantum machine learning platform based on Baidu PaddlePaddle. As most contributors to this project
are also contributors to Paddle Quantum, QuAIRKit incorporates key architectural elements and
interface designs from its predecessor. QuAIRKit focuses more on providing specialized tools and
resources for researchers and developers engaged in cutting-edge quantum algorithm design and
theoretical explorations in quantum information science.
"""

import os
Expand All @@ -103,10 +215,10 @@ def print_info() -> None:
r"""Print the information of QuAIRKit, its dependencies and current environment.
"""
import torch
import matplotlib
import numpy
import scipy
import matplotlib
import torch
print("\n---------VERSION---------")
print("quairkit:", __version__)
print("torch:", torch.__version__)
Expand All @@ -123,8 +235,9 @@ def print_info() -> None:
print("OS version:", platform.version())


import subprocess
import re
import subprocess

# stack overflow #4842448
print("---------DEVICE---------")
if platform.system() == "Windows":
Expand Down
Loading

0 comments on commit 1376d09

Please sign in to comment.