Skip to main content

Quantum circuit simulator for research

Project description

Scaluq

For the Japanese version of this README, see README_ja.md.

Scaluq is a newly redeveloped Python/C++ library based on the quantum circuit simulator Qulacs.
It enables high-speed simulation of large-scale quantum circuits, noisy quantum circuits, and parametric quantum circuits.
This library is released under the MIT License.

Compared to Qulacs, the following improvements have been made:

  • Implementation based on Kokkos allows seamless switching between execution environments (CPU/GPU) without requiring code changes.
  • Improved execution speed.
  • Pointers are hidden from users, making the code simpler and safer to write.
  • Integration of nanobind enables more compact and faster Python bindings.
  • Provides a faster interface for the case where the same circuit is applied to multiple quantum states.

Build Requirements

  • Ninja ≥ 1.10
  • GCC ≥ 11 (≥ 13 if not using CUDA)
  • CMake ≥ 3.24
  • CUDA ≥ 12.6 (only when using CUDA)
  • Python ≥ 3.9 (only when using Python)

Note: It may work with lower versions, but this has not been verified.

Runtime Requirements

  • CUDA ≥ 12.6 (only when using CUDA)

Note: It may work with lower versions, but this has not been verified.

Build Options

Build options can be specified using environment variables when running script/configure or pip install ..

Variable Name Default Description
CMAKE_C_COMPILER - See CMake Documentation
CMAKE_CXX_COMPILER - See CMake Documentation
CMAKE_BUILD_TYPE - See CMake Documentation
CMAKE_INSTALL_PREFIX - See CMake Documentation
SCALUQ_USE_OMP ON Use OpenMP for parallel computation on CPU
SCALUQ_USE_CUDA OFF Enable parallel computation using GPU (CUDA)
SCALUQ_CUDA_ARCH (auto) Target Nvidia GPU architecture (see Kokkos CMake Keywords, e.g., SCALUQ_CUDA_ARCH=AMPERE80)
SCALUQ_USE_TEST ON Include test/ in build targets. You can build and run tests with ctest --test-dir build/
SCALUQ_USE_EXE ON Include exe/ in build targets. You can try running without installing by building with ninja -C build and running build/exe/main
SCALUQ_FLOAT16 OFF Enable f16 precision
SCALUQ_FLOAT32 ON Enable f32 precision
SCALUQ_FLOAT64 ON Enable f64 precision
SCALUQ_BFLOAT16 OFF Enable bf16 precision

Installing as a C++ Library

To install Scaluq as a static C++ library, run the following commands:

git clone https://github.com/qulacs/scaluq
cd scaluq
script/configure
sudo -E env "PATH=$PATH" ninja -C build install
  • Required libraries such as Eigen and Kokkos will be installed together.
  • You can install to a location other than /usr/local/ by setting CMAKE_INSTALL_PREFIX. For example, if you want to install locally or avoid conflicts with other Kokkos builds:
    CMAKE_INSTALL_PREFIX=~/.local script/configure; ninja -C build install
  • sudo is used to install files to /usr/local/, but to preserve the user environment, we use -E and explicitly pass PATH.
  • If you want to build the CUDA-enabled version (when NVIDIA GPU and CUDA are available), set SCALUQ_USE_CUDA=ON. Example:
    SCALUQ_USE_CUDA=ON script/configure; sudo env -E "PATH=$PATH" ninja -C build install

When changing options and rebuilding, make sure to clear the CMake cache by running:

rm build/CMakeCache.txt

An example CMake configuration for a project using the installed Scaluq library is provided in example_project/.

Installing as a Python Library

Scaluq can also be used as a Python library:

pip install scaluq

If you want to use GPU or precisions other than f32 and f64, clone the repository and install with options:

git clone https://github.com/qulacs/scaluq
cd ./scaluq
SCALUQ_USE_CUDA=ON pip install .

Python Documentation

A simple documentation page is available with function descriptions and type information for the Python library version:
https://scaluq.readthedocs.io/en/latest/index.html

Sample Code (C++)

#include <iostream>
#include <cstdint>

#include <scaluq/circuit/circuit.hpp>
#include <scaluq/gate/gate_factory.hpp>
#include <scaluq/operator/operator.hpp>
#include <scaluq/state/state_vector.hpp>

int main() {
    scaluq::initialize();  // must be called before using any scaluq methods
    {
        constexpr Precision Prec = scaluq::Precision::F64;
        constexpr ExecutionSpace Space = scaluq::ExecutionSpace::Default;
        const std::uint64_t n_qubits = 3;
        scaluq::StateVector<Prec, Default> state = scaluq::StateVector<Prec, Default>::Haar_random_state(n_qubits, 0);
        std::cout << state << std::endl;

        scaluq::Circuit<Prec, Default> circuit(n_qubits);
        circuit.add_gate(scaluq::gate::X<Prec, Default>(0));
        circuit.add_gate(scaluq::gate::CNot<Prec, Default>(0, 1));
        circuit.add_gate(scaluq::gate::Y<Prec, Default>(1));
        circuit.add_gate(scaluq::gate::RX<Prec, Default>(1, std::numbers::pi / 2));
        circuit.update_quantum_state(state);

        scaluq::Operator<Prec, Default> observable(n_qubits);
        observable.add_random_operator(1, 0);
        auto value = observable.get_expectation_value(state);
        std::cout << value << std::endl;
    }
    scaluq::finalize();  // must be called last
}

