Skip to main content

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 the MindSpore installation guide to install an appropriate version of MindSpore.

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

Release files for mindquantum 0.12.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distributions (wheels)

Table of built distributions (wheels) for mindquantum 0.12.0
File
mindquantum-0.12.0-cp311-none-any.whl CPython 3.11 none any Details
mindquantum-0.12.0-cp311-cp311-win_amd64.whl CPython 3.11 CPython 3.11 Windows x86-64 Details
mindquantum-0.12.0-cp311-cp311-manylinux1_x86_64.whl CPython 3.11 CPython 3.11 Linux glibc 2.5+ x86-64 Details
mindquantum-0.12.0-cp311-cp311-macosx_11_0_arm64.whl CPython 3.11 CPython 3.11 macOS 11.0+ ARM64 Details
mindquantum-0.12.0-cp311-cp311-macosx_10_15_x86_64.whl CPython 3.11 CPython 3.11 macOS 10.15+ x86-64 Details
mindquantum-0.12.0-cp310-none-any.whl CPython 3.10 none any Details
mindquantum-0.12.0-cp310-cp310-win_amd64.whl CPython 3.10 CPython 3.10 Windows x86-64 Details
mindquantum-0.12.0-cp310-cp310-manylinux1_x86_64.whl CPython 3.10 CPython 3.10 Linux glibc 2.5+ x86-64 Details
mindquantum-0.12.0-cp310-cp310-macosx_11_0_arm64.whl CPython 3.10 CPython 3.10 macOS 11.0+ ARM64 Details
mindquantum-0.12.0-cp310-cp310-macosx_10_15_x86_64.whl CPython 3.10 CPython 3.10 macOS 10.15+ x86-64 Details
mindquantum-0.12.0-cp39-none-any.whl CPython 3.9 none any Details
mindquantum-0.12.0-cp39-cp39-win_amd64.whl CPython 3.9 CPython 3.9 Windows x86-64 Details
mindquantum-0.12.0-cp39-cp39-manylinux1_x86_64.whl CPython 3.9 CPython 3.9 Linux glibc 2.5+ x86-64 Details
mindquantum-0.12.0-cp39-cp39-macosx_11_0_arm64.whl CPython 3.9 CPython 3.9 macOS 11.0+ ARM64 Details
mindquantum-0.12.0-cp39-cp39-macosx_10_15_x86_64.whl CPython 3.9 CPython 3.9 macOS 10.15+ x86-64 Details

Total release size: 696.7 MB

Release files / mindquantum-0.12.0-cp311-none-any.whl

Download URL mindquantum-0.12.0-cp311-none-any.whl
Size 15.1 MB
Tags CPython 3.11
SHA-256 checksum
How to use checksums
c35a301fd7c7cd828d194633802c5500d64abdde9744de23b3d9dfd3f39fbd3a
BLAKE2b-256 checksum
How to use checksums
7b63f42cb1c7dad784493d50451e4a55b8f1784a587547d330a13ca4fce7462e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp311-cp311-win_amd64.whl

Download URL mindquantum-0.12.0-cp311-cp311-win_amd64.whl
Size 12.7 MB
Tags CPython 3.11 Windows x86-64
SHA-256 checksum
How to use checksums
a753767549c7b06b00b3652627a6a2aac5d4c2a8855b16d7bb6c23461206d66a
BLAKE2b-256 checksum
How to use checksums
56c5b8e76f64f00f79552797f07017fcd3f80fea51e9e870bd9f0bfcf4126809
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp311-cp311-manylinux1_x86_64.whl

Download URL mindquantum-0.12.0-cp311-cp311-manylinux1_x86_64.whl
Size 173.0 MB
Tags CPython 3.11 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
e0fad57dab858a5274ec296a8e234594fe05cd61e172719886b2e9526aff8146
BLAKE2b-256 checksum
How to use checksums
8c4a61f24b0b2d21111b0019eb2b79070a0967673087e72373bf44518cc9c7b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp311-cp311-macosx_11_0_arm64.whl

Download URL mindquantum-0.12.0-cp311-cp311-macosx_11_0_arm64.whl
Size 14.9 MB
Tags CPython 3.11 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d996da13932b2a88553876d2170a2fa326d6715f6c70231177c8ffcdf7e141a9
BLAKE2b-256 checksum
How to use checksums
8017dfa4e4ccc6d81e112754cd7a08bc50b229e9523d0658be494505bb3cad04
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp311-cp311-macosx_10_15_x86_64.whl

Download URL mindquantum-0.12.0-cp311-cp311-macosx_10_15_x86_64.whl
Size 16.7 MB
Tags CPython 3.11 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
798ea2d2996bc9661b5236e289e2cfed1bfe026c48d321c5517103b5d3c382f5
BLAKE2b-256 checksum
How to use checksums
0b9db40f4abe95f2b2849ffd24dc4d5beb93550eeb53b3eb071e352822e6ff52
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp310-none-any.whl

