Skip to main content

qstvec

qstvec is a Python package for approximate simulation of quantum circuits based on a sparse and truncated state-vector representation.

It was originally developed for peaked circuits, where the goal is to find the most probable bit string at the output of the circuit.

When only a small fraction of basis states carry most of the probability mass, and a full 2n state-vector simulation becomes unfeasible, qstvec can simulate large circuits by storing only the most relevant amplitudes.

Installation

To install qstvec, you can use:

pip install qstvec

Requirements:

  • The main requirements are NumPy and Qiskit.
  • CuPy is optional and only needed if you want to use the GPU backend. In this case, please refer to the official instructions on how to install CuPy.

After installation, from qstvec import Statevector should work in any Python environment.

For the GPU backend, use from qstvec_gpu import Statevector instead.

Usage

After installation, you can import Statevector from the package:

from qstvec import Statevector

# state vector for a 2-qubit system, initialized with |00>
sv = Statevector(n_qubits=2)

# unitary for a quantum NOT (Pauli-X) gate on single qubit
U = [[0, 1], [1, 0]]

# the unitary will be applied to the least-significant qubit
qargs = [0]                       

# evolve the state vector by applying the unitary
sv.evolve(U, qargs)

# optionally truncate (no effect in this example)
sv.truncate(top_k=0, p_frac=1.0)

# print the most probable bit string, i.e. '01'
print(sv.bit_string())

GPU backend

If you have a GPU device and CuPy installed (as described in the CuPy documentation), you might want to try the GPU backend. (It should be faster, but more limited in terms of memory.)

For this purpose, import Statevector from the GPU package instead:

from qstvec_gpu import Statevector

Examples

In the examples, we use some circuits from BlueQubit's Peaked Portal hackathon.

Little peak

The circuit little_peak.qasm corresponds to BlueQubit's Problem 1: Little Peak.

The Python script little_peak.py illustrates how to read the circuit and evolve the state vector, instruction by instruction, without truncation.

At the end, it prints the most probable bit string.

Sharp peak

The circuit sharp_peak.qasm corresponds to BlueQubit's Problem 3: Sharp Peak.

The Python script sharp_peak.py implements the circuit simulation strategy described in the paper (see below). Basically, it is a block-based simulation strategy where multiple gates are composed into a single unitary, and the state vector is evolved block-by-block rather than instruction-by-instruction.

To use this script, specify the k for top-k truncation and/or the p for p-mass truncation. (Top‑k truncation keeps only the k largest‑probability basis states, while p‑mass truncation keeps enough terms to cover a fraction p of the total probability mass). The default values are k=0 and p=1.0, which mean no truncation.

Examples:

  • python sharp_peak.py 0 0.99 runs a simulation with a 99% fraction of the total probability mass.
  • python sharp_peak.py 2**18 1.0 runs a simulation with a 218 upper limit on the number of terms.

Test gates

This example shows that the results are consistent with a state-vector simulation based on Qiskit.

For this purpose, test_gates.qasm contains examples of all the standard gates available in OpenQASM 2.0 (as specified in qelib1.inc).

The Python script test_gates.py evolves a qiskit Statevector and a qstvec Statevector side-by-side, and checks that the bit strings and probabilities agree after each circuit instruction.

How to cite

If you find this package useful, please cite:

  • Diogo R. Ferreira, A Sparse and Truncated State Vector Simulator for Peaked Circuits, arXiv:2607.07816, 2026

Download files

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

Source Distribution

qstvec-0.1.3.tar.gz (5.1 kB view details)

Uploaded Source

Built Distribution

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

qstvec-0.1.3-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file qstvec-0.1.3.tar.gz.

File metadata

  • Download URL: qstvec-0.1.3.tar.gz
  • Upload date:
  • Size: 5.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for qstvec-0.1.3.tar.gz
Algorithm Hash digest
SHA256 63051474718c8dac0ce1fb03d8292506ef6d9f419fa4e83b6860ff25c876a528
MD5 45fca292886811a18643b320b313afee
BLAKE2b-256 c7ad3b7ce3af4f68e507ea5e3b14d669d9a16d720f2d630c25adec373a599c3c

See more details on using hashes here.

File details

Details for the file qstvec-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: qstvec-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.13.15

File hashes

Hashes for qstvec-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 62f17f667c9418ba29b77cbc36ef036363587c0f41dc8754f507a69d68781c94
MD5 37bd1c1e8f589472eec30032a21f091b
BLAKE2b-256 79249be3714f3a785f71e188bba1efd5bcd9729dcbf975f4b6b04f5f85fdbb90

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.1.3 This release

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

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