Skip to content

Commit 27fc17d

Browse files
committed
Fix all lint issues: formatting, raw pointers, strict float comparison, Julia fmt
1 parent 50e2fcb commit 27fc17d

9 files changed

Lines changed: 46 additions & 43 deletions

File tree

crates/pecos-foreign/tests/conformance_test.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
//! Test the conformance suite itself by running it against a real simulator
2-
//! wrapped as a ForeignSimulator.
2+
//! wrapped as a `ForeignSimulator`.
33
//!
4-
//! We wrap PECOS's SparseStab in C-ABI callbacks and run the conformance tests.
5-
//! Since SparseStab is a correct Clifford simulator, all tests must pass.
4+
//! We wrap PECOS's `SparseStab` in C-ABI callbacks and run the conformance tests.
5+
//! Since `SparseStab` is a correct Clifford simulator, all tests must pass.
66
77
use pecos_core::QubitId;
88
use pecos_foreign::conformance::run_conformance_tests;
@@ -11,7 +11,7 @@ use pecos_simulators::{CliffordGateable, SparseStab};
1111

1212
use std::cell::UnsafeCell;
1313

14-
/// Wrap SparseStab behind C-ABI function pointers.
14+
/// Wrap `SparseStab` behind C-ABI function pointers.
1515
/// This is a "real" foreign simulator -- same interface a Go/C author would use.
1616
struct SimHolder {
1717
sim: UnsafeCell<SparseStab>,

crates/pecos-foreign/tests/engine_test.rs

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ unsafe fn run_circuit(
2828

2929
let mut circuit_bytes: *mut u8 = std::ptr::null_mut();
3030
let mut circuit_len: usize = 0;
31-
unsafe { pecos_circuit_build(circuit, &mut circuit_bytes, &mut circuit_len) };
31+
unsafe { pecos_circuit_build(circuit, &raw mut circuit_bytes, &raw mut circuit_len) };
3232
unsafe { pecos_circuit_free(circuit) };
3333

3434
// Process
@@ -39,8 +39,8 @@ unsafe fn run_circuit(
3939
engine,
4040
circuit_bytes,
4141
circuit_len,
42-
&mut output_bytes,
43-
&mut output_len,
42+
&raw mut output_bytes,
43+
&raw mut output_len,
4444
)
4545
};
4646
unsafe { pecos_free_bytes(circuit_bytes, circuit_len) };
@@ -53,23 +53,21 @@ unsafe fn run_circuit(
5353
pecos_parse_outcomes(
5454
output_bytes,
5555
output_len,
56-
&mut outcomes_ptr,
57-
&mut num_outcomes,
56+
&raw mut outcomes_ptr,
57+
&raw mut num_outcomes,
5858
)
5959
};
6060
unsafe { pecos_free_bytes(output_bytes, output_len) };
6161
assert_eq!(rc, 0, "parse outcomes failed");
6262

63-
let results = if num_outcomes > 0 && !outcomes_ptr.is_null() {
63+
if num_outcomes > 0 && !outcomes_ptr.is_null() {
6464
let slice = unsafe { std::slice::from_raw_parts(outcomes_ptr, num_outcomes) };
6565
let v = slice.to_vec();
6666
unsafe { pecos_free_outcomes(outcomes_ptr, num_outcomes) };
6767
v
6868
} else {
6969
vec![]
70-
};
71-
72-
results
70+
}
7371
}
7472

