Skip to main content

qsengine

A state-vector quantum simulator for Python. You build circuits in Python; a Rust core runs them on every CPU core or on any GPU, and hands back the results.

pip install qsengine
import qsengine

qc = qsengine.QuantumCircuit(2)
qc.h(0)
qc.cx(0, 1)

print(qc.run(shots=1000, seed=1))   # {'00': 513, '11': 487}

Documentation and guides: qsengine.kaiwave.dev


Why qsengine

  • Fast where it counts. Small circuits run on the CPU with almost no per-call overhead; from 14 qubits up, the GPU takes over. On a 22-qubit benchmark qsengine's GPU backend is about 5 times faster than Qiskit Aer.
  • Any GPU, nothing to install. The GPU backend uses wgpu, so it runs on NVIDIA, AMD, Intel and Apple GPUs through Vulkan, DirectX 12 or Metal. No CUDA, no vendor toolkit.
  • Works everywhere. Without a usable GPU the same code runs on the CPU, in full 64-bit precision.
  • Small, plain API. One class, nineteen gates plus any 2x2 unitary, three ways to get a result. Mistakes raise a normal Python ValueError on the line that made them.
  • Built to learn with. The website walks from bra-ket notation to a complete Deutsch-Jozsa run, and every example on it is real qsengine output.

Install

pip install qsengine

One wheel per platform covers CPython 3.9 and newer on Windows, macOS and Linux. A GPU is optional.

Using it

A circuit has a fixed number of qubits, all starting in |0⟩. Gate methods record gates; nothing runs until you ask for a result.

import qsengine

qc = qsengine.QuantumCircuit(3)
qc.h(0)
qc.cx(0, 1)
qc.cx(1, 2)

qc.run(shots=1000)          # measurement counts: {'000': ..., '111': ...}
qc.probabilities()          # exact probabilities of all 8 basis states (NumPy array)
qc.statevector()            # exact complex amplitudes (NumPy array)
Gates Methods
Single qubit x, y, z, h, s, sdg, t, tdg
Angles (radians) rx(q, theta), ry(q, theta), rz(q, theta), p(q, lam), u(q, theta, phi, lam)
Two qubit cx(control, target), cz(control, target), cp(control, target, lam), crz(control, target, theta), swap(q1, q2)
Three qubit ccx(control1, control2, target)
Any 2x2 unitary unitary(matrix, target, controls=[])

Bitstrings put qubit 0 on the right, the same convention as Qiskit. Pass seed to run() for repeatable counts.

Choosing a backend

Every method that runs a circuit takes backend="auto" (the default), "cpu" or "gpu".

CPU GPU auto
Precision 64-bit 32-bit (within 1e-5 of the CPU) 64-bit below 14 qubits, 32-bit from 14
Runs on every CPU core any NVIDIA, AMD, Intel or Apple GPU whichever is faster
Without a GPU works raises RuntimeError falls back to the CPU

The full API, every error message and a guide to each topic are in the documentation.

Performance

Each run simulates 5 layers of (H on every qubit, RZ on every qubit, CNOT chain) and samples 1000 shots. Best of several runs on a Ryzen 5 5500 with a Radeon RX 6600, Windows 10, Qiskit Aer 0.18.2.

qsengine against pure Python and Qiskit Aer

Qubits Pure Python qsengine CPU qsengine GPU Qiskit Aer
6 2.2 ms 0.11 ms 1.3 ms 3.7 ms
10 30 ms 0.30 ms 1.2 ms 5.8 ms
14 740 ms 2.4 ms 1.3 ms 11.7 ms
18 16.2 s 25 ms 4.9 ms 19 ms
22 not run 1.03 s 70 ms 367 ms

Below 14 qubits the CPU backend is 7 to 60 times faster than Aer; from 14 qubits the GPU backend is 3 to 9 times faster. Above about 17 qubits the CPU backend is slower than Aer, which fuses multi-qubit gates. These are one machine's numbers: reproduce them with benchmarks/benchmark.py.

Limitations

Version 1.0 measures every qubit at the end of the circuit. There is no mid-circuit measurement yet, so algorithms such as teleportation that branch on a measurement are not possible. A register holds at most 30 qubits (16 GiB of memory).

Building from source

You need a recent Rust toolchain (tested with 1.88) and Python 3.9 or newer.

git clone https://github.com/kaiwave/qsengine
cd qsengine
python -m venv .venv
source .venv/bin/activate       # Windows: .venv\Scripts\activate
pip install maturin pytest numpy
maturin develop --release       # build and install into the venv

Tests:

