pub struct ConnectomeManager { /* private fields */ }Expand description
Central manager for the FEAGI connectome
§Responsibilities
- Cortical Area Management: Add, remove, query cortical areas
- Brain Region Management: Hierarchical organization
- Neuron/Synapse Queries: High-level API (delegates to NPU)
- Genome I/O: Load/save brain structure
§Data Storage
- Cortical areas: Stored in HashMap for O(1) lookup
- Brain regions: Stored in BrainRegionHierarchy
- Neuron data: Lives in NPU (not stored here)
- Synapse data: Lives in NPU (not stored here)
§Thread Safety
Uses RwLock for concurrent reads with exclusive writes.
Multiple threads can read simultaneously, but writes block.
Implementations§
Source§impl ConnectomeManager
impl ConnectomeManager
Sourcepub fn instance() -> Arc<RwLock<ConnectomeManager>>
pub fn instance() -> Arc<RwLock<ConnectomeManager>>
Sourcepub fn new_for_testing() -> Self
pub fn new_for_testing() -> Self
Calculate optimal visualization voxel granularity for a cortical area
This function determines the granularity for aggregated rendering based on:
- Total voxel count (larger areas get larger chunks)
- Aspect ratio (handles thin dimensions like 1024×900×3)
- Target chunk count (~2k-10k chunks for manageable message size)
§Arguments
dimensions- The cortical area dimensions (width, height, depth)
§Returns
Tuple of (chunk_x, chunk_y, chunk_z) that divides evenly into dimensions
Create a new isolated instance for testing
This bypasses the singleton pattern and creates a fresh instance. Use this in tests to avoid conflicts between parallel test runs.
§Example
let manager = ConnectomeManager::new_for_testing();
// Use manager in isolated testSourcepub fn new_for_testing_with_npu(npu: Arc<TracingMutex<DynamicNPU>>) -> Self
pub fn new_for_testing_with_npu(npu: Arc<TracingMutex<DynamicNPU>>) -> Self
Create a new isolated instance for testing with NPU
This bypasses the singleton pattern and creates a fresh instance with NPU connected. Use this in tests to avoid conflicts between parallel test runs.
§Arguments
npu- Arc<TracingMutex> to connect to this manager
§Example
let npu = Arc::new(TracingMutex::new(RustNPU::new(1_000_000, 10_000_000, 10), "NPU"));
let manager = ConnectomeManager::new_for_testing_with_npu(npu);Sourcepub fn setup_core_morphologies_for_testing(&mut self)
pub fn setup_core_morphologies_for_testing(&mut self)
Set up core morphologies in the registry (for testing only)
This is a test helper to set up core morphologies (projector, block_to_block, etc.) in the morphology registry so that synaptogenesis tests can run.
§Note
This should only be called in tests. Morphologies are typically loaded from genome files. This method is public to allow integration tests to access it.
Sourcepub fn refresh_cortical_area_hashes(
&self,
properties_changed: bool,
geometry_changed: bool,
)
pub fn refresh_cortical_area_hashes( &self, properties_changed: bool, geometry_changed: bool, )
Refresh cortical area-related hashes based on the affected data.
Sourcepub fn add_cortical_area(&mut self, area: CorticalArea) -> BduResult<u32>
pub fn add_cortical_area(&mut self, area: CorticalArea) -> BduResult<u32>
Sourcepub fn remove_cortical_area(
&mut self,
cortical_id: &CorticalID,
) -> BduResult<()>
pub fn remove_cortical_area( &mut self, cortical_id: &CorticalID, ) -> BduResult<()>
Sourcepub fn rename_cortical_area_id(
&mut self,
old_id: &CorticalID,
new_id: CorticalID,
new_cortical_type: CorticalAreaType,
) -> BduResult<()>
pub fn rename_cortical_area_id( &mut self, old_id: &CorticalID, new_id: CorticalID, new_cortical_type: CorticalAreaType, ) -> BduResult<()>
Update a cortical area ID without changing its cortical_idx.
This remaps internal lookup tables, brain-region membership, and mapping keys.
Sourcepub fn rename_cortical_area_id_with_options(
&mut self,
old_id: &CorticalID,
new_id: CorticalID,
new_cortical_type: CorticalAreaType,
update_npu_registry: bool,
) -> BduResult<()>
pub fn rename_cortical_area_id_with_options( &mut self, old_id: &CorticalID, new_id: CorticalID, new_cortical_type: CorticalAreaType, update_npu_registry: bool, ) -> BduResult<()>
Update a cortical area ID without changing its cortical_idx, with optional NPU registry update.
Sourcepub fn get_cortical_area(
&self,
cortical_id: &CorticalID,
) -> Option<&CorticalArea>
pub fn get_cortical_area( &self, cortical_id: &CorticalID, ) -> Option<&CorticalArea>
Get a cortical area by ID
Sourcepub fn get_cortical_area_mut(
&mut self,
cortical_id: &CorticalID,
) -> Option<&mut CorticalArea>
pub fn get_cortical_area_mut( &mut self, cortical_id: &CorticalID, ) -> Option<&mut CorticalArea>
Get a mutable reference to a cortical area
Sourcepub fn get_cortical_idx(&self, cortical_id: &CorticalID) -> Option<u32>
pub fn get_cortical_idx(&self, cortical_id: &CorticalID) -> Option<u32>
Get cortical index by ID
Sourcepub fn get_parent_region_id_for_area(
&self,
cortical_id: &CorticalID,
) -> Option<String>
pub fn get_parent_region_id_for_area( &self, cortical_id: &CorticalID, ) -> Option<String>
Find which brain region contains a cortical area
This is used to populate parent_region_id in API responses for Brain Visualizer.
Delegates to BrainRegionHierarchy for the actual search.
§Arguments
cortical_id- Cortical area to search for
§Returns
Option<String>- Parent region ID (UUID string) if found
Sourcepub fn recompute_brain_region_io_registry(
&mut self,
) -> BduResult<HashMap<String, (Vec<String>, Vec<String>)>>
pub fn recompute_brain_region_io_registry( &mut self, ) -> BduResult<HashMap<String, (Vec<String>, Vec<String>)>>
Recompute brain-region inputs/outputs registries from current cortical mappings.
This drives /v1/region/regions_members (via BrainRegion.properties["inputs"/"outputs"]).
Semantics (matches Python _auto_assign_region_io() and BV expectations):
- outputs: Any cortical area in the region that connects to an area outside the region
- inputs: Any cortical area in the region that receives a connection from outside the region
This function updates the hierarchy in-place and returns the computed base64 ID lists
for downstream persistence into RuntimeGenome.
Sourcepub fn get_root_region_id(&self) -> Option<String>
pub fn get_root_region_id(&self) -> Option<String>
Get the root brain region ID (region with no parent)
§Returns
Option<String>- Root region ID (UUID string) if found
Sourcepub fn get_cortical_id(&self, cortical_idx: u32) -> Option<&CorticalID>
pub fn get_cortical_id(&self, cortical_idx: u32) -> Option<&CorticalID>
Get cortical ID by index
Sourcepub fn get_all_cortical_idx_to_id_mappings(&self) -> AHashMap<u32, String>
pub fn get_all_cortical_idx_to_id_mappings(&self) -> AHashMap<u32, String>
Get all cortical_idx -> cortical_id mappings (for burst loop caching) Returns a HashMap of cortical_idx -> cortical_id (base64 string)
Sourcepub fn get_all_visualization_granularities(
&self,
) -> AHashMap<u32, (u32, u32, u32)>
pub fn get_all_visualization_granularities( &self, ) -> AHashMap<u32, (u32, u32, u32)>
Get all cortical_idx -> visualization_voxel_granularity mappings
Returns a map of cortical_idx to (granularity_x, granularity_y, granularity_z) for areas that have visualization voxel granularity configured.
Sourcepub fn get_cortical_area_ids(&self) -> Vec<&CorticalID>
pub fn get_cortical_area_ids(&self) -> Vec<&CorticalID>
Get all cortical area IDs
Sourcepub fn get_cortical_area_count(&self) -> usize
pub fn get_cortical_area_count(&self) -> usize
Get the number of cortical areas
Sourcepub fn get_upstream_cortical_areas(
&self,
target_cortical_id: &CorticalID,
) -> Vec<u32>
pub fn get_upstream_cortical_areas( &self, target_cortical_id: &CorticalID, ) -> Vec<u32>
Get all cortical areas that have synapses targeting the specified area (upstream/afferent areas)
Reads from the upstream_cortical_areas property stored on the cortical area.
This property is maintained by add_upstream_area() and remove_upstream_area().
§Arguments
target_cortical_id- The cortical area ID to find upstream connections for
§Returns
Vec of cortical_idx values for all upstream areas
Sourcepub fn filter_non_memory_upstream_areas(&self, upstream: &[u32]) -> Vec<u32>
pub fn filter_non_memory_upstream_areas(&self, upstream: &[u32]) -> Vec<u32>
Filter upstream cortical indices to exclude memory areas.
Sourcepub fn refresh_upstream_cortical_areas_from_mappings(
&mut self,
target_cortical_id: &CorticalID,
) -> Vec<u32>
pub fn refresh_upstream_cortical_areas_from_mappings( &mut self, target_cortical_id: &CorticalID, ) -> Vec<u32>
Recompute and persist upstream_cortical_areas for a target area from mapping properties.
This is a recovery path for stale upstream tracking (e.g., bidirectional mappings that were mirrored into properties but not fully regenerated).
Sourcepub fn add_upstream_area(
&mut self,
target_cortical_id: &CorticalID,
src_cortical_idx: u32,
)
pub fn add_upstream_area( &mut self, target_cortical_id: &CorticalID, src_cortical_idx: u32, )
Add an upstream cortical area to a target area’s upstream list
This should be called when synapses are created from src_cortical_idx to target_cortical_id.
§Arguments
target_cortical_id- The cortical area receiving connectionssrc_cortical_idx- The cortical index of the source area
Sourcepub fn get_memory_twin_for_upstream_idx(
&self,
memory_area_idx: u32,
upstream_idx: u32,
) -> Option<CorticalID>
pub fn get_memory_twin_for_upstream_idx( &self, memory_area_idx: u32, upstream_idx: u32, ) -> Option<CorticalID>
Get the memory twin cortical ID for a given memory area and upstream area.
Sourcepub fn ensure_memory_twin_area(
&mut self,
memory_area_id: &CorticalID,
upstream_area_id: &CorticalID,
) -> BduResult<CorticalID>
pub fn ensure_memory_twin_area( &mut self, memory_area_id: &CorticalID, upstream_area_id: &CorticalID, ) -> BduResult<CorticalID>
Ensure a memory twin area exists for the given upstream and memory areas.
Sourcepub fn remove_upstream_area(
&mut self,
target_cortical_id: &CorticalID,
src_cortical_idx: u32,
)
pub fn remove_upstream_area( &mut self, target_cortical_id: &CorticalID, src_cortical_idx: u32, )
Remove an upstream cortical area from a target area’s upstream list
This should be called when all synapses from src_cortical_idx to target_cortical_id are deleted.
§Arguments
target_cortical_id- The cortical area that had connectionssrc_cortical_idx- The cortical index of the source area to remove
Sourcepub fn has_cortical_area(&self, cortical_id: &CorticalID) -> bool
pub fn has_cortical_area(&self, cortical_id: &CorticalID) -> bool
Check if a cortical area exists
Sourcepub fn is_initialized(&self) -> bool
pub fn is_initialized(&self) -> bool
Check if the connectome is initialized (has areas)
Sourcepub fn add_brain_region(
&mut self,
region: BrainRegion,
parent_id: Option<String>,
) -> BduResult<()>
pub fn add_brain_region( &mut self, region: BrainRegion, parent_id: Option<String>, ) -> BduResult<()>
Add a brain region
Sourcepub fn remove_brain_region(&mut self, region_id: &str) -> BduResult<()>
pub fn remove_brain_region(&mut self, region_id: &str) -> BduResult<()>
Remove a brain region
Sourcepub fn change_brain_region_parent(
&mut self,
region_id: &str,
new_parent_id: &str,
) -> BduResult<()>
pub fn change_brain_region_parent( &mut self, region_id: &str, new_parent_id: &str, ) -> BduResult<()>
Change the parent of an existing brain region.
Sourcepub fn get_brain_region(&self, region_id: &str) -> Option<&BrainRegion>
pub fn get_brain_region(&self, region_id: &str) -> Option<&BrainRegion>
Get a brain region by ID
Sourcepub fn get_brain_region_mut(
&mut self,
region_id: &str,
) -> Option<&mut BrainRegion>
pub fn get_brain_region_mut( &mut self, region_id: &str, ) -> Option<&mut BrainRegion>
Get a mutable reference to a brain region
Sourcepub fn get_brain_region_ids(&self) -> Vec<&String>
pub fn get_brain_region_ids(&self) -> Vec<&String>
Get all brain region IDs
Sourcepub fn get_brain_region_hierarchy(&self) -> &BrainRegionHierarchy
pub fn get_brain_region_hierarchy(&self) -> &BrainRegionHierarchy
Get the brain region hierarchy
Sourcepub fn get_morphologies(&self) -> &MorphologyRegistry
pub fn get_morphologies(&self) -> &MorphologyRegistry
Get all morphologies from the loaded genome
Sourcepub fn get_morphology_count(&self) -> usize
pub fn get_morphology_count(&self) -> usize
Get morphology count
Sourcepub fn upsert_morphology(
&mut self,
morphology_id: String,
morphology: Morphology,
)
pub fn upsert_morphology( &mut self, morphology_id: String, morphology: Morphology, )
Insert or overwrite a morphology definition in the in-memory registry.
NOTE: This updates the runtime registry used by mapping/synapse generation. Callers that also maintain a RuntimeGenome (source of truth) MUST update it too.
Sourcepub fn remove_morphology(&mut self, morphology_id: &str) -> bool
pub fn remove_morphology(&mut self, morphology_id: &str) -> bool
Remove a morphology definition from the in-memory registry.
Returns true if the morphology existed and was removed.
NOTE: Callers that also maintain a RuntimeGenome (source of truth) MUST update it too.
Sourcepub fn update_cortical_mapping(
&mut self,
src_area_id: &CorticalID,
dst_area_id: &CorticalID,
mapping_data: Vec<Value>,
) -> BduResult<()>
pub fn update_cortical_mapping( &mut self, src_area_id: &CorticalID, dst_area_id: &CorticalID, mapping_data: Vec<Value>, ) -> BduResult<()>
Update cortical mapping properties between two cortical areas
Following Python’s update_cortical_mapping_properties() logic:
- Updates the source area’s cortical_mapping_dst property
- Triggers synapse regeneration for the affected connection
§Arguments
src_area_id- Source cortical area IDdst_area_id- Destination cortical area IDmapping_data- List of connection specifications
§Returns
BduResult<()>- Ok if successful, Err otherwise
Sourcepub fn regenerate_synapses_for_mapping(
&mut self,
src_area_id: &CorticalID,
dst_area_id: &CorticalID,
) -> BduResult<usize>
pub fn regenerate_synapses_for_mapping( &mut self, src_area_id: &CorticalID, dst_area_id: &CorticalID, ) -> BduResult<usize>
Regenerate synapses for a specific cortical mapping
Creates new synapses based on mapping rules. Only removes existing synapses if a mapping already existed (update case), not for new mappings (allows multiple synapses between the same neurons).
§Arguments
src_area_id- Source cortical area IDdst_area_id- Destination cortical area ID
§Returns
BduResult<usize>- Number of synapses created
Sourcepub fn set_npu(&mut self, npu: Arc<TracingMutex<DynamicNPU>>)
pub fn set_npu(&mut self, npu: Arc<TracingMutex<DynamicNPU>>)
Set the NPU reference for neuron/synapse queries
This should be called once during FEAGI initialization after the NPU is created.
§Arguments
npu- Arc to the Rust NPU (wrapped in TracingMutex for automatic lock tracing)
Sourcepub fn get_npu(&self) -> Option<&Arc<TracingMutex<DynamicNPU>>>
pub fn get_npu(&self) -> Option<&Arc<TracingMutex<DynamicNPU>>>
Get NPU reference (read-only access for queries)
§Returns
Option<&Arc<Mutex<RustNPU>>>- Reference to NPU if connected
Sourcepub fn set_plasticity_executor(
&mut self,
executor: Arc<Mutex<AsyncPlasticityExecutor>>,
)
pub fn set_plasticity_executor( &mut self, executor: Arc<Mutex<AsyncPlasticityExecutor>>, )
Set the PlasticityExecutor reference (optional, only if plasticity feature enabled)
The executor is passed as Arc<Mutex
Sourcepub fn get_plasticity_executor(
&self,
) -> Option<&Arc<Mutex<AsyncPlasticityExecutor>>>
pub fn get_plasticity_executor( &self, ) -> Option<&Arc<Mutex<AsyncPlasticityExecutor>>>
Get the PlasticityExecutor reference (if plasticity feature enabled)
Sourcepub fn get_neuron_capacity(&self) -> usize
pub fn get_neuron_capacity(&self) -> usize
Get neuron capacity from config (lock-free, never acquires NPU lock)
§Returns
usize- Maximum neuron capacity from config (single source of truth)
§Performance
This is a lock-free read from config that never blocks, even during burst processing. Capacity values are set at NPU initialization and never change.
Sourcepub fn get_synapse_capacity(&self) -> usize
pub fn get_synapse_capacity(&self) -> usize
Get synapse capacity from config (lock-free, never acquires NPU lock)
§Returns
usize- Maximum synapse capacity from config (single source of truth)
§Performance
This is a lock-free read from config that never blocks, even during burst processing. Capacity values are set at NPU initialization and never change.
Sourcepub fn update_fatigue_index(&self) -> Option<u8>
pub fn update_fatigue_index(&self) -> Option<u8>
Update fatigue index based on utilization of neuron and synapse arrays
Calculates fatigue index as max(regular_neuron_util%, memory_neuron_util%, synapse_util%) Applies hysteresis: triggers at 85%, clears at 80% Rate limited to max once per 2 seconds to protect against rapid changes
§Safety
This method is completely non-blocking and safe to call during genome loading. If StateManager is unavailable or locked, it will skip the calculation gracefully.
§Returns
Option<u8>- New fatigue index (0-100) if calculation was performed, None if rate limited or StateManager unavailable
Sourcepub fn create_neurons_for_area(
&mut self,
cortical_id: &CorticalID,
) -> BduResult<u32>
pub fn create_neurons_for_area( &mut self, cortical_id: &CorticalID, ) -> BduResult<u32>
Sourcepub fn add_neuron(
&mut self,
cortical_id: &CorticalID,
x: u32,
y: u32,
z: u32,
firing_threshold: f32,
firing_threshold_limit: f32,
leak_coefficient: f32,
resting_potential: f32,
neuron_type: u8,
refractory_period: u16,
excitability: f32,
consecutive_fire_limit: u16,
snooze_length: u16,
mp_charge_accumulation: bool,
) -> BduResult<u64>
pub fn add_neuron( &mut self, cortical_id: &CorticalID, x: u32, y: u32, z: u32, firing_threshold: f32, firing_threshold_limit: f32, leak_coefficient: f32, resting_potential: f32, neuron_type: u8, refractory_period: u16, excitability: f32, consecutive_fire_limit: u16, snooze_length: u16, mp_charge_accumulation: bool, ) -> BduResult<u64>
Add a single neuron to a cortical area
§Arguments
cortical_id- Cortical area IDx- X coordinatey- Y coordinatez- Z coordinatefiring_threshold- Firing threshold (minimum MP to fire)firing_threshold_limit- Firing threshold limit (maximum MP to fire, 0 = no limit)leak_coefficient- Leak coefficientresting_potential- Resting membrane potentialneuron_type- Neuron type (0=excitatory, 1=inhibitory)refractory_period- Refractory periodexcitability- Excitability multiplierconsecutive_fire_limit- Maximum consecutive firessnooze_length- Snooze duration after consecutive fire limitmp_charge_accumulation- Whether membrane potential accumulates
§Returns
The newly created neuron ID
Sourcepub fn delete_neuron(&mut self, neuron_id: u64) -> BduResult<bool>
pub fn delete_neuron(&mut self, neuron_id: u64) -> BduResult<bool>
Sourcepub fn apply_cortical_mapping(
&mut self,
src_cortical_id: &CorticalID,
) -> BduResult<u32>
pub fn apply_cortical_mapping( &mut self, src_cortical_id: &CorticalID, ) -> BduResult<u32>
Sourcepub fn has_neuron(&self, neuron_id: u64) -> bool
pub fn has_neuron(&self, neuron_id: u64) -> bool
Sourcepub fn get_neuron_count(&self) -> usize
pub fn get_neuron_count(&self) -> usize
Get total number of active neurons (lock-free cached read with opportunistic update)
§Returns
The total number of neurons (from cache)
§Performance
This is a lock-free atomic read that never blocks, even during burst processing. Opportunistically updates cache if NPU is available (non-blocking try_lock).
Sourcepub fn update_cached_neuron_count(&self)
pub fn update_cached_neuron_count(&self)
Update the cached neuron count (explicit update)
Use this if you want to force a cache update. Most callers should just use get_neuron_count() which updates opportunistically.
Sourcepub fn refresh_neuron_count_for_area(
&self,
cortical_id: &CorticalID,
) -> Option<usize>
pub fn refresh_neuron_count_for_area( &self, cortical_id: &CorticalID, ) -> Option<usize>
Refresh cached neuron count for a single cortical area from the NPU.
Returns the refreshed count if successful.
Sourcepub fn get_synapse_count(&self) -> usize
pub fn get_synapse_count(&self) -> usize
Get total number of synapses (lock-free cached read with opportunistic update)
§Returns
The total number of synapses (from cache)
§Performance
This is a lock-free atomic read that never blocks, even during burst processing. Opportunistically updates cache if NPU is available (non-blocking try_lock).
Sourcepub fn update_cached_synapse_count(&self)
pub fn update_cached_synapse_count(&self)
Update the cached synapse count (explicit update)
Use this if you want to force a cache update. Most callers should just use get_synapse_count() which updates opportunistically.
Sourcepub fn update_all_cached_stats(&self)
pub fn update_all_cached_stats(&self)
Update all cached stats (neuron and synapse counts)
This is called automatically when NPU is connected and can be called explicitly if you want to force a cache refresh.
Sourcepub fn get_neuron_cortical_idx(&self, neuron_id: u64) -> u32
pub fn get_neuron_cortical_idx(&self, neuron_id: u64) -> u32
Sourcepub fn get_neurons_in_area(&self, cortical_id: &CorticalID) -> Vec<u64>
pub fn get_neurons_in_area(&self, cortical_id: &CorticalID) -> Vec<u64>
Sourcepub fn get_neuron_count_in_area(&self, cortical_id: &CorticalID) -> usize
pub fn get_neuron_count_in_area(&self, cortical_id: &CorticalID) -> usize
Get neuron count for a specific cortical area
§Arguments
cortical_id- The cortical area ID (string)
§Returns
Number of neurons in the area, or 0 if area doesn’t exist or NPU not connected
Get neuron count for a specific cortical area (lock-free cached read)
§Arguments
cortical_id- The cortical area ID
§Returns
The number of neurons in the area (from cache, never blocks on NPU lock)
§Performance
This is a lock-free atomic read that never blocks, even during burst processing. Count is maintained in ConnectomeManager and updated when neurons are created/deleted.
Sourcepub fn get_populated_areas(&self) -> Vec<(String, usize)>
pub fn get_populated_areas(&self) -> Vec<(String, usize)>
Get all cortical areas that have neurons
§Returns
Vec of (cortical_id, neuron_count) for areas with at least one neuron
Sourcepub fn is_area_populated(&self, cortical_id: &CorticalID) -> bool
pub fn is_area_populated(&self, cortical_id: &CorticalID) -> bool
Sourcepub fn get_synapse_count_in_area(&self, cortical_id: &CorticalID) -> usize
pub fn get_synapse_count_in_area(&self, cortical_id: &CorticalID) -> usize
Get total synapse count for a specific cortical area (outgoing only) - lock-free cached read
§Arguments
cortical_id- The cortical area ID
§Returns
Total number of outgoing synapses from neurons in this area (from cache, never blocks on NPU lock)
§Performance
This is a lock-free atomic read that never blocks, even during burst processing. Count is maintained in ConnectomeManager and updated when synapses are created/deleted.
Sourcepub fn get_incoming_synapse_count_in_area(
&self,
cortical_id: &CorticalID,
) -> usize
pub fn get_incoming_synapse_count_in_area( &self, cortical_id: &CorticalID, ) -> usize
Sourcepub fn get_outgoing_synapse_count_in_area(
&self,
cortical_id: &CorticalID,
) -> usize
pub fn get_outgoing_synapse_count_in_area( &self, cortical_id: &CorticalID, ) -> usize
Sourcepub fn are_neurons_connected(
&self,
source_neuron_id: u64,
target_neuron_id: u64,
) -> bool
pub fn are_neurons_connected( &self, source_neuron_id: u64, target_neuron_id: u64, ) -> bool
Sourcepub fn get_connection_weight(
&self,
source_neuron_id: u64,
target_neuron_id: u64,
) -> Option<u8>
pub fn get_connection_weight( &self, source_neuron_id: u64, target_neuron_id: u64, ) -> Option<u8>
Sourcepub fn get_area_connectivity_stats(
&self,
cortical_id: &CorticalID,
) -> (usize, usize, f32)
pub fn get_area_connectivity_stats( &self, cortical_id: &CorticalID, ) -> (usize, usize, f32)
Sourcepub fn get_neuron_cortical_id(&self, neuron_id: u64) -> Option<CorticalID>
pub fn get_neuron_cortical_id(&self, neuron_id: u64) -> Option<CorticalID>
Sourcepub fn get_neuron_density(&self, cortical_id: &CorticalID) -> f32
pub fn get_neuron_density(&self, cortical_id: &CorticalID) -> f32
Sourcepub fn get_all_area_stats(&self) -> Vec<(String, usize, usize, f32)>
pub fn get_all_area_stats(&self) -> Vec<(String, usize, usize, f32)>
Get all cortical areas with connectivity statistics
§Returns
Vec of (cortical_id, neuron_count, synapse_count, density)
Sourcepub fn get_config(&self) -> &ConnectomeConfig
pub fn get_config(&self) -> &ConnectomeConfig
Get the configuration
Sourcepub fn set_config(&mut self, config: ConnectomeConfig)
pub fn set_config(&mut self, config: ConnectomeConfig)
Update configuration
Sourcepub fn load_genome_from_json(&mut self, json_str: &str) -> BduResult<()>
pub fn load_genome_from_json(&mut self, json_str: &str) -> BduResult<()>
Load a genome from JSON string
This method:
- Parses the genome JSON
- Creates cortical areas from the blueprint
- Reconstructs the brain region hierarchy
- Stores neuron morphologies for later processing
§Arguments
json_str- JSON string of the genome
§Returns
Ok(()) if genome loaded successfully
§Errors
Returns error if:
- JSON is malformed
- Required fields are missing
- Cortical areas have invalid data
- Brain region hierarchy is invalid
§Example
use feagi_brain_development::ConnectomeManager;
let manager = ConnectomeManager::instance();
let mut mgr = manager.write();
let genome_json = r#"{ "version": "2.1", "blueprint": {...} }"#;
mgr.load_genome_from_json(genome_json)?;Sourcepub fn ensure_core_cortical_areas(&mut self) -> BduResult<()>
pub fn ensure_core_cortical_areas(&mut self) -> BduResult<()>
Ensure core cortical areas (_death, _power, _fatigue) exist
Core areas are required for brain operation:
_death(cortical_idx=0): Manages neuron death and cleanup_power(cortical_idx=1): Provides power injection for burst engine_fatigue(cortical_idx=2): Monitors brain fatigue and triggers sleep mode
If any core area is missing from the genome, it will be automatically created with default properties (1x1x1 dimensions, minimal configuration).
§Returns
Ok(())if all core areas exist or were successfully createdErr(BduError)if creation fails
Sourcepub fn save_genome_to_json(
&self,
genome_id: Option<String>,
genome_title: Option<String>,
) -> BduResult<String>
👎Deprecated: Use GenomeService::save_genome() instead. This produces incomplete v2.1 format without morphologies/physiology.
pub fn save_genome_to_json( &self, genome_id: Option<String>, genome_title: Option<String>, ) -> BduResult<String>
Save the connectome as a genome JSON
DEPRECATED: This method produces incomplete hierarchical format v2.1 without morphologies/physiology.
Use GenomeService::save_genome() instead, which produces complete flat format v3.0.
This method is kept only for legacy tests. Production code MUST use GenomeService.
§Arguments
genome_id- Optional custom genome ID (generates timestamp-based ID if None)genome_title- Optional custom genome title
§Returns
JSON string representation of the genome (hierarchical v2.1, incomplete)
Sourcepub fn prepare_for_new_genome(&mut self) -> BduResult<()>
pub fn prepare_for_new_genome(&mut self) -> BduResult<()>
Prepare for loading a new genome
Clears all existing cortical areas, brain regions, and resets state. This is typically called before loading a new genome.
Sourcepub fn resize_for_genome(&mut self, genome: &RuntimeGenome) -> BduResult<()>
pub fn resize_for_genome(&mut self, genome: &RuntimeGenome) -> BduResult<()>
Calculate and resize memory for a genome
Analyzes the genome to determine memory requirements and prepares the NPU for the expected neuron/synapse counts.
§Arguments
genome- Genome to analyze for memory requirements
Sourcepub fn create_synapse(
&mut self,
source_neuron_id: u64,
target_neuron_id: u64,
weight: u8,
psp: u8,
synapse_type: u8,
) -> BduResult<()>
pub fn create_synapse( &mut self, source_neuron_id: u64, target_neuron_id: u64, weight: u8, psp: u8, synapse_type: u8, ) -> BduResult<()>
Sourcepub fn get_synapse(
&self,
source_neuron_id: u64,
target_neuron_id: u64,
) -> Option<(u8, u8, u8)>
pub fn get_synapse( &self, source_neuron_id: u64, target_neuron_id: u64, ) -> Option<(u8, u8, u8)>
Sourcepub fn update_synapse_weight(
&mut self,
source_neuron_id: u64,
target_neuron_id: u64,
new_weight: u8,
) -> BduResult<()>
pub fn update_synapse_weight( &mut self, source_neuron_id: u64, target_neuron_id: u64, new_weight: u8, ) -> BduResult<()>
Sourcepub fn remove_synapse(
&mut self,
source_neuron_id: u64,
target_neuron_id: u64,
) -> BduResult<bool>
pub fn remove_synapse( &mut self, source_neuron_id: u64, target_neuron_id: u64, ) -> BduResult<bool>
Sourcepub fn batch_create_neurons(
&mut self,
cortical_id: &CorticalID,
neurons: Vec<(u32, u32, u32, f32, f32, f32, f32, i32, u16, f32, u16, u16, bool)>,
) -> BduResult<Vec<u64>>
pub fn batch_create_neurons( &mut self, cortical_id: &CorticalID, neurons: Vec<(u32, u32, u32, f32, f32, f32, f32, i32, u16, f32, u16, u16, bool)>, ) -> BduResult<Vec<u64>>
Batch create multiple neurons at once (SIMD-optimized)
This is significantly faster than calling add_neuron() in a loop
§Arguments
cortical_id- Target cortical areaneurons- Vector of neuron parameters (x, y, z, firing_threshold, leak, resting_potential, etc.)
§Returns
Vector of created neuron IDs
Sourcepub fn update_neuron_properties(
&mut self,
neuron_id: u64,
firing_threshold: Option<f32>,
leak_coefficient: Option<f32>,
resting_potential: Option<f32>,
excitability: Option<f32>,
) -> BduResult<()>
pub fn update_neuron_properties( &mut self, neuron_id: u64, firing_threshold: Option<f32>, leak_coefficient: Option<f32>, resting_potential: Option<f32>, excitability: Option<f32>, ) -> BduResult<()>
Update properties of an existing neuron
§Arguments
neuron_id- Target neuron IDfiring_threshold- Optional new firing thresholdleak_coefficient- Optional new leak coefficientresting_potential- Optional new resting potentialexcitability- Optional new excitability
§Returns
Ok(()) if neuron updated successfully
Sourcepub fn set_neuron_firing_threshold(
&mut self,
neuron_id: u64,
new_threshold: f32,
) -> BduResult<()>
pub fn set_neuron_firing_threshold( &mut self, neuron_id: u64, new_threshold: f32, ) -> BduResult<()>
Sourcepub fn get_cortical_area_by_name(&self, name: &str) -> Option<CorticalArea>
pub fn get_cortical_area_by_name(&self, name: &str) -> Option<CorticalArea>
Sourcepub fn resize_cortical_area(
&mut self,
cortical_id: &CorticalID,
new_dimensions: CorticalAreaDimensions,
) -> BduResult<()>
pub fn resize_cortical_area( &mut self, cortical_id: &CorticalID, new_dimensions: CorticalAreaDimensions, ) -> BduResult<()>
Resize a cortical area (changes dimensions, may require neuron reallocation)
§Arguments
cortical_id- Target cortical area IDnew_dimensions- New dimensions (width, height, depth)
§Returns
Ok(()) if resized successfully
§Note
This does NOT automatically create/delete neurons. It only updates metadata. Caller must handle neuron population separately.
Sourcepub fn update_brain_region(
&mut self,
region_id: &str,
new_name: Option<String>,
new_description: Option<String>,
) -> BduResult<()>
pub fn update_brain_region( &mut self, region_id: &str, new_name: Option<String>, new_description: Option<String>, ) -> BduResult<()>
Sourcepub fn update_brain_region_properties(
&mut self,
region_id: &str,
properties: HashMap<String, Value>,
) -> BduResult<()>
pub fn update_brain_region_properties( &mut self, region_id: &str, properties: HashMap<String, Value>, ) -> BduResult<()>
Sourcepub fn get_neuron_by_coordinates(
&self,
cortical_id: &CorticalID,
x: u32,
y: u32,
z: u32,
) -> Option<u64>
pub fn get_neuron_by_coordinates( &self, cortical_id: &CorticalID, x: u32, y: u32, z: u32, ) -> Option<u64>
Sourcepub fn get_cortical_area_for_neuron(&self, neuron_id: u64) -> Option<CorticalID>
pub fn get_cortical_area_for_neuron(&self, neuron_id: u64) -> Option<CorticalID>
Sourcepub fn get_all_cortical_ids(&self) -> Vec<CorticalID>
pub fn get_all_cortical_ids(&self) -> Vec<CorticalID>
Sourcepub fn get_all_cortical_indices(&self) -> Vec<u32>
pub fn get_all_cortical_indices(&self) -> Vec<u32>
Sourcepub fn get_cortical_area_names(&self) -> Vec<String>
pub fn get_cortical_area_names(&self) -> Vec<String>
Sourcepub fn list_ipu_areas(&self) -> Vec<CorticalID>
pub fn list_ipu_areas(&self) -> Vec<CorticalID>
Sourcepub fn list_opu_areas(&self) -> Vec<CorticalID>
pub fn list_opu_areas(&self) -> Vec<CorticalID>
Sourcepub fn get_max_cortical_area_dimensions(&self) -> (usize, usize, usize)
pub fn get_max_cortical_area_dimensions(&self) -> (usize, usize, usize)
Sourcepub fn get_cortical_area_properties(
&self,
cortical_id: &CorticalID,
) -> Option<HashMap<String, Value>>
pub fn get_cortical_area_properties( &self, cortical_id: &CorticalID, ) -> Option<HashMap<String, Value>>
Sourcepub fn get_all_brain_region_ids(&self) -> Vec<String>
pub fn get_all_brain_region_ids(&self) -> Vec<String>
Sourcepub fn get_brain_region_names(&self) -> Vec<String>
pub fn get_brain_region_names(&self) -> Vec<String>
Sourcepub fn get_brain_region_properties(
&self,
region_id: &str,
) -> Option<HashMap<String, Value>>
pub fn get_brain_region_properties( &self, region_id: &str, ) -> Option<HashMap<String, Value>>
Sourcepub fn cortical_area_exists(&self, cortical_id: &CorticalID) -> bool
pub fn cortical_area_exists(&self, cortical_id: &CorticalID) -> bool
Sourcepub fn brain_region_exists(&self, region_id: &str) -> bool
pub fn brain_region_exists(&self, region_id: &str) -> bool
Sourcepub fn get_brain_region_count(&self) -> usize
pub fn get_brain_region_count(&self) -> usize
Sourcepub fn get_neurons_by_cortical_area(&self, cortical_id: &CorticalID) -> Vec<u64>
pub fn get_neurons_by_cortical_area(&self, cortical_id: &CorticalID) -> Vec<u64>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for ConnectomeManager
impl !RefUnwindSafe for ConnectomeManager
impl Send for ConnectomeManager
impl Sync for ConnectomeManager
impl Unpin for ConnectomeManager
impl !UnwindSafe for ConnectomeManager
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more