Crates.io | onq |
lib.rs | onq |
version | |
source | src |
created_at | 2025-04-02 14:42:15.493911+00 |
updated_at | 2025-05-07 17:31:24.127368+00 |
description | Operations for Next-generation Quantum computing |
homepage | |
repository | https://github.com/kn0sys/onq |
max_upload_size | |
id | 1616638 |
Cargo.toml error: | TOML parse error at line 21, column 1 | 21 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
onq
is a Rust library for simulating quantum computation and information processing derived strictly from the theoretical first principles.
Unlike conventional quantum computing simulators based on quantum mechanics postulates, onq
explores how computational dynamics might emerge necessarily from a single axiom. It aims to model phenomena analogous to quantum computation (superposition, entanglement analogs, interference, stabilization/measurement analogs) without assuming physics, relying instead on the structural and logical consequences defined by the framework provided during its development context.
This library serves as a tool for:
Key concepts derived and implemented in onq
:
onq::core::QduId
, struct onq::core::Qdu
implicitly managed by VM/Engine) The fundamental unit, analogous to a qubit. Represents a necessary, bounded distinction with inherent qualitative properties. Interpreted as having a minimal binary basis {Quality0, Quality1}.onq::core::PotentialityState
) Represents the state before stabilization. Uses a complex state vector (Vec<Complex<f64>>
) to capture multiple potentialities and phase relationships (inspired by e^(iθ)
). For N QDUs, uses a 2N dimensional vector to model integrated states. Assumes initial state |Q0...Q0>
.onq::operations::Operation
) Transformations derived from interaction principles (T=P⊗P
analog). Implemented as variants acting on the state vector, including:
InteractionPattern
s with derived matrices (analogs for I, X, Y, Z, H, S, T, S†, T†, √X, √X†, plus φ-based rotations).PhaseShift
.ControlledInteraction
(using derived conditional gating logic via 4x4 matrix).RelationalLock
(using derived non-unitary projection onto Bell states).onq::vm::OnqVm
) An interpreter that executes Program
s containing sequences of Instruction
s.onq::vm::Program
, onq::vm::Instruction
, onq::vm::ProgramBuilder
) Defines programs with mixed quantum operations, stabilization, classical memory access (Record
), classical computation (arithmetic, logic, compare), and control flow (labels, jumps, branches).onq::vm::Instruction::Stabilize
, internal SimulationEngine::stabilize
) The analog of measurement. Deterministically resolves PotentialityState
into StableState
. See "Key Differences" below.onq::validation::*
) Functions to check state normalization and Phase Coherence criteria.Understanding onq
requires recognizing its fundamental departures from standard quantum mechanics (QM):
onq
derives from abstract logical necessity, not QM postulates derived from physical observation.onq
: Stabilize
is deterministic. It resolves potentiality based on criteria:
|k>
) must meet an interpreted Phase Coherence threshold (Score_C1(k) > 0.618
) relative to the input state. States failing this cannot be stabilized into.S(k) = Score_C1(k) * |amplitude_k|^2
(interpreting resonance/convergence via amplitude).k
is chosen deterministically from the valid, scored possibilities using a pseudo-random number generator seeded by a hash of the input state vector. (Same input state -> Same outcome).onq
program yields the same stabilization results every time. Statistical distributions seen in QM experiments must emerge differently, if at all (perhaps through variations in initial state preparation or environmental interaction, which are not yet modeled).PhiRotate
may exist, and standard QM operations might be absent if not derivable.RelationalLock
uses non-unitary projection to force the state into specific integrated subspaces (Bell states currently), directly modeling Integration/Coherence. This differs from QM where entanglement arises purely from unitary evolution (e.g., CNOT on superposition).This library is heavily based on interpretation due to the abstract nature and mathematical ambiguities within the source texts provided. Key assumptions include:
|Q0...Q0>
state.T=P⊗P
).|c_k|^2
weighting) are interpretations. The application of the C1 >0.618
threshold as a filter on outcomes is also an interpretation.ControlledInteraction
assumes simple gating based on control quality.RelationalLock
assumes non-unitary projection is a valid mechanism for achieving integrated states.⊗
, ×
, ∇²
, etc.) and terms (φ, ψ in Ω(x)
).Therefore, simulation results reflect the behavior of this specific interpretation of the framework.
Display
trait.// From examples/vm_teleportation.rs
use onq::{
CircuitBuilder, Operation, QduId, Simulator, StableState
};
// Helper for QduId creation for brevity in examples
fn qid(id: u64) -> QduId { QduId(id) }
fn main() {
// Define the three QDUs involved
let msg_q = qid(0); // Message QDU (will be prepared in |+>)
let alice_q = qid(1); // Alice's QDU (part of the Bell pair)
let bob_q = qid(2); // Bob's QDU (part of the Bell pair, receives the state)
println!("QDUs defined: msg={}, alice={}, bob={}", msg_q, alice_q, bob_q);
// --- Build Circuit using Quantum Recovery Logic ---
let mut builder = CircuitBuilder::new();
println!("Building Teleportation Circuit...");
// 1. Prepare Message State: Put msg_q in |+> state
builder = builder.add_op(Operation::InteractionPattern {
target: msg_q,
pattern_id: "Superposition".to_string(), // H analog
});
println!(" Step 1: Prepared Message QDU in |+> state (using Superposition).");
// 2. Create Bell Pair between Alice and Bob: |Φ+> = (1/sqrt(2))(|00> + |11>)
builder = builder.add_op(Operation::InteractionPattern { // H on Alice
target: alice_q,
pattern_id: "Superposition".to_string(),
});
builder = builder.add_op(Operation::ControlledInteraction { // CNOT(Alice, Bob)
control: alice_q,
target: bob_q,
pattern_id: "QualityFlip".to_string(), // X analog
});
println!(" Step 2: Created Bell Pair between Alice and Bob.");
// 3. Alice performs Bell Measurement operations (basis change)
builder = builder.add_op(Operation::ControlledInteraction { // CNOT(Message, Alice)
control: msg_q,
target: alice_q,
pattern_id: "QualityFlip".to_string(),
});
builder = builder.add_op(Operation::InteractionPattern { // H on Message
target: msg_q,
pattern_id: "Superposition".to_string(),
});
println!(" Step 3: Applied Bell Measurement basis change gates (CNOT, H).");
// 4. Quantum Recovery Operations (before stabilization)
// These apply corrections based on the state *before* stabilization.
builder = builder.add_op(Operation::ControlledInteraction { // CNOT(Alice, Bob)
control: alice_q,
target: bob_q,
pattern_id: "QualityFlip".to_string(),
});
builder = builder.add_op(Operation::ControlledInteraction { // CZ(Message, Bob) analog
control: msg_q,
target: bob_q,
pattern_id: "PhaseIntroduce".to_string(), // Use derived Z analog pattern
});
println!(" Step 4: Applied Quantum Recovery gates (CNOT, CZ analog).");
// 5. Stabilize Bob's QDU to observe the teleported state
// Optionally stabilize Alice and Message to see their final states too.
builder = builder.add_op(Operation::Stabilize {
targets: vec![msg_q, alice_q, bob_q],
});
println!(" Step 5: Added final stabilization for all QDUs.");
let circuit = builder.build();
// Print the constructed circuit diagram
println!("\nQuantum Teleportation Circuit (Quantum Recovery):\n{}", circuit);
// --- Run Simulation ---
let simulator = Simulator::new();
println!("\nRunning simulation...");
match simulator.run(&circuit) {
Ok(result) => {
println!("Simulation finished successfully.");
println!("\nSimulation Result Details:");
println!("{}", result);
// --- Basic Result Analysis ---
// Ideally, Bob's QDU (bob_q) now holds the original state of msg_q (which was |+>).
// Stabilizing the |+> state = (1/sqrt(2))[|0> + |1>] depends on the rules.
// Based on our current stabilization (S(0)=0.25, S(1)=0.25), the outcome for Bob
// will be deterministically 0 or 1 based on the final state hash and PRNG.
// A full verification would require state vector tomography (not implemented)
// or running statistical tests if stabilization were probabilistic.
println!("\nAnalysis:");
if let Some(StableState::ResolvedQuality(bob_outcome)) = result.get_stable_state(&bob_q) {
println!("- Bob's QDU ({}) stabilized to state: {}", bob_q, bob_outcome);
println!(" (Note: Expected pre-stabilization state was |+>, outcome {} depends on deterministic stabilization)", bob_outcome);
} else {
println!("- Bob's QDU ({}) was not found in stabilization results.", bob_q);
}
// Print Alice and Message outcomes too
if let Some(StableState::ResolvedQuality(alice_outcome)) = result.get_stable_state(&alice_q) {
println!("- Alice's QDU ({}) stabilized to state: {}", alice_q, alice_outcome);
}
if let Some(StableState::ResolvedQuality(msg_outcome)) = result.get_stable_state(&msg_q) {
println!("- Message's QDU ({}) stabilized to state: {}", msg_q, msg_outcome);
println!(" (These represent the classical bits Alice would send in standard protocol)");
}
println!("\nVerification of perfect state teleportation would require state vector analysis.");
}
Err(e) => {
eprintln!("\n--- Simulation Failed ---");
eprintln!("Error: {}", e);
}
}
}
# Clone the repository (if applicable)
# git clone ...
# cd onq
# Build
cargo build [--release]
# Run tests (unit, integration, doc)
cargo test [--release]
# Run examples
cargo run --example sqrt_flip_demo [--release]
cargo run --example vm_teleportation [--release]
onq/notebooks
directoryLicensed under
MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
Contributions are welcome! Please feel free to submit issues or pull requests.