Download tests/test_pec5d.py from Codexcoder/pec5d-module: direct link, hf CLI and curl.
- Browser
- Download file 11.3 kB
-
https://huggingface.co/datasets/Codexcoder/pec5d-module/resolve/main/tests/test_pec5d.py
- Command line
-
hf download hf://datasets/Codexcoder/pec5d-module/tests/test_pec5d.py
-
curl -L -o test_pec5d.py https://huggingface.co/datasets/Codexcoder/pec5d-module/resolve/main/tests/test_pec5d.py
11.3 kB
| """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 | |