-
Notifications
You must be signed in to change notification settings - Fork 2
5.1 Propagation Contract Tests
Relevant source files
The following files were used as context for generating this wiki page:
This wiki page covers the integration and contract test suites defined in tests/propagate_contract.rs, tests/propagate_into.rs, and tests/propagate_into_alloc.rs. These tests pin the core behavioral contracts of SynapticMesh, ensuring exact mathematical consistency, input validation atomicity, and strict zero-allocation performance guarantees across allocating and buffer-reusing propagation paths.
Sources: tests/propagate_contract.rs:1-49, tests/propagate_into.rs:1-9, tests/propagate_into_alloc.rs:1-9
The consumer contract test suite establishes the ground-truth semantics for spike delivery, synaptic delays, polarity signs, and current summation tests/propagate_contract.rs:3-31. It evaluates these against a deterministic, hand-built 4-neuron, 5-synapse fixture graph that complies with Dale's law tests/propagate_contract.rs:32-88.
Title: "Propagation Fixture and Contract Flow"
graph TD
subgraph NaturalLanguage["Natural Language Space"]
A["SourceSpike"] -->|Delay0| B["ImmediateDelivery"]
A -->|Delay1| C["BufferedDelivery"]
A -->|Delay2| D["DelayedDelivery"]
E["InhibitoryPolarity"] -->|SignFlip| F["SubtractedCurrent"]
end
subgraph CodeSpace["Code Entity Space"]
SM["SynapticMesh::propagate"] -->|Descriptors| SG["SynapticGraph::from_descriptors"]
SG -->|MeshState| TM["SynapticMesh::new"]
TM -->|BufferTick| P["Polarity::Inhibitory / Excitatory"]
end
NaturalLanguage -.-> CodeSpace
Sources: tests/propagate_contract.rs:3-48, tests/propagate_contract.rs:50-88
The test file enforces five primary rules of the propagation contract:
-
Delay & Timing: A spike from source
$s$ on tick$t$ deliversweightto targets on tick$t + \text{delay}$ . A delay of0results in same-tick delivery appearing in the return value of the activeSynapticMesh::propagatecall tests/propagate_contract.rs:11-14. -
Polarity: Synaptic weight magnitude is scaled by the descriptor's
Polarity;Polarity::Inhibitorysubtracts current tests/propagate_contract.rs:15-19. - Summation: Currents arriving at the same neuron on the same tick are summed tests/propagate_contract.rs:20.
-
Single-Hop Semantics:
SynapticMesh::propagateexecutes exactly one network hop. Received currents never trigger spikes internally; spike generation is the responsibility of the external consumer neuron model tests/propagate_contract.rs:21-23. -
Determinism: Identical graphs and spike sequences yield bit-identical current traces, both across runs and following
SynapticMesh::resettests/propagate_contract.rs:24-25.
Sources: tests/propagate_contract.rs:3-31, tests/propagate_contract.rs:113-169
The tests/propagate_into.rs integration suite verifies that zero-allocation caller-buffer methods (SynapticMesh::propagate_into and SynapticMesh::propagate_graded_into) are functionally equivalent to their allocating counterparts across diverse structural topologies (small-world, scale-free, random, and layered) [tests/propagate_into.rs:3-8], tests/propagate_into.rs:64-167.
Title: "Buffer Reuse Equivalence and Error Atomicity Architecture"
graph TD
subgraph NaturalLanguage["Natural Language Space"]
T1["AllocatingPath"] -->|Equals| T2["BufferReusePath"]
E1["InvalidInputSize"] -->|TriggersError| E2["FullStateRollback"]
end
subgraph CodeSpace["Code Entity Space"]
SM1["SynapticMesh::propagate"] -->|CompareVectors| SM2["SynapticMesh::propagate_into"]
GM1["SynapticMesh::propagate_graded"] -->|CompareVectors| GM2["SynapticMesh::propagate_graded_into"]
ERR["MeshErrorInfo"] -->|PreservesTick| TICK["SynapticMesh::tick"]
end
NaturalLanguage -.-> CodeSpace
Sources: tests/propagate_into.rs:3-8, tests/propagate_into.rs:64-102, tests/propagate_into.rs:170-201
When propagation inputs fail validation (e.g., mismatched slice lengths or overflow conditions), the mesh guarantees strict atomicity:
- The internal tick counter remains unincremented [tests/propagate_into.rs:7-8], tests/propagate_into.rs:182.
- Delay ring buffers remain unaltered tests/propagate_into.rs:7-8.
- Caller output buffers are left pristine and unmodified [tests/propagate_into.rs:7-8], tests/propagate_into.rs:183.
Sources: tests/propagate_into.rs:3-9, tests/propagate_into.rs:170-201
To guarantee that runtime simulation loops remain free of heap allocations, tests/propagate_into_alloc.rs implements a dedicated integration test binary equipped with a custom global allocator tests/propagate_into_alloc.rs:3-9.
struct CountingAlloc;
static ALLOCATIONS: AtomicU64 = AtomicU64::new(0);
unsafe impl GlobalAlloc for CountingAlloc {
unsafe fn alloc(&self, layout: Layout) -> *mut u8 {
ALLOCATIONS.fetch_add(1, Ordering::SeqCst);
unsafe { System.alloc(layout) }
}
// ... realloc, alloc_zeroed, dealloc forwarded to System
}
#[global_allocator]
static GLOBAL: CountingAlloc = CountingAlloc;Sources: tests/propagate_into_alloc.rs:10-46
- Initialization occurs outside the measured window via
SynapticMesh::new, which allocates internal ring buffers and graph structures [tests/propagate_into_alloc.rs:5-8], tests/propagate_into_alloc.rs:57-60. - The test loop executes multiple consecutive ticks of boolean and graded propagation into pre-allocated scratch buffers tests/propagate_into_alloc.rs:67-93.
-
allocation_deltaasserts that the allocation counter delta duringpropagate_intoandpropagate_graded_intois strictly0[tests/propagate_into.rs:48-53], tests/propagate_into_alloc.rs:81-93.
Sources: tests/propagate_into_alloc.rs:3-9, tests/propagate_into_alloc.rs:48-94
- 1. Overview
- 1.1. Getting Started & Public API
- 1.2. Release History and Versioning
- 2. Core Runtime: SynapticMesh
- 2.1. Propagation APIs and Tick Semantics
- 2.2. Spike Delay Buffer (Ring Buffer)
- 2.3. Core Types and Error Model
- 2.4. Checkpointing and Serde State Restoration
- 3. Topology Subsystem
- 3.1. SynapticGraph and CSR Representation
- 3.2. Topology Generators
- 3.3. Wiring Rules, Dale's Law and Delay Assignment
- 3.4. Topology Digest
- 4. Sparse Maps and Channel Routing
- 4.1. ChannelRouter and RouterConfig
- 4.2. Neuromodulation and Plasticity
- 4.3. SparseSynapticMap (CSR)
- 5. Testing, Benchmarks and Quality Gates
- 5.1. Propagation Contract Tests
- 5.2. Checkpoint Resume Property Suite
- 5.3. Benchmarks and Unit Test Module
- 6. Build, CI and Project Tooling
- 6.1. Cargo Manifest, Profiles and Dependencies
- 6.2. CI Workflows and Packaging Validation
- 6.3. Code Quality, Licensing and Review Gates
- 7. Glossary