File size: 2,824 Bytes
07fb183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""Fail-closed Wave-4 CUDA capability/learning-semantics gate."""

from __future__ import annotations

from pathlib import Path

from src.acceleration.cuda import CUDABackend
from src.acceleration.cuda.plasticity.contracts import (
    LEARNING_CONTRACT_ID,
    LEARNING_CONTRACT_STATUS,
    PLASTICITY_SEMANTICS,
)

ROOT = Path(__file__).resolve().parents[1]
LEARNING_CONTRACT = (
    ROOT / "docs" / "02-architecture" / "MHRN_LEARNING_SYNAPSE_CONTRACT.md"
)


def failures() -> list[str]:
    problems: list[str] = []
    caps = CUDABackend().capabilities()

    expected = {
        "supports_recurrent": True,
        "supports_plasticity": True,
        "supports_pan_hyperstate": False,
        "supports_structural_plasticity": False,
        "max_neurons": 4096,
        "max_ticks": 2000,
        "max_edges": 65536,
        "deterministic": True,
        "plasticity_semantics": "NON_CANONICAL_DRAFT",
        "execution_mode": "BOUNDED_REPLAY_REFERENCE",
    }
    actual = caps.to_mapping()
    for key, value in expected.items():
        if actual.get(key) != value:
            problems.append(
                f"CUDA capability mismatch: {key}={actual.get(key)!r}, expected {value!r}"
            )

    if PLASTICITY_SEMANTICS != "NON_CANONICAL_DRAFT":
        problems.append(
            "plasticity semantics must remain NON_CANONICAL_DRAFT until contract alignment"
        )
    if LEARNING_CONTRACT_ID != "mhrn-learning-synapse-v1":
        problems.append(f"unexpected learning contract id: {LEARNING_CONTRACT_ID}")
    if LEARNING_CONTRACT_STATUS != "ALIGNMENT_PENDING":
        problems.append(
            "learning contract status must remain ALIGNMENT_PENDING in Wave 4"
        )

    if not LEARNING_CONTRACT.is_file():
        problems.append("canonical learning/synapse contract document is missing")
    else:
        text = LEARNING_CONTRACT.read_text(encoding="utf-8")
        required = (
            "canonical design contract; backend implementation alignment pending",
            "learning_contract_id = mhrn-learning-synapse-v1",
            "CPU and CUDA must not implement two merely similar learning rules",
        )
        for phrase in required:
            if phrase not in text:
                problems.append(
                    "learning contract document no longer contains required boundary: "
                    + phrase
                )

    return problems


def main() -> int:
    problems = failures()
    if problems:
        raise SystemExit(
            "Wave-4 CUDA semantic boundary failed:\n" + "\n".join(problems)
        )
    print("Wave-4 CUDA semantic boundary: PASS")
    print("plasticity_semantics=NON_CANONICAL_DRAFT")
    print("learning_contract_status=ALIGNMENT_PENDING")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())