Download runtime/quantum/mod.rs from Snapkitty/carry-agent: direct link, hf CLI and curl.
- Browser
- Download file 5.9 kB
-
https://huggingface.co/Snapkitty/carry-agent/resolve/main/runtime/quantum/mod.rs
- Command line
-
hf download hf://Snapkitty/carry-agent/runtime/quantum/mod.rs
-
curl -L -o mod.rs https://huggingface.co/Snapkitty/carry-agent/resolve/main/runtime/quantum/mod.rs
5.9 kB
| // CARRY Sovereign Agent Quantum Simulator & Research Platform | |
| // Module exports | |
| pub mod core; | |
| pub mod fsm; | |
| pub mod agents; | |
| pub mod dag; | |
| pub mod icp; | |
| pub mod asp; | |
| pub mod ftb; | |
| pub mod topological; | |
| pub mod emulator_6052; | |
| pub mod gitc; | |
| pub mod benchmarks; | |
| mod tests { | |
| use super::core::*; | |
| use super::fsm::*; | |
| use super::agents::*; | |
| use super::dag::*; | |
| use super::icp::*; | |
| use super::asp::*; | |
| use super::ftb::*; | |
| use super::topological::*; | |
| use super::emulator_6052::*; | |
| use super::gitc::*; | |
| use super::benchmarks::*; | |
| fn test_core_simulator_statevector_and_purity() { | |
| let mut sim = QuantumSimulator::new(2, SimulationMode::StateVector, ErrorModel::None); | |
| assert!(sim.state.is_valid_state()); | |
| assert_eq!(sim.state.purity(), 1.0); | |
| let bell = BenchmarkSuite::build_bell_circuit(); | |
| for g in &bell.gates { | |
| sim.apply_gate(g).unwrap(); | |
| } | |
| assert!(sim.state.is_valid_state()); | |
| assert_eq!(sim.entanglement_graph.are_entangled(0, 1), true); | |
| } | |
| fn test_density_matrix_simulator() { | |
| let mut sim = QuantumSimulator::new(2, SimulationMode::DensityMatrix, ErrorModel::None); | |
| assert!(sim.state.is_valid_state()); | |
| assert_eq!(sim.state.purity(), 1.0); | |
| sim.apply_gate(&Gate::h(0)).unwrap(); | |
| assert!(sim.state.is_valid_state()); | |
| } | |
| fn test_quantum_fsm_and_max_cycle() { | |
| let mut fsm = QuantumFSM::new(3); | |
| assert_eq!(fsm.state, QuantumFSMState::Init); | |
| fsm.transition(QuantumFSMState::Prepare, "agent1", vec![0], "PREP", "None", "StateReady").unwrap(); | |
| fsm.transition(QuantumFSMState::Entangle, "agent1", vec![0, 1], "ENT", "StateReady", "Entangled").unwrap(); | |
| fsm.transition(QuantumFSMState::Compute, "agent1", vec![0, 1], "COMP", "Entangled", "Computed").unwrap(); | |
| // 4th transition exceeds max_cycle = 3 | |
| let res = fsm.transition(QuantumFSMState::Measure, "agent1", vec![0], "MEAS", "Computed", "Measured"); | |
| assert!(res.is_err()); | |
| assert_eq!(fsm.state, QuantumFSMState::CycleLimit); | |
| } | |
| fn test_agent_pair_cross_verification() { | |
| let primary = Agent::new_primary("a1_compute", vec![0, 1], 100); | |
| let partner = Agent::new_partner("a2_verify", "a1_compute", AgentRole::PartnerVerify, vec![0, 1]); | |
| let pair = AgentPair::new(primary, partner, "group_0").unwrap(); | |
| let sim = QuantumSimulator::new(2, SimulationMode::StateVector, ErrorModel::None); | |
| let ver = pair.cross_verify_state(&sim).unwrap(); | |
| assert!(ver.contains("PARTNER_VERIFIED")); | |
| } | |
| fn test_quantum_dag_provenance() { | |
| let mut dag = QuantumDAG::new(); | |
| let n1 = dag.add_node(QuantumDAGNodeType::Input, "LoadInput", "a1", vec![0], vec![]).unwrap(); | |
| let n2 = dag.add_node(QuantumDAGNodeType::StatePreparation, "Prep", "a1", vec![0], vec![n1]).unwrap(); | |
| let n3 = dag.add_node(QuantumDAGNodeType::ICPGate, "ICP", "icp_gate", vec![0], vec![n2]).unwrap(); | |
| let _n4 = dag.add_node(QuantumDAGNodeType::Commit, "Commit", "a1", vec![0], vec![n3]).unwrap(); | |
| assert!(dag.validate_path().is_ok()); | |
| } | |
| fn test_icp_governance_gate_and_halt() { | |
| let mut icp = ICPGate::new(); | |
| let mut sim = QuantumSimulator::new(2, SimulationMode::StateVector, ErrorModel::None); | |
| let mut fsm = QuantumFSM::new(10); | |
| // Attempt operation on out-of-bounds qubit 5 -> must HALT | |
| let res = icp.execute_pipeline("agent1", 5, "H", &mut sim, &mut fsm, |s| { | |
| s.apply_gate(&Gate::h(5)).map(|_| "OK".to_string()) | |
| }); | |
| assert!(res.is_err()); | |
| assert_eq!(fsm.state, QuantumFSMState::Halted); | |
| } | |
| fn test_asp_constraint_engine() { | |
| let mut asp = ASPEngine::new(); | |
| asp.add_fact(ASPFact::Qubit("q0".to_string())); | |
| asp.add_fact(ASPFact::Agent("a1".to_string())); | |
| asp.add_fact(ASPFact::Controls("a1".to_string(), "q0".to_string())); | |
| match asp.solve() { | |
| ASPSolverResult::SAT { .. } => {} | |
| _ => panic!("Expected SAT"), | |
| } | |
| // Add invalid control reference | |
| asp.add_fact(ASPFact::Controls("a1".to_string(), "q99".to_string())); // q99 doesn't exist | |
| match asp.solve() { | |
| ASPSolverResult::UNSAT { .. } => {} | |
| _ => panic!("Expected UNSAT"), | |
| } | |
| } | |
| fn test_6052_emulator_hard_cycle_stop() { | |
| let mut emu = Emulator6052::new(2); | |
| for _ in 0..5 { | |
| emu.push_instruction(Insn6052::QGATE { gate: Gate::h(0) }); | |
| } | |
| let mut sim = QuantumSimulator::new(1, SimulationMode::StateVector, ErrorModel::None); | |
| let mut fsm = QuantumFSM::new(10); | |
| let receipt = emu.execute(&mut sim, &mut fsm); | |
| assert_eq!(receipt.status, "CYCLE_LIMIT"); | |
| assert_eq!(receipt.cycles_executed, 2); | |
| } | |
| fn test_gitc_experiment() { | |
| let mut gitc = GITCExperiment::new(5); | |
| let summary = gitc.run_experiment().unwrap(); | |
| assert!(summary.contains("GITC_EXPERIMENT_COMPLETE")); | |
| assert_eq!(gitc.results.len(), 5); | |
| } | |
| fn test_reference_circuits_benchmark() { | |
| let bell = BenchmarkSuite::build_bell_circuit(); | |
| let report = BenchmarkSuite::run_benchmark("Bell", &bell, 100).unwrap(); | |
| assert_eq!(report.num_qubits, 2); | |
| assert_eq!(report.status, "SUCCESS"); | |
| let grover = BenchmarkSuite::build_grover_circuit(); | |
| let report2 = BenchmarkSuite::run_benchmark("Grover", &grover, 100).unwrap(); | |
| assert_eq!(report2.num_qubits, 2); | |
| } | |
| } | |