Skip to content

Commit eeec156

Browse files
authored
Stabilizer cleanup (#255)
* clean up the stabilizer simulators being used on the Python/Selene-Plugin side... * fix caught bug in new stabilizer sim implementations * Adding Tableau support to more stabilizer simulators
1 parent e0cf995 commit eeec156

59 files changed

Lines changed: 3089 additions & 4499 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

.github/workflows/selene-plugins.yml

Lines changed: 11 additions & 145 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,13 @@ on:
1111
- 'python/selene-plugins/**'
1212
- 'crates/pecos-qsim/**'
1313
- 'crates/pecos-core/**'
14-
- 'crates/pecos-quest/**'
1514
- '.github/workflows/selene-plugins.yml'
1615
pull_request:
1716
branches: [master, development, dev]
1817
paths:
1918
- 'python/selene-plugins/**'
2019
- 'crates/pecos-qsim/**'
2120
- 'crates/pecos-core/**'
22-
- 'crates/pecos-quest/**'
2321
- '.github/workflows/selene-plugins.yml'
2422
workflow_dispatch:
2523

@@ -60,61 +58,18 @@ jobs:
6058
- name: Cache Rust
6159
uses: Swatinem/rust-cache@v2
6260

63-
# Install CUDA Toolkit for GPU support (compile-time only, no GPU needed)
64-
# Linux: Use network method with non-cuda-sub-packages for libcublas
65-
# Windows: Use local method with specific sub-packages to avoid VS integration bug
66-
# macOS: NVIDIA dropped CUDA support in 2019
67-
- name: Install CUDA Toolkit (Linux)
68-
if: runner.os == 'Linux'
69-
uses: Jimver/cuda-toolkit@v0.2.30
70-
with:
71-
cuda: '12.6.3'
72-
method: 'network'
73-
sub-packages: '["nvcc", "cudart-dev"]'
74-
non-cuda-sub-packages: '["libcublas", "libcublas-dev"]'
75-
76-
# Set up Visual Studio environment on Windows (required for nvcc to find cl.exe)
77-
- name: Set up Visual Studio environment (Windows)
78-
if: runner.os == 'Windows'
79-
uses: ilammy/msvc-dev-cmd@v1
80-
with:
81-
arch: x64
82-
83-
# Windows CUDA: Uses specific sub-packages to avoid VS 17.3.x bug
84-
# See: https://github.com/Jimver/cuda-toolkit/issues/382
85-
- name: Install CUDA Toolkit (Windows)
86-
if: runner.os == 'Windows'
87-
uses: Jimver/cuda-toolkit@v0.2.30
88-
with:
89-
cuda: '12.5.1'
90-
method: 'local'
91-
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust"]'
92-
9361
- name: Build Selene plugins (Unix)
9462
if: runner.os != 'Windows'
9563
run: |
96-
# Build all selene plugin Rust libraries
97-
# pecos-selene-quest is built with CUDA feature on Linux (not macOS - NVIDIA dropped CUDA support in 2019)
98-
if [ "${{ runner.os }}" = "Linux" ]; then
99-
cargo build --release -p pecos-selene-quest --features cuda
100-
else
101-
cargo build --release -p pecos-selene-quest
102-
fi
10364
cargo build --release \
104-
-p pecos-selene-qulacs \
105-
-p pecos-selene-sparsestab \
65+
-p pecos-selene-stab \
10666
-p pecos-selene-statevec
10767
108-
# Windows: Use PowerShell to avoid Git Bash PATH conflict where Git's /usr/bin/link
109-
# shadows MSVC's link.exe linker
11068
- name: Build Selene plugins (Windows)
11169
if: runner.os == 'Windows'
11270
shell: pwsh
11371
run: |
114-
# Build pecos-selene-quest with CUDA feature
115-
cargo build --release -p pecos-selene-quest --features cuda
116-
# Build other plugins
117-
cargo build --release -p pecos-selene-qulacs -p pecos-selene-sparsestab -p pecos-selene-statevec
72+
cargo build --release -p pecos-selene-stab -p pecos-selene-statevec
11873
11974
- name: Copy libraries to Python packages (Unix)
12075
if: runner.os != 'Windows'
@@ -127,49 +82,25 @@ jobs:
12782
fi
12883
12984
# Copy libraries
130-
mkdir -p python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib
131-
mkdir -p python/selene-plugins/pecos-selene-qulacs/python/pecos_selene_qulacs/_dist/lib
132-
mkdir -p python/selene-plugins/pecos-selene-sparsestab/python/pecos_selene_sparsestab/_dist/lib
85+
mkdir -p python/selene-plugins/pecos-selene-stab/python/pecos_selene_stab/_dist/lib
13386
mkdir -p python/selene-plugins/pecos-selene-statevec/python/pecos_selene_statevec/_dist/lib
13487
135-
cp target/release/libpecos_selene_quest.$EXT python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib/
136-
cp target/release/libpecos_selene_qulacs.$EXT python/selene-plugins/pecos-selene-qulacs/python/pecos_selene_qulacs/_dist/lib/
137-
cp target/release/libpecos_selene_sparsestab.$EXT python/selene-plugins/pecos-selene-sparsestab/python/pecos_selene_sparsestab/_dist/lib/
88+
cp target/release/libpecos_selene_stab.$EXT python/selene-plugins/pecos-selene-stab/python/pecos_selene_stab/_dist/lib/
13889
cp target/release/libpecos_selene_statevec.$EXT python/selene-plugins/pecos-selene-statevec/python/pecos_selene_statevec/_dist/lib/
13990
140-
# Copy QuEST CUDA backend if it exists (built when --features cuda is used)
141-
# This backend is loaded at runtime via dlopen, allowing the wheel to work
142-
# on systems both with and without NVIDIA CUDA installed
143-
if [ -f "target/release/libpecos_quest_cuda.$EXT" ]; then
144-
echo "Copying QuEST CUDA backend..."
145-
cp target/release/libpecos_quest_cuda.$EXT python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib/
146-
fi
147-
14891
- name: Copy libraries to Python packages (Windows)
14992
if: runner.os == 'Windows'
15093
shell: pwsh
15194
run: |
152-
New-Item -ItemType Directory -Force -Path python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib
153-
New-Item -ItemType Directory -Force -Path python/selene-plugins/pecos-selene-qulacs/python/pecos_selene_qulacs/_dist/lib
154-
New-Item -ItemType Directory -Force -Path python/selene-plugins/pecos-selene-sparsestab/python/pecos_selene_sparsestab/_dist/lib
95+
New-Item -ItemType Directory -Force -Path python/selene-plugins/pecos-selene-stab/python/pecos_selene_stab/_dist/lib
15596
New-Item -ItemType Directory -Force -Path python/selene-plugins/pecos-selene-statevec/python/pecos_selene_statevec/_dist/lib
15697
157-
Copy-Item target/release/pecos_selene_quest.dll python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib/
158-
Copy-Item target/release/pecos_selene_qulacs.dll python/selene-plugins/pecos-selene-qulacs/python/pecos_selene_qulacs/_dist/lib/
159-
Copy-Item target/release/pecos_selene_sparsestab.dll python/selene-plugins/pecos-selene-sparsestab/python/pecos_selene_sparsestab/_dist/lib/
98+
Copy-Item target/release/pecos_selene_stab.dll python/selene-plugins/pecos-selene-stab/python/pecos_selene_stab/_dist/lib/
16099
Copy-Item target/release/pecos_selene_statevec.dll python/selene-plugins/pecos-selene-statevec/python/pecos_selene_statevec/_dist/lib/
161100
162-
# Copy QuEST CUDA backend if it exists (built when --features cuda is used)
163-
if (Test-Path target/release/pecos_quest_cuda.dll) {
164-
Write-Host "Copying QuEST CUDA backend..."
165-
Copy-Item target/release/pecos_quest_cuda.dll python/selene-plugins/pecos-selene-quest/python/pecos_selene_quest/_dist/lib/
166-
}
167-
168101
- name: Install Python packages
169102
run: |
170-
uv pip install --system -e ./python/selene-plugins/pecos-selene-quest[test]
171-
uv pip install --system -e ./python/selene-plugins/pecos-selene-qulacs[test]
172-
uv pip install --system -e ./python/selene-plugins/pecos-selene-sparsestab[test]
103+
uv pip install --system -e ./python/selene-plugins/pecos-selene-stab[test]
173104
uv pip install --system -e ./python/selene-plugins/pecos-selene-statevec[test]
174105
175106
- name: Run tests
@@ -185,12 +116,8 @@ jobs:
185116
matrix:
186117
os: [ubuntu-latest, macos-latest, macos-15-intel, windows-latest]
187118
plugin:
188-
- name: pecos-selene-quest
189-
package: pecos_selene_quest
190-
- name: pecos-selene-qulacs
191-
package: pecos_selene_qulacs
192-
- name: pecos-selene-sparsestab
193-
package: pecos_selene_sparsestab
119+
- name: pecos-selene-stab
120+
package: pecos_selene_stab
194121
- name: pecos-selene-statevec
195122
package: pecos_selene_statevec
196123

@@ -213,62 +140,16 @@ jobs:
213140
- name: Cache Rust
214141
uses: Swatinem/rust-cache@v2
215142

216-
# Install CUDA Toolkit for GPU support (compile-time only, no GPU needed)
217-
# Linux: Use network method with non-cuda-sub-packages for libcublas
218-
# Windows: Use local method with specific sub-packages to avoid VS integration bug
219-
# macOS: NVIDIA dropped CUDA support in 2019
220-
- name: Install CUDA Toolkit (Linux)
221-
if: runner.os == 'Linux' && matrix.plugin.name == 'pecos-selene-quest'
222-
uses: Jimver/cuda-toolkit@v0.2.30
223-
with:
224-
cuda: '12.6.3'
225-
method: 'network'
226-
sub-packages: '["nvcc", "cudart-dev"]'
227-
non-cuda-sub-packages: '["libcublas", "libcublas-dev"]'
228-
229-
# Set up Visual Studio environment on Windows (required for nvcc to find cl.exe)
230-
- name: Set up Visual Studio environment (Windows)
231-
if: runner.os == 'Windows' && matrix.plugin.name == 'pecos-selene-quest'
232-
uses: ilammy/msvc-dev-cmd@v1
233-
with:
234-
arch: x64
235-
236-
# Windows CUDA: Uses specific sub-packages to avoid VS 17.3.x bug
237-
# See: https://github.com/Jimver/cuda-toolkit/issues/382
238-
- name: Install CUDA Toolkit (Windows)
239-
if: runner.os == 'Windows' && matrix.plugin.name == 'pecos-selene-quest'
240-
uses: Jimver/cuda-toolkit@v0.2.30
241-
with:
242-
cuda: '12.5.1'
243-
method: 'local'
244-
sub-packages: '["nvcc", "cudart", "cublas", "cublas_dev", "thrust"]'
245-
246143
- name: Build Rust library (Unix)
247144
if: runner.os != 'Windows'
248145
run: |
249-
# Build pecos-selene-quest with CUDA feature on Linux (not macOS - NVIDIA dropped CUDA support in 2019)
250-
if [ "${{ matrix.plugin.name }}" = "pecos-selene-quest" ]; then
251-
if [ "${{ runner.os }}" = "Linux" ]; then
252-
cargo build --release -p ${{ matrix.plugin.name }} --features cuda
253-
else
254-
cargo build --release -p ${{ matrix.plugin.name }}
255-
fi
256-
else
257-
cargo build --release -p ${{ matrix.plugin.name }}
258-
fi
146+
cargo build --release -p ${{ matrix.plugin.name }}
259147
260-
# Windows: Use PowerShell to avoid Git Bash PATH conflict where Git's /usr/bin/link
261-
# shadows MSVC's link.exe linker
262148
- name: Build Rust library (Windows)
263149
if: runner.os == 'Windows'
264150
shell: pwsh
265151
run: |
266-
# Build pecos-selene-quest with CUDA feature
267-
if ("${{ matrix.plugin.name }}" -eq "pecos-selene-quest") {
268-
cargo build --release -p ${{ matrix.plugin.name }} --features cuda
269-
} else {
270-
cargo build --release -p ${{ matrix.plugin.name }}
271-
}
152+
cargo build --release -p ${{ matrix.plugin.name }}
272153
273154
- name: Copy library to Python package (Unix)
274155
if: runner.os != 'Windows'
@@ -282,15 +163,6 @@ jobs:
282163
mkdir -p "$PLUGIN_DIR/python/${{ matrix.plugin.package }}/_dist/lib"
283164
cp "target/release/lib${{ matrix.plugin.package }}.$EXT" "$PLUGIN_DIR/python/${{ matrix.plugin.package }}/_dist/lib/"
284165
285-
# Copy QuEST CUDA backend if it exists (built when --features cuda is used for pecos-selene-quest)
286-
# Only available on Linux (NVIDIA dropped macOS CUDA support in 2019)
287-
# This backend is loaded at runtime via dlopen, allowing the wheel to work
288-
# on systems both with and without NVIDIA CUDA installed
289-
if [ "${{ matrix.plugin.name }}" = "pecos-selene-quest" ] && [ -f "target/release/libpecos_quest_cuda.$EXT" ]; then
290-
echo "Copying QuEST CUDA backend..."
291-
cp "target/release/libpecos_quest_cuda.$EXT" "$PLUGIN_DIR/python/${{ matrix.plugin.package }}/_dist/lib/"
292-
fi
293-
294166
- name: Copy library to Python package (Windows)
295167
if: runner.os == 'Windows'
296168
shell: pwsh
@@ -299,12 +171,6 @@ jobs:
299171
New-Item -ItemType Directory -Force -Path "$pluginDir/python/${{ matrix.plugin.package }}/_dist/lib"
300172
Copy-Item "target/release/${{ matrix.plugin.package }}.dll" "$pluginDir/python/${{ matrix.plugin.package }}/_dist/lib/"
301173
302-
# Copy QuEST CUDA backend if it exists (built when --features cuda is used for pecos-selene-quest)
303-
if ("${{ matrix.plugin.name }}" -eq "pecos-selene-quest" -and (Test-Path "target/release/pecos_quest_cuda.dll")) {
304-
Write-Host "Copying QuEST CUDA backend..."
305-
Copy-Item "target/release/pecos_quest_cuda.dll" "$pluginDir/python/${{ matrix.plugin.package }}/_dist/lib/"
306-
}
307-
308174
- name: Build wheel
309175
run: |
310176
cd python/selene-plugins/${{ matrix.plugin.name }}

Cargo.lock

Lines changed: 2 additions & 26 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,8 @@ resolver = "2"
33
members = [
44
"python/pecos-rslib",
55
"python/pecos-rslib-cuda",
6-
"python/selene-plugins/pecos-selene-sparsestab",
6+
"python/selene-plugins/pecos-selene-stab",
77
"python/selene-plugins/pecos-selene-statevec",
8-
"python/selene-plugins/pecos-selene-quest",
9-
"python/selene-plugins/pecos-selene-qulacs",
108
"julia/pecos-julia-ffi",
119
"go/pecos-go-ffi",
1210
"crates/pecos*",

Justfile

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -191,16 +191,7 @@ build-selene:
191191
set -euo pipefail
192192
echo "Building Selene plugins..."
193193

194-
# Build Rust libraries (with GPU support if CUDA available)
195-
if {{pecos}} cuda check -q >/dev/null 2>&1; then
196-
echo "CUDA detected, building with GPU support..."
197-
cargo build --release -p pecos-selene-quest --features cuda
198-
else
199-
echo "CUDA not detected, building CPU-only..."
200-
cargo build --release -p pecos-selene-quest
201-
fi
202-
203-
cargo build --release -p pecos-selene-qulacs -p pecos-selene-sparsestab -p pecos-selene-statevec
194+
cargo build --release -p pecos-selene-stab -p pecos-selene-statevec
204195

205196
# Copy libraries to Python package directories
206197
echo "Copying libraries to Python packages..."

crates/benchmarks/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,16 @@ cuquantum = ["dep:pecos-cuquantum"]
2020
quest = ["dep:pecos-quest"]
2121
quest-cuda = ["quest", "pecos-quest/cuda"]
2222
qulacs = ["dep:pecos-qulacs"]
23-
all-sims = ["gpu-sims", "cuquantum", "quest", "qulacs"]
23+
cppsparsesim = ["dep:pecos-cppsparsesim"]
24+
all-sims = ["gpu-sims", "cuquantum", "quest", "qulacs", "cppsparsesim"]
2425

2526
[dependencies]
2627
# Optional simulator dependencies for benchmarking
2728
pecos-gpu-sims = { path = "../pecos-gpu-sims", optional = true }
2829
pecos-cuquantum = { path = "../pecos-cuquantum", optional = true }
2930
pecos-quest = { path = "../pecos-quest", optional = true }
3031
pecos-qulacs = { path = "../pecos-qulacs", optional = true }
32+
pecos-cppsparsesim = { workspace = true, optional = true }
3133
pecos-core.workspace = true
3234
pecos-qsim.workspace = true
3335

crates/benchmarks/benches/benchmarks.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,16 @@ use criterion::{Criterion, criterion_group, criterion_main};
1414

1515
mod modules {
1616
pub mod allocation_overhead;
17+
pub mod cpu_stabilizer_comparison;
1718
pub mod dem_sampler;
1819
pub mod dod_statevec;
1920
// TODO: pub mod hadamard_ops;
2021
#[cfg(feature = "gpu-sims")]
2122
pub mod gpu_influence_sampler;
2223
pub mod measurement_sampling;
2324
pub mod noise_models;
25+
#[cfg(feature = "cppsparsesim")]
26+
pub mod sparse_stab_vs_cpp;
2427
// TODO: pub mod pauli_ops;
2528
pub mod rng;
2629
pub mod set_ops;
@@ -33,13 +36,17 @@ mod modules {
3336

3437
#[cfg(feature = "gpu-sims")]
3538
use modules::gpu_influence_sampler;
39+
#[cfg(feature = "cppsparsesim")]
40+
use modules::sparse_stab_vs_cpp;
3641
use modules::{
37-
allocation_overhead, dem_sampler, dod_statevec, measurement_sampling, noise_models, rng,
38-
set_ops, sparse_state_vec, stabilizer_sims, state_vec_sims, surface_code, trig,
42+
allocation_overhead, cpu_stabilizer_comparison, dem_sampler, dod_statevec,
43+
measurement_sampling, noise_models, rng, set_ops, sparse_state_vec, stabilizer_sims,
44+
state_vec_sims, surface_code, trig,
3945
};
4046

4147
fn all_benchmarks(c: &mut Criterion) {
4248
allocation_overhead::benchmarks(c);
49+
cpu_stabilizer_comparison::benchmarks(c);
4350
dem_sampler::benchmarks(c);
4451
dod_statevec::benchmarks(c);
4552
#[cfg(feature = "gpu-sims")]
@@ -51,6 +58,8 @@ fn all_benchmarks(c: &mut Criterion) {
5158
sparse_state_vec::benchmarks(c);
5259
stabilizer_sims::benchmarks(c);
5360
state_vec_sims::benchmarks(c);
61+
#[cfg(feature = "cppsparsesim")]
62+
sparse_stab_vs_cpp::benchmarks(c);
5463
surface_code::benchmarks(c);
5564
trig::benchmarks(c);
5665
// TODO: pauli_ops::benchmarks(c);

0 commit comments

Comments
 (0)