7573
#[test]
@@ -105,7 +103,7 @@ fn test_bell_state_correlation() {
105103
let q0: usize = 0;
106104
let q1: usize = 1;
107105
let pair = [q0, q1];
108-
pecos_circuit_h(c, &q0, 1);
106+
pecos_circuit_h(c, &raw const q0, 1);
109107
pecos_circuit_cx(c, pair.as_ptr(), 1);
110108
pecos_circuit_mz(c, [q0, q1].as_ptr(), 2);
111109
})
@@ -131,8 +129,8 @@ fn test_deterministic_x_gate() {
131129
let outcomes = unsafe {
132130
run_circuit(engine, |c| {
133131
let q: usize = 0;
134-
pecos_circuit_x(c, &q, 1);
135-
pecos_circuit_mz(c, &q, 1);
132+
pecos_circuit_x(c, &raw const q, 1);
133+
pecos_circuit_mz(c, &raw const q, 1);
136134
})
137135
};
138136

@@ -148,8 +146,8 @@ fn test_circuit_reuse() {
148146
let outcomes1 = unsafe {
149147
run_circuit(engine, |c| {
150148
let q: usize = 0;
151-
pecos_circuit_h(c, &q, 1);
152-
pecos_circuit_mz(c, &q, 1);
149+
pecos_circuit_h(c, &raw const q, 1);
150+
pecos_circuit_mz(c, &raw const q, 1);
153151
})
154152
};
155153
assert_eq!(outcomes1.len(), 1);
@@ -177,8 +175,8 @@ fn test_rotation_gate() {
177175
let outcomes = unsafe {
178176
run_circuit(engine, |c| {
179177
let q: usize = 0;
180-
pecos_circuit_rx(c, std::f64::consts::PI, &q, 1);
181-
pecos_circuit_mz(c, &q, 1);
178+
pecos_circuit_rx(c, std::f64::consts::PI, &raw const q, 1);
179+
pecos_circuit_mz(c, &raw const q, 1);
182180
})
183181
};
184182

@@ -189,26 +187,26 @@ fn test_rotation_gate() {
189187
#[test]
190188
fn test_circuit_builder_reset() {
191189
// Test that circuit builder reset works
192-
let circuit = unsafe { pecos_circuit_new() };
190+
let circuit = pecos_circuit_new();
193191

194192
// Build first circuit
195193
unsafe {
196194
let q: usize = 0;
197-
pecos_circuit_h(circuit, &q, 1);
195+
pecos_circuit_h(circuit, &raw const q, 1);
198196
}
199197
let mut bytes1: *mut u8 = std::ptr::null_mut();
200198
let mut len1: usize = 0;
201-
unsafe { pecos_circuit_build(circuit, &mut bytes1, &mut len1) };
199+
unsafe { pecos_circuit_build(circuit, &raw mut bytes1, &raw mut len1) };
202200

203201
// Reset and build second circuit
204202
unsafe { pecos_circuit_reset(circuit) };
205203
unsafe {
206204
let q: usize = 0;
207-
pecos_circuit_x(circuit, &q, 1);
205+
pecos_circuit_x(circuit, &raw const q, 1);
208206
}
209207
let mut bytes2: *mut u8 = std::ptr::null_mut();
210208
let mut len2: usize = 0;
211-
unsafe { pecos_circuit_build(circuit, &mut bytes2, &mut len2) };
209+
unsafe { pecos_circuit_build(circuit, &raw mut bytes2, &raw mut len2) };
212210

213211
// Both should produce valid circuits
214212
assert!(len1 > 0);

crates/pecos-foreign/tests/foreign_decoder_test.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Integration test for ForeignDecoder.
1+
//! Integration test for `ForeignDecoder`.
22
//!
33
//! Implements a trivial "XOR decoder" as C-ABI functions in Rust, wraps it
4-
//! into a ForeignDecoder, and verifies it works through the Decoder trait.
4+
//! into a `ForeignDecoder`, and verifies it works through the Decoder trait.
55
66
use ndarray::array;
77
use pecos_decoder_core::Decoder;
@@ -122,7 +122,7 @@ fn test_foreign_decoder_basic() {
122122

123123
// XOR of [0, 1, 0, 1] = 0
124124
assert_eq!(result.observable, vec![0, 0]);
125-
assert_eq!(result.weight, 1.0);
125+
assert!((result.weight - 1.0).abs() < f64::EPSILON);
126126
assert_eq!(result.converged, Some(true));
127127
}
128128

crates/pecos-foreign/tests/foreign_simulator_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Integration test for ForeignSimulator.
1+
//! Integration test for `ForeignSimulator`.
22
//!
33
//! Implements a toy computational-basis simulator as C-ABI functions, wraps it
4-
//! into a ForeignSimulator, and verifies it works through CliffordGateable.
4+
//! into a `ForeignSimulator`, and verifies it works through `CliffordGateable`.
55
//!
66
//! The toy simulator only tracks classical bit flips -- it's not a real quantum
77
//! simulator, but it exercises the full vtable -> trait pipeline.

crates/pecos-foreign/tests/neo_integration_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
//! Integration test: ForeignSimulator with pecos-neo's CircuitRunner.
1+
//! Integration test: `ForeignSimulator` with pecos-neo's `CircuitRunner`.
22
//!
33
//! Proves that a foreign simulator (C-ABI vtable) can be used with
4-
//! pecos-neo's typed command system -- no ByteMessage serialization needed.
4+
//! pecos-neo's typed command system -- no `ByteMessage` serialization needed.
55
66
use pecos_core::QubitId;
77
use pecos_foreign::{ForeignMeasurementResult, ForeignSimulator, ForeignSimulatorVTable};

crates/pecos-selene-core/tests/adapter_conformance_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
//! Verify the SeleneAdapter works with Selene's own conformance test suite.
1+
//! Verify the `SeleneAdapter` works with Selene's own conformance test suite.
22
//!
3-
//! Tests both rotation-capable (StateVec) and Clifford-only (Stabilizer) paths.
3+
//! Tests both rotation-capable (`StateVec`) and Clifford-only (Stabilizer) paths.
44
55
use anyhow::{Result, anyhow};
66
use pecos_core::{Angle64, QubitId};

docs/development/foreign-plugins.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ A decoder plugin implements 3 methods:
7878
```python
7979
import pecos_rslib
8080

81+
8182
class MyDecoder:
8283
def __init__(self, checks, bits):
8384
self._checks = checks
@@ -94,6 +95,7 @@ class MyDecoder:
9495
def bit_count(self) -> int:
9596
return self._bits
9697

98+
9799
# Wrap and use
98100
decoder = pecos_rslib.PyForeignDecoder(MyDecoder(100, 50))
99101
result = decoder.decode(syndrome_bytes)
@@ -204,6 +206,7 @@ For universal (non-Clifford) simulators, add 3 rotation methods. All other rotat
204206
```python
205207
import pecos_rslib
206208
209+
207210
class MyStabilizerSim:
208211
def __init__(self, n):
209212
self.n = n
@@ -224,14 +227,15 @@ class MyStabilizerSim:
224227
def mz(self, qubits: list[int]) -> list[tuple[bool, bool]]:
225228
results = []
226229
for q in qubits:
227-
outcome = False # measurement outcome
230+
outcome = False # measurement outcome
228231
deterministic = True # whether outcome was deterministic
229232
results.append((outcome, deterministic))
230233
return results
231234
232235
def reset(self):
233236
pass # reset to |0...0>
234237
238+
235239
sim = pecos_rslib.PyForeignSimulator(MyStabilizerSim(10))
236240
```
237241

julia/PECOS.jl/src/Decoder.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ struct DecodingResult
4949
"""Weight/cost of the solution."""
5050
weight::Float64
5151
"""Whether the decoder converged (nothing = unknown)."""
52-
converged::Union{Bool, Nothing}
52+
converged::Union{Bool,Nothing}
5353
end
5454

5555
DecodingResult(observable, weight) = DecodingResult(observable, weight, nothing)
@@ -58,9 +58,10 @@ DecodingResult(observable, weight) = DecodingResult(observable, weight, nothing)
5858
Abstract type for all PECOS-compatible decoders.
5959
6060
Subtypes must implement:
61-
- `decode(d, syndrome::Vector{UInt8}) -> DecodingResult`
62-
- `check_count(d) -> Int`
63-
- `bit_count(d) -> Int`
61+
62+
- `decode(d, syndrome::Vector{UInt8}) -> DecodingResult`
63+
- `check_count(d) -> Int`
64+
- `bit_count(d) -> Int`
6465
"""
6566
abstract type AbstractDecoder end
6667

@@ -78,7 +79,7 @@ function bit_count end
7879

7980
# Global registry: maps Ptr{Cvoid} handles to Julia decoder objects.
8081
# Julia objects can't cross FFI directly, so we use integer handles.
81-
const _decoder_registry = Dict{UInt, AbstractDecoder}()
82+
const _decoder_registry = Dict{UInt,AbstractDecoder}()
8283
const _decoder_next_handle = Ref{UInt}(0)
8384
const _decoder_lock = ReentrantLock()
8485

@@ -97,7 +98,7 @@ function _unregister_decoder(handle::Ptr{Cvoid})
9798
end
9899
end
99100

100-
function _lookup_decoder(handle::Ptr{Cvoid})::Union{AbstractDecoder, Nothing}
101+
function _lookup_decoder(handle::Ptr{Cvoid})::Union{AbstractDecoder,Nothing}
101102
lock(_decoder_lock) do
102103
get(_decoder_registry, UInt(handle), nothing)
103104
end

julia/PECOS.jl/src/Simulator.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ function rzz! end
8989
# Registry (same pattern as Decoder.jl)
9090
# ============================================================================
9191

92-
const _sim_registry = Dict{UInt, AbstractCliffordSimulator}()
92+
const _sim_registry = Dict{UInt,AbstractCliffordSimulator}()
9393
const _sim_next_handle = Ref{UInt}(0)
9494
const _sim_lock = ReentrantLock()
9595

@@ -108,7 +108,7 @@ function _unregister_simulator(handle::Ptr{Cvoid})
108108
end
109109
end
110110

111-
function _lookup_simulator(handle::Ptr{Cvoid})::Union{AbstractCliffordSimulator, Nothing}
111+
function _lookup_simulator(handle::Ptr{Cvoid})::Union{AbstractCliffordSimulator,Nothing}
112112
lock(_sim_lock) do
113113
get(_sim_registry, UInt(handle), nothing)
114114
end

0 commit comments

Comments
 (0)