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
59// Convert from feagi_npu_neural::types::FeagiError
60impl From<feagi_npu_neural::types::FeagiError> for BduError {
61    fn from(err: feagi_npu_neural::types::FeagiError) -> Self {
62        match &err {
63            feagi_npu_neural::types::FeagiError::InvalidArea(msg) => {
64                BduError::InvalidArea(msg.clone())
65            }
66            feagi_npu_neural::types::FeagiError::InvalidRegion(msg) => {
67                BduError::InvalidArea(msg.clone())
68            }
69            _ => BduError::Internal(err.to_string()),
70        }
71    }
72}
73
74// Convert from feagi_structures::FeagiDataError
75impl From<feagi_structures::FeagiDataError> for BduError {
76    fn from(err: feagi_structures::FeagiDataError) -> Self {
77        BduError::Internal(err.to_string())
78    }
79}
80
81// Convert from feagi_evolutionary::EvoError
82impl From<feagi_evolutionary::EvoError> for BduError {
83    fn from(err: feagi_evolutionary::EvoError) -> Self {
84        match &err {
85            feagi_evolutionary::EvoError::InvalidGenome(msg) => {
86                BduError::InvalidGenome(msg.clone())
87            }
88            feagi_evolutionary::EvoError::InvalidArea(msg) => BduError::InvalidArea(msg.clone()),
89            _ => BduError::Internal(err.to_string()),
90        }
91    }
92}
93
94// Note: Dimensions has been moved to feagi-types and is re-exported from feagi-bdu::lib