By including scaluq/all.hpp, you can omit template arguments using SCALUQ_OMIT_TEMPLATE.

#include <iostream>
#include <cstdint>

#include <scaluq/all.hpp>

namespace my_scaluq {
    SCALUQ_OMIT_TEMPLATE(scaluq::Precision::F64, scaluq::ExecutionSpace::Default)
}

using namespace my_scaluq;

int main() {
    scaluq::initialize();  // must be called before using any scaluq methods
    {
        const std::uint64_t n_qubits = 3;
        StateVector state = StateVector::Haar_random_state(n_qubits, 0);
        std::cout << state << std::endl;

        Circuit circuit(n_qubits);
        circuit.add_gate(gate::X(0));
        circuit.add_gate(gate::CNot(0, 1));
        circuit.add_gate(gate::Y(1));
        circuit.add_gate(gate::RX(1, std::numbers::pi / 2));
        circuit.update_quantum_state(state);

        Operator observable(n_qubits);
        observable.add_random_operator(1, 0);
        auto value = observable.get_expectation_value(state);
        std::cout << value << std::endl;
    }
    scaluq::finalize();  // must be called last
}

Sample Code (Python)

from scaluq.default.f64 import *
import math

n_qubits = 3
state = StateVector.Haar_random_state(n_qubits, 0)

circuit = Circuit(n_qubits)
circuit.add_gate(gate.X(0))
circuit.add_gate(gate.CNot(0, 1))
circuit.add_gate(gate.Y(1))
circuit.add_gate(gate.RX(1, math.pi / 2))
circuit.update_quantum_state(state)

observable = Operator(n_qubits)
observable.add_random_operator(1, 0)
value = observable.get_expectation_value(state)
print(value)

Specifying Precision and Execution Space

Scaluq supports multiple floating-point precisions: f16, f32, f64, and bf16.
By default, only f32 and f64 are enabled.
While f64 is generally recommended, lower precisions like f32 can be up to 2–4x faster in applications such as quantum machine learning that do not require high precision.

Precision C++ Template Argument Python Submodule Description
f16 Precision::F16 f16 IEEE754 binary16
f32 Precision::F32 f32 IEEE754 binary32
f64 Precision::F64 f64 IEEE754 binary64
bf16 Precision::BF16 bf16 bfloat16

Execution spaces determine whether computation is performed on CPU or GPU:

Execution Space C++ Template Argument Python Submodule Description
default ExecutionSpace::Default default GPU if CUDA is enabled, otherwise CPU
host ExecutionSpace::Host host Always CPU

Note: You can only perform operations between objects with the same precision and execution space. For example, a gate created for 32-bit precision cannot be used with a 64-bit StateVector, even if both are CPU-based.

In C++, classes like StateVector, Circuit, Gate, and Operator accept Precision and ExecutionSpace as template arguments.

In Python, you import from submodules like scaluq.default.f32 or scaluq.host.f64 based on your desired configuration.

You can dynamically select the submodule using importlib:

import importlib

prec = 'f64'
space = 'default'
scaluq_sub = importlib.import_module(f'scaluq.{space}.{prec}')
StateVector = scaluq_sub.StateVector
gate = scaluq_sub.gate

state = StateVector(3)
x = gate.X(0)
x.update_quantum_state(state)
print(state)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

