Skip to main content

A hybrid quantum-classic framework for quantum computing

Project description

MindQuantum

查看中文

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. MindQuantum Architecture

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 to cp38-cp38 or cp39-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

Apache License 2.0

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

mindquantum-0.5.0-cp39-cp39-win_amd64.whl (909.5 kB view details)

Uploaded CPython 3.9Windows x86-64

mindquantum-0.5.0-cp37-cp37m-win_amd64.whl (909.3 kB view details)

Uploaded CPython 3.7mWindows x86-64

File details

Details for the file mindquantum-0.5.0-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: mindquantum-0.5.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 909.5 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.1

File hashes

Hashes for mindquantum-0.5.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 f1cfdb8dd61632c8c499968babacbe7398c0992d0230eed12d3e8471d1e72c89
MD5 255a33173176f406251045473f420613
BLAKE2b-256 4eed56822fae88b02e98c16442c3e7e1703cb86a463f0d5cad2eadede6a60739

See more details on using hashes here.

File details

Details for the file mindquantum-0.5.0-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: mindquantum-0.5.0-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 909.3 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.8.0 pkginfo/1.8.2 readme-renderer/33.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.8 tqdm/4.63.0 importlib-metadata/4.11.2 keyring/23.5.0 rfc3986/2.0.0 colorama/0.4.4 CPython/3.7.1

File hashes

Hashes for mindquantum-0.5.0-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 05d829adab6f0451e52e1fb935dd08538c7b13a0be2fab91b6d73657754cea13
MD5 ddd5ad8af56746b9c4bbde1b4300e0f3
BLAKE2b-256 0d6d5aad86ba8f79d05e378f2f7f07adeb518976fe8a93bcbc9be4005d9d1251

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page