Explainability¶
Bitstream-level explainability and causal attribution for SC decisions. Anchored to formal verification properties.
Replay Guardrails¶
ExplainabilityEngine.explain_spike and ExplainabilityEngine.replay_bitstream
validate deterministic replay inputs before allocating streams or mutating
provenance. threshold_q16 must be an integer in [0, 65535], replay lengths
must be positive integers, and spike_threshold_count must be between 0 and
the replayed bitstream length. Rejected inputs raise ValueError before any
decision node or provenance step is recorded.
Quick Start¶
from sc_neurocore.explainability.explainability import (
ExplainabilityEngine, CausalAttributor, FormalPropertyLink,
)
sc_neurocore.explainability.explainability
¶
Bitstream-level explainability with deterministic replay and provenance.
Leverages bit-true deterministic SC streams and LFSR replay to generate
full provenance traces: "why this spike fired" as a verifiable bitstream
decision tree. Integrates with the predictive_coding.ReasoningTrace
for neuro-symbolic explanations and produces hash-verified audit trails.
LFSRReplay
¶
Deterministic LFSR-16 replay engine.
Mirrors core_engine::Lfsr16 polynomial: x^16 + x^14 + x^13 + x^11 + 1.
Given the same seed, reproduces the exact same bitstream for formal
verification and replay-based auditing.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 | |
step()
¶
Advance one step, return new register value.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
71 72 73 74 75 | |
encode(threshold, length)
¶
Generate a bitstream by comparing LFSR output against threshold.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
77 78 79 80 81 82 83 | |
reset()
¶
Reset to initial seed for replay.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
85 86 87 | |
DecisionMargin
dataclass
¶
How close a decision was to flipping.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
99 100 101 102 103 104 105 106 | |
DecisionNode
dataclass
¶
One node in a spike decision tree.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 | |
SpikeDecisionTree
¶
Captures "why this spike fired" as a verifiable decision tree.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 | |
add_decision(neuron_id, bitstream, threshold, scc=0.0, parent=None, timestep=0, layer_id='', contributing_neurons=None, threshold_q16=0)
¶
Record a spike decision from bitstream observation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
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 176 177 178 179 180 181 182 183 184 185 186 187 188 189 | |
nodes_at_layer(layer_id)
¶
Return all nodes at a given layer.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
210 211 212 | |
nodes_at_timestep(timestep)
¶
Return all nodes at a given timestep.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
214 215 216 | |
get_node(neuron_id)
¶
Look up a node by neuron ID.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
218 219 220 221 222 223 | |
spike_path()
¶
Return the chain of spiking nodes from root down.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
225 226 227 228 229 230 231 | |
ProvenanceStep
dataclass
¶
One step in a full provenance chain.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
265 266 267 268 269 270 271 272 273 | |
ProvenanceTrace
¶
Full chain from input → encoding → computation → spike decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 | |
chain_hash
property
¶
Hash of the entire provenance chain for tamper detection.
add_step(stage, description, data=None, metadata=None)
¶
Record one provenance step.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 | |
RegulatoryMetadata
dataclass
¶
IEC 62304 / FDA SaMD traceability fields.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
342 343 344 345 346 347 348 349 350 351 352 353 | |
FormalPropertyLink
dataclass
¶
Cross-reference to SymbiYosys formal verification.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
356 357 358 359 360 361 362 363 364 | |
VerifiabilityReport
dataclass
¶
Formal audit report with hash verification.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
367 368 369 370 371 372 373 374 375 376 377 378 379 | |
SensitivityResult
dataclass
¶
Result of a 'what-if' threshold perturbation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
385 386 387 388 389 390 391 392 393 394 | |
SensitivityAnalyzer
¶
Counterfactual analysis: 'would the decision flip if threshold ±N?'
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 | |
critical_delta(node)
staticmethod
¶
Smallest threshold change that flips the decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
423 424 425 426 427 428 429 | |
CausalAttribution
dataclass
¶
Attribution of a spike to upstream neurons.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
435 436 437 438 439 440 441 442 443 444 445 446 | |
top_contributors
property
¶
Sorted (descending) list of contributing neurons.
CausalAttributor
¶
Computes causal attribution from input neurons to output spike.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
attribute(target, input_bitstreams, weights=None)
staticmethod
¶
Compute per-input-neuron contribution to the target popcount.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 | |
DiffEntry
dataclass
¶
One field that differs between two explanations.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
475 476 477 478 479 480 481 | |
ExplanationDiff
¶
Compares two decision nodes to find divergence points.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 | |
TemporalWindow
¶
Records decisions across timesteps for temporal attribution.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 | |
peak_timestep()
¶
Timestep with the highest spike rate.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
528 529 530 531 532 533 534 535 536 537 | |
NaturalLanguageExplainer
¶
Generates human-readable explanation strings.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
enhance_with_local_llm(text, *, bridge, question='Rewrite this deterministic spike explanation for a human operator. Preserve all numeric facts and keep the wording concise.')
staticmethod
¶
Enhance a deterministic explanation through the local LLM bridge.
The caller must supply a configured LocalLLMBridge instance so this
module keeps no hard runtime dependency on any local model server.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 | |
explain_node_with_local_llm(node, *, bridge, question='Explain this spike decision for a human operator in two short paragraphs. Do not change or invent numeric values.')
staticmethod
¶
Generate a local-LLM-enhanced explanation for one decision node.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 | |
MultiLayerTrace
¶
Traces decisions across network layers.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 | |
propagation_path()
¶
Per-layer spike rate for visualising propagation.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
657 658 659 660 661 662 | |
SymbolicPathStep
dataclass
¶
One step in a symbolic decision path.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
668 669 670 671 672 673 674 | |
SymbolicPath
¶
Human-readable symbolic path: input → encoding → decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 | |
ExplainabilityEngine
¶
End-to-end explainability: replay + decision tree + provenance.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |
explain_spike(neuron_id, threshold_q16, bitstream_length, spike_threshold_count, scc=0.0, timestep=0, layer_id='', contributing_neurons=None)
¶
Explain one spike decision via deterministic replay.
Replays the LFSR from the current seed state, generates the exact bitstream, and records the decision in the tree and trace.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 | |
verify(regulatory=None, formal_properties=None)
¶
Generate a verifiability report with full replay check.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 | |
replay_bitstream(threshold_q16, length)
¶
Replay a bitstream from the engine's seed (for external comparison).
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
819 820 821 822 823 824 825 826 827 828 829 830 831 | |
sensitivity(node, perturbations=None)
¶
Run sensitivity analysis on a decision node.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
833 834 835 836 837 838 839 | |
attribute(target, input_bitstreams, weights=None)
¶
Compute causal attribution for a decision.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
841 842 843 844 845 846 847 848 | |
explain_spike_with_local_llm(neuron_id, threshold_q16, bitstream_length, spike_threshold_count, *, bridge, scc=0.0, timestep=0, layer_id='', contributing_neurons=None, question='Explain this spike decision for a human operator in two short paragraphs. Do not change or invent numeric values.')
¶
Run the deterministic explainability path, then enhance it locally.
Source code in src/sc_neurocore/explainability/explainability.py
| Python | |
|---|---|
850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 | |