Skip to main content

A hybrid quantum-classic framework for quantum computing

Project description

MindQuantum

PyPI - Python Version PyPI Downloads API Tutorial Issues Release LICENSE PRs Welcome

查看中文

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.

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⟩

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')
Circuit SVG

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

  1. Beginner Tutorial

  2. Middle Level Tutorial

  3. Advanced Tutorial

Case Library

  1. General Quantum Algorithms

  2. NISQ Algorithms

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

  1. Clone source.

    cd ~
    git clone https://gitee.com/mindspore/mindquantum.git
    
  2. 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
    
  3. 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

Welcome to access the white paper of MindQuantum. When using MindQuantum for research, please cite:

@misc{xu2024mindspore,
      title={MindSpore Quantum: A User-Friendly, High-Performance, and AI-Compatible Quantum Computing Framework},
      author={Xusheng Xu and Jiangyu Cui and Zidong Cui and Runhong He and Qingyu Li and Xiaowei Li and Yanling Lin and Jiale Liu and Wuxin Liu and Jiale Lu and others},
      year={2024},
      eprint={2406.17248},
      archivePrefix={arXiv},
      primaryClass={quant-ph},
      url={https://arxiv.org/abs/2406.17248},
}

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.11.0-cp311-none-any.whl (5.2 MB view details)

Uploaded CPython 3.11

mindquantum-0.11.0-cp311-cp311-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.11Windows x86-64

mindquantum-0.11.0-cp311-cp311-manylinux1_x86_64.whl (163.6 MB view details)

Uploaded CPython 3.11

mindquantum-0.11.0-cp311-cp311-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.11macOS 11.0+ ARM64

mindquantum-0.11.0-cp311-cp311-macosx_10_15_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.11macOS 10.15+ x86-64

mindquantum-0.11.0-cp310-none-any.whl (5.2 MB view details)

Uploaded CPython 3.10

mindquantum-0.11.0-cp310-cp310-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.10Windows x86-64

mindquantum-0.11.0-cp310-cp310-manylinux1_x86_64.whl (163.6 MB view details)

Uploaded CPython 3.10

mindquantum-0.11.0-cp310-cp310-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

mindquantum-0.11.0-cp310-cp310-macosx_10_15_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.10macOS 10.15+ x86-64

mindquantum-0.11.0-cp39-none-any.whl (5.2 MB view details)

Uploaded CPython 3.9

mindquantum-0.11.0-cp39-cp39-win_amd64.whl (5.5 MB view details)

Uploaded CPython 3.9Windows x86-64

mindquantum-0.11.0-cp39-cp39-manylinux1_x86_64.whl (163.6 MB view details)

Uploaded CPython 3.9

mindquantum-0.11.0-cp39-cp39-macosx_11_0_arm64.whl (4.8 MB view details)

Uploaded CPython 3.9macOS 11.0+ ARM64

mindquantum-0.11.0-cp39-cp39-macosx_10_15_x86_64.whl (5.8 MB view details)

Uploaded CPython 3.9macOS 10.15+ x86-64

File details

Details for the file mindquantum-0.11.0-cp311-none-any.whl.

File metadata

  • Download URL: mindquantum-0.11.0-cp311-none-any.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.11
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for mindquantum-0.11.0-cp311-none-any.whl
Algorithm Hash digest
SHA256 a384a6a0bb65ab7c1915a5e134ee5824d87f28290ae0eca3902d7f4966f55b68
MD5 5c426289a21adc27ea2b81dca9136bec
BLAKE2b-256 27d945a44bfde45a5bad4f2fd5b1f3cb83ec718385d59a3a32bd5a8752f87cba

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp311-cp311-win_amd64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp311-cp311-win_amd64.whl
Algorithm Hash digest
SHA256 15f4a42d2a43c95d887409d02fe295c873bbf4749d34d63d505f3e8551c96c31
MD5 ead36b8c477b47cb5866104fd2c851e2
BLAKE2b-256 438fb8a0d8c95e558a39595d68480ef1efea9e652fda240e23a20c787f42357d

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp311-cp311-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp311-cp311-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 1f72f2f2ae8963dbb3ab477200a55fe567e777282601018425e4ce7567354cd1
MD5 8270fad5570c0d9205cdc96e2b52e87e
BLAKE2b-256 8afa123a090f582b15c30fa7a94cecb54079ad3efa2420ae997de3731ca210a8

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp311-cp311-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp311-cp311-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 44501a5b35db7cb3720f99d7abd5b59bdb7ae82da8251a6b80da42be28159974
MD5 6f5929a52df104f234cbeb0c0af17261
BLAKE2b-256 42b1651eefc81b8d41355b48089c3f904a62cd47baea33f8eac7966db7624c9b

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp311-cp311-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp311-cp311-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 3027b1a7f9f0b2de631432d557048fcf348f0946db238fd58c6d225406317d6f
MD5 50348606e60b63740c5d97a5f1625a19
BLAKE2b-256 74efeacecc0ce31b2c5c56e585fc39a41cc3626bcbf18d6720cc02162828d5d8

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp310-none-any.whl.

File metadata

  • Download URL: mindquantum-0.11.0-cp310-none-any.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.10
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for mindquantum-0.11.0-cp310-none-any.whl
Algorithm Hash digest
SHA256 543b28fb19587387e67c23ec9b7324a94ca149a1527cda624a0597b3a255cf78
MD5 eb4ad66e6decc89deaa0ebe0dd6067e2
BLAKE2b-256 b1b8017b98bb92a310ef15e021ff17220a20560661de65ac2fd905abfcb449d8

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp310-cp310-win_amd64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 c9aee0d32fe4057a2e4e2500582913e8052b99d77ccc34a6cbed008c5f0d329b
MD5 08f4f2dd7fe2d6a45f269a4d5c3de02d
BLAKE2b-256 d48f5ada1d790d101d11a3d486577c82889f2b8f387cc89034a30733dbe9bb80

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp310-cp310-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp310-cp310-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 3f272a862b9f155c88d8adc2d549a8d492c55690e24f505ac4e9a70a41976bae
MD5 059179ebb4c6e9adbbe56b47c68efa7b
BLAKE2b-256 f85e06afbbb5e549dde33bcccec019cf32810e5300c3341da9e8b6157870727d

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 2bdc674d09470564945a494f070729586a9e94b4fc8a5fb900f1c0aff0cbc666
MD5 014eb1856cc707adbdd906792eaec41a
BLAKE2b-256 95fb30f3e0494eb919e4b0f8be958ba1cd3f005b7f5131b2eebbf2fa8a9d7621

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp310-cp310-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp310-cp310-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 6c1812f9a716ca3f1deaa9c716aa449783edbb4ac9171368ef5113b26afcfef2
MD5 fe433edab2dc49dd6f74babe3930696a
BLAKE2b-256 08198d75e089c8778f9909a2946e68a29150a27121d4407c96ee7180c5052f60

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp39-none-any.whl.

File metadata

  • Download URL: mindquantum-0.11.0-cp39-none-any.whl
  • Upload date:
  • Size: 5.2 MB
  • Tags: CPython 3.9
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for mindquantum-0.11.0-cp39-none-any.whl
Algorithm Hash digest
SHA256 8bef7e27bc700eb8cea6d7e946eabe2910265fbaced25e77b308700538b76df6
MD5 242390fcab78982fa5fc7c0a716829fa
BLAKE2b-256 8b3d3c5e14e99643114d8743d056b240a9784955b7e374dde696d5ce985a9bdb

See more details on using hashes here.

File details

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

File metadata

  • Download URL: mindquantum-0.11.0-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 5.5 MB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.11.10

File hashes

Hashes for mindquantum-0.11.0-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 8adddacab2ae59c0f1a7cb0a82bfc3cc498117464a4bc672f0b77d49f3f96414
MD5 ebfb94a0bab9fc01146476695cb57bb3
BLAKE2b-256 1be16b955d8b205f73129bd219e39632839b43afa2fa72217f81d83556f38428

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp39-cp39-manylinux1_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp39-cp39-manylinux1_x86_64.whl
Algorithm Hash digest
SHA256 2378936c664334ea713898e19ade6680f97dbe1ac06b83ed6b870e811f2b0350
MD5 8a69aff1e2caecc99d3e4df7708f30c1
BLAKE2b-256 615ae4561c7ab2a8ec77d8dfb504b21ff8cf947c5cb27d839d0904bd890de797

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp39-cp39-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp39-cp39-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 e79ef997425845bf39a3cb31c6ae68fdfc5ca452f8e69bac5d9d1ef1bfd094bd
MD5 f909c2c683dc55cdcb13c57bdfd1c5f1
BLAKE2b-256 f98dbf05b0b78ea86c1e47da2bd9e059bd578b373d31a18cde0cd18af12ff161

See more details on using hashes here.

File details

Details for the file mindquantum-0.11.0-cp39-cp39-macosx_10_15_x86_64.whl.

File metadata

File hashes

Hashes for mindquantum-0.11.0-cp39-cp39-macosx_10_15_x86_64.whl
Algorithm Hash digest
SHA256 72a0e4026a2a721567acb6cb10e83332099537dd951621bc3dba6b17f61cbe75
MD5 1778fcd4cf860b8e99861acbab5db25b
BLAKE2b-256 e6df7d4b9e7676b15d20ba39d347d1c48ed2d17d975b8b9b043c1b24c47b43ba

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