Skip to content

Commit 7b086e0

Browse files
committed
update documentation
1 parent e2846eb commit 7b086e0

File tree

9 files changed

+241
-37
lines changed

9 files changed

+241
-37
lines changed

src/circuits/mod.rs

Lines changed: 45 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,35 @@ use std::fmt;
1717
/// This structure embodies (Sequential Ordering) by defining a precise
1818
/// list of interactions to be simulated. It captures a specific process or algorithm within the framework.
1919
///
20-
/// Analogy: Similar to `cirq.Circuit` or `qiskit.QuantumCircuit`, representing the
21-
/// sequence of gates and measurements applied to qubits.
20+
/// Analogy: Similar to `cirq.Circuit` or `qiskit.QuantumCircuit`.
21+
///
22+
/// # Examples
23+
///
24+
/// ```
25+
/// # use onq::{Circuit, CircuitBuilder, Operation, QduId, LockType};
26+
/// # fn qid(id: u64) -> QduId { QduId(id) }
27+
/// let q0 = qid(0);
28+
/// let q1 = qid(1);
29+
///
30+
/// // Create using methods
31+
/// let mut circuit1 = Circuit::new();
32+
/// circuit1.add_operation(Operation::InteractionPattern { target: q0, pattern_id: "Superposition".to_string()});
33+
/// circuit1.add_operation(Operation::ControlledInteraction { control: q0, target: q1, pattern_id: "QualityFlip".to_string()});
34+
///
35+
/// // Create using builder
36+
/// let circuit2 = CircuitBuilder::new()
37+
/// .add_op(Operation::InteractionPattern { target: q0, pattern_id: "Superposition".to_string()})
38+
/// .add_op(Operation::ControlledInteraction { control: q0, target: q1, pattern_id: "QualityFlip".to_string()})
39+
/// .build();
40+
///
41+
/// assert_eq!(circuit1.len(), 2);
42+
/// assert!(circuit1.qdus().contains(&q0));
43+
/// assert!(circuit1.qdus().contains(&q1));
44+
/// assert_eq!(circuit1, circuit2);
45+
///
46+
/// // Print the circuit diagram
47+
/// println!("{}", circuit1);
48+
/// ```
2249
#[derive(Clone, PartialEq)] // PartialEq useful for testing circuits
2350
pub struct Circuit {
2451
/// The unique set of QDUs involved across all operations in this circuit.
@@ -115,7 +142,22 @@ impl Default for Circuit {
115142
// Circuit Builder
116143
//-------------------------------------------------------------------------
117144

118-
/// A helper struct for programmatically constructing `Circuit` instances using method chaining.
145+
/// A helper struct for programmatically constructing [`Circuit`] instances using method chaining.
146+
///
147+
/// # Examples
148+
/// ```
149+
/// # use onq::{Circuit, CircuitBuilder, Operation, QduId, LockType};
150+
/// # fn qid(id: u64) -> QduId { QduId(id) }
151+
/// let q0 = qid(0);
152+
/// let q1 = qid(1);
153+
///
154+
/// let circuit = CircuitBuilder::new()
155+
/// .add_op(Operation::InteractionPattern { target: q0, pattern_id: "Superposition".to_string()})
156+
/// .add_op(Operation::ControlledInteraction { control: q0, target: q1, pattern_id: "QualityFlip".to_string()})
157+
/// .build();
158+
///
159+
/// assert_eq!(circuit.len(), 2);
160+
/// ```
119161
pub struct CircuitBuilder {
120162
circuit: Circuit,
121163
// Potential future fields:

src/core/constants.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
// Example: src/core/constants.rs
1+
//! Mathematical constants potentially relevant to simulation.
2+
3+
/// Mathematical constants derived from or relevant to the framework
24
pub mod onq_constants {
5+
/// The golden ratio constant φ (Phi).
36
pub const PHI: f64 = 1.618_033_988_749_895;
4-
// Add PI here too for consistency, though std::f64::consts::PI exists
7+
/// Used for phase angles (`e^(iθ)`)
58
pub const PI: f64 = std::f64::consts::PI;
69
}
710

src/core/error.rs

Lines changed: 27 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// src/core/error.rs
1+
//! Error handling logic
22
33
use std::fmt;
44

@@ -21,23 +21,43 @@ impl fmt::Display for QduId {
2121
pub enum OnqError {
2222
/// Failure to maintain coherent state or unified reference.
2323
/// Analogous to failing (Phase Coherence).
24-
Incoherence { message: String },
24+
Incoherence {
25+
/// Incoherence failure message
26+
message: String
27+
},
2528

2629
/// Failure to stabilize or maintain stable patterns.
2730
/// Analogous to failing (Frame Stability) or (Pattern Convergence).
28-
Instability { message: String },
31+
Instability {
32+
/// Instability failure message
33+
message: String
34+
},
2935

3036
/// Compromised distinction boundary, losing qualitative distinction
31-
BoundaryFailure { qdu_id: QduId, message: String },
37+
BoundaryFailure {
38+
/// Compromised QDU
39+
qdu_id: QduId,
40+
/// BoundaryFailure failure message
41+
message: String
42+
},
3243

3344
/// Invalid reference, relationship, or connection between elements
34-
ReferenceViolation { message: String },
45+
ReferenceViolation {
46+
/// ReferenceViolation failure message
47+
message: String
48+
},
3549

3650
/// An applied operation is inconsistent with the current state or framework rules
37-
InvalidOperation { message: String },
51+
InvalidOperation {
52+
/// InvalidOperation failure message
53+
message: String
54+
},
3855

3956
/// General error encountered during the simulation process itself.
40-
SimulationError { message: String },
57+
SimulationError {
58+
/// SimulationError failure message
59+
message: String
60+
},
4161
// Future: Could add variants like `FrameNotFound`, `QduNotFound` if needed by simulation logic.
4262
}
4363

src/core/frame.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// src/core/frame.rs
1+
//! QDU interaction logic
22
33
use std::fmt;
44
// Potentially use Arc later if frames need to be shared reference-counted objects

src/core/qdu.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// src/core/qdu.rs
1+
//! ONQ qubit representation data structure
22
33
use super::error::QduId;
44
use std::fmt;

src/core/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// src/core/state.rs
1+
//! ONQ state vector representation
22
33
// Make sure `num-complex` is in Cargo.toml: `num-complex = "0.4"`
44
use num_complex::Complex;

src/lib.rs

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,50 @@
11
// src/lib.rs
22

3-
//! `onq` - A library for simulating quantum information processing
3+
#![warn(missing_docs)] // Enforce documentation warnings during build
4+
5+
//! `onq`: Operations for Next Generation Quantum Computating Simulation Library
6+
//!
7+
//! This library provides Rust structures and functions for simulating computation
8+
//! based *only* on abstract principles.
9+
//!
10+
//! ## Core Idea
11+
//!
12+
//! Unlike standard quantum simulators modeling quantum mechanics, `onq` explores
13+
//! computation emerging necessarily from a self-containing distinction. It models
14+
//! phenomena analogous to quantum computation (superposition,
15+
//! entanglement analogs, interference, stabilization) without assuming physics,
16+
//! relying solely on the structural and logical consequences defined by the framework
17+
//!
18+
//! ## Key Components
419
//!
5-
//! This library provides structures and tools derived strictly from nature
6-
//! to model phenomena analogous to quantum computation.
20+
//! * **Core Types (`onq::core`):** Defines fundamental concepts like `QduId`,
21+
//! `PotentialityState` (complex state vectors), and `StableState`.
22+
//! * **Operations (`onq::operations`):** Defines quantum operations (`Operation`, `LockType`)
23+
//! (analogs of H, X, Z, S, T, CNOT, CZ, CPhase, etc.).
24+
//! * **Circuits (`onq::circuits`):** Provides `Circuit` to represent ordered sequences
25+
//! of quantum operations and `CircuitBuilder` for easy construction.
26+
//! * **Validation (`onq::validation`):** Offers functions to check state validity
27+
//! (normalization, phase coherence interpretation).
28+
//! * **ONQ Virtual Machine (`onq::vm`):** An interpreter (`OnqVm`) that executes
29+
//! `Program`s containing mixed sequences of `Instruction`s (quantum ops, classical ops,
30+
//! control flow based on stabilization results).
31+
//! * **Simulation Engine (`onq::simulation::engine` - internal):** Handles the underlying
32+
//! state vector evolution and stabilization logic.
33+
//!
34+
//! ## Interpretation & Differences from QM
35+
//!
36+
//! Users should be aware that `onq` simulation relies heavily on **interpretations**
37+
//! of the abstract and sometimes mathematically ambiguous framework.
38+
//! Key differences from standard Quantum Mechanics include:
39+
//!
40+
//! * **Stabilization vs Measurement:** `Stabilize` is deterministic (seeded by state hash),
41+
//! uses scoring (interpreting Phase Coherence and Pattern Resonance),
42+
//! and resolves potentiality based on framework rules, not probabilistic collapse.
43+
//! * **Locking:** `RelationalLock` uses non-unitary projection to model state integration.
44+
//! * **Operations:** Gate availability and behavior are strictly based on derivations.
45+
//!
46+
//! **See the project README for detailed explanations of concepts, interpretations, and limitations.**
47+
748

849
pub mod core;
950
pub mod operations;

src/operations/mod.rs

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,13 +88,15 @@ pub enum Operation {
8888
///
8989
/// Analogy: Could be analogous to operations creating/breaking entanglement or
9090
/// enforcing phase coherence, but details depend on derivation.
91-
/// **Placeholder Name:** Needs better grounding.
9291
RelationalLock {
92+
/// The first QDU involved in the lock.
9393
qdu1: QduId,
94+
/// The second QDU involved in the lock.
9495
qdu2: QduId,
9596
/// The target integrated/entangled state type for the lock.
9697
lock_type: LockType,
97-
establish: bool, // If true, project onto lock state; if false, currently no-op.
98+
/// If true, project onto lock state; if false, currently no-op.
99+
establish: bool,
98100
},
99101

100102
/// Represents the Stabilization Protocol (SP).
@@ -123,8 +125,29 @@ pub enum Operation {
123125

124126
impl Operation {
125127
/// Returns a list of all QDU IDs directly mentioned in the operation's parameters.
126-
/// This helps the simulator identify potentially affected states, although interactions
127-
/// might implicitly affect other connected QDUs within the same frame.
128+
///
129+
/// This helps identify which parts of the state vector might be affected by an operation,
130+
/// although the actual effect (especially for multi-QDU gates) modifies the global state.
131+
///
132+
/// # Examples
133+
/// ```
134+
/// # use onq::{Operation, QduId, LockType};
135+
/// let q0 = QduId(0);
136+
/// let q1 = QduId(1);
137+
/// let op_h = Operation::InteractionPattern { target: q0, pattern_id: "H".to_string() };
138+
/// let op_cx = Operation::ControlledInteraction { control: q0, target: q1, pattern_id: "X".to_string() };
139+
/// let op_lock = Operation::RelationalLock { qdu1: q0, qdu2: q1, lock_type: LockType::BellPhiPlus, establish: true };
140+
/// let op_stab = Operation::Stabilize { targets: vec![q0, q1] };
141+
///
142+
/// assert_eq!(op_h.involved_qdus(), vec![q0]);
143+
/// // Note: Order might not be guaranteed depending on internal representation if changed from vec!
144+
/// let mut cx_qdus = op_cx.involved_qdus(); cx_qdus.sort();
145+
/// assert_eq!(cx_qdus, vec![q0, q1]);
146+
/// let mut lock_qdus = op_lock.involved_qdus(); lock_qdus.sort();
147+
/// assert_eq!(lock_qdus, vec![q0, q1]);
148+
/// let mut stab_qdus = op_stab.involved_qdus(); stab_qdus.sort();
149+
/// assert_eq!(stab_qdus, vec![q0, q1]);
150+
/// ```
128151
pub fn involved_qdus(&self) -> Vec<QduId> {
129152
match self {
130153
Operation::PhaseShift { target, .. } => vec![*target],

0 commit comments

Comments
 (0)