Spike-Level Debugger¶
Temporal spike debugger: trace execution, find divergence, analyze causality.
Tracer¶
sc_neurocore.debug.tracer
¶
Record full SNN execution trace for post-hoc analysis.
Captures per-neuron per-timestep: voltage, spike, input current. Enables temporal debugging: find where spikes diverge, trace causal chains through synaptic connections, compare two runs.
SpikeTracer
¶
Records execution trace during SNN simulation.
Wraps a Network and intercepts step_all to record spikes, voltages, and currents at every timestep.
Usage¶
tracer = SpikeTracer(network) trace = tracer.run(duration=0.1, dt=0.001) divergence = find_divergence(trace, expected_spikes)
Source code in src/sc_neurocore/debug/tracer.py
83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
run(duration, dt=0.001, seed=42)
¶
Run the network and record full execution trace.
Source code in src/sc_neurocore/debug/tracer.py
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 | |
ExecutionTrace
dataclass
¶
Complete execution trace of an SNN run.
Attributes¶
n_neurons : int Total neurons across all populations. n_steps : int Number of simulation timesteps. spikes : ndarray of shape (n_steps, n_neurons) Binary spike matrix. voltages : ndarray of shape (n_steps, n_neurons) Membrane voltages. currents : ndarray of shape (n_steps, n_neurons) Input currents. population_labels : list of str Population names. population_ranges : list of (start, end) Neuron index ranges per population.
Source code in src/sc_neurocore/debug/tracer.py
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 | |
spike_count
property
¶
Total spikes in the trace.
firing_rates
property
¶
Per-neuron firing rate (spikes per step).
neuron_trace(neuron_id)
¶
Extract full trace for one neuron.
Source code in src/sc_neurocore/debug/tracer.py
62 63 64 65 66 67 68 69 | |
spike_times(neuron_id)
¶
Timesteps when a neuron spiked.
Source code in src/sc_neurocore/debug/tracer.py
71 72 73 | |
population_spikes(pop_label)
¶
Spike matrix for one population.
Source code in src/sc_neurocore/debug/tracer.py
75 76 77 78 79 80 | |
Analyzer¶
sc_neurocore.debug.analyzer
¶
Analyze execution traces to debug SNN behavior.
- find_divergence: compare two traces, find first timestep where spikes differ
- causal_chain: trace backward from a spike to find which input spikes caused it
- spike_diff: summary of differences between two traces
DivergencePoint
dataclass
¶
First point where two traces diverge.
Source code in src/sc_neurocore/debug/analyzer.py
24 25 26 27 28 29 30 31 32 33 34 | |
CausalEvent
dataclass
¶
One event in a causal spike chain.
Source code in src/sc_neurocore/debug/analyzer.py
37 38 39 40 41 42 43 44 45 | |
find_divergence(trace_a, trace_b)
¶
Find the first timestep where two traces produce different spikes.
Useful for comparing ANN-converted SNN vs directly-trained SNN, or Python simulation vs hardware output.
Returns None if traces are identical.
Source code in src/sc_neurocore/debug/analyzer.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 | |
causal_chain(trace, neuron_id, timestep, max_depth=10)
¶
Trace backward from a spike to find causal input events.
Starting from neuron_id at timestep, finds the chain of spikes that contributed current to this neuron in preceding timesteps.
Parameters¶
trace : ExecutionTrace neuron_id : int Target neuron. timestep : int Timestep of the spike to explain. max_depth : int Maximum backward steps to trace.
Returns¶
list of CausalEvent Causal chain from target backward to inputs.
Source code in src/sc_neurocore/debug/analyzer.py
106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 | |
spike_diff(trace_a, trace_b)
¶
Summary of spike differences between two traces.
Returns¶
dict with keys: total_mismatches: int mismatch_rate: float (fraction of timestep*neuron pairs) first_divergence: DivergencePoint or None per_neuron_mismatches: ndarray
Source code in src/sc_neurocore/debug/analyzer.py
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | |