omega_meta_sona/
lib.rs

1//! # Omega Meta-SONA
2//!
3//! Self-Organizing Neural Architecture (META-SONA) - The intelligence design engine
4//! for ExoGenesis Omega.
5//!
6//! ## Overview
7//!
8//! META-SONA is the component that enables ExoGenesis Omega to design new cognitive
9//! architectures. While SONA optimizes weights within a fixed architecture, META-SONA
10//! optimizes the architecture itself.
11//!
12//! ## Features
13//!
14//! - **Architecture Search**: Monte Carlo Tree Search (MCTS) for exploring architecture space
15//! - **Hyperparameter Optimization**: Proximal Policy Optimization (PPO) for tuning
16//! - **Multi-Objective Fitness**: Evaluation across capability, efficiency, alignment, and novelty
17//! - **Intelligence Factory**: Create and evolve intelligences from specifications
18//!
19//! ## Architecture
20//!
21//! ```text
22//!                    ┌─────────────────────┐
23//!                    │   META-SONA         │
24//!                    └──────────┬──────────┘
25//!                               │
26//!          ┌────────────────────┼────────────────────┐
27//!          │                    │                    │
28//!          ▼                    ▼                    ▼
29//! ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
30//! │ Architecture    │  │ Intelligence    │  │  Fitness        │
31//! │ Search (MCTS)   │  │ Factory         │  │  Evaluation     │
32//! └─────────────────┘  └─────────────────┘  └─────────────────┘
33//!          │                    │                    │
34//!          ▼                    ▼                    ▼
35//! ┌─────────────────┐  ┌─────────────────┐  ┌─────────────────┐
36//! │ PPO             │  │ Architecture    │  │  Benchmarks     │
37//! │ Optimization    │  │ Space           │  │  & Metrics      │
38//! └─────────────────┘  └─────────────────┘  └─────────────────┘
39//! ```
40//!
41//! ## Usage
42//!
43//! ```rust
44//! use omega_meta_sona::{IntelligenceFactory, IntelligenceSpec};
45//!
46//! #[tokio::main]
47//! async fn main() -> Result<(), Box<dyn std::error::Error>> {
48//!     // Create factory
49//!     let mut factory = IntelligenceFactory::new();
50//!
51//!     // Define specification
52//!     let spec = IntelligenceSpec {
53//!         name: "My AI".to_string(),
54//!         min_capability: 0.8,
55//!         ..Default::default()
56//!     };
57//!
58//!     // Create intelligence
59//!     let intelligence = factory.create_intelligence(spec).await?;
60//!
61//!     println!("Created: {} with fitness {:.2}",
62//!         intelligence.name,
63//!         intelligence.architecture.fitness.unwrap().overall
64//!     );
65//!
66//!     Ok(())
67//! }
68//! ```
69//!
70//! ## Components
71//!
72//! ### Architecture Module
73//!
74//! Defines how architectures are represented and encoded:
75//! - `ArchitectureSpace`: The space of all possible architectures
76//! - `ArchitectureEncoding`: Vector representations for optimization
77//! - `ComputationalGraph`: Graph structure of neural architectures
78//!
79//! ### Search Module
80//!
81//! Algorithms for discovering architectures:
82//! - `MCTS`: Monte Carlo Tree Search with UCB1 selection
83//! - Parallel simulations and rollouts
84//! - Architecture-specific exploration bonuses
85//!
86//! ### Optimization Module
87//!
88//! Refinement of discovered architectures:
89//! - `PPOOptimizer`: Proximal Policy Optimization
90//! - Generalized Advantage Estimation (GAE)
91//! - Clipped surrogate objectives
92//!
93//! ### Fitness Module
94//!
95//! Multi-objective evaluation:
96//! - Capability evaluation (benchmarks)
97//! - Efficiency evaluation (resource usage)
98//! - Alignment evaluation (safety tests)
99//! - Novelty evaluation (innovation metrics)
100//!
101//! ### Factory Module
102//!
103//! Intelligence creation and evolution:
104//! - `IntelligenceFactory`: Main API for creating intelligences
105//! - Specification-based creation
106//! - Multi-generation evolution
107
108pub mod architecture;
109pub mod search;
110pub mod optimization;
111pub mod fitness;
112pub mod factory;
113
114// Re-export main types
115pub use architecture::{
116    ArchitectureSpace, ArchitectureEncoding, ArchitectureNode,
117    NodeType, Parameters, Connection, ComputationalGraph,
118};
119pub use search::{MCTS, MCTSConfig, MCTSError};
120pub use optimization::{PPOOptimizer, PPOConfig, Trajectory, OptimizationResult};
121pub use fitness::{FitnessEvaluator, MetricWeight, EvaluationError};
122pub use factory::{IntelligenceFactory, IntelligenceSpec, FactoryError};
123
124/// Version information
125pub const VERSION: &str = env!("CARGO_PKG_VERSION");
126
127/// Result type for META-SONA operations
128pub type Result<T> = std::result::Result<T, Box<dyn std::error::Error + Send + Sync>>;
129
130/// Meta-SONA orchestrator - main entry point
131pub struct MetaSONA {
132    factory: IntelligenceFactory,
133}
134
135impl MetaSONA {
136    /// Create a new MetaSONA instance
137    pub fn new() -> Self {
138        Self {
139            factory: IntelligenceFactory::new(),
140        }
141    }
142
143    /// Create a new intelligence from specification
144    pub async fn create_intelligence(&mut self, spec: IntelligenceSpec) -> Result<omega_core::Intelligence> {
145        self.factory.create_intelligence(spec).await
146            .map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)
147    }
148
149    /// Evolve an architecture through multiple generations
150    pub async fn evolve_architecture(
151        &mut self,
152        base: omega_core::Architecture,
153        generations: usize,
154    ) -> Result<omega_core::Architecture> {
155        self.factory.evolve_architecture(base, generations).await
156            .map_err(|e| Box::new(e) as Box<dyn std::error::Error + Send + Sync>)
157    }
158
159    /// Get the intelligence factory
160    pub fn factory(&self) -> &IntelligenceFactory {
161        &self.factory
162    }
163}
164
165impl Default for MetaSONA {
166    fn default() -> Self {
167        Self::new()
168    }
169}
170
171#[cfg(test)]
172mod tests {
173    use super::*;
174
175    #[tokio::test]
176    async fn test_meta_sona_creation() {
177        let mut meta_sona = MetaSONA::new();
178        let spec = IntelligenceSpec::default();
179
180        let result = meta_sona.create_intelligence(spec).await;
181        assert!(result.is_ok());
182    }
183
184    #[tokio::test]
185    async fn test_meta_sona_evolution() {
186        let mut meta_sona = MetaSONA::new();
187
188        let base_arch = omega_core::Architecture {
189            id: "base".to_string(),
190            name: "Base".to_string(),
191            paradigm: omega_core::Paradigm::Neural,
192            substrate: omega_core::SubstrateType::Digital,
193            fitness: None,
194            lineage: vec![],
195            created_at: chrono::Utc::now(),
196        };
197
198        let result = meta_sona.evolve_architecture(base_arch, 2).await;
199        assert!(result.is_ok());
200    }
201}