Quantum circuit simulator for research
Project description
Qulacs
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
Multi-thread 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:
- Create an empty project.
- Select "x64" as an active solution platform.
- Right Click your project name in Solution Explorer, and select "Properties".
- At "VC++ Directories" section, add the full path to
./qulacs/include
to "Include Directories" - At "VC++ Directories" section, add the full path to
./qulacs/lib
to "Library Directories" - At "C/C++ -> Code Generation" section, change "Runtime library" to "Multi-threaded (/MT)".
- 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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distributions
File details
Details for the file qulacs-0.5.1-cp310-cp310-win_amd64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp310-cp310-win_amd64.whl
- Upload date:
- Size: 664.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
Algorithm | Hash digest | |
---|---|---|
SHA256 | daa8cba228974625e556bfe4f701de4a05f91e2a0dad115729e2d06d5a346533 |
|
MD5 | 30a93b65023405729f22f62bc6277c44 |
|
BLAKE2b-256 | 644adfc1deab9bdfabc2aa24e2420d0d587a149ec220a2cfc77d012e4231622d |
File details
Details for the file qulacs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp310-cp310-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 703.3 kB
- Tags: CPython 3.10, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 4943449a610ac367f3c2d8d9f276f895ebdd5ee9fa737ae7b19650991a97927b |
|
MD5 | adc311765f6247a4efab0fab088829ba |
|
BLAKE2b-256 | cbb9e3157a6a07d59104abf736bc3f1b162e0ca20fbe36ed7cb313572bf4163b |
File details
Details for the file qulacs-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp310-cp310-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.10, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ebbec66d1874de191a094b09a746accea39a8849294db379d5eb2df8e2295ec0 |
|
MD5 | b2ac70f6440cf27e383f5ac5b0609ef3 |
|
BLAKE2b-256 | b6da0e5fa30d99c66410d468286b54c5ff51db3fdcc50a4809d7493afb5a22a5 |
File details
Details for the file qulacs-0.5.1-cp39-cp39-win_amd64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp39-cp39-win_amd64.whl
- Upload date:
- Size: 647.0 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9b1ab088b3e6525279961fb1a29923d73213b2282b1f5e1f3e58dfc6469ec057 |
|
MD5 | 228a771fa055adef5017f27d19ebc56d |
|
BLAKE2b-256 | 1e0609248fa0c0557ab08ebdea2674d332d09348234246d5d86579647c268e41 |
File details
Details for the file qulacs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp39-cp39-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 703.5 kB
- Tags: CPython 3.9, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | d7a9d21963be69023809462fd7693ea0182c9466bcb7f60da62a06d7cdb8a0b3 |
|
MD5 | e43501ec34b57e76c68d90868653100d |
|
BLAKE2b-256 | 2955b48bfe1e327496f4fac48e6c62a17d2ec407349a5b0768ed55386d7c869a |
File details
Details for the file qulacs-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp39-cp39-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.9, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d6037826815a89cecb9663ae1395b0a09f6528debdef348d2cb0f2f0fde3eba |
|
MD5 | 8ebeccd560371e5566a59577bec3cf49 |
|
BLAKE2b-256 | 9c710da6355acfddb3f99f8b8eff4259039a5fbb92b9453c153f8112fa8996e5 |
File details
Details for the file qulacs-0.5.1-cp38-cp38-win_amd64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp38-cp38-win_amd64.whl
- Upload date:
- Size: 663.8 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | c552f8595371a6fb06b567d64d83dc13281c1b459a892aa1301d7a1840db4aa8 |
|
MD5 | 41ec1568709ad5b3543406395b8a9673 |
|
BLAKE2b-256 | 5dbf8c392db2b6702a0ca9e9238f36b3123bc2829b020b4e11bf5253be48e25d |
File details
Details for the file qulacs-0.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp38-cp38-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 703.1 kB
- Tags: CPython 3.8, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 54bb45a7c1a59475e10748c7507cd25e6030b8a7b4ace77a35748d9952ce3e27 |
|
MD5 | d931a34ab3b9cbd94523ce8297caff60 |
|
BLAKE2b-256 | 65f39d7a5b6b0b226628cd83452796f1c4e1fb8275b86167c3248d68346ce2a0 |
File details
Details for the file qulacs-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp38-cp38-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.8, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0d7f7a3a9dc8c9032fe2d7f741588ee67a0f027dcb94835576938ff58acd761e |
|
MD5 | 6b275844d3690c4b1b743f1b414f2b95 |
|
BLAKE2b-256 | 190af5d5fdf2475db3118a596a9a8a8cfa8a0adc32a03e6c796ab2f52312e4b4 |
File details
Details for the file qulacs-0.5.1-cp37-cp37m-win_amd64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp37-cp37m-win_amd64.whl
- Upload date:
- Size: 660.4 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
Algorithm | Hash digest | |
---|---|---|
SHA256 | 46a928f89a5320e886b96e123030aaefcaa429a6bbf96f3029c924c8bfc053b8 |
|
MD5 | d657e6b32e2ade202839485f6ac8bcd1 |
|
BLAKE2b-256 | b51a9602260a704d2a04f95f97992f41e71e34aea11aed9b5b1ecf7b0eed20ee |
File details
Details for the file qulacs-0.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp37-cp37m-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 720.0 kB
- Tags: CPython 3.7m, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6cd960fd5e7afefddd59e0f72fbdd506d52ef67dc7974a7f2ce75cd5a1ec623c |
|
MD5 | 046547f51686512cecd3e1b9ee23d930 |
|
BLAKE2b-256 | d251b0b8616223bd164ced92dd77ea8806b5af99cd79578faaf86a65950a3e35 |
File details
Details for the file qulacs-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
.
File metadata
- Download URL: qulacs-0.5.1-cp37-cp37m-macosx_10_9_x86_64.whl
- Upload date:
- Size: 1.4 MB
- Tags: CPython 3.7m, macOS 10.9+ x86-64
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6eb59ab2389713815c7edb706e1e349c6359e8f46b645857a6ebbc0c4baf7367 |
|
MD5 | 55c9984b555a4a0e14b430aac8c3769c |
|
BLAKE2b-256 | 55312d27d9f78046ca3a1d7b5251136cde6ca76fd33a7e0112a7c3057ec25d85 |