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)

print(qc)                   # text drawing, one wire per qubit
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.2

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.2
File Size Uploaded Provenance Actions
qsengine-1.0.2.tar.gz 44.3 kB With provenance Details for qsengine-1.0.2.tar.gz

Built distributions (wheels)

Table of built distributions (wheels) for qsengine 1.0.2
File Actions
qsengine-1.0.2-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for qsengine-1.0.2-cp39-abi3-win_amd64.whl
qsengine-1.0.2-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.2-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
qsengine-1.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for qsengine-1.0.2-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
qsengine-1.0.2-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for qsengine-1.0.2-cp39-abi3-macosx_11_0_arm64.whl
qsengine-1.0.2-cp39-abi3-macosx_10_12_x86_64.whl CPython 3.9 abi3 macOS 10.12+ x86-64 Details for qsengine-1.0.2-cp39-abi3-macosx_10_12_x86_64.whl

Total release size: 10.7 MB

Release files / qsengine-1.0.2.tar.gz

Download URL qsengine-1.0.2.tar.gz
Size 44.3 kB
Tags Source
SHA-256 checksum
How to use checksums
fd25a8400a55791ea7d8d61011fc4b251ee175649a7addd6a354593145c30cdc
BLAKE2b-256 checksum
How to use checksums
b8c19e536f188a5db37976ad08b5608b150c2c3951d3c0fd04d883df512d7a8c
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 Nov 2, 2026.

Transparency log

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

Download URL qsengine-1.0.2-cp39-abi3-win_amd64.whl
Size 2.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
264cb2f427c4aae7dd3eb0183f7ad2dcd061ea1736aec5106b968fcf96ee3c5b
BLAKE2b-256 checksum
How to use checksums
bae10964bcf0def11ab3e22fb05577a538541fb32dd3f51d9dc4bd180abf7804
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 Nov 2, 2026.

Transparency log

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

Download URL qsengine-1.0.2-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
cdeb65e60a81b206b27e1b765be26d5f49b3e7cfbb118d8fd525ff8766646bb3
BLAKE2b-256 checksum
How to use checksums
c07158da2a0bf1ecd16949260498bc8b6cedb566bbb9ad679703bb6aed1ee6bc
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 Nov 2, 2026.

Transparency log

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

Download URL qsengine-1.0.2-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
fff8eeb47794d90655a0bd1d5c2f408e5241e2f6a99266f81bfbc09e551b6add
BLAKE2b-256 checksum
How to use checksums
c977ccb6ab0a0d3ba16025a3480f842fde433d0202f7ea94dcbc1feaf3b32c27
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 Nov 2, 2026.

Transparency log

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

Download URL qsengine-1.0.2-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
2e0556e4f93c505572825f0f78d5cdfdfed93b75ecda40a224bd499f66e740bf
BLAKE2b-256 checksum
How to use checksums
3622bdaa336d50559a8b800925c965841f69131e2148e9785f7053f8c1477c13
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 Nov 2, 2026.

Transparency log

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

Download URL qsengine-1.0.2-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
422b0f7bbd9046b2f9576348c093919bcdf9628f96edabef8d00cd0ace46df9c
BLAKE2b-256 checksum
How to use checksums
789a6fc2ed433cdf2c421e2135a4bc0e2d32eecacffb3b02637dc9813ce04041
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 Nov 2, 2026.

Transparency log

Security for qsengine 1.0.2

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.2.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 Nov 2, 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