spikeling 1.0.2__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. spikeling-1.0.2/LICENSE +21 -0
  2. spikeling-1.0.2/PKG-INFO +136 -0
  3. spikeling-1.0.2/README.md +110 -0
  4. spikeling-1.0.2/core/__init__.py +1 -0
  5. spikeling-1.0.2/core/__main__.py +81 -0
  6. spikeling-1.0.2/core/compiler/__init__.py +0 -0
  7. spikeling-1.0.2/core/compiler/compiler.py +522 -0
  8. spikeling-1.0.2/core/encoder/__init__.py +0 -0
  9. spikeling-1.0.2/core/encoder/encoder.py +221 -0
  10. spikeling-1.0.2/core/examples/agent_brain.spk +82 -0
  11. spikeling-1.0.2/core/examples/signal_detector.spk +78 -0
  12. spikeling-1.0.2/core/examples/signal_test.py +121 -0
  13. spikeling-1.0.2/core/examples/sound_localizer.spk +18 -0
  14. spikeling-1.0.2/core/examples/test_gating_accuracy_regression.py +83 -0
  15. spikeling-1.0.2/core/examples/test_tone_detector.py +78 -0
  16. spikeling-1.0.2/core/examples/tone_detector.spk +22 -0
  17. spikeling-1.0.2/core/examples/word_learner.spk +297 -0
  18. spikeling-1.0.2/core/hardware/__init__.py +0 -0
  19. spikeling-1.0.2/core/hardware/acoustic_adapter.py +69 -0
  20. spikeling-1.0.2/core/hardware/acoustic_anomaly_detector.py +189 -0
  21. spikeling-1.0.2/core/hardware/baseline_deviation.py +192 -0
  22. spikeling-1.0.2/core/hardware/emg_adapter.py +154 -0
  23. spikeling-1.0.2/core/hardware/environmental_adapter.py +155 -0
  24. spikeling-1.0.2/core/hardware/sensor_adapter.py +112 -0
  25. spikeling-1.0.2/core/hardware/system_telemetry_adapter.py +249 -0
  26. spikeling-1.0.2/core/hardware/video_adapter.py +146 -0
  27. spikeling-1.0.2/core/memory/__init__.py +0 -0
  28. spikeling-1.0.2/core/memory/memory.py +172 -0
  29. spikeling-1.0.2/core/runtime/__init__.py +0 -0
  30. spikeling-1.0.2/core/runtime/runtime.py +676 -0
  31. spikeling-1.0.2/core/stdlib/neurons.spk +21 -0
  32. spikeling-1.0.2/core/trainer/__init__.py +0 -0
  33. spikeling-1.0.2/core/trainer/trainer.py +466 -0
  34. spikeling-1.0.2/pyproject.toml +58 -0
  35. spikeling-1.0.2/pyspike.py +417 -0
  36. spikeling-1.0.2/pyspike_causal.py +276 -0
  37. spikeling-1.0.2/pyspike_neuron_models.py +209 -0
  38. spikeling-1.0.2/pyspike_surrogate_gradient.py +215 -0
  39. spikeling-1.0.2/setup.cfg +4 -0
  40. spikeling-1.0.2/spikeling.egg-info/PKG-INFO +136 -0
  41. spikeling-1.0.2/spikeling.egg-info/SOURCES.txt +43 -0
  42. spikeling-1.0.2/spikeling.egg-info/dependency_links.txt +1 -0
  43. spikeling-1.0.2/spikeling.egg-info/entry_points.txt +2 -0
  44. spikeling-1.0.2/spikeling.egg-info/requires.txt +3 -0
  45. spikeling-1.0.2/spikeling.egg-info/top_level.txt +5 -0
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Gavin Branaa
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,136 @@
1
+ Metadata-Version: 2.4
2
+ Name: spikeling
3
+ Version: 1.0.2
4
+ Summary: A domain-specific language and runtime for spiking neural networks: one .spk file, four backends (Python, C, Verilog, GDScript).
5
+ Author-email: Gavin Branaa <gbranaa4@gmail.com>
6
+ License: MIT
7
+ Project-URL: Homepage, https://github.com/tritsystem/Spikeling
8
+ Project-URL: Repository, https://github.com/tritsystem/Spikeling
9
+ Project-URL: Issues, https://github.com/tritsystem/Spikeling/issues
10
+ Project-URL: Changelog, https://github.com/tritsystem/Spikeling/blob/main/CHANGELOG.md
11
+ Keywords: spiking neural network,neuromorphic,dsl,lif,stdp,reservoir computing,fpga
12
+ Classifier: Development Status :: 5 - Production/Stable
13
+ Classifier: Environment :: Console
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: License :: OSI Approved :: MIT License
17
+ Classifier: Operating System :: OS Independent
18
+ Classifier: Programming Language :: Python :: 3 :: Only
19
+ Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
20
+ Requires-Python: >=3.10
21
+ Description-Content-Type: text/markdown
22
+ License-File: LICENSE
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest; extra == "dev"
25
+ Dynamic: license-file
26
+
27
+ # 🧠 Spikeling
28
+
29
+ A neuromorphic **domain-specific language and runtime for spiking neural
30
+ networks**, by Gavin Branaa. You describe a network of spiking neurons and
31
+ synapses in a compact `.spk` file, and run that one description on any of four
32
+ backends:
33
+
34
+ - an **interactive Python runtime** (development + STDP learning),
35
+ - generated **C** (embedded / production),
36
+ - generated **Verilog** (FPGA / hardware simulation), and
37
+ - **GDScript** (give a Godot game a live spiking "mind").
38
+
39
+ One language, four targets.
40
+
41
+ ---
42
+
43
+ ## Quick start
44
+
45
+ ```bash
46
+ cd core
47
+ python -m core # run the default example, interactively
48
+ python -m core path/to/network.spk # run your own .spk network
49
+ ```
50
+
51
+ Full DSL reference, runtime details, and the C-compilation path are in
52
+ [`core/README.md`](core/README.md).
53
+
54
+ ## The `.spk` language in 30 seconds
55
+
56
+ ```spk
57
+ neuron LeftMic threshold=110 leak=5 type=LIF
58
+ neuron RightMic threshold=110 leak=5 type=LIF
59
+ neuron Motor threshold=80 leak=3 type=LIF
60
+
61
+ connect LeftMic -> Motor weight=0.8
62
+ connect RightMic -> Motor weight=0.8
63
+
64
+ action Motor -> [MOTOR_FIRE]
65
+
66
+ refractory=400ms
67
+ learn=STDP rate=0.01
68
+ ```
69
+
70
+ | Directive | Meaning |
71
+ |---|---|
72
+ | `neuron <name> threshold=<n> leak=<n> [type=LIF]` | define a neuron |
73
+ | `connect <src> -> <dst> weight=<w>` | weighted synapse |
74
+ | `action <neuron> -> [<COMMAND>]` | map a spike to a named command |
75
+ | `refractory=<n>ms` | global refractory period |
76
+ | `learn=STDP rate=<r>` | enable spike-timing-dependent plasticity |
77
+
78
+ *(The GDScript backend uses a compact variant — `synapse SRC -> DST weight=N` —
79
+ documented in [`godot-runtime/`](godot-runtime/README.md).)*
80
+
81
+ ## Neuron types
82
+
83
+ | Type | What it is |
84
+ |---|---|
85
+ | `LIF` | Leaky integrate-and-fire — fast, standard |
86
+ | `Izhikevich` | Cortical model — bursting, adaptation |
87
+ | `AdEx` | Adaptive exponential — realism/speed balance |
88
+ | `Resonator` | Damped oscillator — responds only to input near its own frequency (a frequency-domain primitive). See [`resonator-prototype/`](resonator-prototype/README.md) |
89
+
90
+ ---
91
+
92
+ ## Repository map
93
+
94
+ | Folder | What it is | Status |
95
+ |---|---|---|
96
+ | [`core/`](core/README.md) | The canonical Python package: compiler, runtime, encoder, stdlib, examples. **Start here.** | Active — source of truth |
97
+ | [`resonator-prototype/`](resonator-prototype/README.md) | The `Resonator` neuron type + benchmarks vs Goertzel/FFT | Active |
98
+ | [`godot-runtime/`](godot-runtime/README.md) | GDScript backend — run a `.spk` brain live inside Godot | Active |
99
+ | [`godot-plugin/`](godot-plugin/README.md) | Godot editor addon wrapping the brain | Active |
100
+ | [`sdk-verilog/`](sdk-verilog/README_INDEX.md) | C + Verilog hardware backend, with testbench | Active |
101
+ | [`parallel-audio/`](parallel-audio/README_INDEX.md) | Real-time microphone/audio input engine (C, miniaudio + FFT) | Active, newest |
102
+ | [`benchmarks/`](benchmarks/BENCHMARKS.md) | Performance studies (dormant-vs-polling, gated resonators) | Active |
103
+ | [`fps-game/`](fps-game/README_INDEX.md) | An FPS whose enemy AI is driven by Spikeling brains | Complete |
104
+ | [`ai-apps/`](ai-apps/README_INDEX.md) | Ollama/RAG assistant apps built around Spikeling | Active |
105
+ | [`research/`](research/README_INDEX.md) | Stochastic-resonance experiments (does noise help inference?) | Exploratory |
106
+ | [`legacy-versions/`](legacy-versions/README_INDEX.md) | Superseded earlier scripts | Reference only |
107
+ | `build-artifacts/` | Compiled binaries (generated; excluded from git) | Generated |
108
+
109
+ **Not included here:** a separate, unrelated project is kept out of this
110
+ repository via `.gitignore`.
111
+
112
+ ## Agent orchestration as an SNN
113
+
114
+ An experimental line of work tests whether a spiking neural network can serve
115
+ as the control layer for a multi-agent pipeline — routing tasks, managing
116
+ concurrency, and arbitrating conflicts through spike-based inhibition rather
117
+ than classical scheduling logic.
118
+
119
+ | File | What it does | What was verified |
120
+ |---|---|---|
121
+ | [`core/examples/agent_brain.spk`](core/examples/agent_brain.spk) | SNN definition for agent-routing and winner-take-all inhibition | Routing and lateral inhibition fire correctly in the Python runtime |
122
+ | [`spiking_orchestrator.py`](spiking_orchestrator.py) | Drives the agent pipeline from spike events | Integrates with the runtime; event dispatch works end-to-end |
123
+ | [`spiking_scheduler.py`](spiking_scheduler.py) | Maps spike activity to agent-slot concurrency scheduling | Mechanism works; falsified as a differentiator — produces identical assignments to classical greedy graph coloring |
124
+ | [`agent_runner.py`](agent_runner.py) | Executes individual agents under scheduler control | Runs agents correctly within the allocated slots |
125
+ | [`benchmark_scheduler.py`](benchmark_scheduler.py) | Compares SNN scheduler against greedy coloring across workloads | Confirms parity; no throughput advantage found |
126
+ | [`test_soft_conflicts.py`](test_soft_conflicts.py) | Tests a ternary consensus gate for soft (probabilistic) conflicts | Shows a small, real accuracy win under high conflict load, at substantial added complexity |
127
+ | [`test_incremental_scheduling.py`](test_incremental_scheduling.py) | Tests online incremental task arrival against classical online coloring | Exact tie — no advantage from the SNN path on incremental arrival |
128
+
129
+ The honest summary: the SNN routing and inhibition primitives work, but the
130
+ scheduling and arbitration results did not beat well-known classical baselines.
131
+
132
+ ---
133
+
134
+ ## License
135
+
136
+ MIT (source code). See [`LICENSE`](LICENSE).
@@ -0,0 +1,110 @@
1
+ # 🧠 Spikeling
2
+
3
+ A neuromorphic **domain-specific language and runtime for spiking neural
4
+ networks**, by Gavin Branaa. You describe a network of spiking neurons and
5
+ synapses in a compact `.spk` file, and run that one description on any of four
6
+ backends:
7
+
8
+ - an **interactive Python runtime** (development + STDP learning),
9
+ - generated **C** (embedded / production),
10
+ - generated **Verilog** (FPGA / hardware simulation), and
11
+ - **GDScript** (give a Godot game a live spiking "mind").
12
+
13
+ One language, four targets.
14
+
15
+ ---
16
+
17
+ ## Quick start
18
+
19
+ ```bash
20
+ cd core
21
+ python -m core # run the default example, interactively
22
+ python -m core path/to/network.spk # run your own .spk network
23
+ ```
24
+
25
+ Full DSL reference, runtime details, and the C-compilation path are in
26
+ [`core/README.md`](core/README.md).
27
+
28
+ ## The `.spk` language in 30 seconds
29
+
30
+ ```spk
31
+ neuron LeftMic threshold=110 leak=5 type=LIF
32
+ neuron RightMic threshold=110 leak=5 type=LIF
33
+ neuron Motor threshold=80 leak=3 type=LIF
34
+
35
+ connect LeftMic -> Motor weight=0.8
36
+ connect RightMic -> Motor weight=0.8
37
+
38
+ action Motor -> [MOTOR_FIRE]
39
+
40
+ refractory=400ms
41
+ learn=STDP rate=0.01
42
+ ```
43
+
44
+ | Directive | Meaning |
45
+ |---|---|
46
+ | `neuron <name> threshold=<n> leak=<n> [type=LIF]` | define a neuron |
47
+ | `connect <src> -> <dst> weight=<w>` | weighted synapse |
48
+ | `action <neuron> -> [<COMMAND>]` | map a spike to a named command |
49
+ | `refractory=<n>ms` | global refractory period |
50
+ | `learn=STDP rate=<r>` | enable spike-timing-dependent plasticity |
51
+
52
+ *(The GDScript backend uses a compact variant — `synapse SRC -> DST weight=N` —
53
+ documented in [`godot-runtime/`](godot-runtime/README.md).)*
54
+
55
+ ## Neuron types
56
+
57
+ | Type | What it is |
58
+ |---|---|
59
+ | `LIF` | Leaky integrate-and-fire — fast, standard |
60
+ | `Izhikevich` | Cortical model — bursting, adaptation |
61
+ | `AdEx` | Adaptive exponential — realism/speed balance |
62
+ | `Resonator` | Damped oscillator — responds only to input near its own frequency (a frequency-domain primitive). See [`resonator-prototype/`](resonator-prototype/README.md) |
63
+
64
+ ---
65
+
66
+ ## Repository map
67
+
68
+ | Folder | What it is | Status |
69
+ |---|---|---|
70
+ | [`core/`](core/README.md) | The canonical Python package: compiler, runtime, encoder, stdlib, examples. **Start here.** | Active — source of truth |
71
+ | [`resonator-prototype/`](resonator-prototype/README.md) | The `Resonator` neuron type + benchmarks vs Goertzel/FFT | Active |
72
+ | [`godot-runtime/`](godot-runtime/README.md) | GDScript backend — run a `.spk` brain live inside Godot | Active |
73
+ | [`godot-plugin/`](godot-plugin/README.md) | Godot editor addon wrapping the brain | Active |
74
+ | [`sdk-verilog/`](sdk-verilog/README_INDEX.md) | C + Verilog hardware backend, with testbench | Active |
75
+ | [`parallel-audio/`](parallel-audio/README_INDEX.md) | Real-time microphone/audio input engine (C, miniaudio + FFT) | Active, newest |
76
+ | [`benchmarks/`](benchmarks/BENCHMARKS.md) | Performance studies (dormant-vs-polling, gated resonators) | Active |
77
+ | [`fps-game/`](fps-game/README_INDEX.md) | An FPS whose enemy AI is driven by Spikeling brains | Complete |
78
+ | [`ai-apps/`](ai-apps/README_INDEX.md) | Ollama/RAG assistant apps built around Spikeling | Active |
79
+ | [`research/`](research/README_INDEX.md) | Stochastic-resonance experiments (does noise help inference?) | Exploratory |
80
+ | [`legacy-versions/`](legacy-versions/README_INDEX.md) | Superseded earlier scripts | Reference only |
81
+ | `build-artifacts/` | Compiled binaries (generated; excluded from git) | Generated |
82
+
83
+ **Not included here:** a separate, unrelated project is kept out of this
84
+ repository via `.gitignore`.
85
+
86
+ ## Agent orchestration as an SNN
87
+
88
+ An experimental line of work tests whether a spiking neural network can serve
89
+ as the control layer for a multi-agent pipeline — routing tasks, managing
90
+ concurrency, and arbitrating conflicts through spike-based inhibition rather
91
+ than classical scheduling logic.
92
+
93
+ | File | What it does | What was verified |
94
+ |---|---|---|
95
+ | [`core/examples/agent_brain.spk`](core/examples/agent_brain.spk) | SNN definition for agent-routing and winner-take-all inhibition | Routing and lateral inhibition fire correctly in the Python runtime |
96
+ | [`spiking_orchestrator.py`](spiking_orchestrator.py) | Drives the agent pipeline from spike events | Integrates with the runtime; event dispatch works end-to-end |
97
+ | [`spiking_scheduler.py`](spiking_scheduler.py) | Maps spike activity to agent-slot concurrency scheduling | Mechanism works; falsified as a differentiator — produces identical assignments to classical greedy graph coloring |
98
+ | [`agent_runner.py`](agent_runner.py) | Executes individual agents under scheduler control | Runs agents correctly within the allocated slots |
99
+ | [`benchmark_scheduler.py`](benchmark_scheduler.py) | Compares SNN scheduler against greedy coloring across workloads | Confirms parity; no throughput advantage found |
100
+ | [`test_soft_conflicts.py`](test_soft_conflicts.py) | Tests a ternary consensus gate for soft (probabilistic) conflicts | Shows a small, real accuracy win under high conflict load, at substantial added complexity |
101
+ | [`test_incremental_scheduling.py`](test_incremental_scheduling.py) | Tests online incremental task arrival against classical online coloring | Exact tie — no advantage from the SNN path on incremental arrival |
102
+
103
+ The honest summary: the SNN routing and inhibition primitives work, but the
104
+ scheduling and arbitration results did not beat well-known classical baselines.
105
+
106
+ ---
107
+
108
+ ## License
109
+
110
+ MIT (source code). See [`LICENSE`](LICENSE).
@@ -0,0 +1 @@
1
+ # Spikeling — Neuromorphic AI Runtime
@@ -0,0 +1,81 @@
1
+ """
2
+ spikeling/__main__.py
3
+ =====================
4
+ Entry point for the Spikeling neuromorphic runtime.
5
+
6
+ Usage:
7
+ python -m spikeling # reflex demo (sound localizer)
8
+ python -m spikeling --train # interactive trainer
9
+ python -m spikeling --train path/to/network.spk # train a specific network
10
+ python -m spikeling path/to/network.spk # run any network interactively
11
+ python -m spikeling --no-interactive # compile only
12
+ """
13
+
14
+ import sys
15
+ import os
16
+
17
+ # Windows' legacy console codepage (cp1252 etc.) can't encode the box-drawing
18
+ # characters the interactive runtime prints (runtime.py's banner) -- crashes the
19
+ # very first `python -m core` a new user tries, on a default Windows terminal,
20
+ # with no non-ASCII input involved at all. Reconfigure as early as possible,
21
+ # before any print happens; a no-op on already-UTF-8 setups (Linux/macOS, or a
22
+ # UTF-8 Windows Terminal).
23
+ for _stream in (sys.stdout, sys.stderr):
24
+ if hasattr(_stream, "reconfigure"):
25
+ try:
26
+ _stream.reconfigure(encoding="utf-8", errors="replace")
27
+ except Exception:
28
+ pass
29
+
30
+ sys.path.insert(0, os.path.dirname(__file__))
31
+
32
+ from compiler.compiler import compile_file
33
+ from runtime.runtime import SpikelingRuntime
34
+
35
+
36
+ def main():
37
+ args = sys.argv[1:]
38
+ train_mode = "--train" in args
39
+ no_ui = "--no-interactive" in args
40
+ spk_args = [a for a in args if not a.startswith("--")]
41
+
42
+ # Default networks
43
+ base = os.path.dirname(__file__)
44
+ default_demo = os.path.join(base, "examples", "sound_localizer.spk")
45
+ default_learner = os.path.join(base, "examples", "word_learner.spk")
46
+
47
+ if train_mode:
48
+ spk_path = spk_args[0] if spk_args else default_learner
49
+ else:
50
+ spk_path = spk_args[0] if spk_args else default_demo
51
+
52
+ if not os.path.exists(spk_path):
53
+ print(f"[spikeling] error: file not found - {spk_path}")
54
+ sys.exit(1)
55
+
56
+ print(f"[spikeling] compiling {spk_path} ...")
57
+ output_dir = os.path.dirname(os.path.abspath(spk_path))
58
+ ast = compile_file(spk_path, output_dir=output_dir)
59
+ rt = SpikelingRuntime(ast)
60
+
61
+ if no_ui:
62
+ print("[spikeling] compiled successfully (--no-interactive mode)")
63
+ print(rt.state_report())
64
+ return
65
+
66
+ if train_mode:
67
+ # Wire in the trainer
68
+ from trainer.trainer import SpikelingTrainer
69
+ memory_path = os.path.join(output_dir, "spikeling_memory.json")
70
+ trainer = SpikelingTrainer(rt, memory_path=memory_path)
71
+ trainer.run_interactive()
72
+ else:
73
+ # Reflex / benchmark demo
74
+ for action in ast.actions:
75
+ cmd = action.command
76
+ rt.register_handler(cmd, lambda c=cmd: None)
77
+ rt.run_interactive()
78
+
79
+
80
+ if __name__ == "__main__":
81
+ main()
File without changes