scaluq-0.1.0.tar.gz (116.4 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

scaluq-0.1.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.12+manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

scaluq-0.1.0-cp312-abi3-macosx_14_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.12+macOS 14.0+ ARM64

scaluq-0.1.0-cp312-abi3-macosx_13_0_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.12+macOS 13.0+ x86-64

scaluq-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.11manylinux: glibc 2.27+ x86-64manylinux: glibc 2.28+ x86-64

scaluq-0.1.0-cp311-cp311-macosx_14_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.11macOS 14.0+ ARM64

scaluq-0.1.0-cp311-cp311-macosx_13_0_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.11macOS 13.0+ x86-64

scaluq-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.10manylinux: glibc 2.28+ x86-64

scaluq-0.1.0-cp310-cp310-macosx_14_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.10macOS 14.0+ ARM64

scaluq-0.1.0-cp310-cp310-macosx_13_0_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.10macOS 13.0+ x86-64

scaluq-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl (8.3 MB view details)

Uploaded CPython 3.9manylinux: glibc 2.28+ x86-64

scaluq-0.1.0-cp39-cp39-macosx_14_0_arm64.whl (8.7 MB view details)

Uploaded CPython 3.9macOS 14.0+ ARM64

scaluq-0.1.0-cp39-cp39-macosx_13_0_x86_64.whl (9.2 MB view details)

Uploaded CPython 3.9macOS 13.0+ x86-64

File details

Details for the file scaluq-0.1.0.tar.gz.

File metadata

  • Download URL: scaluq-0.1.0.tar.gz
  • Upload date:
  • Size: 116.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.3

File hashes

Hashes for scaluq-0.1.0.tar.gz
Algorithm Hash digest
SHA256 f480dc07616759a1cf700a876ca80702fa6bd96179c089faf016ec99933855f1
MD5 ea2b7b00a131e8a74a685f1489776e43
BLAKE2b-256 f30d92d3e767924111deed30b52f4125358579e7e0ee0b3c2e297838cb22ad76

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp312-abi3-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5375aeaef5ebe4f7642a29d85c770a27336c91360ea70c7e6f401cc011df03c1
MD5 7c59b28e61e48fb05830e7597e3a3c10
BLAKE2b-256 3eae654c237e536bec7249dd613277007e482810585135c4f8fee1d35e3ccc51

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp312-abi3-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp312-abi3-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 7d84a15a2e71606957493767d1adbf19c329b2cd8233fa1583ff9f5e4ba538e6
MD5 3a61ed01f6fa867c8c03c4f0c5bfef1a
BLAKE2b-256 581a9b5d394c56f0eb8becffd909196ebd6442be501c696442d1d30a36b333a4

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp312-abi3-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp312-abi3-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 3f61e821642c3134ccef1880e68b423ee161646d441ff95f18bcf8110a99de55
MD5 e37f92a4a75cab95e65c00c683b62341
BLAKE2b-256 7b26996991167d9695023f558b427387ec19e6c614fa5fbd9a3ca5180c658b07

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 5c59c8a027628f8df38b891631777c2b8af9c671dbb6611c88b759378a23ac4b
MD5 489ef07e16b699533d9f43ca6f59bc7c
BLAKE2b-256 a1ddba9b13b9921488ac7195193602e02953733a415689b6538eee457ea2bdeb

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp311-cp311-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp311-cp311-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 0a3f2490ae700d0d5bcb35d405bffeb86ecdb83a2c17ef012c1ad3cf72430f4a
MD5 ad71b32748bade96ea1fb0b1b94119ba
BLAKE2b-256 375d521ea8a3cabadb29e6cf893433823b9f009e6d002654ba79ac37121e3645

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp311-cp311-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp311-cp311-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 947d1d370178ca2aa6097482fdd41baefb514a58a63a5164aeb5e2a56d4b34ec
MD5 afc8ecb036b1ae9293ec5befb79a07b3
BLAKE2b-256 109a471c57cd68ffc5fdda400adff6a87e3f473d0dd911036f278446383a551e

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp310-cp310-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 40c27b98f4bf4a36ceffa95fc5801496d541c3fc0b8bfb55bd8c38a9a4e84af2
MD5 7e31b94fb0080f6dbfabf3fa368310c5
BLAKE2b-256 4623a883102cc4606e30654fdf06f6d425cd52f2e56225b7647e55481706b24b

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp310-cp310-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp310-cp310-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 32e9164d97cfe1968e0c4208020a975b6134da6d27f753e97b1bfd4fe0c1a3cd
MD5 9311e68f18515f11ecd833735e701c62
BLAKE2b-256 017121fafe3f57bbc3e307f33a000ff2eff2faab48044cad7bb336c1a6c2dd44

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp310-cp310-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp310-cp310-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 666a950fb2427c61d61affb1e480b06af2af8a4fa901d64a2b559fc707b5b7a8
MD5 6a21ad8ec4c7ed77bbf10189c5c3d5e7
BLAKE2b-256 8d5c3db801d1cf1489d116db4d5aadd22c37314219fb0fa4cd2bd227d42bda59

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp39-cp39-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b85dc988a496c2b8ff194152abe7ea9a2159df64b3c01546d413f525f4a87cef
MD5 3b1be79c33f9ba5fb95fadcee98a66bf
BLAKE2b-256 738c014c7dc70e132194d2014c6b5c5049c96db79efda17f4087aec65f4d7cbb

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp39-cp39-macosx_14_0_arm64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp39-cp39-macosx_14_0_arm64.whl
Algorithm Hash digest
SHA256 af54712074aeb6028bc3b816a93afd9dfc7fb4d65cfaa6312b9bcd2819e92a54
MD5 9e8c154bbbe369f032bbbdf20cf1a029
BLAKE2b-256 953f3eb04f1284eabe278751d2edc326f9b3a5eb9c8ddf8b10d605bd5fe5a937

See more details on using hashes here.

File details

Details for the file scaluq-0.1.0-cp39-cp39-macosx_13_0_x86_64.whl.

File metadata

File hashes

Hashes for scaluq-0.1.0-cp39-cp39-macosx_13_0_x86_64.whl
Algorithm Hash digest
SHA256 3b05b91943c2b3ae0102335e23ec1b804575f098b8a4c8e56a3c69ec7cb3e584
MD5 55c0cc15165c207ab749015e59ad5acd
BLAKE2b-256 3a258668f4456cb4daa2dc73a05d9d0f1d9d597fc7436d3d7f0c3441cf23ad09

See more details on using hashes here.

Supported by

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