Skip to content

Commit 6b892d1

Browse files
committed
linter
1 parent a4724ae commit 6b892d1

File tree

5 files changed

+161
-25
lines changed

5 files changed

+161
-25
lines changed

qdp/qdp-core/tests/iqp_encoding.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -618,7 +618,11 @@ fn test_iqp_fwt_threshold_boundary() {
618618

619619
assert_eq!(tensor.ndim, 2, "Tensor should be 2D");
620620
let shape_slice = std::slice::from_raw_parts(tensor.shape, tensor.ndim as usize);
621-
assert_eq!(shape_slice[1], 1 << num_qubits, "Should have 2^n amplitudes");
621+
assert_eq!(
622+
shape_slice[1],
623+
1 << num_qubits,
624+
"Should have 2^n amplitudes"
625+
);
622626

623627
println!(
624628
"PASS: IQP FWT threshold boundary test with shape [{}, {}]",
@@ -650,7 +654,8 @@ fn test_iqp_fwt_larger_qubit_counts() {
650654
.collect();
651655

652656
let result = engine.encode(&data, num_qubits, "iqp");
653-
let dlpack_ptr = result.expect(&format!("IQP encoding for {} qubits should succeed", num_qubits));
657+
let dlpack_ptr = result
658+
.unwrap_or_else(|_| panic!("IQP encoding for {} qubits should succeed", num_qubits));
654659
assert!(!dlpack_ptr.is_null());
655660

656661
unsafe {
@@ -665,7 +670,10 @@ fn test_iqp_fwt_larger_qubit_counts() {
665670
num_qubits
666671
);
667672

668-
println!(" {} qubits: shape [{}, {}] - PASS", num_qubits, shape_slice[0], shape_slice[1]);
673+
println!(
674+
" {} qubits: shape [{}, {}] - PASS",
675+
num_qubits, shape_slice[0], shape_slice[1]
676+
);
669677

670678
if let Some(deleter) = managed.deleter {
671679
deleter(dlpack_ptr);
@@ -696,7 +704,8 @@ fn test_iqp_z_fwt_correctness() {
696704
.collect();
697705

698706
let result = engine.encode(&data, num_qubits, "iqp-z");
699-
let dlpack_ptr = result.expect(&format!("IQP-Z encoding for {} qubits should succeed", num_qubits));
707+
let dlpack_ptr = result
708+
.unwrap_or_else(|_| panic!("IQP-Z encoding for {} qubits should succeed", num_qubits));
700709
assert!(!dlpack_ptr.is_null());
701710

702711
unsafe {
@@ -706,7 +715,10 @@ fn test_iqp_z_fwt_correctness() {
706715
let shape_slice = std::slice::from_raw_parts(tensor.shape, tensor.ndim as usize);
707716
assert_eq!(shape_slice[1], (1 << num_qubits) as i64);
708717

709-
println!(" IQP-Z {} qubits: shape [{}, {}] - PASS", num_qubits, shape_slice[0], shape_slice[1]);
718+
println!(
719+
" IQP-Z {} qubits: shape [{}, {}] - PASS",
720+
num_qubits, shape_slice[0], shape_slice[1]
721+
);
710722

711723
if let Some(deleter) = managed.deleter {
712724
deleter(dlpack_ptr);
@@ -740,7 +752,12 @@ fn test_iqp_fwt_batch_various_sizes() {
740752
.collect();
741753

742754
let result = engine.encode_batch(&batch_data, num_samples, sample_size, num_qubits, "iqp");
743-
let dlpack_ptr = result.expect(&format!("IQP batch encoding for {} qubits should succeed", num_qubits));
755+
let dlpack_ptr = result.unwrap_or_else(|_| {
756+
panic!(
757+
"IQP batch encoding for {} qubits should succeed",
758+
num_qubits
759+
)
760+
});
744761
assert!(!dlpack_ptr.is_null());
745762

746763
unsafe {
@@ -793,7 +810,10 @@ fn test_iqp_fwt_zero_parameters_identity() {
793810
let shape_slice = std::slice::from_raw_parts(tensor.shape, tensor.ndim as usize);
794811
assert_eq!(shape_slice[1], (1 << num_qubits) as i64);
795812

796-
println!(" IQP zero params {} qubits: verified shape - PASS", num_qubits);
813+
println!(
814+
" IQP zero params {} qubits: verified shape - PASS",
815+
num_qubits
816+
);
797817

798818
if let Some(deleter) = managed.deleter {
799819
deleter(dlpack_ptr);

qdp/qdp-python/benchmark/benchmark_iqp_fwt.py

Lines changed: 39 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@
3333
import time
3434

3535
import torch
36-
import numpy as np
3736

3837
from _qdp import QdpEngine
3938

@@ -64,7 +63,7 @@ def theoretical_speedup(n: int) -> float:
6463
New: O(n * 2^n)
6564
Speedup: 2^n / n
6665
"""
67-
return (2 ** n) / n
66+
return (2**n) / n
6867

6968

7069
def benchmark_single_encode(
@@ -79,7 +78,11 @@ def benchmark_single_encode(
7978
Returns:
8079
(avg_time_ms, throughput_samples_per_sec)
8180
"""
82-
data_len = iqp_full_data_len(num_qubits) if encoding == "iqp" else iqp_z_data_len(num_qubits)
81+
data_len = (
82+
iqp_full_data_len(num_qubits)
83+
if encoding == "iqp"
84+
else iqp_z_data_len(num_qubits)
85+
)
8386
data = [0.1 * i for i in range(data_len)]
8487

8588
# Warmup
@@ -115,12 +118,19 @@ def benchmark_batch_encode(
115118
Returns:
116119
(avg_time_ms, throughput_samples_per_sec)
117120
"""
118-
data_len = iqp_full_data_len(num_qubits) if encoding == "iqp" else iqp_z_data_len(num_qubits)
121+
data_len = (
122+
iqp_full_data_len(num_qubits)
123+
if encoding == "iqp"
124+
else iqp_z_data_len(num_qubits)
125+
)
119126

120127
# Create batch data
121128
batch_data = torch.tensor(
122-
[[0.1 * (i + j * data_len) for i in range(data_len)] for j in range(batch_size)],
123-
dtype=torch.float64
129+
[
130+
[0.1 * (i + j * data_len) for i in range(data_len)]
131+
for j in range(batch_size)
132+
],
133+
dtype=torch.float64,
124134
)
125135

126136
# Warmup
@@ -146,7 +156,11 @@ def benchmark_batch_encode(
146156

147157
def verify_correctness(engine: QdpEngine, num_qubits: int, encoding: str) -> bool:
148158
"""Verify that encoding produces normalized quantum states."""
149-
data_len = iqp_full_data_len(num_qubits) if encoding == "iqp" else iqp_z_data_len(num_qubits)
159+
data_len = (
160+
iqp_full_data_len(num_qubits)
161+
if encoding == "iqp"
162+
else iqp_z_data_len(num_qubits)
163+
)
150164
data = [0.1 * i for i in range(data_len)]
151165

152166
qtensor = engine.encode(data, num_qubits, encoding)
@@ -238,7 +252,9 @@ def main():
238252
print(BAR)
239253
print("SINGLE SAMPLE ENCODING PERFORMANCE")
240254
print(BAR)
241-
print(f"{'Encoding':<10} {'Qubits':>6} {'Time (ms)':>12} {'Throughput':>15} {'Theory Speedup':>15}")
255+
print(
256+
f"{'Encoding':<10} {'Qubits':>6} {'Time (ms)':>12} {'Throughput':>15} {'Theory Speedup':>15}"
257+
)
242258
print(SEP)
243259

244260
for enc in encodings:
@@ -247,23 +263,29 @@ def main():
247263
engine, n, enc, args.iterations, args.warmup
248264
)
249265
theory = theoretical_speedup(n)
250-
print(f"{enc:<10} {n:>6} {avg_time:>12.4f} {throughput:>12.1f}/s {theory:>15.1f}x")
266+
print(
267+
f"{enc:<10} {n:>6} {avg_time:>12.4f} {throughput:>12.1f}/s {theory:>15.1f}x"
268+
)
251269
print()
252270

253271
# Batch encoding benchmark
254272
print(BAR)
255273
print(f"BATCH ENCODING PERFORMANCE (batch_size={args.batch_size})")
256274
print(BAR)
257-
print(f"{'Encoding':<10} {'Qubits':>6} {'Batch Time':>12} {'Throughput':>15} {'State Size':>12}")
275+
print(
276+
f"{'Encoding':<10} {'Qubits':>6} {'Batch Time':>12} {'Throughput':>15} {'State Size':>12}"
277+
)
258278
print(SEP)
259279

260280
for enc in encodings:
261281
for n in args.qubits:
262282
avg_time, throughput = benchmark_batch_encode(
263283
engine, n, enc, args.batch_size, args.iterations, args.warmup
264284
)
265-
state_size = 2 ** n
266-
print(f"{enc:<10} {n:>6} {avg_time:>10.4f}ms {throughput:>12.1f}/s {state_size:>12}")
285+
state_size = 2**n
286+
print(
287+
f"{enc:<10} {n:>6} {avg_time:>10.4f}ms {throughput:>12.1f}/s {state_size:>12}"
288+
)
267289
print()
268290

269291
# Summary with theoretical vs actual analysis
@@ -272,12 +294,14 @@ def main():
272294
print(BAR)
273295
print("FWT optimization reduces complexity from O(4^n) to O(n * 2^n)")
274296
print()
275-
print(f"{'Qubits':>6} {'Old O(4^n)':>15} {'New O(n*2^n)':>15} {'Theory Speedup':>15}")
297+
print(
298+
f"{'Qubits':>6} {'Old O(4^n)':>15} {'New O(n*2^n)':>15} {'Theory Speedup':>15}"
299+
)
276300
print(SEP)
277301

278302
for n in args.qubits:
279-
old_ops = 4 ** n
280-
new_ops = n * (2 ** n)
303+
old_ops = 4**n
304+
new_ops = n * (2**n)
281305
speedup = old_ops / new_ops
282306
print(f"{n:>6} {old_ops:>15,} {new_ops:>15,} {speedup:>15.1f}x")
283307

qdp/qdp-python/uv.lock

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

0 commit comments

Comments
 (0)