Download tests/simulation.rs from Snapkitty/automated-operator: direct link, hf CLI and curl.
- Browser
- Download file 5.7 kB
-
https://huggingface.co/Snapkitty/automated-operator/resolve/main/tests/simulation.rs
- Command line
-
hf download hf://Snapkitty/automated-operator/tests/simulation.rs
-
curl -L -o simulation.rs https://huggingface.co/Snapkitty/automated-operator/resolve/main/tests/simulation.rs
5.7 kB
| // Copyright 2026 Bel Esprit D'Accord Irrevocable Trust (EIN: 42-697643) | |
| // | |
| // Licensed under the Apache License, Version 2.0 (the "License"); | |
| // you may not use this file except in compliance with the License. | |
| // You may obtain a copy of the License at | |
| // | |
| // http://www.apache.org/licenses/LICENSE-2.0 | |
| // | |
| // OR | |
| // | |
| // Licensed under the GNU Affero General Public License, Version 3.0 | |
| // (the "AGPL"); you may not use this file except in compliance with the AGPL. | |
| // You may obtain a copy of the AGPL at | |
| // | |
| // https://www.gnu.org/licenses/agpl-3.0.html | |
| //! 10,000-Epoch Simulation Test for AutomatedOperator | |
| //! | |
| //! This test validates the core invariants under extended operation: | |
| //! - P2: Entropy bound never exceeded | |
| //! - P4: Determinism (same seed → same sequence) | |
| //! - P6: Sovereign compliance enforced | |
| //! - P7: No mode collapse (novelty > 0.30) | |
| use automated_operator::{AutomatedOperator, Ed25519PublicKey, ScoreWeights, ENTROPY_BOUND}; | |
| fn execute_10k_operator_simulation() { | |
| let anchor = Ed25519PublicKey([0xFF; 32]); | |
| let seed = [42u8; 32]; | |
| let mut operator = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT); | |
| let total_iterations = 10_000; | |
| let mut entropy_violations = 0; | |
| let mut null_generations = 0; | |
| let mut novelties = Vec::with_capacity(total_iterations); | |
| for epoch in 0..total_iterations { | |
| // Phase 1 & 2: Generate, Score, and Select | |
| if let Some(obj) = operator.next_objective() { | |
| // Invariant Check: P2 (Entropy Bound) | |
| if operator.state().entropy_budget < 0.0 || operator.state().entropy_budget > ENTROPY_BOUND { | |
| entropy_violations += 1; | |
| } | |
| // Invariant Check: P6 (Sovereign Compliance) | |
| assert_eq!( | |
| obj.target_space_hash[0], | |
| anchor.0[0], | |
| "Sovereign compliance violation at epoch {}", epoch | |
| ); | |
| // Track novelty to prove P7 (Non-Triviality / No Mode Collapse) | |
| let novelty = operator.novelty_estimate(&obj); | |
| novelties.push(novelty); | |
| // Phase 3 & 4: Simulate Engine Result Pipeline | |
| let mock_result_hash = [epoch as u8; 32]; | |
| let mock_proof_hash = [0xAA; 32]; | |
| operator.receive_result(mock_result_hash, mock_proof_hash); | |
| } else { | |
| // Null generation occurs if entropy budget requires relaxing | |
| null_generations += 1; | |
| } | |
| } | |
| // --- Simulation Diagnostics --- | |
| let avg_novelty: f32 = novelties.iter().sum::<f32>() / novelties.len() as f32; | |
| let min_novelty = novelties.iter().fold(f32::INFINITY, |a, &b| a.min(b)); | |
| let max_novelty = novelties.iter().fold(f32::NEG_INFINITY, |a, &b| a.max(b)); | |
| println!("========================================"); | |
| println!("AUTOMATED OPERATOR: 10K SIMULATION RUN"); | |
| println!("========================================"); | |
| println!("Total Epochs: {}", total_iterations); | |
| println!("Valid Objectives: {}", novelties.len()); | |
| println!("Null Generations: {} (Budget Relaxations)", null_generations); | |
| println!("Entropy Violations: {}", entropy_violations); | |
| println!("----------------------------------------"); | |
| println!("Novelty Distribution:"); | |
| println!(" Average: {:.4}", avg_novelty); | |
| println!(" Minimum: {:.4}", min_novelty); | |
| println!(" Maximum: {:.4}", max_novelty); | |
| println!("========================================"); | |
| // Hard Assertions for CI Pipeline | |
| assert_eq!(entropy_violations, 0, "FATAL: Entropy budget was breached."); | |
| assert!(avg_novelty > 0.30, "FATAL: Mode collapse detected. Novelty too low: {}", avg_novelty); | |
| assert!(novelties.len() > 9000, "FATAL: Too many null generations, operator stalled."); | |
| } | |
| fn test_determinism_same_seed_same_sequence() { | |
| let seed = [42u8; 32]; | |
| let anchor = Ed25519PublicKey([1u8; 32]); | |
| let mut op1 = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT); | |
| let mut op2 = AutomatedOperator::new(seed, anchor, ScoreWeights::DEFAULT); | |
| for epoch in 0..100 { | |
| let o1 = op1.next_objective(); | |
| let o2 = op2.next_objective(); | |
| assert_eq!(o1, o2, "Determinism violated at epoch {}", epoch); | |
| if o1.is_some() { | |
| op1.receive_result([1u8; 32], [2u8; 32]); | |
| op2.receive_result([1u8; 32], [2u8; 32]); | |
| } | |
| } | |
| } | |
| fn test_sovereign_compliance_enforced() { | |
| let anchor = Ed25519PublicKey([0xFFu8; 32]); | |
| let mut op = AutomatedOperator::new([0u8; 32], anchor, ScoreWeights::DEFAULT); | |
| for epoch in 0..1000 { | |
| if let Some(obj) = op.next_objective() { | |
| assert_eq!(obj.target_space_hash[0], 0xFF, "Sovereign compliance violation at epoch {}", epoch); | |
| op.receive_result([1u8; 32], [2u8; 32]); | |
| } | |
| } | |
| } | |
| fn test_novelty_increases_over_time() { | |
| let mut op = AutomatedOperator::new([0u8; 32], Ed25519PublicKey([0xFF; 32]), ScoreWeights::DEFAULT); | |
| let mut novelties = Vec::new(); | |
| for _ in 0..50 { | |
| if let Some(obj) = op.next_objective() { | |
| let novelty = op.novelty_estimate(&obj); | |
| novelties.push(novelty); | |
| op.receive_result([1u8; 32], [2u8; 32]); | |
| } | |
| } | |
| let avg_novelty: f32 = novelties.iter().sum::<f32>() / novelties.len() as f32; | |
| println!("Average novelty over 50 epochs: {:.4}", avg_novelty); | |
| assert!(avg_novelty > 0.30, "Average novelty too low: {}", avg_novelty); | |
| } |