Qulacs is a Python/C++ library for fast simulation of large, noisy, or parametric quantum circuits.
Qulacs is developed at QunaSys, Osaka University, NTT, and Fujitsu.
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.
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)
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.
Install with default options (Multi-thread without GPU):
pip install .
If AVX2 instructions are not supported, SIMD optimization is automatically disabled.
Install with GPU support (CUDA is required):
USE_GPU=Yes pip install .
Install single-thread Qulacs:
USE_OMP=No pip install .
The number of threads used in Qulacs installed with default options can be controlled via the environment variable OMP_NUM_THREADS or QULACS_NUM_THREADS.
While OMP_NUM_THREADS affects the parallelization of other libraries, QULACS_NUM_THREADS controls only the parallelization of QULACS.
Or, if you want to force only Qulacs to use a single thread, You can install single-thread Qulacs with the above command.
For development purpose, optional dependencies can be installed as follows.
# Install development tools
pip install .[dev]
# Install dependencies for document generation
pip install .[doc]
Uninstall Qulacs:
pip uninstall qulacs
Use Qulacs 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:
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:
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”.
Qulacs
Qulacs is a Python/C++ library for fast simulation of large, noisy, or parametric quantum circuits. Qulacs is developed at QunaSys, Osaka University, NTT, and Fujitsu.
Qulacs is licensed under the MIT license.
Quick Install for Python
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.
If you have NVIDIA GPU and CUDA is installed, GPU-version can be installed with the following command:
Features
Note Qulacs-Osaka/qulacs-osaka was integrated into the qulacs/qulacs. For more details, please refer to Information section.
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
If your system supports AVX2 instructions, SIMD optimization is automatically enabled. If you want to enable GPU simulator, install qulacs through
qulacs-gpupackage or build from source. Note thatqulacs-gpuincludes CPU simulator. You don’t need to install both.Qulacs is tested on the following systems.
If you encounter some troubles, see troubleshooting.
How to install
Install with default options (Multi-thread without GPU):
If AVX2 instructions are not supported, SIMD optimization is automatically disabled.
Install with GPU support (CUDA is required):
Install single-thread Qulacs:
The number of threads used in Qulacs installed with default options can be controlled via the environment variable
OMP_NUM_THREADSorQULACS_NUM_THREADS. WhileOMP_NUM_THREADSaffects the parallelization of other libraries,QULACS_NUM_THREADScontrols only the parallelization of QULACS. Or, if you want to force only Qulacs to use a single thread, You can install single-thread Qulacs with the above command.For development purpose, optional dependencies can be installed as follows.
Uninstall Qulacs:
Use Qulacs as C++ library
Build with GCC
Static libraries of Qulacs can be built with the following commands:
To build shared libraries, execute
make sharedat./qulacs/buildfolder. When you want to build with GPU, usebuild_gcc_with_gpu.shinstead ofbuild_gcc.sh.Then, you can build your codes with the following gcc command:
If you want to run your codes with GPU, include
cppsim/state_gpu.hppand useQuantumStateGpuinstead ofQuantumStateand build with the following command:Build with MSVC
Static libraries of Qulacs can be built with the following command:
When you want to build with GPU, use
build_msvc_2017_with_gpu.bat. If you use MSVC with other versions, usebuild_msvc_2015.bator edit the generator name inbuild_msvc_2017.bat.Your C++ codes can be built with Qulacs with the following process:
./qulacs/includeto “Include Directories”./qulacs/libto “Library Directories”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
If you want to run it on GPU, install GPU-enabled qulacs and replace
QuantumStatein the above codes withQuantumStateGpu.C++ sample code
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:If you want to run it on GPU, include
cppsim/state_gpu.hppand replaceQuantumStatewithQuantumStateGpu.How to cite
Please cite this arXiv paper: Qulacs: a fast and versatile quantum circuit simulator for research purpose