-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy path56_metabolic_epigenetic_coupling.py
More file actions
161 lines (130 loc) · 6.79 KB
/
56_metabolic_epigenetic_coupling.py
File metadata and controls
161 lines (130 loc) · 6.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
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
81
82
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
155
156
157
158
159
160
161
"""
Example 56: Metabolic-Epigenetic Coupling — Cost-Gated Retrieval
================================================================
Demonstrates how metabolic state gates access to epigenetic memory,
implementing the paper's cost-gated retrieval model in Section 6.1.1.
Core idea: Memory retrieval isn't free. When the cell is starving,
only deeply embedded (permanent) memories remain accessible, while
transient memories are effectively "silenced." This creates emergent
behavior where resource pressure narrows cognitive focus.
Access(d) = Open if R > threshold for marker strength
= Silenced if R <= threshold
Biological Analogy:
- Chromatin remodeling requires ATP in real cells
- Under metabolic stress, cells silence non-essential genes
- Only constitutively active (housekeeping) genes remain expressed
- This is how biology achieves "graceful degradation" under stress
References:
- Article Section 6.1: RAG as Digital Methylation
- Article Section 6.1.1: Metabolic-Epigenetic Coupling
- Article Section 6.6: Bioenergetic Intelligence
"""
from operon_ai.state.metabolism import ATP_Store, MetabolicState, MetabolicAccessPolicy
from operon_ai.state.histone import HistoneStore, MarkerType, MarkerStrength
def main():
try:
print("=" * 60)
print("Metabolic-Epigenetic Coupling — Cost-Gated Retrieval")
print("=" * 60)
# =================================================================
# SECTION 1: Set Up Coupled Systems
# =================================================================
print("\n--- Section 1: Coupling ATP_Store with HistoneStore ---")
atp = ATP_Store(budget=100, silent=True)
policy = MetabolicAccessPolicy(retrieval_cost=5)
histones = HistoneStore(energy_gate=(atp, policy), silent=True)
# Store memories at different strengths
histones.add_marker(
"User prefers concise responses",
marker_type=MarkerType.PHOSPHORYLATION,
strength=MarkerStrength.WEAK,
tags=["preference"],
)
histones.add_marker(
"Always validate SQL before execution",
marker_type=MarkerType.ACETYLATION,
strength=MarkerStrength.MODERATE,
tags=["safety"],
)
histones.add_marker(
"Production DB credentials are read-only",
marker_type=MarkerType.METHYLATION,
strength=MarkerStrength.STRONG,
tags=["safety", "critical"],
)
histones.add_marker(
"NEVER run DELETE without WHERE clause",
marker_type=MarkerType.METHYLATION,
strength=MarkerStrength.PERMANENT,
tags=["safety", "critical"],
)
print(f" Stored 4 markers (WEAK, MODERATE, STRONG, PERMANENT)")
print(f" ATP: {atp.atp}/{atp.max_atp}")
print(f" Metabolic state: {atp.get_state().value}")
# =================================================================
# SECTION 2: Normal State — Full Access
# =================================================================
print("\n--- Section 2: NORMAL state — all memories accessible ---")
result = histones.retrieve_context()
print(f" Retrieved {len(result.markers)} markers:")
for m in result.markers:
print(f" [{m.strength.name:10s}] {m.content}")
print(f" ATP after retrieval: {atp.atp}")
# =================================================================
# SECTION 3: Drain to CONSERVING — Weak markers silenced
# =================================================================
print("\n--- Section 3: CONSERVING state — weak context silenced ---")
atp.consume(70, "expensive_operation")
print(f" ATP: {atp.atp}/{atp.max_atp} → {atp.get_state().value}")
result = histones.retrieve_context()
print(f" Retrieved {len(result.markers)} markers (STRONG+ only):")
for m in result.markers:
print(f" [{m.strength.name:10s}] {m.content}")
# =================================================================
# SECTION 4: Drain to STARVING — Only permanent memories
# =================================================================
print("\n--- Section 4: STARVING state — only permanent memories ---")
# Need to consume more. At this point state may block low-priority ops.
# The energy gate consumes directly, so it still works.
atp.consume(15, "critical_op", priority=5)
print(f" ATP: {atp.atp}/{atp.max_atp} → {atp.get_state().value}")
result = histones.retrieve_context()
print(f" Retrieved {len(result.markers)} markers (PERMANENT only):")
for m in result.markers:
print(f" [{m.strength.name:10s}] {m.content}")
print(f" The cell retains only its most critical constraint:")
print(f" 'NEVER run DELETE without WHERE clause'")
# =================================================================
# SECTION 5: Recovery — Regenerate ATP, memories return
# =================================================================
print("\n--- Section 5: Recovery — regenerate ATP ---")
atp.regenerate(80)
print(f" ATP: {atp.atp}/{atp.max_atp} → {atp.get_state().value}")
result = histones.retrieve_context()
print(f" Retrieved {len(result.markers)} markers (full access restored):")
for m in result.markers:
print(f" [{m.strength.name:10s}] {m.content}")
# =================================================================
# SECTION 6: Statistics
# =================================================================
print("\n--- Section 6: Statistics ---")
stats = histones.get_statistics()
print(f" Total retrievals: {stats['total_retrievals']}")
print(f" Gated retrievals: {stats['gated_retrievals']}")
print(f" Markers by strength: {stats['by_strength']}")
# =================================================================
# SECTION 7: Without coupling — backward compatible
# =================================================================
print("\n--- Section 7: Uncoupled HistoneStore — backward compatible ---")
uncoupled = HistoneStore(silent=True)
uncoupled.add_marker("test", strength=MarkerStrength.WEAK, tags=["test"])
result = uncoupled.retrieve_context(tags=["test"])
print(f" Uncoupled store: {len(result.markers)} markers (no ATP check)")
print("\n" + "=" * 60)
print("DONE — Cost-Gated Retrieval demonstrated successfully")
print("=" * 60)
except Exception as e:
print(f"\nError: {e}")
raise
if __name__ == "__main__":
main()