Skip to main content

Quantum circuit simulator for research

Project description

Qulacs

Ubuntu CI macOS CI Windows CI Wheel build Downloads

Qulacs is a Python/C++ library for fast simulation of large, noisy, or parametric quantum circuits. Qulacs is developed at QunaSys, Osaka University, and NTT.

Qulacs is licensed under the MIT license.

Quick Install for Python

pip install qulacs

If your CPU is older than Intel Haswell architecture, the binary installed with the above command does not work. In this case, please install Qulacs with the following command. Even if your CPU is newer than Haswell, Qulacs installed with the below command shows better performance but takes a longer time. See "Install Python library from source" section for detail.

pip install git+https://github.com/qulacs/qulacs.git

If you have NVIDIA GPU and CUDA is installed, GPU-version can be installed with the following command:

pip install qulacs-gpu

Features

Note Qulacs-Osaka/qulacs-osaka was integrated into the qulacs/qulacs. For more details, please refer to Information section.

  • Fast quantum circuit simulation with parallelized C/C++ backend
  • Noisy quantum gate for simulation of NISQ devices
  • Parametric quantum gates for variational methods
  • Circuit compression for fast simulation
  • GPU support for fast simulation
  • Many utility functions for research

Performance

The time for simulating random quantum circuits is compared with several quantum circuit simulators in November 2020.

See the benchmark repository and Section VI and VII of our paper for the detail of this benchmark.

Note that the plots with names ending with "opt" and "heavy opt" perform circuit optimization for fast simulation, where the time for optimization is included in the execution time.

Single-thread benchmark

single thread benchmark

Multi-thread benchmark

multi thread benchmark

GPU benchmark

GPU benchmark

Install Python library from source

To install Qulacs optimized for your system, we recommend the following install procedure for faster simulation of quantum circuits, while this requires a compiler and takes time for installation. In addition, you can enable or disable optimization features such as SIMD optimization, OpenMP parallelization, and GPU support.

A binary that is installed via pip command is optimized for Haswell architecture. Thus, Qulacs installed via pip command does not work with a CPU older than Haswell. If your CPU is newer than Haswell, Qualcs built from source shows the better performance.

Requirements

  • C++ compiler (gcc or VisualStudio)
    • gcc/g++ >= 7.0.0 (checked in Linux, MacOS, cygwin, MinGW, and WSL)
    • Microsoft VisualStudio C++ 2015 or later
  • Boost >= 1.71.0 (Minimum version tested in CI)
  • Python >= 3.7
  • CMake >= 3.0
  • git
  • (option) CUDA >= 8.0
  • (option) AVX2 support

If your system supports AVX2 instructions, SIMD optimization is automatically enabled. If you want to enable GPU simulator, install qulacs through qulacs-gpu package or build from source. Note that qulacs-gpu includes CPU simulator. You don't need to install both.

Qulacs is tested on the following systems.

  • Ubuntu 20.04
  • macOS Big Sur 11
  • Windows Server 2019

If you encounter some troubles, see troubleshooting.

How to install

Install with default options (Multi-thread without GPU):

python setup.py install

If AVX2 instructions are not supported, SIMD optimization is automatically disabled.

Install with GPU support (CUDA is required):

USE_GPU=Yes python setup.py install

Install single-thread Qulacs:

USE_OMP=No python setup.py install

The number of threads used in Qulacs installed with default options can be controlled via the environment variable OMP_NUM_THREADS. However, typically this option also affects the parallelization of other libraries. If you want to force only Qulacs to use a single thread, You can install single-thread Qulacs with the above command.

Uninstall Qulacs:

pip uninstall qulacs

Use Qualcs as C++ library

Build with GCC

Static libraries of Qulacs can be built with the following commands:

git clone https://github.com/qulacs/qulacs.git
cd qulacs
./script/build_gcc.sh

To build shared libraries, execute make shared at ./qulacs/build folder. When you want to build with GPU, use build_gcc_with_gpu.sh instead of build_gcc.sh.

