Coder Social home page Coder Social logo

sghkk / qulacs Goto Github PK

View Code? Open in Web Editor NEW

This project forked from qulacs/qulacs

0.0 0.0 0.0 1.13 MB

Variational Quantum Circuit Simulator for Quantum Computation Research

License: MIT License

CMake 3.89% C++ 50.79% Shell 0.10% Batchfile 0.08% Python 1.23% C 32.22% Cuda 11.58% Dockerfile 0.11%

qulacs's Introduction

Qulacs

Build Status Downloads

Qulacs is a python/C++ library for fast simulation of large, noisy, or parametric quantum circuits.

Qulacs is licensed under the MIT license.

Quick Install

pip install qulacs

If you have NVIDIA GPU with CUDA installed try:

pip install qulacs-gpu

Feature

  • 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

  • Compared following libraries on January, 2020
Package Version
Qulacs GPU 0.1.9
Cirq 0.6.0
Qiskit Aer 0.3.4
ProjectQ 0.4.2
qHiPSTER latest master branch
Python interface of QuEST (PyQuest-cffi) 3.0.0
qsim latest master branch

Test environment:

  • Azure NC6s_v3 (6vcpu / Mem112GiB)
  • Intel(R) Xeon(R) CPU E5-2690 v4 @ 2.60GHz
  • Tesla V100 PCIE (driver 440.33.01)

What is Benchmarked

for each qubit number N:

  • Apply simultaneous random single-qubit Pauli-X rotation

and then repeat:

  • Apply CNOT(i,(i+1)%N) for all i in [0..N-1]
  • Apply simultaneous random single-qubit Pauli-X rotation

for N times.

Note that measured time include time for create quantum circuit.

Single thread benchmark

single thread benchmark

Multi thread / GPU benchmark

multi thread benchmark

This benchmark was done with majour quantum circuit simulator with python interface.
Yao is quantum circuit simulator using Julia that is as fast as Qulacs.
Benchmark inculde Yao can be found here.

Requirement

  • C++ compiler (gcc or VisualStudio)
    • gcc/g++ >= 7.0.0 (checked in Linux, MacOS, cygwin, MinGW, and WSL)
    • Microsoft VisualStudio C++ 2015 or 2017
  • python 2.7 or 3.x
  • 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.

Qulacs is tested on the following systems.

  • Ubuntu 16.04 / 18.04
  • MacOS X Sierra
  • Windows 10

Install from Source

If you encounter some troubles, see troubleshooting.

Install python libs from source

Install (Multi-thread without GPU)

python setup.py install

Install (Multithread with GPU. CUDA is required)

python setup_gpu.py install

Install (Single-thread without GPU. For launching multiple qulacs processes.)

python setup_singlethread.py install

Uninstall

pip uninstall qulacs

Build C++ and python library

GCC

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

When you want to build with GPU, use build_gcc_with_gpu.sh.

MSVC

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 MSVC2015, replace 2017 in file names to 2015.

Tutorial and API document

See the following documents for more detail.

Sample code

Python

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 to QuantumStateGpu.

C++

#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;
}

Build command for g++:

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

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

How to cite

Please cite this GitHub URL: https://github.com/qulacs/qulacs

in bibtex style:

@misc{Qulacs,
title = {{Qulacs}},
year = {2018},
eprint = "https://github.com/qulacs/qulacs"
}

qulacs's People

Contributors

corryvrequan avatar hal0taso avatar heyaroom avatar kamakiri01 avatar kosukemtr avatar kwkbtr avatar mshrn avatar puyokw avatar roger-luo avatar shukob avatar tenninyan avatar y-yu avatar yamamoto-takahiro avatar yoooopeeee avatar yurisan avatar yuya-o-nakagawa avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.