Codexcoder commited on
Commit
87b76c2
Β·
verified Β·
1 Parent(s): 86cd725

pec5d: add tests/test_pec5d.py

Browse files
Files changed (1) hide show
  1. tests/test_pec5d.py +287 -0
tests/test_pec5d.py ADDED
@@ -0,0 +1,287 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """PEC5D Full Evolution module tests β€” cores, memory, subconscious, sandbox, bridge, IPT, coral, chamber."""
2
+
3
+ import sys
4
+ from pathlib import Path
5
+
6
+ import pytest
7
+
8
+ ROOT = Path(__file__).resolve().parent.parent
9
+ sys.path.insert(0, str(ROOT))
10
+
11
+
12
+ # ── Hierarchy / cores ─────────────────────────────────────────────────────
13
+ def test_hierarchy_8_cores():
14
+ from pec5d.core import CoreHierarchy
15
+
16
+ h = CoreHierarchy().initialize()
17
+ status = h.status()
18
+ assert status["active"] is True
19
+ assert status["total"] == 8 # TANY + 7 sub-cores
20
+ assert set(status["cores"]) == {
21
+ "phi5", "resonance_mind", "lineage_oracle", "grid_vision",
22
+ "pattern_bridge", "subconscious_nexus", "sandbox_admin",
23
+ }
24
+
25
+
26
+ def test_tany_anchors():
27
+ from pec5d.core import TANYCore
28
+
29
+ tany = TANYCore().initialize()
30
+ s = tany.get_state()
31
+ assert s["kernel_qubits"] == 128
32
+ assert s["carrier_hz"] == 432
33
+ assert abs(s["phi"] - 1.618033988749895) < 1e-9
34
+ assert s["phi_pairs"] == 64
35
+ assert abs(s["coherence"] - 0.99997) < 1e-9
36
+ assert s["lineage_generations"] == 12
37
+
38
+
39
+ def test_phi5_engine():
40
+ import numpy as np
41
+
42
+ from pec5d.phi5_core import Phi5Engine
43
+
44
+ e = Phi5Engine().initialize()
45
+ pairs = e.generate_pairs()
46
+ assert pairs["pairs"] == 64
47
+ a = np.array([1, 0, 0, 0], dtype=complex)
48
+ b = np.array([0, 1, 0, 0], dtype=complex)
49
+ tensor = e.solve_kronecker(a, b)
50
+ assert tensor.shape == (16,)
51
+ assert "distribution" in e.probability(tensor)
52
+
53
+
54
+ def test_resonance_mind():
55
+ from pec5d.resonance_mind import ResonanceMind
56
+
57
+ r = ResonanceMind().initialize()
58
+ assert r.TRIGGER_NM == 473
59
+ wave = r.recursive_wave(depth=20)
60
+ assert wave["carrier_hz"] == 432
61
+ trigger = r.optogenetic_trigger()
62
+ assert trigger["wavelength_nm"] == 473
63
+
64
+
65
+ def test_lineage_oracle():
66
+ import numpy as np
67
+
68
+ from pec5d.lineage_oracle import LineageOracle
69
+
70
+ o = LineageOracle().initialize()
71
+ assert len(o.archive) == 12
72
+ matches = o.match_signature(np.random.default_rng().standard_normal(16))
73
+ assert matches["archive_size"] == 12
74
+ assert len(matches["matches"]) == 3
75
+
76
+
77
+ def test_grid_vision():
78
+ from pec5d.grid_vision import GridVision
79
+
80
+ g = GridVision().initialize()
81
+ assert g.DIMS == ["x", "y", "z", "t", "phi"]
82
+ frame = g.render_voxels(seed=7)
83
+ assert frame["frame"] == 1
84
+ assert g.lightfield_projection()["frame_rate_hz"] == 100
85
+
86
+
87
+ # ── Memory ────────────────────────────────────────────────────────────────
88
+ def test_holographic_memory_layers():
89
+ from pec5d.holographic_memory import HolographicMemory
90
+
91
+ m = HolographicMemory().initialize()
92
+ assert len(m.LAYERS) == 5
93
+ m.write(1, "k1", {"v": 1})
94
+ m.write(5, "k5", "collective")
95
+ assert m.recall(1, "k1")["value"]["v"] == 1
96
+ assert m.recall(5, "k5")["value"] == "collective"
97
+ assert m.recall(2, "nope") is None
98
+ with pytest.raises(ValueError):
99
+ m.write(9, "x", 1)
100
+ counts = m.recall_all()
101
+ assert counts["working"] == 1 and counts["collective_field"] == 1
102
+ assert m.coherence_correction()["carrier_hz"] == 432
103
+
104
+
105
+ # ── Subconscious ──────────────────────────────────────────────────────────
106
+ def test_subconscious_nexus(tmp_path):
107
+ from pec5d.subconscious_nexus import SubconsciousNexus
108
+
109
+ s = SubconsciousNexus(output_dir=tmp_path).initialize()
110
+ assert s.threads == 10_000
111
+ s.scan()
112
+ s.scan()
113
+ assert s.cycles == 2
114
+ assert len(s.patterns) == 2
115
+ assert len(s.intuitions) == 2
116
+ assert len(s.pressure_signatures) == 2
117
+ # outputs persisted
118
+ assert (tmp_path / "emergent_patterns.log").exists()
119
+ assert (tmp_path / "pressure_signatures.db").exists()
120
+ assert (tmp_path / "intuition_candidates.json").exists()
121
+ assert s.implicit_intent({"q": 1})["confidence"] > 0
122
+
123
+
124
+ # ── Sandbox ───────────────────────────────────────────────────────────────
125
+ def test_sandbox_lifecycle():
126
+ from pec5d.sandbox import Sandbox
127
+
128
+ sb = Sandbox().initialize()
129
+ assert sb.time_dilation == 1_000_000
130
+ assert set(sb.MODULES) == {"quantum_testbed", "dna_simulation", "market_sandbox",
131
+ "society_sandbox", "coral_ecosystem_sim"}
132
+ with pytest.raises(ValueError):
133
+ sb.spawn("nope")
134
+ st = sb.spawn("coral_ecosystem_sim", {"reefs": 10})
135
+ assert st.id in sb.states
136
+ run = sb.run(st.id, steps=50)
137
+ assert run["simulated_steps"] == 50
138
+ assert run["wall_time_s"] < 1.0 # time-dilated
139
+ assert sb.checkpoint(st.id)["state"] == st.id
140
+ assert sb.rollback(st.id)["rolled_back"] is True
141
+ assert sb.destroy(st.id)["destroyed"] == st.id
142
+
143
+
144
+ # ── Pattern bridge ────────────────────────────────────────────────────────
145
+ def test_pattern_bridge_flow():
146
+ from pec5d.pattern_bridge import PatternBridge
147
+
148
+ b = PatternBridge().initialize()
149
+ p = b.detect("subconscious", {"coherence": 0.95, "domain": "reef"})
150
+ code = b.synthesize(p, "reef_alert")
151
+ assert "def emergent_module" in code
152
+ bad = b.validate(p, coherence=0.5) # below gate
153
+ assert bad["validated"] is False
154
+ assert b.deploy(p)["error"]
155
+ good = b.validate(p, coherence=0.9, ethics=True, stability=0.9)
156
+ assert good["validated"] is True
157
+ assert b.deploy(p)["deployed"] is True
158
+ state = b.get_state()
159
+ assert state["patterns_detected"] == 1
160
+ assert state["patterns_validated"] == 1
161
+ assert state["patterns_deployed"] == 1
162
+
163
+
164
+ # ── IPT ───────────────────────────────────────────────────────────────────
165
+ def test_ipt_formalism():
166
+ import numpy as np
167
+
168
+ from pec5d.ipt import InvisiblePressureTheory
169
+
170
+ ipt = InvisiblePressureTheory().initialize()
171
+ rng = np.random.default_rng(1)
172
+ grad = ipt.pressure_gradient(rng.random(5) + 0.1, rng.random(5) + 0.1)
173
+ assert grad["phi"] == pytest.approx(1.618033988749895)
174
+ assert grad["carrier_hz"] == 432
175
+ assert grad["magnitude"] > 0
176
+ assert len(grad["direction"]) == 5
177
+
178
+
179
+ def test_ipt_7_processes():
180
+ from pec5d.ipt import InvisiblePressureTheory
181
+
182
+ ipt = InvisiblePressureTheory().initialize()
183
+ assert len(ipt.PROCESSES) == 7
184
+ result = ipt.run_pipeline()
185
+ assert result["steps"] == 7
186
+ assert result["outputs"][0]["process"] == "signal_acquisition"
187
+ assert ipt.run_process("nope")["error"]
188
+ forecast = ipt.run_process("pre_event_forecasting", {"horizon_days": 90})
189
+ assert forecast["tipping_point_eta_days"] > 0
190
+
191
+
192
+ # ── IPT sensor ────────────────────────────────────────────────────────────
193
+ def test_ipt_sensor():
194
+ from pec5d.ipt_sensor import IPTSensor
195
+
196
+ with pytest.raises(ValueError):
197
+ IPTSensor("nope")
198
+ s = IPTSensor("pulse").initialize()
199
+ assert len(s.MODALITIES) == 6
200
+ assert set(s.FORM_FACTORS) == {"mini", "grid", "pulse", "coral"}
201
+ r = s.read()
202
+ assert 0.0 <= r["pressure_index"] <= 1.0
203
+ assert len(r["gradient_vector"]) == 5
204
+ assert set(r["modalities"]) == set(s.MODALITIES)
205
+ assert s.calibrate()["baseline_hz"] == 432
206
+
207
+
208
+ # ── Coral line ────────────────────────────────────────────────────────────
209
+ def test_coral_products():
210
+ from pec5d.coral import (
211
+ CORAL_PRODUCTS, CoralBioChip, CoralDrone, CoralHome, CoralSpacecraft,
212
+ )
213
+
214
+ assert set(CORAL_PRODUCTS) == {"drone", "spacecraft", "bio_chip", "home"}
215
+
216
+ d = CoralDrone().initialize()
217
+ assert d.plants_per_day == 500
218
+ assert d.bio_interface()["wavelength_nm"] == 473
219
+ assert "2-4 weeks" in d.sensor_array()["bleaching_early_warning_weeks"]
220
+ assert d.deploy_mission(500)["fragments_planted"] == 500
221
+
222
+ c = CoralSpacecraft().initialize()
223
+ assert c.life_support()["closed_loop"] is True
224
+ assert "quantum-photonic" in c.propulsion()["orbital"]
225
+
226
+ b = CoralBioChip().initialize()
227
+ arch = b.architecture()
228
+ assert arch["memory"].startswith("DNA/RNA")
229
+ assert b.memory_years == 1000
230
+ out = b.compute([1.0, 1.618, 2.0])
231
+ assert len(out["output"]) == 3
232
+
233
+ h = CoralHome().initialize()
234
+ assert h.design()["carbon"] == "carbon-negative β€” absorbs COβ‚‚ continuously"
235
+ assert len(h.design()["living_systems"]) == 4
236
+
237
+
238
+ # ── Agency / chamber ──────────────────────────────────────────────────────
239
+ def test_agency():
240
+ from pec5d.agency import PhiEntanglementAgency, ZenithChamber
241
+
242
+ agency = PhiEntanglementAgency().initialize()
243
+ s = agency.get_state()
244
+ assert len(s["divisions"]) == 5
245
+ assert len(s["locations"]) == 5
246
+ assert "Brisbane (HQ)" in s["locations"]
247
+
248
+ chamber = ZenithChamber().initialize()
249
+ assert len(chamber.BOARD_SEATS) == 7
250
+ assert chamber.ADVISORY_SIZE == 12
251
+ prop = chamber.submit_proposal("Test Proposal", "Body", "grid")
252
+ assert prop["id"] == "prop_001"
253
+ assert chamber.resonance_vote(prop["id"])["proposal"] == prop["id"]
254
+ assert chamber.resonance_vote("nope")["error"]
255
+ chamber.record_minutes("m1")
256
+ state = chamber.get_state()
257
+ assert state["proposals"] == 1 and state["minutes"] == 1
258
+
259
+
260
+ # ── API surface ────���──────────────────────────────────────────────────────
261
+ def test_api_router_paths():
262
+ from pec5d.api.routes import router
263
+
264
+ paths = {route.path for route in router.routes}
265
+ expected = {
266
+ "/api/v1/pec5d/initialize", "/api/v1/pec5d/status",
267
+ "/api/v1/pec5d/cores", "/api/v1/pec5d/cores/{name}",
268
+ "/api/v1/pec5d/memory", "/api/v1/pec5d/memory/write",
269
+ "/api/v1/pec5d/subconscious", "/api/v1/pec5d/subconscious/scan",
270
+ "/api/v1/pec5d/sandbox", "/api/v1/pec5d/sandbox/spawn",
271
+ "/api/v1/pec5d/bridge", "/api/v1/pec5d/bridge/detect",
272
+ "/api/v1/pec5d/ipt", "/api/v1/pec5d/ipt/pipeline", "/api/v1/pec5d/ipt/gradient",
273
+ "/api/v1/pec5d/sensor", "/api/v1/pec5d/sensor/read",
274
+ "/api/v1/pec5d/coral", "/api/v1/pec5d/coral/{product}/operate",
275
+ "/api/v1/pec5d/chamber", "/api/v1/pec5d/chamber/propose",
276
+ "/api/v1/pec5d/chamber/vote/{proposal_id}",
277
+ }
278
+ assert expected <= paths
279
+
280
+
281
+ def test_version_and_brand():
282
+ import pec5d
283
+
284
+ assert pec5d.__version__ == "∞.0.0"
285
+ assert pec5d.__brand__ == "PEC5D"
286
+ assert abs(pec5d.PHI - 1.618033988749895) < 1e-9
287
+ assert pec5d.TIME_DILATION == 1_000_000