atomik-core 0.2.0__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.
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: atomik-core
3
+ Version: 0.2.0
4
+ Summary: ATOMiK delta-state algebra — O(1) state reconstruction for any processor
5
+ Author-email: ATOMiK Project <matt@atomik.dev>
6
+ License-Expression: Apache-2.0
7
+ Project-URL: Homepage, https://atomik.tech
8
+ Project-URL: Documentation, https://atomik.tech/docs
9
+ Project-URL: Repository, https://github.com/MatthewHRockwell/ATOMiK
10
+ Project-URL: Changelog, https://github.com/MatthewHRockwell/ATOMiK/releases
11
+ Project-URL: Issues, https://github.com/MatthewHRockwell/ATOMiK/issues
12
+ Keywords: state-management,delta-state,xor-algebra,lock-free,distributed-systems,fingerprinting,change-detection
13
+ Classifier: Development Status :: 4 - Beta
14
+ Classifier: Intended Audience :: Developers
15
+ Classifier: Intended Audience :: Science/Research
16
+ Classifier: Operating System :: OS Independent
17
+ Classifier: Programming Language :: Python :: 3
18
+ Classifier: Programming Language :: Python :: 3.9
19
+ Classifier: Programming Language :: Python :: 3.10
20
+ Classifier: Programming Language :: Python :: 3.11
21
+ Classifier: Programming Language :: Python :: 3.12
22
+ Classifier: Programming Language :: Python :: 3.13
23
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
24
+ Classifier: Topic :: System :: Distributed Computing
25
+ Classifier: Typing :: Typed
26
+ Requires-Python: >=3.9
27
+ Description-Content-Type: text/markdown
28
+ Provides-Extra: dev
29
+ Requires-Dist: pytest>=7.0.0; extra == "dev"
30
+ Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
31
+
32
+ # atomik-core
33
+
34
+ **O(1) state reconstruction. 99% less bandwidth. Formally proven.**
35
+
36
+ ATOMiK is a delta-state algebra that replaces snapshots, event replay, and full-state replication with four operations. Works on any processor — no FPGA required.
37
+
38
+ ## Install
39
+
40
+ ```bash
41
+ pip install atomik-core
42
+ ```
43
+
44
+ **Zero dependencies.** Python 3.9+.
45
+
46
+ ## Quick Start
47
+
48
+ ```python
49
+ from atomik_core import AtomikContext
50
+
51
+ # Create a context and set initial state
52
+ ctx = AtomikContext()
53
+ ctx.load(0xDEADBEEF)
54
+
55
+ # Accumulate deltas (XOR — order doesn't matter)
56
+ ctx.accum(0x000000FF)
57
+ print(f"State: 0x{ctx.read():08x}") # 0xdeadbe10
58
+
59
+ # Undo any delta by re-applying it (self-inverse)
60
+ ctx.rollback(0x000000FF)
61
+ assert ctx.read() == 0xDEADBEEF
62
+ ```
63
+
64
+ ## The 4 Operations
65
+
66
+ | Operation | What it does | Complexity |
67
+ |-----------|-------------|------------|
68
+ | `load(value)` | Set reference state, clear accumulator | O(1) |
69
+ | `accum(delta)` | XOR delta into accumulator | O(1) |
70
+ | `read()` | Reconstruct state: reference ^ accumulator | O(1) |
71
+ | `swap()` | Atomic snapshot + new epoch | O(1) |
72
+
73
+ Everything else — rollback, merge, fingerprinting, streaming — is built on these four.
74
+
75
+ ## Why ATOMiK?
76
+
77
+ ### 99% Less Network Traffic
78
+
79
+ Send 8-byte deltas instead of full state copies.
80
+
81
+ ```python
82
+ from atomik_core import DeltaStream
83
+
84
+ # Sender and receiver start with same reference
85
+ sender = DeltaStream()
86
+ receiver = DeltaStream()
87
+ sender.load(0, initial_state=0xCAFE)
88
+ receiver.load(0, initial_state=0xCAFE)
89
+
90
+ # Sender produces a delta (8 bytes, not full state)
91
+ msg = sender.accum(0, delta=0x00FF)
92
+
93
+ # Receiver applies it — converges to same state
94
+ receiver.apply(msg)
95
+ assert sender.read(0) == receiver.read(0)
96
+ ```
97
+
98
+ | State Size | Full Replication (10K updates) | ATOMiK Deltas | Reduction |
99
+ |-----------|-------------------------------|---------------|-----------|
100
+ | 1 KB | 10.2 MB | 80 KB | **99.2%** |
101
+ | 64 KB | 655 MB | 80 KB | **99.99%** |
102
+
103
+ ### 333,333x Less Memory for Rollback
104
+
105
+ ATOMiK uses 24 bytes regardless of history length. No snapshot stack.
106
+
107
+ ```python
108
+ ctx = AtomikContext()
109
+ ctx.load(0xAAAA)
110
+
111
+ # Apply 1 million deltas...
112
+ for i in range(1_000_000):
113
+ ctx.accum(i)
114
+
115
+ # Undo all of them (XOR self-inverse)
116
+ for i in range(1_000_000):
117
+ ctx.rollback(i)
118
+
119
+ assert ctx.read() == 0xAAAA # Back to original
120
+ # Memory used: 24 bytes. Snapshot approach: 8 MB.
121
+ ```
122
+
123
+ ### 1,291x Faster Change Detection
124
+
125
+ Track changes incrementally in O(1), not O(n).
126
+
127
+ ```python
128
+ from atomik_core import Fingerprint
129
+
130
+ fp = Fingerprint(width=64)
131
+ fp.load(reference_data) # Set reference fingerprint
132
+
133
+ # When a field changes, update in O(1):
134
+ fp.accumulate_delta(old_value, new_value)
135
+
136
+ if fp.changed:
137
+ print("Data modified!")
138
+ ```
139
+
140
+ ### No Consensus Protocol
141
+
142
+ XOR is commutative — deltas can arrive in any order. All nodes converge.
143
+
144
+ ```python
145
+ # Three nodes, each produces deltas independently
146
+ nodes = [DeltaStream() for _ in range(3)]
147
+ for n in nodes:
148
+ n.load(0, 0xAAAA)
149
+
150
+ m0 = nodes[0].accum(0, 0x0001)
151
+ m1 = nodes[1].accum(0, 0x0010)
152
+ m2 = nodes[2].accum(0, 0x0100)
153
+
154
+ # Broadcast all-to-all (any order)
155
+ for i, node in enumerate(nodes):
156
+ for j, msg in enumerate([m0, m1, m2]):
157
+ if i != j:
158
+ node.apply(msg)
159
+
160
+ # All converge — no Raft, no Paxos, no leader election
161
+ assert nodes[0].read(0) == nodes[1].read(0) == nodes[2].read(0)
162
+ ```
163
+
164
+ ## Multi-Context Table
165
+
166
+ Track state across 256 independent addresses:
167
+
168
+ ```python
169
+ from atomik_core import AtomikTable
170
+
171
+ table = AtomikTable(num_contexts=256)
172
+ table.load(addr=0, initial_state=0x1000)
173
+ table.load(addr=1, initial_state=0x2000)
174
+
175
+ table.accum(addr=0, delta=0x0001)
176
+ assert table.read(0) == 0x1001
177
+ assert table.read(1) == 0x2000 # Independent
178
+
179
+ # Batch update multiple addresses at once
180
+ table.batch_accum({0: 0x0010, 1: 0x0020, 2: 0x0030})
181
+
182
+ # Snapshot all non-zero contexts
183
+ active = table.snapshot()
184
+ ```
185
+
186
+ ## Formally Proven
187
+
188
+ Every algebraic property is proven in Lean4 — not tested, proven:
189
+
190
+ - **Commutativity**: `accum(a); accum(b) == accum(b); accum(a)`
191
+ - **Associativity**: `(a ^ b) ^ c == a ^ (b ^ c)`
192
+ - **Self-inverse**: `accum(d); accum(d) == identity`
193
+ - **Identity**: `accum(0) == identity`
194
+
195
+ 92 theorems total. [See proofs →](https://github.com/MatthewHRockwell/ATOMiK/tree/main/math/proofs)
196
+
197
+ ## C Library
198
+
199
+ Single-header C99 library with the same API:
200
+
201
+ ```c
202
+ #define ATOMIK_IMPLEMENTATION
203
+ #include "atomik_core.h"
204
+
205
+ atomik_ctx_t ctx;
206
+ atomik_init(&ctx);
207
+ atomik_load(&ctx, 0xDEADBEEFCAFEBABEULL);
208
+ atomik_accum(&ctx, 0x00000000000000FFULL);
209
+ uint64_t state = atomik_read(&ctx);
210
+ ```
211
+
212
+ ## Hardware Upgrade Path
213
+
214
+ When software performance isn't enough:
215
+
216
+ | Implementation | Throughput | Latency |
217
+ |---------------|-----------|---------|
218
+ | Python (`atomik-core`) | 5M ops/sec | ~200 ns |
219
+ | C (`atomik_core.h`) | 500M ops/sec | ~2 ns |
220
+ | FPGA (ATOMiK hardware) | 69.7 Gops/sec | 10.6 ns/op |
221
+
222
+ Same API. Same algebra. Same proofs. Just faster.
223
+
224
+ ## Examples
225
+
226
+ - [Distributed Cache Sync](examples/distributed_cache.py) — 3-node convergence without consensus
227
+ - [IoT Sensor Fusion](examples/iot_sensor_fusion.py) — 99.2% bandwidth reduction
228
+ - [Real-Time Analytics](examples/realtime_analytics.py) — Trading P&L tracking at 2.5M ops/sec
229
+
230
+ ## License
231
+
232
+ Apache 2.0 for evaluation and non-commercial use. [Commercial license](https://github.com/MatthewHRockwell/ATOMiK) required for production deployment. Patent pending.
@@ -0,0 +1,201 @@
1
+ # atomik-core
2
+
3
+ **O(1) state reconstruction. 99% less bandwidth. Formally proven.**
4
+
5
+ ATOMiK is a delta-state algebra that replaces snapshots, event replay, and full-state replication with four operations. Works on any processor — no FPGA required.
6
+
7
+ ## Install
8
+
9
+ ```bash
10
+ pip install atomik-core
11
+ ```
12
+
13
+ **Zero dependencies.** Python 3.9+.
14
+
15
+ ## Quick Start
16
+
17
+ ```python
18
+ from atomik_core import AtomikContext
19
+
20
+ # Create a context and set initial state
21
+ ctx = AtomikContext()
22
+ ctx.load(0xDEADBEEF)
23
+
24
+ # Accumulate deltas (XOR — order doesn't matter)
25
+ ctx.accum(0x000000FF)
26
+ print(f"State: 0x{ctx.read():08x}") # 0xdeadbe10
27
+
28
+ # Undo any delta by re-applying it (self-inverse)
29
+ ctx.rollback(0x000000FF)
30
+ assert ctx.read() == 0xDEADBEEF
31
+ ```
32
+
33
+ ## The 4 Operations
34
+
35
+ | Operation | What it does | Complexity |
36
+ |-----------|-------------|------------|
37
+ | `load(value)` | Set reference state, clear accumulator | O(1) |
38
+ | `accum(delta)` | XOR delta into accumulator | O(1) |
39
+ | `read()` | Reconstruct state: reference ^ accumulator | O(1) |
40
+ | `swap()` | Atomic snapshot + new epoch | O(1) |
41
+
42
+ Everything else — rollback, merge, fingerprinting, streaming — is built on these four.
43
+
44
+ ## Why ATOMiK?
45
+
46
+ ### 99% Less Network Traffic
47
+
48
+ Send 8-byte deltas instead of full state copies.
49
+
50
+ ```python
51
+ from atomik_core import DeltaStream
52
+
53
+ # Sender and receiver start with same reference
54
+ sender = DeltaStream()
55
+ receiver = DeltaStream()
56
+ sender.load(0, initial_state=0xCAFE)
57
+ receiver.load(0, initial_state=0xCAFE)
58
+
59
+ # Sender produces a delta (8 bytes, not full state)
60
+ msg = sender.accum(0, delta=0x00FF)
61
+
62
+ # Receiver applies it — converges to same state
63
+ receiver.apply(msg)
64
+ assert sender.read(0) == receiver.read(0)
65
+ ```
66
+
67
+ | State Size | Full Replication (10K updates) | ATOMiK Deltas | Reduction |
68
+ |-----------|-------------------------------|---------------|-----------|
69
+ | 1 KB | 10.2 MB | 80 KB | **99.2%** |
70
+ | 64 KB | 655 MB | 80 KB | **99.99%** |
71
+
72
+ ### 333,333x Less Memory for Rollback
73
+
74
+ ATOMiK uses 24 bytes regardless of history length. No snapshot stack.
75
+
76
+ ```python
77
+ ctx = AtomikContext()
78
+ ctx.load(0xAAAA)
79
+
80
+ # Apply 1 million deltas...
81
+ for i in range(1_000_000):
82
+ ctx.accum(i)
83
+
84
+ # Undo all of them (XOR self-inverse)
85
+ for i in range(1_000_000):
86
+ ctx.rollback(i)
87
+
88
+ assert ctx.read() == 0xAAAA # Back to original
89
+ # Memory used: 24 bytes. Snapshot approach: 8 MB.
90
+ ```
91
+
92
+ ### 1,291x Faster Change Detection
93
+
94
+ Track changes incrementally in O(1), not O(n).
95
+
96
+ ```python
97
+ from atomik_core import Fingerprint
98
+
99
+ fp = Fingerprint(width=64)
100
+ fp.load(reference_data) # Set reference fingerprint
101
+
102
+ # When a field changes, update in O(1):
103
+ fp.accumulate_delta(old_value, new_value)
104
+
105
+ if fp.changed:
106
+ print("Data modified!")
107
+ ```
108
+
109
+ ### No Consensus Protocol
110
+
111
+ XOR is commutative — deltas can arrive in any order. All nodes converge.
112
+
113
+ ```python
114
+ # Three nodes, each produces deltas independently
115
+ nodes = [DeltaStream() for _ in range(3)]
116
+ for n in nodes:
117
+ n.load(0, 0xAAAA)
118
+
119
+ m0 = nodes[0].accum(0, 0x0001)
120
+ m1 = nodes[1].accum(0, 0x0010)
121
+ m2 = nodes[2].accum(0, 0x0100)
122
+
123
+ # Broadcast all-to-all (any order)
124
+ for i, node in enumerate(nodes):
125
+ for j, msg in enumerate([m0, m1, m2]):
126
+ if i != j:
127
+ node.apply(msg)
128
+
129
+ # All converge — no Raft, no Paxos, no leader election
130
+ assert nodes[0].read(0) == nodes[1].read(0) == nodes[2].read(0)
131
+ ```
132
+
133
+ ## Multi-Context Table
134
+
135
+ Track state across 256 independent addresses:
136
+
137
+ ```python
138
+ from atomik_core import AtomikTable
139
+
140
+ table = AtomikTable(num_contexts=256)
141
+ table.load(addr=0, initial_state=0x1000)
142
+ table.load(addr=1, initial_state=0x2000)
143
+
144
+ table.accum(addr=0, delta=0x0001)
145
+ assert table.read(0) == 0x1001
146
+ assert table.read(1) == 0x2000 # Independent
147
+
148
+ # Batch update multiple addresses at once
149
+ table.batch_accum({0: 0x0010, 1: 0x0020, 2: 0x0030})
150
+
151
+ # Snapshot all non-zero contexts
152
+ active = table.snapshot()
153
+ ```
154
+
155
+ ## Formally Proven
156
+
157
+ Every algebraic property is proven in Lean4 — not tested, proven:
158
+
159
+ - **Commutativity**: `accum(a); accum(b) == accum(b); accum(a)`
160
+ - **Associativity**: `(a ^ b) ^ c == a ^ (b ^ c)`
161
+ - **Self-inverse**: `accum(d); accum(d) == identity`
162
+ - **Identity**: `accum(0) == identity`
163
+
164
+ 92 theorems total. [See proofs →](https://github.com/MatthewHRockwell/ATOMiK/tree/main/math/proofs)
165
+
166
+ ## C Library
167
+
168
+ Single-header C99 library with the same API:
169
+
170
+ ```c
171
+ #define ATOMIK_IMPLEMENTATION
172
+ #include "atomik_core.h"
173
+
174
+ atomik_ctx_t ctx;
175
+ atomik_init(&ctx);
176
+ atomik_load(&ctx, 0xDEADBEEFCAFEBABEULL);
177
+ atomik_accum(&ctx, 0x00000000000000FFULL);
178
+ uint64_t state = atomik_read(&ctx);
179
+ ```
180
+
181
+ ## Hardware Upgrade Path
182
+
183
+ When software performance isn't enough:
184
+
185
+ | Implementation | Throughput | Latency |
186
+ |---------------|-----------|---------|
187
+ | Python (`atomik-core`) | 5M ops/sec | ~200 ns |
188
+ | C (`atomik_core.h`) | 500M ops/sec | ~2 ns |
189
+ | FPGA (ATOMiK hardware) | 69.7 Gops/sec | 10.6 ns/op |
190
+
191
+ Same API. Same algebra. Same proofs. Just faster.
192
+
193
+ ## Examples
194
+
195
+ - [Distributed Cache Sync](examples/distributed_cache.py) — 3-node convergence without consensus
196
+ - [IoT Sensor Fusion](examples/iot_sensor_fusion.py) — 99.2% bandwidth reduction
197
+ - [Real-Time Analytics](examples/realtime_analytics.py) — Trading P&L tracking at 2.5M ops/sec
198
+
199
+ ## License
200
+
201
+ Apache 2.0 for evaluation and non-commercial use. [Commercial license](https://github.com/MatthewHRockwell/ATOMiK) required for production deployment. Patent pending.
@@ -0,0 +1,61 @@
1
+ """ATOMiK Core — Delta-state algebra for any processor.
2
+
3
+ Pure-software implementation of the ATOMiK instruction set:
4
+ LOAD — Set initial reference state
5
+ ACCUM — XOR delta into accumulator
6
+ READ — Reconstruct current state (reference XOR accumulator)
7
+ SWAP — Atomic read-and-reset (snapshot + new epoch)
8
+
9
+ Zero dependencies. Works on any Python 3.9+ interpreter.
10
+
11
+ Backed by 92 Lean4 theorems proving:
12
+ - Commutativity: accum(a); accum(b) == accum(b); accum(a)
13
+ - Associativity: (a ^ b) ^ c == a ^ (b ^ c)
14
+ - Self-inverse: accum(d); accum(d) == identity
15
+ - Identity: accum(0) == identity
16
+
17
+ Quick start:
18
+ from atomik_core import AtomikContext
19
+
20
+ ctx = AtomikContext()
21
+ ctx.load(0xDEADBEEF)
22
+ ctx.accum(0x000000FF)
23
+ assert ctx.read() == 0xDEADBE10
24
+
25
+ Multi-context table:
26
+ from atomik_core import AtomikTable
27
+
28
+ table = AtomikTable(num_contexts=256)
29
+ table.load(addr=0, initial_state=0xCAFEBABE)
30
+ table.accum(addr=0, delta=0x00000001)
31
+ assert table.read(addr=0) == 0xCAFEBABF
32
+
33
+ SPDX-License-Identifier: Apache-2.0
34
+ """
35
+
36
+ __version__ = "0.2.0"
37
+
38
+ from atomik_core.context import AtomikContext
39
+ from atomik_core.table import AtomikTable
40
+ from atomik_core.stream import DeltaStream, DeltaMessage
41
+ from atomik_core.fingerprint import Fingerprint
42
+ from atomik_core.benchmark import (
43
+ bench_rollback,
44
+ bench_change_detection,
45
+ bench_convergence,
46
+ bench_bandwidth,
47
+ bench_throughput,
48
+ )
49
+
50
+ __all__ = [
51
+ "AtomikContext",
52
+ "AtomikTable",
53
+ "DeltaStream",
54
+ "DeltaMessage",
55
+ "Fingerprint",
56
+ "bench_rollback",
57
+ "bench_change_detection",
58
+ "bench_convergence",
59
+ "bench_bandwidth",
60
+ "bench_throughput",
61
+ ]