axicor-core 0.1.0

Axicor SNN engine — C-ABI memory contracts, SoA layouts, and IPC primitives
Documentation
use serde::{Deserialize, Serialize};
use std::fs;
use std::path::Path;

/// Configures exactly *what* piece of the brain this node simulates,
/// and *where* its neighbors are located.
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct InstanceConfig {
    #[serde(default)]
    pub model_id_v1: Option<crate::config::sys::SystemMeta>,
    #[serde(default)]
    pub depart_id_v1: Option<crate::config::sys::SystemMeta>,
    #[serde(default)]
    pub shard_id_v1: Option<crate::config::sys::SystemMeta>,

    /// Reference to the zone folder name (e.g. "V1")
    pub zone_id: String,

    /// Offset of this shard in the global brain space (in voxels)
    pub world_offset: Coordinate,

    /// Dimensions of this shard (in voxels)
    pub dimensions: Dimensions,

    /// Neighborhood topology. "Self" means loopback (toroidal graph mapping),
    /// otherwise an IP:Port string. Left blank if bounded.
    pub neighbors: Neighbors,

    /// Shard-specific runtime settings
    pub settings: ShardSettings,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq)]
pub struct ShardSettings {
    #[serde(default = "default_checkpoints")]
    pub save_checkpoints_interval_ticks: u32,

    // [DOD FIX] Adding night phase configuration at the shard level
    #[serde(default = "default_night_interval")]
    pub night_interval_ticks: u64,

    #[serde(default = "default_prune")]
    pub prune_threshold: i16,

    #[serde(default = "default_max_sprouts")]
    pub max_sprouts: u16,

    #[serde(default)]
    pub ghost_capacity: u32,
}
fn default_checkpoints() -> u32 {
    100_000
}
fn default_night_interval() -> u64 {
    10_000
} // Default: Night every 1 second of simulation
fn default_prune() -> i16 {
    15
}
fn default_max_sprouts() -> u16 {
    4
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Coordinate {
    pub x: u32,
    pub y: u32,
    pub z: u32,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Dimensions {
    pub w: u32,
    pub d: u32,
    pub h: u32,
}

#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Default)]
pub struct Neighbors {
    pub x_plus: Option<String>,
    pub x_minus: Option<String>,
    pub y_plus: Option<String>,
    pub y_minus: Option<String>,
    pub z_plus: Option<String>,  // Added for Roof
    pub z_minus: Option<String>, // Added for Floor
}

impl InstanceConfig {
    /// Parses an Instance Config (e.g. `shard_04.toml`) from string.
    pub fn parse(src: &str) -> Result<Self, toml::de::Error> {
        toml::from_str(src)
    }

    /// Loads and parses an Instance Config from a file.
    pub fn load(path: &Path) -> Result<Self, String> {
        let content = fs::read_to_string(path)
            .map_err(|e| format!("Failed to read InstanceConfig at {:?}: {}", path, e))?;
        Self::parse(&content)
            .map_err(|e| format!("Failed to parse TOML InstanceConfig from {:?}: {}", path, e))
    }
}

#[cfg(test)]
#[path = "test_instance.rs"]
mod test_instance;