A hybrid quantum-classic framework for quantum computing
Project description
MindQuantum
- MindQuantum
What is MindQuantum
MindQuantum is a new-generation quantum computing framework based on MindSpore, focusing on the implementation of NISQ algorithms. It combines the HiQ high-performance quantum computing simulator with the parallel automatic differentiation capability of MindSpore. MindQuantum is easy-to-use with ultra-high performance. It can efficiently handle problems like quantum machine learning, quantum chemistry simulation, and quantum optimization. MindQuantum provides an efficient platform for researchers, teachers and students to quickly design and verify quantum algorithms, making quantum computing at your fingertips.
First experience
Build parameterized quantum circuit
The below example shows how to build a parameterized quantum circuit.
from mindquantum import *
import numpy as np
encoder = Circuit().h(0).rx({'a0': 2}, 0).ry('a1', 1)
print(encoder)
print(encoder.get_qs(pr={'a0': np.pi / 2, 'a1': np.pi / 2}, ket=True))
Then you will get,
┏━━━┓ ┏━━━━━━━━━━┓
q0: ──┨ H ┠─┨ RX(2*a0) ┠───
┗━━━┛ ┗━━━━━━━━━━┛
┏━━━━━━━━┓
q1: ──┨ RY(a1) ┠───────────
┗━━━━━━━━┛
-1/2j¦00⟩
-1/2j¦01⟩
-1/2j¦10⟩
-1/2j¦11⟩
In jupyter notebook, we can just call svg()
of any circuit to display the circuit in svg picture (dark
and light
mode are also supported).
circuit = (qft(range(3)) + BarrierGate(True)).measure_all()
circuit.svg() # circuit.svg('light')
Train quantum neural network
ansatz = CPN(encoder.hermitian(), {'a0': 'b0', 'a1': 'b1'})
sim = Simulator('mqvector', 2)
ham = Hamiltonian(-QubitOperator('Z0 Z1'))
grad_ops = sim.get_expectation_with_grad(
ham,
encoder.as_encoder() + ansatz.as_ansatz(),
)
import mindspore as ms
ms.set_context(mode=ms.PYNATIVE_MODE, device_target='CPU')
net = MQLayer(grad_ops)
encoder_data = ms.Tensor(np.array([[np.pi / 2, np.pi / 2]]))
opti = ms.nn.Adam(net.trainable_params(), learning_rate=0.1)
train_net = ms.nn.TrainOneStepCell(net, opti)
for i in range(100):
train_net(encoder_data)
print(dict(zip(ansatz.params_name, net.trainable_params()[0].asnumpy())))
The trained parameters are,
{'b1': 1.5720831, 'b0': 0.006396801}
Tutorials
-
Basic usage
-
Variational quantum algorithm
-
GENERAL QUANTUM ALGORITHM
API
For more API, please refer to MindQuantum API.
Installation
Confirming System Environment Information
- The hardware platform should be CPU with avx2 supported.
- Refer to MindQuantum Installation Guide, install MindSpore, version 1.4.0 or later is required.
- See setup.py for the remaining dependencies.
Install by Source Code
1.Download Source Code from Gitee
cd ~
git clone https://gitee.com/mindspore/mindquantum.git
2.Compiling MindQuantum
cd ~/mindquantum
bash build.sh
cd output
pip install mindquantum-*.whl
Install by pip
Install MindSpore
Please refer to MindSpore installation guide to install MindSpore that at least 1.4.0 version.
Install MindQuantum
pip install mindquantum
Build from source
-
Clone source.
cd ~ git clone https://gitee.com/mindspore/mindquantum.git
-
Build MindQuantum
For linux system, please make sure your cmake version >= 3.18.3, and then run code:
cd ~/mindquantum bash build.sh --gitee
Here
--gitee
is telling the script to download third party from gitee. If you want to download from github, you can ignore this flag. If you want to build under GPU, please make sure you have install CUDA 11.x and the GPU driver, and then run code:cd ~/mindquantum bash build.sh --gitee --gpu
For windows system, please make sure you have install MinGW-W64 and CMake >= 3.18.3, and then run:
cd ~/mindquantum ./build.bat /Gitee
For Mac system, please make sure you have install openmp and CMake >= 3.18.3, and then run:
cd ~/mindquantum bash build.sh --gitee
-
Install whl
Please go to output, and install mindquantum wheel package by
pip
.
Verifying Successful Installation
Successfully installed, if there is no error message such as No module named 'mindquantum' when execute the following command:
python -c 'import mindquantum'
Install with Docker
Mac or Windows users can install MindQuantum through Docker. Please refer to Docker installation guide
Note
Please set the parallel core number before running MindQuantum scripts. For example, if you want to set the parallel core number to 4, please run the command below:
export OMP_NUM_THREADS=4
For large servers, please set the number of parallel kernels appropriately according to the size of the model to achieve optimal results.
Building binary wheels
If you would like to build some binary wheels for redistribution, please have a look to our binary wheel building guide
Quick Start
For more details about how to build a parameterized quantum circuit and a quantum neural network and how to train these models, see the MindQuantum Tutorial.
Docs
More details about installation guide, tutorials and APIs, please see the User Documentation.
Community
Governance
Check out how MindSpore Open Governance works.
Contributing
Welcome contributions. See our Contributor Wiki for more details.
How to cite
When using MindQuantum for research, please cite:
@misc{mq_2021,
author = {MindQuantum Developer},
title = {MindQuantum, version 0.6.0},
month = {March},
year = {2021},
url = {https://gitee.com/mindspore/mindquantum}
}
License
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
Hashes for mindquantum-0.9.11-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d9d3dabce342ef69b7f348052e770adf2e3e0bf820268fe4b80efa6f6ba97fb7 |
|
MD5 | 6156ca92a3603bbd4b32dd2f2d8aea5d |
|
BLAKE2b-256 | 27e3dd4e39316c5375939a2ffd84944afc7cde803503a4f36be16e7935a369b4 |
Hashes for mindquantum-0.9.11-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a4dbadf6442e53b32b39f16cbc4d1f968e031872276393c692557c0e37f1777d |
|
MD5 | 7aaf274f654791eb9454bb2dc2e742f5 |
|
BLAKE2b-256 | 7f9a6d869a5e632b8a80f92ff9d4bd6c3dcae9e319c9fb0384b3bf9c81500cf2 |
Hashes for mindquantum-0.9.11-cp39-cp39-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1ff433337c1857442747e5c1fcf61f0fd6e67c5604b1ca3f3d41a9eef6ca83dd |
|
MD5 | d3f30c256dce17e97d5a27b66be8f4c4 |
|
BLAKE2b-256 | bd2d43ec318855d9782c2d2e1ffe8beb90483d051a0ab8423a70f3976ccda269 |
Hashes for mindquantum-0.9.11-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 69581bde442b18fd5f955b950945a2e141157d8edab558ae5de76939f8377b69 |
|
MD5 | 4bc7ab7b6145b134813e9a6006921ea0 |
|
BLAKE2b-256 | 45c43a9009b9ed105056a53bce835b088c0f05bce1d672f7eedc11bde55c33ce |
Hashes for mindquantum-0.9.11-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c5bed187de40800ffbde1bf9e69c41b4bb2a50ceb428b26a7deaf520ed4d96fa |
|
MD5 | f8539b21e6218d96da207750a911f6c5 |
|
BLAKE2b-256 | b35045f13fa43d3a6082c65c22ab247aa2b0bfcb0000f7cdc77c83170b00d831 |
Hashes for mindquantum-0.9.11-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a936570c5fdc6b1472d45148aceb979335387d57f6456246a13acb1c5758d995 |
|
MD5 | 40b5970f7f77a721f3dc66fb7c9bc29b |
|
BLAKE2b-256 | 2732ba830c40b8ec5a9058aa132886b29a0b16f0091211db41eedd1e4a5864bf |
Hashes for mindquantum-0.9.11-cp38-cp38-macosx_11_0_arm64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 139b94bd376950fa3c0e2a2c21b23c8a58dcb4b6a4dcf824da55a337ea653e34 |
|
MD5 | 2888db9f9a09d4aa20be7086006b0545 |
|
BLAKE2b-256 | eb8c081da6414057f2457d562acce6b6d6a7a67c0d5f8558bbfff181a77ef6c7 |
Hashes for mindquantum-0.9.11-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25a16c32be14199105512fd8a711b8c6510ecdc03fec4b24cc3e45ff34d5198c |
|
MD5 | 29bab7ee19a314461e6a0880053bb4c6 |
|
BLAKE2b-256 | fc99dcda119fe8f636ac072861c7102ce468d7d5ed6dfbcce6beeef312935196 |
Hashes for mindquantum-0.9.11-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2b502154ae78c79da0d8bb65f7b3bf0b27303ddc9e57d826a20c8af0726d22f6 |
|
MD5 | 9301b6e8bc11e978f85c9bdb516ab503 |
|
BLAKE2b-256 | 98a3d1140d8c6c2a6474fdb3f124ad74328446abb1229cfde11124b7d76a3092 |
Hashes for mindquantum-0.9.11-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9908e43308bf2fcb4164ab5462562ec065ac6391f1d468af54a279e1a9f506b6 |
|
MD5 | d46c0341ab6fa5a76d9e886f9c6656bd |
|
BLAKE2b-256 | d5fb6e03d9a8c4584183a1f1ca646cf354545f045684bc7fc4ef89d5ae37d92a |
Hashes for mindquantum-0.9.11-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81d251ef1af9e8531e25d9b95ce175e31e041b6ec2d28e3034cde36dc284ccdc |
|
MD5 | 2f06f6eaa2b18369aed958a460a4d818 |
|
BLAKE2b-256 | c9e5873fef7eba5ea7732f7c12099bbd9bc9698ffd960481a48efd34b8375164 |