Skip to content

Commit 05969e5

Browse files
authored
Make llvm not default for Rust (#192)
* make the llvm feature not default for Rust
1 parent dd8bdce commit 05969e5

File tree

11 files changed

+88
-23
lines changed

11 files changed

+88
-23
lines changed

.github/workflows/rust-test.yml

Lines changed: 28 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,13 @@ jobs:
7474
run: rustup component add clippy
7575

7676
- name: Run clippy
77-
run: cargo clippy --workspace --all-targets -- -D warnings
77+
run: |
78+
echo "Running clippy with all features (including LLVM)..."
79+
cargo clippy --workspace --exclude pecos --exclude pecos-quest --all-targets --all-features -- -D warnings
80+
echo "Running clippy on pecos with all non-GPU features..."
81+
cargo clippy -p pecos --all-targets --features "llvm,selene,qasm,phir,all-simulators" -- -D warnings
82+
echo "Running clippy on pecos-quest with CPU features only..."
83+
cargo clippy -p pecos-quest --all-targets --features "cpu" -- -D warnings
7884
7985
rust-lint-no-llvm:
8086
runs-on: ubuntu-latest
@@ -245,11 +251,16 @@ jobs:
245251
246252
echo "RUSTFLAGS: $RUSTFLAGS"
247253
248-
cargo test --no-run
254+
cargo test --no-run --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
255+
cargo test --no-run -p pecos-quest --features cpu
256+
cargo test --no-run -p pecos-decoders --all-features
249257
250258
- name: Compile tests (Linux/Windows)
251259
if: matrix.os != 'macos-latest'
252-
run: cargo test --no-run
260+
run: |
261+
cargo test --no-run --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
262+
cargo test --no-run -p pecos-quest --features cpu
263+
cargo test --no-run -p pecos-decoders --all-features
253264
254265
- name: Run tests (macOS)
255266
if: matrix.os == 'macos-latest'
@@ -264,23 +275,32 @@ jobs:
264275
unset PKG_CONFIG_PATH
265276
export LIBRARY_PATH=/usr/lib
266277
267-
cargo test --workspace
278+
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
279+
cargo test -p pecos-quest --features cpu
280+
cargo test -p pecos-decoders --all-features
268281
269282
- name: Run tests (Linux)
270283
if: matrix.os == 'ubuntu-latest'
271-
run: cargo test --workspace
284+
run: |
285+
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm
286+
cargo test -p pecos-quest --features cpu
287+
cargo test -p pecos-decoders --all-features
272288
273289
- name: Run tests (Windows)
274290
if: matrix.os == 'windows-latest'
275291
run: |
276292
# Run all non-doctest tests
277-
cargo test --workspace --exclude pecos-rslib --lib --bins --tests --examples
293+
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --exclude pecos-rslib --features llvm --lib --bins --tests --examples
294+
cargo test -p pecos-quest --features cpu --lib --bins --tests --examples
295+
cargo test -p pecos-decoders --all-features --lib --bins --tests --examples
278296
279297
# For Windows, we need to run doctests for the pecos crate specially
280298
# to ensure they run from the crate directory
281299
cd crates/pecos
282-
cargo test --doc
300+
cargo test --doc --features llvm
283301
cd ../..
284302
285303
# Run doctests for other crates normally
286-
cargo test --workspace --exclude pecos-rslib --exclude pecos --doc
304+
cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --exclude pecos-rslib --exclude pecos --features llvm --doc
305+
cargo test -p pecos-quest --doc
306+
cargo test -p pecos-decoders --all-features --doc

Makefile

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,14 +237,32 @@ lint-fix: ## Fix all auto-fixable linting issues (Rust, Python, Julia)
237237
# -------
238238

239239
.PHONY: rstest
240-
rstest: ## Run Rust tests
241-
@$(ADD_LLVM_TO_PATH) cargo test --workspace --release
240+
rstest: ## Run Rust tests (with GPU features only if CUDA available)
241+
@if [ "$(CUDA_AVAILABLE)" = "no" ]; then \
242+
echo "CUDA not detected - testing all features except GPU"; \
243+
$(ADD_LLVM_TO_PATH) cargo test --workspace --release --exclude pecos-quest --exclude pecos-decoders --features llvm; \
244+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-quest --release --features cpu; \
245+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-decoders --release --all-features; \
246+
else \
247+
echo "CUDA detected - testing with all features including GPU"; \
248+
$(ADD_LLVM_TO_PATH) cargo test --workspace --release --exclude pecos-quest --exclude pecos-decoders --features llvm; \
249+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-quest --release --all-features; \
250+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-decoders --release --all-features; \
251+
fi
242252

243253
.PHONY: rstest-all
244-
rstest-all: ## Run Rust tests with all features except GPU
245-
@$(ADD_LLVM_TO_PATH) cargo test --workspace --exclude pecos-quest --exclude pecos-decoders
246-
@$(ADD_LLVM_TO_PATH) cargo test -p pecos-quest
247-
@$(ADD_LLVM_TO_PATH) cargo test -p pecos-decoders --all-features
254+
rstest-all: ## Run Rust tests with all features (including GPU if CUDA available)
255+
@if [ "$(CUDA_AVAILABLE)" = "no" ]; then \
256+
echo "CUDA not detected - testing all features except GPU"; \
257+
$(ADD_LLVM_TO_PATH) cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm; \
258+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-quest --features cpu; \
259+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-decoders --all-features; \
260+
else \
261+
echo "CUDA detected - testing with all features including GPU"; \
262+
$(ADD_LLVM_TO_PATH) cargo test --workspace --exclude pecos-quest --exclude pecos-decoders --features llvm; \
263+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-quest --all-features; \
264+
$(ADD_LLVM_TO_PATH) cargo test -p pecos-decoders --all-features; \
265+
fi
248266

249267
# Decoder-specific commands
250268
# -------------------------

crates/pecos-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ env_logger.workspace = true
2323
log.workspace = true
2424

2525
[features]
26-
default = ["qasm", "llvm", "phir", "selene"]
26+
default = ["qasm", "phir", "selene"]
2727
qasm = ["pecos/qasm"]
2828
llvm = ["pecos/llvm"]
2929
phir = ["pecos/phir"]

crates/pecos-hugr-qis/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ tket.workspace = true
2727
tket-qsystem.workspace = true
2828

2929
[features]
30-
default = ["llvm"]
30+
default = []
3131
llvm = ["tket-qsystem/llvm"]
3232

3333
[lints]

crates/pecos-qis-core/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ features = ["llvm14-0"]
3030
optional = true
3131

3232
[features]
33-
default = ["llvm"]
33+
default = []
3434
llvm = ["dep:inkwell"]
3535

3636
[build-dependencies]

crates/pecos/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pecos-quest = { workspace = true, optional = true }
3838
pecos-qulacs = { workspace = true, optional = true }
3939

4040
[features]
41-
default = ["selene", "llvm", "qasm", "phir", "all-simulators"]
41+
default = ["selene", "qasm", "phir", "all-simulators"]
4242
qasm = []
4343
llvm = ["pecos-qis-core/llvm", "pecos-hugr-qis", "pecos-hugr-qis?/llvm"]
4444
phir = []

julia/pecos-julia-ffi/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ crate-type = ["cdylib"]
1717

1818
[dependencies]
1919
# PECOS - the meta crate that includes everything via its prelude
20-
pecos = { workspace = true }
20+
# Enable llvm feature explicitly for full Julia functionality
21+
pecos = { workspace = true, features = ["llvm"] }
2122

2223
[lints]
2324
workspace = true

python/pecos-rslib/rust/Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ test = false
2121

2222
[dependencies]
2323
# Use the pecos metacrate which includes all simulators and runtimes by default
24-
pecos = { workspace = true }
24+
# Enable llvm feature explicitly for full Python functionality
25+
pecos = { workspace = true, features = ["llvm"] }
2526

2627
pyo3 = { workspace=true, features = ["extension-module", "abi3-py310", "generate-import-lib"] }
2728
parking_lot.workspace = true

python/quantum-pecos/src/pecos/engines/hybrid_engine.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,9 @@ def initialize_sim_components(
154154
self.machine.init(num_qubits)
155155
self.error_model.init(num_qubits, self.machine)
156156
self.op_processor.init()
157+
# Pass seed to quantum simulator if one was set
158+
if self.seed is not None:
159+
self.qsim.qsim_params["seed"] = self.seed
157160
self.qsim.init(num_qubits)
158161

159162
def shot_reinit_components(self) -> None:

python/quantum-pecos/src/pecos/simulators/quantum_simulator.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,20 @@ def init(self, num_qubits: int) -> None:
114114
if self.backend is None:
115115
self.state = SparseSim
116116

117-
self.state = self.state(num_qubits=num_qubits, **self.qsim_params)
117+
# Try to initialize with all params including seed
118+
# If the simulator doesn't support seed, retry without it
119+
try:
120+
self.state = self.state(num_qubits=num_qubits, **self.qsim_params)
121+
except TypeError as e:
122+
if "seed" in str(e) and "unexpected keyword argument" in str(e):
123+
# Simulator doesn't support seed parameter, retry without it
124+
params_without_seed = {
125+
k: v for k, v in self.qsim_params.items() if k != "seed"
126+
}
127+
self.state = self.state(num_qubits=num_qubits, **params_without_seed)
128+
else:
129+
# Different TypeError, re-raise it
130+
raise
118131

119132
def shot_reinit(self) -> None:
120133
"""Run all code needed at the beginning of each shot, e.g., resetting state."""

0 commit comments

Comments
 (0)