betterwithage commited on
Commit
10b2de5
·
verified ·
1 Parent(s): 9e72252

code(atelier): ouroboros.py from szl-khipu — not a 1.5B retrain

Browse files
Files changed (1) hide show
  1. ouroboros.py +70 -0
ouroboros.py ADDED
@@ -0,0 +1,70 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ # Copyright 2026 SZL Holdings
3
+ """Loop tax: MEASURED attempt times vs DERIVED overhead. Never fabricate joules."""
4
+
5
+ from __future__ import annotations
6
+
7
+ from typing import Any, Mapping, Sequence
8
+
9
+ Attempt = Mapping[str, Any]
10
+
11
+
12
+ def loop_tax(
13
+ attempts: Sequence[Attempt],
14
+ wall_ms: float | None,
15
+ max_budget: int,
16
+ ) -> dict[str, Any]:
17
+ """Self-check arithmetic from szl-ouroboros.
18
+
19
+ attempts [220 fail, 900 ok], wall=1300 →
20
+ modelMs=1120, peak=900, overhead=180, serializationTax=220, deadHop=220.
21
+ """
22
+ model_ms = float(sum(float(a["ms"]) for a in attempts))
23
+ peak = float(max((float(a["ms"]) for a in attempts), default=0.0))
24
+ if wall_ms is None:
25
+ overhead: float | None = None
26
+ overhead_label = "UNAVAILABLE"
27
+ else:
28
+ overhead = max(0.0, float(wall_ms) - model_ms)
29
+ overhead_label = "DERIVED"
30
+ serialization_tax = max(0.0, model_ms - peak)
31
+ dead_hop = 0.0
32
+ for a in attempts:
33
+ if bool(a["ok"]):
34
+ break
35
+ dead_hop += float(a["ms"])
36
+ steps = len(attempts)
37
+ within = steps <= int(max_budget)
38
+ any_ok = any(bool(a["ok"]) for a in attempts)
39
+ if not within:
40
+ exit_kind = "budgetExhausted"
41
+ elif any_ok:
42
+ exit_kind = "converged"
43
+ else:
44
+ exit_kind = "aborted"
45
+ return {
46
+ "modelMs": model_ms,
47
+ "peakAttemptMs": peak,
48
+ "overheadMs": overhead,
49
+ "serializationTaxMs": serialization_tax,
50
+ "deadHopMs": dead_hop,
51
+ "withinBudget": within,
52
+ "exit": exit_kind,
53
+ "honesty": {
54
+ "modelMs": "MEASURED",
55
+ "peakAttemptMs": "MEASURED",
56
+ "overheadMs": overhead_label,
57
+ "serializationTaxMs": "DERIVED",
58
+ "deadHopMs": "DERIVED",
59
+ },
60
+ }
61
+
62
+
63
+ OUROBOROS_SELFCHECK: dict[str, Any] = loop_tax(
64
+ [
65
+ {"ok": False, "ms": 220},
66
+ {"ok": True, "ms": 900},
67
+ ],
68
+ 1300,
69
+ 4,
70
+ )