Skip to main content

feagi_brain_development/
types.rs

1// Copyright 2025 Neuraville Inc.
2// SPDX-License-Identifier: Apache-2.0
3
4/*!
5Core types for BDU operations.
6
7These types match the Python API for seamless integration.
8*/
9
10/// Cortical area identifier (6-character string in Python)
11pub type AreaId = String;
12
13/// 3D position (x, y, z)
14pub type Position = (u32, u32, u32);
15
16/// Synaptic weight (0-255 in u8, converted from Python float)
17pub type Weight = u8;
18
19/// Result type for BDU operations
20pub type BduResult<T> = Result<T, BduError>;
21
22/// Errors that can occur during BDU operations
23#[derive(Debug, thiserror::Error)]
24pub enum BduError {
25    #[error("Invalid area: {0}")]
26    InvalidArea(String),
27
28    #[error("Invalid morphology: {0}")]
29    InvalidMorphology(String),
30
31    #[error("Invalid position: {0:?}")]
32    InvalidPosition(Position),
33
34    #[error("Dimension mismatch: expected {expected:?}, got {actual:?}")]
35    DimensionMismatch {
36        expected: (usize, usize, usize),
37        actual: (usize, usize, usize),
38    },
39
40    #[error("Out of bounds: position {pos:?} not in dimensions {dims:?}")]
41    OutOfBounds {
42        pos: Position,
43        dims: (usize, usize, usize),
44    },
45
46    #[error("Invalid genome: {0}")]
47    InvalidGenome(String),
48
49    #[error("Invalid neuron: {0}")]
50    InvalidNeuron(String),
51
52    #[error("Invalid synapse: {0}")]
53    InvalidSynapse(String),
54
55    #[error("Internal error: {0}")]
56    Internal(String),
57
58    /// Region IO designation policy violation (cross-region mapping vs declared interface)
59    #[error("Region IO policy violation: {0}")]
60    RegionIoPolicyViolation(String),
61}
62
63// Convert from feagi_npu_neural::types::FeagiError
64impl From<feagi_npu_neural::types::FeagiError> for BduError {
65    fn from(err: feagi_npu_neural::types::FeagiError) -> Self {
66        match &err {
67            feagi_npu_neural::types::FeagiError::InvalidArea(msg) => {
68                BduError::InvalidArea(msg.clone())
69            }
70            feagi_npu_neural::types::FeagiError::InvalidRegion(msg) => {
71                BduError::InvalidArea(msg.clone())
72            }
73            _ => BduError::Internal(err.to_string()),
74        }
75    }
76}
77
78// Convert from feagi_structures::FeagiDataError
79impl From<feagi_structures::FeagiDataError> for BduError {
80    fn from(err: feagi_structures::FeagiDataError) -> Self {
81        BduError::Internal(err.to_string())
82    }
83}
84
85// Convert from feagi_evolutionary::EvoError
86impl From<feagi_evolutionary::EvoError> for BduError {
87    fn from(err: feagi_evolutionary::EvoError) -> Self {
88        match &err {
89            feagi_evolutionary::EvoError::InvalidGenome(msg) => {
90                BduError::InvalidGenome(msg.clone())
91            }
92            feagi_evolutionary::EvoError::InvalidArea(msg) => BduError::InvalidArea(msg.clone()),
93            _ => BduError::Internal(err.to_string()),
94        }
95    }
96}
97
98// Note: Dimensions has been moved to feagi-types and is re-exported from feagi-bdu::lib