File size: 11,251 Bytes
87b76c2 | 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 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 | """PEC5D Full Evolution module tests β cores, memory, subconscious, sandbox, bridge, IPT, coral, chamber."""
import sys
from pathlib import Path
import pytest
ROOT = Path(__file__).resolve().parent.parent
sys.path.insert(0, str(ROOT))
# ββ Hierarchy / cores βββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_hierarchy_8_cores():
from pec5d.core import CoreHierarchy
h = CoreHierarchy().initialize()
status = h.status()
assert status["active"] is True
assert status["total"] == 8 # TANY + 7 sub-cores
assert set(status["cores"]) == {
"phi5", "resonance_mind", "lineage_oracle", "grid_vision",
"pattern_bridge", "subconscious_nexus", "sandbox_admin",
}
def test_tany_anchors():
from pec5d.core import TANYCore
tany = TANYCore().initialize()
s = tany.get_state()
assert s["kernel_qubits"] == 128
assert s["carrier_hz"] == 432
assert abs(s["phi"] - 1.618033988749895) < 1e-9
assert s["phi_pairs"] == 64
assert abs(s["coherence"] - 0.99997) < 1e-9
assert s["lineage_generations"] == 12
def test_phi5_engine():
import numpy as np
from pec5d.phi5_core import Phi5Engine
e = Phi5Engine().initialize()
pairs = e.generate_pairs()
assert pairs["pairs"] == 64
a = np.array([1, 0, 0, 0], dtype=complex)
b = np.array([0, 1, 0, 0], dtype=complex)
tensor = e.solve_kronecker(a, b)
assert tensor.shape == (16,)
assert "distribution" in e.probability(tensor)
def test_resonance_mind():
from pec5d.resonance_mind import ResonanceMind
r = ResonanceMind().initialize()
assert r.TRIGGER_NM == 473
wave = r.recursive_wave(depth=20)
assert wave["carrier_hz"] == 432
trigger = r.optogenetic_trigger()
assert trigger["wavelength_nm"] == 473
def test_lineage_oracle():
import numpy as np
from pec5d.lineage_oracle import LineageOracle
o = LineageOracle().initialize()
assert len(o.archive) == 12
matches = o.match_signature(np.random.default_rng().standard_normal(16))
assert matches["archive_size"] == 12
assert len(matches["matches"]) == 3
def test_grid_vision():
from pec5d.grid_vision import GridVision
g = GridVision().initialize()
assert g.DIMS == ["x", "y", "z", "t", "phi"]
frame = g.render_voxels(seed=7)
assert frame["frame"] == 1
assert g.lightfield_projection()["frame_rate_hz"] == 100
# ββ Memory ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_holographic_memory_layers():
from pec5d.holographic_memory import HolographicMemory
m = HolographicMemory().initialize()
assert len(m.LAYERS) == 5
m.write(1, "k1", {"v": 1})
m.write(5, "k5", "collective")
assert m.recall(1, "k1")["value"]["v"] == 1
assert m.recall(5, "k5")["value"] == "collective"
assert m.recall(2, "nope") is None
with pytest.raises(ValueError):
m.write(9, "x", 1)
counts = m.recall_all()
assert counts["working"] == 1 and counts["collective_field"] == 1
assert m.coherence_correction()["carrier_hz"] == 432
# ββ Subconscious ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_subconscious_nexus(tmp_path):
from pec5d.subconscious_nexus import SubconsciousNexus
s = SubconsciousNexus(output_dir=tmp_path).initialize()
assert s.threads == 10_000
s.scan()
s.scan()
assert s.cycles == 2
assert len(s.patterns) == 2
assert len(s.intuitions) == 2
assert len(s.pressure_signatures) == 2
# outputs persisted
assert (tmp_path / "emergent_patterns.log").exists()
assert (tmp_path / "pressure_signatures.db").exists()
assert (tmp_path / "intuition_candidates.json").exists()
assert s.implicit_intent({"q": 1})["confidence"] > 0
# ββ Sandbox βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_sandbox_lifecycle():
from pec5d.sandbox import Sandbox
sb = Sandbox().initialize()
assert sb.time_dilation == 1_000_000
assert set(sb.MODULES) == {"quantum_testbed", "dna_simulation", "market_sandbox",
"society_sandbox", "coral_ecosystem_sim"}
with pytest.raises(ValueError):
sb.spawn("nope")
st = sb.spawn("coral_ecosystem_sim", {"reefs": 10})
assert st.id in sb.states
run = sb.run(st.id, steps=50)
assert run["simulated_steps"] == 50
assert run["wall_time_s"] < 1.0 # time-dilated
assert sb.checkpoint(st.id)["state"] == st.id
assert sb.rollback(st.id)["rolled_back"] is True
assert sb.destroy(st.id)["destroyed"] == st.id
# ββ Pattern bridge ββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_pattern_bridge_flow():
from pec5d.pattern_bridge import PatternBridge
b = PatternBridge().initialize()
p = b.detect("subconscious", {"coherence": 0.95, "domain": "reef"})
code = b.synthesize(p, "reef_alert")
assert "def emergent_module" in code
bad = b.validate(p, coherence=0.5) # below gate
assert bad["validated"] is False
assert b.deploy(p)["error"]
good = b.validate(p, coherence=0.9, ethics=True, stability=0.9)
assert good["validated"] is True
assert b.deploy(p)["deployed"] is True
state = b.get_state()
assert state["patterns_detected"] == 1
assert state["patterns_validated"] == 1
assert state["patterns_deployed"] == 1
# ββ IPT βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_ipt_formalism():
import numpy as np
from pec5d.ipt import InvisiblePressureTheory
ipt = InvisiblePressureTheory().initialize()
rng = np.random.default_rng(1)
grad = ipt.pressure_gradient(rng.random(5) + 0.1, rng.random(5) + 0.1)
assert grad["phi"] == pytest.approx(1.618033988749895)
assert grad["carrier_hz"] == 432
assert grad["magnitude"] > 0
assert len(grad["direction"]) == 5
def test_ipt_7_processes():
from pec5d.ipt import InvisiblePressureTheory
ipt = InvisiblePressureTheory().initialize()
assert len(ipt.PROCESSES) == 7
result = ipt.run_pipeline()
assert result["steps"] == 7
assert result["outputs"][0]["process"] == "signal_acquisition"
assert ipt.run_process("nope")["error"]
forecast = ipt.run_process("pre_event_forecasting", {"horizon_days": 90})
assert forecast["tipping_point_eta_days"] > 0
# ββ IPT sensor ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_ipt_sensor():
from pec5d.ipt_sensor import IPTSensor
with pytest.raises(ValueError):
IPTSensor("nope")
s = IPTSensor("pulse").initialize()
assert len(s.MODALITIES) == 6
assert set(s.FORM_FACTORS) == {"mini", "grid", "pulse", "coral"}
r = s.read()
assert 0.0 <= r["pressure_index"] <= 1.0
assert len(r["gradient_vector"]) == 5
assert set(r["modalities"]) == set(s.MODALITIES)
assert s.calibrate()["baseline_hz"] == 432
# ββ Coral line ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_coral_products():
from pec5d.coral import (
CORAL_PRODUCTS, CoralBioChip, CoralDrone, CoralHome, CoralSpacecraft,
)
assert set(CORAL_PRODUCTS) == {"drone", "spacecraft", "bio_chip", "home"}
d = CoralDrone().initialize()
assert d.plants_per_day == 500
assert d.bio_interface()["wavelength_nm"] == 473
assert "2-4 weeks" in d.sensor_array()["bleaching_early_warning_weeks"]
assert d.deploy_mission(500)["fragments_planted"] == 500
c = CoralSpacecraft().initialize()
assert c.life_support()["closed_loop"] is True
assert "quantum-photonic" in c.propulsion()["orbital"]
b = CoralBioChip().initialize()
arch = b.architecture()
assert arch["memory"].startswith("DNA/RNA")
assert b.memory_years == 1000
out = b.compute([1.0, 1.618, 2.0])
assert len(out["output"]) == 3
h = CoralHome().initialize()
assert h.design()["carbon"] == "carbon-negative β absorbs COβ continuously"
assert len(h.design()["living_systems"]) == 4
# ββ Agency / chamber ββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_agency():
from pec5d.agency import PhiEntanglementAgency, ZenithChamber
agency = PhiEntanglementAgency().initialize()
s = agency.get_state()
assert len(s["divisions"]) == 5
assert len(s["locations"]) == 5
assert "Brisbane (HQ)" in s["locations"]
chamber = ZenithChamber().initialize()
assert len(chamber.BOARD_SEATS) == 7
assert chamber.ADVISORY_SIZE == 12
prop = chamber.submit_proposal("Test Proposal", "Body", "grid")
assert prop["id"] == "prop_001"
assert chamber.resonance_vote(prop["id"])["proposal"] == prop["id"]
assert chamber.resonance_vote("nope")["error"]
chamber.record_minutes("m1")
state = chamber.get_state()
assert state["proposals"] == 1 and state["minutes"] == 1
# ββ API surface βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
def test_api_router_paths():
from pec5d.api.routes import router
paths = {route.path for route in router.routes}
expected = {
"/api/v1/pec5d/initialize", "/api/v1/pec5d/status",
"/api/v1/pec5d/cores", "/api/v1/pec5d/cores/{name}",
"/api/v1/pec5d/memory", "/api/v1/pec5d/memory/write",
"/api/v1/pec5d/subconscious", "/api/v1/pec5d/subconscious/scan",
"/api/v1/pec5d/sandbox", "/api/v1/pec5d/sandbox/spawn",
"/api/v1/pec5d/bridge", "/api/v1/pec5d/bridge/detect",
"/api/v1/pec5d/ipt", "/api/v1/pec5d/ipt/pipeline", "/api/v1/pec5d/ipt/gradient",
"/api/v1/pec5d/sensor", "/api/v1/pec5d/sensor/read",
"/api/v1/pec5d/coral", "/api/v1/pec5d/coral/{product}/operate",
"/api/v1/pec5d/chamber", "/api/v1/pec5d/chamber/propose",
"/api/v1/pec5d/chamber/vote/{proposal_id}",
}
assert expected <= paths
def test_version_and_brand():
import pec5d
assert pec5d.__version__ == "β.0.0"
assert pec5d.__brand__ == "PEC5D"
assert abs(pec5d.PHI - 1.618033988749895) < 1e-9
assert pec5d.TIME_DILATION == 1_000_000
|