Skip to content

fix #26: Add StatevectorSampler backend for running quantum circuits#30

Open
at264939-ctrl wants to merge 1 commit into
Qiskit:mainfrom
at264939-ctrl:add-statevector-sampler
Open

fix #26: Add StatevectorSampler backend for running quantum circuits#30
at264939-ctrl wants to merge 1 commit into
Qiskit:mainfrom
at264939-ctrl:add-statevector-sampler

Conversation

@at264939-ctrl
Copy link
Copy Markdown

Summary

Implements a pure-Rust statevector-based sampler that allows users to execute QuantumCircuit objects locally and obtain shot-based measurement results. This addresses the lack of any backend/simulation capability in qiskit-rs.

Design

  • No additional dependencies: uses a built-in xorshift64 PRNG instead of pulling in rand.
  • No C API dependency for simulation: the Qiskit C API does not currently expose simulation primitives, so this implements the linear algebra directly in Rust.
  • The sampler walks circuit.instructions(), applies the corresponding unitary matrices to a dense statevector of size 2^n, then samples outcomes from the Born-rule probability distribution.

What's included

  • src/sampler.rs — StatevectorSampler, SamplerResult, gate matrices for all 25+ gates exposed by QuantumCircuit
  • src/lib.rs — re-exports StatevectorSampler and SamplerResult
  • tests/test_sampler.rs — integration tests (Bell state, GHZ-10, X gate, Hadamard statistics, RZ phase)

Usage

use qiskit_rs::{QuantumCircuit, StatevectorSampler};

let mut qc = QuantumCircuit::new(2, 2);
qc.h(0);
qc.cx(0, 1);
qc.measure(0, 0);
qc.measure(1, 1);

let sampler = StatevectorSampler::new();
let result = sampler.run(&mut qc, 1024);
println!("{:?}", result.counts());
// {"00": 507, "11": 517}

Implements a pure-Rust statevector simulator that executes QuantumCircuit
objects and returns shot-based measurement results.

- Add StatevectorSampler with support for all exposed gates
- Add SamplerResult with counts() and probabilities() methods
- Add unit tests and integration tests
- No additional dependencies required

Closes Qiskit#26
@CLAassistant
Copy link
Copy Markdown

CLAassistant commented May 6, 2026

CLA assistant check
All committers have signed the CLA.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants