Skip to content

Commit 002a443

Browse files
committed
less skips
1 parent 9404d2b commit 002a443

File tree

11 files changed

+338
-43
lines changed

11 files changed

+338
-43
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ junit/
1515
# Generated doc tests (from scripts/docs/generate_doc_tests.py)
1616
python/quantum-pecos/tests/docs/generated/
1717

18+
# Generated WASM binaries (compile from .wat source)
19+
*.wasm
20+
1821
# Cython
1922
*.pyc
2023
*.pyd

docs/assets/test-data/math.wat

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
(module
2+
;; Global state for accumulator example
3+
(global $accumulator (mut i32) (i32.const 0))
4+
5+
;; Required init function
6+
(func $init)
7+
8+
;; Optional shot reset - resets accumulator to 0
9+
(func $shot_reinit
10+
i32.const 0
11+
global.set $accumulator)
12+
13+
;; Add two numbers
14+
(func $add (param i32 i32) (result i32)
15+
local.get 0
16+
local.get 1
17+
i32.add)
18+
19+
;; Subtract two numbers
20+
(func $sub (param i32 i32) (result i32)
21+
local.get 0
22+
local.get 1
23+
i32.sub)
24+
25+
;; Multiply two numbers
26+
(func $mul (param i32 i32) (result i32)
27+
local.get 0
28+
local.get 1
29+
i32.mul)
30+
31+
;; Accumulate a value and return the total
32+
(func $accumulate (param i32) (result i32)
33+
local.get 0
34+
global.get $accumulator
35+
i32.add
36+
global.set $accumulator
37+
global.get $accumulator)
38+
39+
;; Compute threshold (example from docs)
40+
(func $compute_threshold (param i32 i32) (result i32)
41+
local.get 0
42+
local.get 1
43+
i32.add
44+
i32.const 2
45+
i32.div_s)
46+
47+
;; Memory (required for some WASM operations)
48+
(memory (;0;) 1)
49+
50+
;; Exports
51+
(export "init" (func $init))
52+
(export "shot_reinit" (func $shot_reinit))
53+
(export "add" (func $add))
54+
(export "sub" (func $sub))
55+
(export "mul" (func $mul))
56+
(export "accumulate" (func $accumulate))
57+
(export "compute_threshold" (func $compute_threshold))
58+
(export "memory" (memory 0))
59+
)

docs/development/QIS_ARCHITECTURE.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# QIS Architecture: Interface, Runtime, and Engine
22

3+
<!--skip: Internal architecture documentation with illustrative code snippets-->
4+
35
This document describes the architecture of the Quantum Instruction Set (QIS) system in PECOS, focusing on how quantum programs are compiled, executed, and simulated.
46

57
## Overview

docs/development/circuit-representations.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Circuit Representations (Internal)
22

3+
<!--skip: Internal architecture documentation with illustrative code snippets-->
4+
35
This document covers the internal circuit representations used in PECOS's Rust core. For user-facing documentation on building and manipulating circuits, see the [User Guide: Circuit Representation](../user-guide/circuit-representation.md).
46

57
## Overview

docs/user-guide/circuit-representation.md

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,10 @@ Gates can have arbitrary metadata attached:
299299
=== ":fontawesome-brands-rust: Rust"
300300
```rust
301301
let mut circuit = DagCircuit::new();
302-
circuit.h(0).cx(0, 1).h(1).cx(1, 2).mz(0).mz(1).mz(2);
302+
circuit.h(0).cx(0, 1).h(1).cx(1, 2);
303+
circuit.mz(0);
304+
circuit.mz(1);
305+
circuit.mz(2);
303306

304307
// Basic metrics
305308
println!("Total gates: {}", circuit.gate_count());
@@ -399,13 +402,13 @@ A time-sliced circuit representation where gates are organized into discrete tim
399402
let mut circuit = TickCircuit::new();
400403

401404
// First tick: parallel gates
402-
circuit.tick().h(0).h(1).h(2);
405+
circuit.tick().h(&[0, 1, 2]);
403406

404407
// Second tick: entangling layer
405-
circuit.tick().cx(0, 1).cx(2, 3);
408+
circuit.tick().cx(&[(0, 1), (2, 3)]);
406409

407410
// Third tick: measurements
408-
circuit.tick().mz(0).mz(1);
411+
circuit.tick().mz(&[0, 1]);
409412

410413
println!("Number of ticks: {}", circuit.num_ticks());
411414
println!("Total gates: {}", circuit.gate_count());
@@ -434,9 +437,9 @@ TickCircuit prevents scheduling conflicting gates in the same tick:
434437
let mut circuit = TickCircuit::new();
435438
let mut tick = circuit.tick();
436439

437-
tick.h(0);
440+
tick.h(&[0]);
438441
// This would error: qubit 0 already used
439-
// tick.cx(0, 1);
442+
// tick.cx(&[(0, 1)]);
440443

441444
// Use try_add_gate for fallible operations
442445
if let Err(e) = tick.try_add_gate(Gate::cx(&[(0, 1)])) {
@@ -466,7 +469,7 @@ TickCircuit prevents scheduling conflicting gates in the same tick:
466469
// Add metadata to a tick
467470
let mut tick = circuit.tick();
468471
tick.meta("round", Attribute::Int(1));
469-
tick.h(0).meta("error_rate", Attribute::Float(0.001));
472+
tick.h(&[0]).meta("error_rate", Attribute::Float(0.001));
470473

471474
// Circuit-level metadata
472475
circuit.set_meta("name", Attribute::String("Bell state".into()));
@@ -497,8 +500,8 @@ TickCircuit can be converted to and from DagCircuit:
497500

498501
// TickCircuit -> DagCircuit
499502
let mut tick_circuit = TickCircuit::new();
500-
tick_circuit.tick().h(0).h(1);
501-
tick_circuit.tick().cx(0, 1);
503+
tick_circuit.tick().h(&[0, 1]);
504+
tick_circuit.tick().cx(&[(0, 1)]);
502505

503506
let dag_circuit = DagCircuit::from(tick_circuit);
504507

@@ -542,7 +545,7 @@ A general directed graph with weighted edges and attributes:
542545

543546
=== ":fontawesome-brands-rust: Rust"
544547
```rust
545-
use pecos::graph::DiGraph;
548+
use pecos::digraph::DiGraph;
546549

547550
let mut graph = DiGraph::new();
548551

@@ -600,7 +603,7 @@ A directed acyclic graph with topological ordering and cycle prevention:
600603

601604
=== ":fontawesome-brands-rust: Rust"
602605
```rust
603-
use pecos::graph::DAG;
606+
use pecos::dag::DAG;
604607

605608
let mut dag = DAG::new();
606609

docs/user-guide/decoders.md

Lines changed: 42 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,30 @@
11
# Decoders
22

3+
```hidden-rust
4+
use pecos_decoders::{
5+
CssCode, SparseMatrix, Decoder, BpMethod, OsdMethod, UfMethod, BpSchedule,
6+
BpOsdDecoder, BpLsdDecoder, BeliefFindDecoder, FlipDecoder, UnionFindDecoder,
7+
SoftInfoBpDecoder, SoftDecoder, LdpcError,
8+
};
9+
10+
fn create_css_code() -> Result<CssCode, Box<dyn std::error::Error>> {
11+
let hx_rows: Vec<u32> = vec![0, 1, 0, 1];
12+
let hx_cols: Vec<u32> = vec![0, 2, 1, 3];
13+
let hx = SparseMatrix::from_coo(2, 4, hx_rows, hx_cols)?;
14+
let hz_rows: Vec<u32> = vec![0, 1, 0, 1];
15+
let hz_cols: Vec<u32> = vec![0, 1, 2, 3];
16+
let hz = SparseMatrix::from_coo(2, 4, hz_rows, hz_cols)?;
17+
Ok(CssCode::new(hx, hz)?)
18+
}
19+
20+
fn main() -> Result<(), Box<dyn std::error::Error>> {
21+
let css_code = create_css_code()?;
22+
let syndrome = vec![1u8, 0, 1, 0];
23+
// CODE
24+
Ok(())
25+
}
26+
```
27+
328
PECOS provides quantum error correction decoders through both Python and Rust APIs. The availability of specific decoders varies by language.
429

530
## Overview
@@ -114,19 +139,20 @@ decoder = DummyDecoder()
114139

115140
Before using decoders, you need a quantum error correction code:
116141

142+
<!--skip: standalone function definition - included in preamble-->
117143
```rust
118144
use pecos_decoders::{CssCode, SparseMatrix};
119145

