ruvector_consciousness/traits.rs
1//! Trait hierarchy for consciousness computation engines.
2//!
3//! All Φ computation algorithms implement [`PhiEngine`]. Extension traits
4//! provide causal emergence and quantum-collapse integration.
5
6use crate::error::ConsciousnessError;
7use crate::types::{ComputeBudget, EmergenceResult, PhiAlgorithm, PhiResult, TransitionMatrix};
8
9/// Core trait for integrated information (Φ) computation.
10///
11/// Implementations must be thread-safe (`Send + Sync`) so they can be shared
12/// across parallel pipelines.
13pub trait PhiEngine: Send + Sync {
14 /// Compute Φ for the given transition probability matrix.
15 ///
16 /// The `state` parameter specifies the current system state as an index
17 /// into the TPM. If `None`, computes Φ over the stationary distribution.
18 fn compute_phi(
19 &self,
20 tpm: &TransitionMatrix,
21 state: Option<usize>,
22 budget: &ComputeBudget,
23 ) -> Result<PhiResult, ConsciousnessError>;
24
25 /// Return the algorithm identifier.
26 fn algorithm(&self) -> PhiAlgorithm;
27
28 /// Estimate computational cost without performing the computation.
29 fn estimate_cost(&self, n: usize) -> u64;
30}
31
32/// Extension trait for causal emergence computation.
33pub trait EmergenceEngine: Send + Sync {
34 /// Compute causal emergence for a system at multiple scales.
35 ///
36 /// Finds the coarse-graining of the micro-level TPM that maximizes
37 /// effective information, then computes the emergence metric.
38 fn compute_emergence(
39 &self,
40 tpm: &TransitionMatrix,
41 budget: &ComputeBudget,
42 ) -> Result<EmergenceResult, ConsciousnessError>;
43
44 /// Compute effective information for a given TPM.
45 fn effective_information(&self, tpm: &TransitionMatrix) -> Result<f64, ConsciousnessError>;
46}
47
48/// Trait for quantum-inspired consciousness collapse.
49///
50/// Integrates with `ruqu-exotic` quantum collapse search to model
51/// consciousness as a measurement-like collapse from superposition
52/// of possible partitions.
53pub trait ConsciousnessCollapse: Send + Sync {
54 /// Collapse the partition superposition to find the MIP.
55 ///
56 /// Instead of exhaustive enumeration, models partitions as amplitudes
57 /// and uses Grover-like iterations biased by information loss to
58 /// probabilistically find the minimum information partition.
59 fn collapse_to_mip(
60 &self,
61 tpm: &TransitionMatrix,
62 iterations: usize,
63 seed: u64,
64 ) -> Result<PhiResult, ConsciousnessError>;
65}