Then, you can build your codes with the following gcc command:

g++ -O2 -I ./<qulacs_path>/include -L ./<qulacs_path>/lib <your_code>.cpp -lvqcsim_static -lcppsim_static -lcsim_static -fopenmp

If you want to run your codes with GPU, include cppsim/state_gpu.hpp and use QuantumStateGpu instead of QuantumState and build with the following command:

nvcc -O2 -I ./<qulacs_path>/include -L ./<qulacs_path>/lib <your_code>.cu -lvqcsim_static -lcppsim_static -lcsim_static -lgpusim_static -D _USE_GPU -lcublas -Xcompiler -fopenmp

Build with MSVC

Static libraries of Qulacs can be built with the following command:

git clone https://github.com/qulacs/qulacs.git
cd qulacs
script/build_msvc_2017.bat

When you want to build with GPU, use build_msvc_2017_with_gpu.bat. If you use MSVC with other versions, use build_msvc_2015.bat or edit the generator name in build_msvc_2017.bat.

Your C++ codes can be built with Qulacs with the following process:

  1. Create an empty project.
  2. Select "x64" as an active solution platform.
  3. Right Click your project name in Solution Explorer, and select "Properties".
  4. At "VC++ Directories" section, add the full path to ./qulacs/include to "Include Directories"
  5. At "VC++ Directories" section, add the full path to ./qulacs/lib to "Library Directories"
  6. At "C/C++ -> Code Generation" section, change "Runtime library" to "Multi-threaded (/MT)".
  7. At "Linker -> Input" section, add vqcsim_static.lib;cppsim_static.lib;csim_static.lib; to "Additional Dependencies".

Tutorial and API documents

See the following documents for tutorials.

Python sample code

from qulacs import Observable, QuantumCircuit, QuantumState
from qulacs.gate import Y,CNOT,merge

state = QuantumState(3)
state.set_Haar_random_state()

circuit = QuantumCircuit(3)
circuit.add_X_gate(0)
merged_gate = merge(CNOT(0,1),Y(1))
circuit.add_gate(merged_gate)
circuit.add_RX_gate(1,0.5)
circuit.update_quantum_state(state)

observable = Observable(3)
observable.add_operator(2.0, "X 2 Y 1 Z 0")
observable.add_operator(-3.0, "Z 2")
value = observable.get_expectation_value(state)
print(value)

If you want to run it on GPU, install GPU-enabled qulacs and replace QuantumState in the above codes with QuantumStateGpu.

C++ sample code

#include <iostream>
#include <cppsim/state.hpp>
#include <cppsim/circuit.hpp>
#include <cppsim/observable.hpp>
#include <cppsim/gate_factory.hpp>
#include <cppsim/gate_merge.hpp>

int main(){
    QuantumState state(3);
    state.set_Haar_random_state();

    QuantumCircuit circuit(3);
    circuit.add_X_gate(0);
    auto merged_gate = gate::merge(gate::CNOT(0,1),gate::Y(1));
    circuit.add_gate(merged_gate);
    circuit.add_RX_gate(1,0.5);
    circuit.update_quantum_state(&state);

    Observable observable(3);
    observable.add_operator(2.0, "X 2 Y 1 Z 0");
    observable.add_operator(-3.0, "Z 2");
    auto value = observable.get_expectation_value(&state);
    std::cout << value << std::endl;
    return 0;
}

If you place the above codes in the root directory of this repository(e.g., qulacs/main.cpp), you can build your codes with the following command:

g++ -O2 -I ./include -L ./lib main.cpp -fopenmp -lcppsim_static -lcsim_static

If you want to run it on GPU, include cppsim/state_gpu.hpp and replace QuantumState with QuantumStateGpu.

How to cite

Please cite this arXiv paper: Qulacs: a fast and versatile quantum circuit simulator for research purpose

Information

Experimental new features of Qulacs that have been developed in the Osaka University repository Qulacs-Osaka/qulacs-osaka will be integrated into the original Qulacs. The following new features will be added!!!

Integration date