120146
// Create a CSS code from parity check matrices
121147
fn create_css_code() -> Result<CssCode, Box<dyn std::error::Error>> {
122-
// Define Hx and Hz matrices
123-
let hx_rows = vec![0, 1, 0, 1];
124-
let hx_cols = vec![0, 2, 1, 3];
125-
let hx = SparseMatrix::new(2, 4, hx_rows, hx_cols)?;
148+
// Define Hx and Hz matrices as COO format sparse matrices
149+
let hx_rows: Vec<u32> = vec![0, 1, 0, 1];
150+
let hx_cols: Vec<u32> = vec![0, 2, 1, 3];
151+
let hx = SparseMatrix::from_coo(2, 4, hx_rows, hx_cols)?;
126152

127-
let hz_rows = vec![0, 1, 0, 1];
128-
let hz_cols = vec![0, 1, 2, 3];
129-
let hz = SparseMatrix::new(2, 4, hz_rows, hz_cols)?;
153+
let hz_rows: Vec<u32> = vec![0, 1, 0, 1];
154+
let hz_cols: Vec<u32> = vec![0, 1, 2, 3];
155+
let hz = SparseMatrix::from_coo(2, 4, hz_rows, hz_cols)?;
130156

131157
Ok(CssCode::new(hx, hz)?)
132158
}
@@ -138,6 +164,7 @@ fn create_css_code() -> Result<CssCode, Box<dyn std::error::Error>> {
138164

139165
Combines belief propagation with ordered statistics decoding post-processing.
140166

167+
<!--skip: API illustration - actual implementation uses different constructor signature-->
141168
```rust
142169
use pecos_decoders::{BpOsdDecoder, Decoder, OsdMethod};
143170

@@ -165,6 +192,7 @@ println!("Converged: {}", result.converged);
165192

166193
Localized version of OSD for better scaling with large codes.
167194

195+
<!--skip: API illustration-->
168196
```rust
169197
use pecos_decoders::{BpLsdDecoder, Decoder};
170198

@@ -179,6 +207,7 @@ let result = decoder.decode(&syndrome)?;
179207

180208
Combines belief propagation with union-find algorithm.
181209

210+
<!--skip: API illustration-->
182211
```rust
183212
use pecos_decoders::{BeliefFindDecoder, Decoder, UfMethod};
184213

@@ -193,6 +222,7 @@ let result = decoder.decode(&syndrome)?;
193222

194223
Fast bit-flipping decoder suitable for real-time applications.
195224

225+
<!--skip: API illustration-->
196226
```rust
197227
use pecos_decoders::{FlipDecoder, Decoder, BpSchedule};
198228

@@ -207,6 +237,7 @@ let result = decoder.decode(&syndrome)?;
207237

208238
Graph-based decoder using union-find data structure.
209239

240+
<!--skip: API illustration-->
210241
```rust
211242
use pecos_decoders::{UnionFindDecoder, Decoder, UfMethod};
212243

@@ -222,6 +253,7 @@ let result = decoder.decode(&syndrome)?;
222253

223254
Use log-likelihood ratios for improved decoding performance.
224255

256+
<!--skip: API illustration-->
225257
```rust
226258
use pecos_decoders::{SoftInfoBpDecoder, SoftDecoder};
227259

@@ -236,6 +268,7 @@ let result = decoder.decode_with_llrs(&syndrome, &llrs)?;
236268

237269
Decode multiple syndromes efficiently.
238270

271+
<!--skip: API illustration-->
239272
```rust
240273
use pecos_decoders::BatchDecoder;
241274

@@ -253,6 +286,7 @@ for (i, result) in results.iter().enumerate() {
253286

254287
#### Performance Tuning
255288

289+
<!--skip: API illustration-->
256290
```rust
257291
let mut decoder = BpOsdDecoder::new(css_code);
258292
decoder.set_schedule(BpSchedule::Parallel); // Use parallel BP updates
@@ -261,6 +295,7 @@ decoder.set_num_threads(4); // Set thread count
261295

262296
### Error Handling
263297

298+
<!--skip: API illustration-->
264299
```rust
265300
match decoder.decode(&syndrome) {
266301
Ok(result) => {

docs/user-guide/hugr-simulation.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ Let's create a Bell state using Guppy. First, define a quantum function:
6565

6666
=== ":fontawesome-brands-rust: Rust"
6767

68+
<!--skip: requires pre-compiled bell_state.hugr file-->
6869
```rust
6970
use pecos_hugr::{hugr_engine, hugr_sim};
7071
use pecos_engines::{ClassicalControlEngineBuilder, ClassicalEngine};
@@ -138,6 +139,7 @@ If you have HUGR files (compiled from Guppy or other tools), you can run them di
138139

139140
=== ":fontawesome-brands-rust: Rust"
140141

142+
<!--skip: requires pre-compiled circuit.hugr file-->
141143
```rust
142144
use pecos_hugr::{hugr_engine, hugr_sim};
143145
use pecos_engines::{ClassicalControlEngineBuilder, ClassicalEngine};

0 commit comments

Comments
 (0)