A hybrid quantum-classic framework for quantum computing
Project description
MindQuantum
- What is MindQuantum
- First experience
- API
- Installation
- Verifying Successful Installation
- Install with Docker
- Note
- Quick Start
- Docs
- Community
- Contributing
- License
What is MindQuantum
MindQuantum is a general quantum computing framework developed by MindSpore and HiQ, that can be used to build and train different quantum neural networks. Thanks to the powerful algorithm of quantum software group of Huawei and High-performance automatic differentiation ability of MindSpore, MindQuantum can efficiently handle problems such as quantum machine learning, quantum chemistry simulation, and quantum optimization, which provides an efficient platform for researchers, teachers and students to quickly design and verify quantum machine learning algorithms.
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⟩
Train quantum neural network
ansatz = CPN(encoder.hermitian(), {'a0': 'b0', 'a1': 'b1'})
sim = Simulator('projectq', 2)
ham = Hamiltonian(-QubitOperator('Z0 Z1'))
grad_ops = sim.get_expectation_with_grad(ham,
encoder + ansatz,
encoder_params_name=encoder.params_name,
ansatz_params_name=ansatz.params_name)
import mindspore as ms
ms.context.set_context(mode=ms.context.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}
API
For more API, please refers to MindQuantum API
Installation
Confirming System Environment Information
- The hardware platform should be Linux CPU with avx2 supported.
- Refer to MindQuantum Installation Guide, install MindSpore, version 1.3.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
pip install https://hiq.huaweicloud.com/download/mindspore/cpu/x86_64/mindspore-1.3.0-cp38-cp38-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
Install MindQuantum
- Linux
pip install https://hiq.huaweicloud.com/download/mindquantum/newest/linux/mindquantum-master-cp37-cp37m-linux_x86_64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
- Windows
pip install https://hiq.huaweicloud.com/download/mindquantum/newest/windows/mindquantum-master-cp37-cp37m-win_amd64.whl -i https://pypi.tuna.tsinghua.edu.cn/simple
- Change
cp37-cp37m
tocp38-cp38
orcp39-cp39
according to your python version.- When the network is connected, dependency items are automatically downloaded during .whl package installation. (For details about other dependency items, see setup.py). In other cases, you need to manually install dependency items.
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.
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.
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.5.0rc1-cp39-cp39-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4043fbfd191c1fb96c6c709b4afa49accae48290e01e7260f5f585a23745ed80 |
|
MD5 | bb32e450b8b913c67810ca964c9f25df |
|
BLAKE2b-256 | 4cc715a60ed44e16154478c61dbb6501ac7a663805e83ee16bdaf8a845d7cb10 |
Hashes for mindquantum-0.5.0rc1-cp37-cp37m-win_amd64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ffb0cc9ff182f7f4df46db110712efc151c1ea4f79e5526d609e140490db8757 |
|
MD5 | 4863bef1b8fdaca6bed54d85b874ac97 |
|
BLAKE2b-256 | fdc819f49c555fd554e85b769799bb61c6e5526d22fc4603ee116a98ac4ba5f6 |
Hashes for mindquantum-0.5.0rc1-cp37-cp37m-manylinux1_x86_64.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ee5346249ba7608bd67c3cbe2ab47177581389f6db783156c076d1f11251756 |
|
MD5 | ad94184cc4768b853343c47da3e3a98d |
|
BLAKE2b-256 | 41b636d56badaa9af0ec4cfad2c1b6f98b32f7c52911a3e35102360e521d6dc0 |