Scheduled around August 2022.

New features

The main new features are as follows

  • Providing type hint files for Python
    • Configure tools such as mypy to take full advantage of type hint information.
    • mypy can detect the use of incorrect argument types in the qulacs API.
  • Sending exceptions with detailed information
    • Makes it easier to understand the cause of the error.
    • (For Jupyter Notebook users) kernel is less likely to crash if incorrect input is given.
  • Added backprop (gradient calculation by error back propagation method) to ParametricQuantumCircuit
    • It is faster than calculating gradients one by one.
  • Gradient Calculator

Scope of impact

The existing functionality has not been changed, so the existing code using Qulacs will continue to work as is. However, since the implementation language of csim has been changed from C to C++, changes may be necessary if you have been using direct calls to csim. Due to the C++ change, all complex numbers are now handled by std::complex.

Add dependency libraries

This integration adds boost as a dependency library. There will be some changes in the installation procedure.

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

qulacs-0.5.2-cp310-cp310-win_amd64.whl (672.0 kB view details)

Uploaded CPython 3.10 Windows x86-64

qulacs-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (722.3 kB view details)

Uploaded CPython 3.10 manylinux: glibc 2.17+ x86-64

qulacs-0.5.2-cp310-cp310-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.10 macOS 10.9+ x86-64

qulacs-0.5.2-cp39-cp39-win_amd64.whl (654.1 kB view details)

Uploaded CPython 3.9 Windows x86-64

qulacs-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (722.4 kB view details)

Uploaded CPython 3.9 manylinux: glibc 2.17+ x86-64

qulacs-0.5.2-cp39-cp39-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.9 macOS 10.9+ x86-64

qulacs-0.5.2-cp38-cp38-win_amd64.whl (672.0 kB view details)

Uploaded CPython 3.8 Windows x86-64

qulacs-0.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (722.0 kB view details)

Uploaded CPython 3.8 manylinux: glibc 2.17+ x86-64

qulacs-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.8 macOS 10.9+ x86-64

qulacs-0.5.2-cp37-cp37m-win_amd64.whl (668.0 kB view details)

Uploaded CPython 3.7m Windows x86-64

qulacs-0.5.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (737.1 kB view details)

Uploaded CPython 3.7m manylinux: glibc 2.17+ x86-64

qulacs-0.5.2-cp37-cp37m-macosx_10_9_x86_64.whl (1.4 MB view details)

Uploaded CPython 3.7m macOS 10.9+ x86-64

File details

Details for the file qulacs-0.5.2-cp310-cp310-win_amd64.whl.

File metadata

  • Download URL: qulacs-0.5.2-cp310-cp310-win_amd64.whl
  • Upload date:
  • Size: 672.0 kB
  • Tags: CPython 3.10, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for qulacs-0.5.2-cp310-cp310-win_amd64.whl
Algorithm Hash digest
SHA256 0589fe4f463521b2fe97ffa9f44d46e51882950de775d8247a558c8bed580a5b
MD5 c3e7ad93140ecf07f8d9654451e949a2
BLAKE2b-256 12ddd7580bdb79f540d68224c1f57a9022ca927185e7240414ad14f4af1bc2e9

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d385ecac50fa72f4a682676cb387ce62e6d0aa5688f90be90b650226290005ed
MD5 e943d6bc689b7f1284ec5dd3ce6eb204
BLAKE2b-256 0c1a7da557823350c7e333bc03a8bb0bce1f0b9108c480e5511677dbd659b593

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp310-cp310-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp310-cp310-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 cc9696db20418c76e0155e445453d669504bdd18da34819476eb849889424c79
MD5 0e4715c1d4515d1b496008444d91c849
BLAKE2b-256 ce421688b1a2e5a1de5e1069fcc4499277af5595634f235b382b76e1eeb2cf37

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp39-cp39-win_amd64.whl.

File metadata

  • Download URL: qulacs-0.5.2-cp39-cp39-win_amd64.whl
  • Upload date:
  • Size: 654.1 kB
  • Tags: CPython 3.9, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for qulacs-0.5.2-cp39-cp39-win_amd64.whl