Download URL mindquantum-0.12.0-cp310-none-any.whl
Size 15.1 MB
Tags CPython 3.10
SHA-256 checksum
How to use checksums
763494302a3cca17e877f3b411c122a571507b54f2068e0155a2395f5c7d5fef
BLAKE2b-256 checksum
How to use checksums
b8e147f59659239a82e8a5b261fe6a1ebc15885e088a3d1f1400542a09b65b8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp310-cp310-win_amd64.whl

Download URL mindquantum-0.12.0-cp310-cp310-win_amd64.whl
Size 12.6 MB
Tags CPython 3.10 Windows x86-64
SHA-256 checksum
How to use checksums
5468df4f363a46dadfc5efabab3b8d913f92a0ea61601564cccceff921c8c923
BLAKE2b-256 checksum
How to use checksums
bbde129a8e49eb20b09977986f8791d645f817dc0c2a6d639eb63a616349be28
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp310-cp310-manylinux1_x86_64.whl

Download URL mindquantum-0.12.0-cp310-cp310-manylinux1_x86_64.whl
Size 173.0 MB
Tags CPython 3.10 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
79b3b12be5bc10245feb3b0d93c3edd9c6e6cb1337f95e6cb1172fe3a3918e12
BLAKE2b-256 checksum
How to use checksums
8babd1d9cc4ea3c502130e44e6dfa780a91acd0a1bad0e5f3fd3a5fb1bc8b954
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp310-cp310-macosx_11_0_arm64.whl

Download URL mindquantum-0.12.0-cp310-cp310-macosx_11_0_arm64.whl
Size 14.7 MB
Tags CPython 3.10 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
595020be29830aa4bc463afd8b125aa4302b521c598649c54561f6a0f3aff566
BLAKE2b-256 checksum
How to use checksums
250b2d10eeb49860539a3fc1856a8f58cbb155e9be4b46fd8f297e4c1730500d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp310-cp310-macosx_10_15_x86_64.whl

Download URL mindquantum-0.12.0-cp310-cp310-macosx_10_15_x86_64.whl
Size 16.7 MB
Tags CPython 3.10 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
9e638e127e0a7600b3e5087ce3f0ee130ddf7700c1787ceb4b476597535d2ef1
BLAKE2b-256 checksum
How to use checksums
8de655cc8a8a9efe352c3b94de94de03ac3d2aad090ad4cda73de7d77448f668
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp39-none-any.whl

Download URL mindquantum-0.12.0-cp39-none-any.whl
Size 15.1 MB
Tags CPython 3.9
SHA-256 checksum
How to use checksums
accee49e1fb7eaa472837e6bc24f979a442bc11fc4d8e83bb867dc990c5263dd
BLAKE2b-256 checksum
How to use checksums
50548814a425f4a499bb0143f495daca4d3fe4e84c231045d1fecab9fb822bff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp39-cp39-win_amd64.whl

Download URL mindquantum-0.12.0-cp39-cp39-win_amd64.whl
Size 12.7 MB
Tags CPython 3.9 Windows x86-64
SHA-256 checksum
How to use checksums
9c6c42802024300f5de619e43c4c2cc23deffee411f260d70ec6e53296e50e4f
BLAKE2b-256 checksum
How to use checksums
19a6f4cf1f83ff1f7f7aef58a45ff55533bcb127dbe29d45a1fb2f5c2ed0109f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp39-cp39-manylinux1_x86_64.whl

Download URL mindquantum-0.12.0-cp39-cp39-manylinux1_x86_64.whl
Size 173.0 MB
Tags CPython 3.9 Linux glibc 2.5+ x86-64
SHA-256 checksum
How to use checksums
ef8f1c9aef7d08de0bc2f078772cc0d35f0aec5caf949bcdea995ee7d5739ff1
BLAKE2b-256 checksum
How to use checksums
fa783006677b7a90d30bea19daf2e8e06be315597f1989ca8f317ae0dd5e7efb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp39-cp39-macosx_11_0_arm64.whl

Download URL mindquantum-0.12.0-cp39-cp39-macosx_11_0_arm64.whl
Size 14.9 MB
Tags CPython 3.9 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
1b826a6ba3268b1eb74447d517717a06e5deedfa26d249aadde2a425b1252294
BLAKE2b-256 checksum
How to use checksums
a2b562e2a1e7e46808eb16f3b5bf370afd7c88e1e8d4db184678bbe1bcd615d7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release files / mindquantum-0.12.0-cp39-cp39-macosx_10_15_x86_64.whl

Download URL mindquantum-0.12.0-cp39-cp39-macosx_10_15_x86_64.whl
Size 16.7 MB
Tags CPython 3.9 macOS 10.15+ x86-64
SHA-256 checksum
How to use checksums
3bc771c033412293559d5df36d92d52d037ceb5d3d722c13833be7864d5cd33a
BLAKE2b-256 checksum
How to use checksums
56ff96da2b09dae27c8cd7823b5175b18cb67fb14b62d282fd8ff10d09a82fe1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.11.10

Release history Release notifications | RSS feed

This release

0.12.0 This release

15 release files

0.9.0

11 release files

0.7.0

9 release files

0.6.0

3 release files

0.5.0

2 release files

0.3.1

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page