cargo test --release            # Rust tests (GPU tests skip without a GPU)
pytest                          # Python tests, checked against a NumPy reference

To build without the GPU backend, use cargo build --no-default-features for Rust.

The website lives in site/ (Next.js, static export, maths rendered with KaTeX at build time):

cd site
npm install
npm run dev                     # local preview
npm run build                   # static site in site/out/

Docs pages are Markdown (site/app/docs/**/page.mdx) with $maths$, tables and fenced code; <Output printed="..." /> shows what a snippet prints. To add a page, create its page.mdx and list it in DOCS in site/app/content.js, which drives the sidebar and the previous/next links.

Project layout

src/                Rust core and Python bindings
  engine.rs           CPU backend (64-bit, multithreaded with Rayon)
  gpu.rs              GPU backend (wgpu compute shader in shaders/)
  circuit.rs          QuantumCircuit: records gates, fuses them, runs them
  python.rs           PyO3 bindings for the qsengine Python module
qsengine.pyi        Type hints for editors
tests/              Python tests against NumPy
benchmarks/         Benchmark script, results and plot
site/               Documentation and learning website
docs/RUST_GUIDE.md  A guide to every Rust feature the engine uses

Licence

MIT, see LICENSE. Made by kaiwave.

Metadata

Release files for qsengine 1.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for qsengine 1.0.1
File Size Uploaded Provenance Actions
qsengine-1.0.1.tar.gz 42.1 kB With provenance Details for qsengine-1.0.1.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for qsengine 1.0.1
File Actions
qsengine-1.0.1-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for qsengine-1.0.1-cp39-abi3-win_amd64.whl
qsengine-1.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for qsengine-1.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
qsengine-1.0.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for qsengine-1.0.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
qsengine-1.0.1-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for qsengine-1.0.1-cp39-abi3-macosx_11_0_arm64.whl
qsengine-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for qsengine-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 10.7 MB

Release files / qsengine-1.0.1.tar.gz

Download URL qsengine-1.0.1.tar.gz
Size 42.1 kB
Tags Source
SHA-256 checksum
How to use checksums
45a8d145bb5d2fa07ce96bd957e61d7e7d0943f0d90834bbf8c43ac5e71cf6ba
BLAKE2b-256 checksum
How to use checksums
cca6e41a98de2ef7eef0778dc096cf49b291241399cbbb07134c65077e7cc118
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / qsengine-1.0.1-cp39-abi3-win_amd64.whl

Download URL qsengine-1.0.1-cp39-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
6bad436e80aac7f8c9af27fafc20cae30d7a85a1a41a4b59003e2ef53ae86839
BLAKE2b-256 checksum
How to use checksums
72ffdef30b501ecc27387f1374a57335e95f5a8ff78cfc47ba30b63d6e7845c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / qsengine-1.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL qsengine-1.0.1-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 2.4 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
c0d7bbbbe885557c493a471e76a7c1b01d0632cd70fab44ed5a453a099bad280
BLAKE2b-256 checksum
How to use checksums
4aa52349b87ae908e77f334dae63c3e073dc07f0fbecfdbc750f126a3f1cddad
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / qsengine-1.0.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL qsengine-1.0.1-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 2.4 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9b38a93d29316330f30ff14a99bed577e3b7a029f7f70ec8f87474ae3e59597d
BLAKE2b-256 checksum
How to use checksums
86949491e9251ef3481cae8bedb18214f92fe4ece63482d5da145d938202455a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / qsengine-1.0.1-cp39-abi3-macosx_11_0_arm64.whl

Download URL qsengine-1.0.1-cp39-abi3-macosx_11_0_arm64.whl
Size 1.8 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
d106169f11518838e13de0ddfe9905e4d5b7b8f694a6f0d42c5078edb7436cde
BLAKE2b-256 checksum
How to use checksums
6448dbe7a6f204fd1ade316aa8a6382caa1141155113c3f56673923410deb7bc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Release files / qsengine-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl

Download URL qsengine-1.0.1-cp39-abi3-macosx_10_12_x86_64.whl
Size 1.8 MB
Tags CPython 3.9 abi3 macOS 10.12+ x86-64
SHA-256 checksum
How to use checksums
9fdb48d727216afdcdec5acb00f609a00802ecefcb9daff01dbde153f47f8009
BLAKE2b-256 checksum
How to use checksums
319d0b98a9ff6bbf0dbb202bdd908629df7d68625f13d702351b202d3a6e8910
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

Security for qsengine 1.0.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 6 files in this release have been uploaded with provenance metadata.

Select from 6 files

Attestation for qsengine-1.0.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 31, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page