Algorithm Hash digest
SHA256 acb170f49a658dd25b42b5ea8354a865596107d66a0c0672e470a955cf567720
MD5 7cc579cb22898614e31d8db55aa975f1
BLAKE2b-256 074c30602b58f6e3e398098f04391ed29ee7d5457a96b3afe30c5644aaa6105d

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ef5999cf50e072d2abc9ac2ed1a5423868d8c2730b44c931633d1489fe8cfdfc
MD5 07c2761612b102107abde0a4d209ad11
BLAKE2b-256 8b29d83abb49016fc3875597cf300c7b6de686f7a3abd2fdbd35d0178e714328

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp39-cp39-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp39-cp39-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 8a10a024dc902e1f34a714f23758870ca9502c3bb9aee44ae33a801ddc04a6cb
MD5 1c645b257f5c31830f66911e7774564d
BLAKE2b-256 9862811493a3c74e98420d5c4494c5edd31042627031b6da74d2a381e4599888

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp38-cp38-win_amd64.whl.

File metadata

  • Download URL: qulacs-0.5.2-cp38-cp38-win_amd64.whl
  • Upload date:
  • Size: 672.0 kB
  • Tags: CPython 3.8, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for qulacs-0.5.2-cp38-cp38-win_amd64.whl
Algorithm Hash digest
SHA256 738f630af9433dc9ca2c55b3940ce0827b672f910704b46b24188f8f827089ff
MD5 71b089ecfb925014a690eac2b7732ca4
BLAKE2b-256 30f68b144f1bd5b8321eec567e222368a3b44c6d2cc94d4520199b9f087589f6

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 43cb1a348dc1cfaeab5e80e873a665f3b444ef06e103440036841ed06c507a7b
MD5 084305817a471951edd9acdfae55c1dd
BLAKE2b-256 908ddc5efa306dab68a1553cb9a3f5ed6a8194abe669ba702437d50148b7c21f

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp38-cp38-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 f85a672bb1c2caa6593da54b62210fbdd56547e6fa614ab47274351b209a9d6b
MD5 a6b72fb59798d3b0c6ce62e6ab15654a
BLAKE2b-256 732672214856ca50317fdc4968ed3f03c87a5416f225cf6e0ae227ec05a01226

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp37-cp37m-win_amd64.whl.

File metadata

  • Download URL: qulacs-0.5.2-cp37-cp37m-win_amd64.whl
  • Upload date:
  • Size: 668.0 kB
  • Tags: CPython 3.7m, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.5

File hashes

Hashes for qulacs-0.5.2-cp37-cp37m-win_amd64.whl
Algorithm Hash digest
SHA256 5d1806afbe58df13d3d8bbdf64dda5e55cabd7badd0ff71eb5dd96048323c1a7
MD5 141832441837b33a9967bcd47e765bd8
BLAKE2b-256 d430ac42a624560bc8b9a5612f3ce5fb6ed4d1f7a28e18821676b91863241761

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 00805bcf601756f7e018a85268e807ac021b8b2934b23e0a8563b37bdfedcf50
MD5 af82acc4ce3fcbbabcf0dc65d4f19e51
BLAKE2b-256 fc6bbbe1154cd804e663a50a1d543d1336313ed0555601944ab93942788c8429

See more details on using hashes here.

File details

Details for the file qulacs-0.5.2-cp37-cp37m-macosx_10_9_x86_64.whl.

File metadata

File hashes

Hashes for qulacs-0.5.2-cp37-cp37m-macosx_10_9_x86_64.whl
Algorithm Hash digest
SHA256 e8bed44f4dd6037fd349af22bd558003dde7c31aac8309a099e83ea86ac8b229
MD5 78369b6946c79e02839a052e47195e16
BLAKE2b-256 d93f1a193e31a9a53f5b515247b6e4970930f227418863775e02cf4cde2acdc1

See more details on using hashes here.

Supported by

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