Skip to content

Commit

Permalink
update v0.3.0
Browse files Browse the repository at this point in the history
  • Loading branch information
LeiZhang-116-4 committed Dec 16, 2024
1 parent 194cd4a commit f17bd79
Show file tree
Hide file tree
Showing 47 changed files with 6,018 additions and 1,992 deletions.
2 changes: 1 addition & 1 deletion docs/update_quairkit_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ def _update_conf_py(source_directory: str = _sphinx_source_dir):
author = "QuAIR"
# The full version, including alpha/beta/rc tags
release = "0.2.0"
release = "0.3.0"
# -- General configuration ---------------------------------------------------
Expand Down
164 changes: 26 additions & 138 deletions quairkit/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,151 +47,39 @@
cd QuAIRKit
pip install -e .
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,
Functionality
-------------
- Quantum neural network algorithm simulation
- Quantum circuit simulation & visualization
- Quantum channel simulation
- Quantum algorithm/information tools
`quairkit`: QuAIRKit source code
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
- ``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
Tutorials
---------
- `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>`_
Check out the tutorial folder on `GitHub <https://github.com/QuAIR/QuAIRKit>`_ for more information.
Relations with Paddle Quantum
-----------------------------
`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 @@ -206,19 +94,20 @@
from . import loss
from . import qinfo
from .circuit import Circuit
from . import application

name = "quairkit"
__version__ = "0.2.0"
__version__ = "0.3.0"


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


import re
import subprocess

import re
# stack overflow #4842448
print("---------DEVICE---------")
if platform.system() == "Windows":
Expand Down
20 changes: 20 additions & 0 deletions quairkit/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# !/usr/bin/env python3
# Copyright (c) 2024 QuAIR team. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

r"""
The application library of QuAIRKit.
"""

from .comb import PQCombNet
20 changes: 20 additions & 0 deletions quairkit/application/comb/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# !/usr/bin/env python3
# Copyright (c) 2024 QuAIR team. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

r"""
The module of PQCombNet.
"""

from .comb import PQCombNet
Loading

0 comments on commit f17bd79

Please sign in to comment.