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_gpu-0.8.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | c669077c9b254df5f2ac0d36e45fd0841d99c3e0671a810c8d6e2dde756e5349 |
|
MD5 | 42775c14f6774b9b79b571f87f980a0e |
|
BLAKE2b-256 | 7b509cbd90ab4ae4301132d9383722bd36144108bb630f9e2130f8911e8d03cc |
Hashes for mindquantum_gpu-0.8.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 249bf687d152303f05f1280bdc4c84c9466c2ac50b0d2af4174884d129bbfb15 |
|
MD5 | a646ce48f81fc745985c9b2d93b917a8 |
|
BLAKE2b-256 | 469979fb15a8a61a5bbbf130732f0a6c6f740ae612a36ada4378d1bdc99f2aa3 |
Hashes for mindquantum_gpu-0.8.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2231c39b6a1e915c75a4a5c9c3f952b67e7cd73d58b34b040d797a6f2ce9b5e2 |
|
MD5 | 793df80516af8a4c6fd166ce2c5b5459 |
|
BLAKE2b-256 | 73624ac5cc215b1096ebf985cf40333f0dcca62ada6ca96647b892ab0111c124 |
Hashes for mindquantum-0.8.0-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0b56a06e17b13d768d37b904133c2900e0889bb70e1e634f816a5775b68b153b |
|
MD5 | 85e09e2fb3909787ea8eaf85e2e3dd20 |
|
BLAKE2b-256 | e876d2b8ec57eeb8ed043399bf01d435c0783802802fddf166bf10e6707cf276 |
Hashes for mindquantum-0.8.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 47cead74a3f57185757f9ea15c538d1a7099f6b027916e258bad88c5327e9776 |
|
MD5 | 8a01afb7a5ace1edfe5da99ec3080380 |
|
BLAKE2b-256 | 30d0d608ed73431a6fda767f18960d78d88991505b91db7e124c9f7cbf83c6d4 |
Hashes for mindquantum-0.8.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | dd543981da53b0763f2575da6ecb6df78e1dd8dfaa5dc80aa45199ec457d8dd2 |
|
MD5 | 7dcffb1db33dab6abce26a8607a39694 |
|
BLAKE2b-256 | 66dd52f341bd879038a894fe9a85ce4ecb887481c0cac7da65be2f36ec93af74 |
Hashes for mindquantum-0.8.0-cp38-cp38-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | fcb769eb2997c34efe6dbe107aa640b5d26d463a44019a995ab24d0e4fe9c71a |
|
MD5 | afcc5ecb8741e02130dd110d83133540 |
|
BLAKE2b-256 | 61040fdb8f725d521d266f48e292cfd86561bbfd4e6bc6d8a2adef2f9a0387d5 |
Hashes for mindquantum-0.8.0-cp38-cp38-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e055c7c3505921ec7ebb4a8ebfd7a0552bddf53426fd5bbedb93bd3885b6e0f |
|
MD5 | 33cf00dd390594a3c0c39cc661468913 |
|
BLAKE2b-256 | 3ef84c5f7339864307213b47ee28ada65d3c1be2397f6263dfb84001fa616ed3 |
Hashes for mindquantum-0.8.0-cp38-cp38-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef4f997ddaa7fffddf73b0b6a7163c0abc0ea9a8aee72277758f54874866a44e |
|
MD5 | f05463f99b1ce0adfeef603aa8e3a4fa |
|
BLAKE2b-256 | bcec128b57c8697876ce1bb45ba43d5fd3f95ca41c3198dcd109ebbc771298a0 |
Hashes for mindquantum-0.8.0-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | d3881ba8adc6d28af14ad3d42507dd759f516d6d85d4fe4d06e135fa53f805d3 |
|
MD5 | bb161726a757fbab14ec9833f17cea58 |
|
BLAKE2b-256 | 6ed245b82560af916cf404e8fe89b1e25cc331b9f234e2c92d4f671040e1b23f |
Hashes for mindquantum-0.8.0-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b243e41305840444b57d75bd31ce35d769f234000f0bc3b564382a039c472dc4 |
|
MD5 | 784a9ba5375a77f3488d285728b19301 |
|
BLAKE2b-256 | e9d443aa2f521ae9bfa17e04d07504ed8fe61e5b2c5eb30686622e2a1c31b099 |
Hashes for mindquantum-0.8.0-cp37-cp37m-macosx_10_15_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 97a6d8b2e4ecdf9d628a43e4d5afcbb8e5421b99fc2bae4842ae7fd10a517d87 |
|
MD5 | 1862587a17ec0b2f07a6c4afb3a7881d |
|
BLAKE2b-256 | a3e7e76d61068f3ee072cd97b1dc0c94e09bba8f52b64f27523cf75ba1a03cb5 |