Skip to content

SQKQuantum is a new-generation quantum computing framework based on SQS, focusing on the implementation of NISQ algorithms

License

Notifications You must be signed in to change notification settings

sqklab/sqkquantum

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

sqkquantum

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

What is sqkquantum

sqkquantum is a new-generation quantum computing framework based on SQKQuantum, focusing on the implementation of NISQ algorithms. It combines the SQK high-performance quantum computing simulator with the parallel automatic differentiation capability of SQKQuantum. sqkquantum is easy-to-use with ultra-high performance. It can efficiently handle problems like quantum machine learning, quantum chemistry simulation, and quantum optimization. sqkquantum provides an efficient platform for researchers, teachers and students to quickly design and verify quantum algorithms, making quantum computing at your fingertips.

sqkquantum Architecture

First experience

Build parameterized quantum circuit

The below example shows how to build a parameterized quantum circuit.

from sqkquantum 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 SQKQUANTUM 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. Basic usage

  2. Variational quantum algorithm

  3. GENERAL QUANTUM ALGORITHM

API

For more API, please refer to sqkquantum API.

Installation

Confirming System Environment Information

  • The hardware platform should be CPU with avx2 supported.
  • Refer to sqkquantum Installation Guide, install SQKQuantum, 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://github.com/sqklab/sqkquantum.git

2.Compiling sqkquantum

cd ~/sqkquantum
bash build.sh
cd output
pip install sqkquantum-*.whl

Install by pip

Install SQKQuantum

Please refer to SQKQuantum installation guide to install SQKQuantum that at least 1.4.0 version.

Install sqkquantum

pip install sqkquantum

Build from source

  1. Clone source.

    cd ~
    git clone https://github.com/sqklab/sqkquantum.git
  2. Build sqkquantum

    For linux system, please make sure your cmake version >= 3.18.3, and then run code:

    cd ~/sqkquantum
    bash build.sh --github

    Here --github is telling the script to download third party from github. 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 ~/sqkquantum
    bash build.sh --github --gpu

    For windows system, please make sure you have install MinGW-W64 and CMake >= 3.18.3, and then run:

    cd ~/sqkquantum
    ./build.bat /Gitee

    For Mac system, please make sure you have install openmp and CMake >= 3.18.3, and then run:

    cd ~/sqkquantum
    bash build.sh --github
  3. Install whl

    Please go to output, and install sqkquantum wheel package by pip.

Verifying Successful Installation

Successfully installed, if there is no error message such as No module named 'sqkquantum' when execute the following command:

python -c 'import sqkquantum'

Install with Docker

Mac or Windows users can install sqkquantum through Docker. Please refer to Docker installation guide

Note

Please set the parallel core number before running sqkquantum 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 sqkquantum Tutorial.

Docs

More details about installation guide, tutorials and APIs, please see the User Documentation.

Community

Governance

Check out how SQKQuantum Open Governance works.

Contributing

Welcome contributions. See our Contributor Wiki for more details.

How to cite

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

License

Apache License 2.0

About

SQKQuantum is a new-generation quantum computing framework based on SQS, focusing on the implementation of NISQ algorithms

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published