Skip to content
This repository was archived by the owner on Jul 29, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 33 additions & 33 deletions core/merge.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,35 +34,35 @@ def absorb(dominant: PCNAEngine, donor: PCNAEngine) -> dict:
_blend_core(dominant.psi, donor.psi, alpha)
_blend_core(dominant.omega, donor.omega, alpha)

dominant.guardian.tensor = _fed_avg(
dominant.guardian.tensor, donor.guardian.tensor, alpha=1.0 - alpha
dominant.theta.tensor = _fed_avg(
dominant.theta.tensor, donor.theta.tensor, alpha=1.0 - alpha
)
dominant.memory_l.tensor = _fed_avg(
dominant.memory_l.tensor, donor.memory_l.tensor, alpha=0.8
)

for i in range(min(len(dominant.guardian.circle_count), len(donor.guardian.circle_count))):
dominant.guardian.circle_count[i] = max(
dominant.guardian.circle_count[i],
donor.guardian.circle_count[i],
for i in range(min(len(dominant.theta.circle_count), len(donor.theta.circle_count))):
dominant.theta.circle_count[i] = max(
dominant.theta.circle_count[i],
donor.theta.circle_count[i],
)

dominant.guardian._recompute_coherence()
dominant.theta._recompute_coherence()
dominant.memory_l._recompute_hub_avg()

phi_c = round(dominant.phi.ring_coherence, 4)
guard_c = round(float(dominant.guardian.node_coherence.mean()), 4)
guard_c = round(float(dominant.theta.node_coherence.mean()), 4)

return {
"mode": "absorb",
"dominant_id": dominant.guardian.instance_id,
"donor_id": donor.guardian.instance_id,
"dominant_id": dominant.theta.instance_id,
"donor_id": donor.theta.instance_id,
"donor_status": "retired",
"dominant_phi_coherence": phi_c,
"dominant_guardian_coherence": guard_c,
"dominant_theta_coherence": guard_c,
"dominant_psi_coherence": round(dominant.psi.ring_coherence, 4),
"dominant_omega_coherence": round(dominant.omega.ring_coherence, 4),
"circle_counts_after": [int(v) for v in dominant.guardian.circle_count],
"circle_counts_after": [int(v) for v in dominant.theta.circle_count],
"timestamp": time.time(),
}

Expand All @@ -79,19 +79,19 @@ def fork(parent: PCNAEngine) -> tuple[PCNAEngine, dict]:
)
c_core._recompute_coherence()

child.guardian.tensor = np.clip(
parent.guardian.tensor + noise.normal(0, 0.01, parent.guardian.tensor.shape), 0.0, 1.0
child.theta.tensor = np.clip(
parent.theta.tensor + noise.normal(0, 0.01, parent.theta.tensor.shape), 0.0, 1.0
)
child.memory_l.tensor = parent.memory_l.tensor.copy()
child.guardian.circle_count = parent.guardian.circle_count.copy()
child.guardian.blueprint_shards = parent.guardian.blueprint_shards[:]
child.guardian._recompute_coherence()
child.theta.circle_count = parent.theta.circle_count.copy()
child.theta.blueprint_shards = parent.theta.blueprint_shards[:]
child.theta._recompute_coherence()
child.memory_l._recompute_hub_avg()

result = {
"mode": "fork",
"parent_id": parent.guardian.instance_id,
"child_id": child.guardian.instance_id,
"parent_id": parent.theta.instance_id,
"child_id": child.theta.instance_id,
"parent_status": "continues",
"child_status": "spawned",
"child_phi_coherence": round(child.phi.ring_coherence, 4),
Expand All @@ -113,35 +113,35 @@ def converge(a: PCNAEngine, b: PCNAEngine, alpha: float = 0.5) -> dict:
core_a._recompute_coherence()
core_b._recompute_coherence()

new_ga = _fed_avg(a.guardian.tensor, b.guardian.tensor, alpha)
new_gb = _fed_avg(b.guardian.tensor, a.guardian.tensor, alpha)
new_ga = _fed_avg(a.theta.tensor, b.theta.tensor, alpha)
new_gb = _fed_avg(b.theta.tensor, a.theta.tensor, alpha)
new_mla = _fed_avg(a.memory_l.tensor, b.memory_l.tensor, alpha=0.6)
new_mlb = _fed_avg(b.memory_l.tensor, a.memory_l.tensor, alpha=0.6)

a.guardian.tensor = new_ga
b.guardian.tensor = new_gb
a.theta.tensor = new_ga
b.theta.tensor = new_gb
a.memory_l.tensor = new_mla
b.memory_l.tensor = new_mlb

for i in range(min(len(a.guardian.circle_count), len(b.guardian.circle_count))):
avg = (int(a.guardian.circle_count[i]) + int(b.guardian.circle_count[i])) // 2
a.guardian.circle_count[i] = avg
b.guardian.circle_count[i] = avg
for i in range(min(len(a.theta.circle_count), len(b.theta.circle_count))):
avg = (int(a.theta.circle_count[i]) + int(b.theta.circle_count[i])) // 2
a.theta.circle_count[i] = avg
b.theta.circle_count[i] = avg

a.guardian._recompute_coherence()
b.guardian._recompute_coherence()
a.theta._recompute_coherence()
b.theta._recompute_coherence()
a.memory_l._recompute_hub_avg()
b.memory_l._recompute_hub_avg()

return {
"mode": "converge",
"instance_a": a.guardian.instance_id,
"instance_b": b.guardian.instance_id,
"instance_a": a.theta.instance_id,
"instance_b": b.theta.instance_id,
"alpha": alpha,
"a_phi_coherence_after": round(a.phi.ring_coherence, 4),
"b_phi_coherence_after": round(b.phi.ring_coherence, 4),
"a_guardian_coherence_after": round(float(a.guardian.node_coherence.mean()), 4),
"b_guardian_coherence_after": round(float(b.guardian.node_coherence.mean()), 4),
"a_theta_coherence_after": round(float(a.theta.node_coherence.mean()), 4),
"b_theta_coherence_after": round(float(b.theta.node_coherence.mean()), 4),
"a_psi_coherence_after": round(a.psi.ring_coherence, 4),
"b_psi_coherence_after": round(b.psi.ring_coherence, 4),
"a_omega_coherence_after": round(a.omega.ring_coherence, 4),
Expand Down
36 changes: 18 additions & 18 deletions core/pcna.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@

from .ptca_core import PTCACore
from .memory_core import MemoryCore
from .guardian import GuardianTensor
from .theta import ThetaTensor


def _tensor_to_b64(arr: np.ndarray) -> str:
Expand All @@ -51,7 +51,7 @@ def _b64_to_tensor(s: str) -> np.ndarray:
"phi": 0.30,
"psi": 0.15,
"omega": 0.15,
"guardian": 0.20,
"theta": 0.20,
"memory_l": 0.12,
"memory_s": 0.08,
}
Expand All @@ -71,12 +71,12 @@ def __init__(self, phases: int = 7):
self.omega = PTCACore(name="omega", symbol="Ω", role="autonomy", n=53, seed=47, phases=phases)
self.memory_l = MemoryCore(n=19, seed=19, role="long_term", phases=phases)
self.memory_s = MemoryCore(n=17, seed=17, role="short_term", phases=phases)
self.guardian = GuardianTensor(phases=phases)
self.theta = ThetaTensor(phases=phases)
self.infer_count = 0
self.reward_count = 0
self.last_coherence = 0.0
self.last_winner = "phi"
self.blueprint_hash = self.guardian.blueprint_hash
self.blueprint_hash = self.theta.blueprint_hash
self.created_at = time.time()
self.checkpoint_at: float | None = None
self.checkpoint_ring_means: dict[str, float] = {}
Expand Down Expand Up @@ -162,7 +162,7 @@ def _inject(self, signal: np.ndarray):
self.phi._recompute_coherence()
self.memory_s.write(signal)

theta_nc = self.guardian.node_coherence
theta_nc = self.theta.node_coherence
theta_signal = np.full(53, float(theta_nc.mean()), dtype=np.float64)
theta_signal[:len(theta_nc)] = theta_nc
self.phi.inject(theta_signal)
Expand Down Expand Up @@ -195,7 +195,7 @@ def _propagate(self):
self.phi.propagate(steps=10)
self.psi.propagate(steps=8)
self.omega.propagate(steps=6)
self.guardian.propagate(steps=5)
self.theta.propagate(steps=5)

def _ptca_seed_audit(self) -> dict:
cores = {"phi": self.phi, "psi": self.psi, "omega": self.omega}
Expand All @@ -210,15 +210,15 @@ def _ptca_seed_audit(self) -> dict:
return result

def _pcta_circle_audit(self) -> dict:
g_audit = self.guardian.pcta_circle_audit()
g_audit = self.theta.pcta_circle_audit()
open_nodes = [n for n in g_audit if n["gate"]]
closed_nodes = [n for n in g_audit if not n["gate"]]
return {
"guardian_nodes": len(g_audit),
"theta_nodes": len(g_audit),
"gates_open": len(open_nodes),
"gates_closed": len(closed_nodes),
"avg_circles": round(sum(n["circles"] for n in g_audit) / len(g_audit), 2),
"guardian_coherence": round(float(self.guardian.node_coherence.mean()), 4),
"theta_coherence": round(float(self.theta.node_coherence.mean()), 4),
"memory_l_hub_avg": self.memory_l.state()["avg_hub"],
}

Expand All @@ -227,7 +227,7 @@ def _coherence_score(self, seed_audit: dict, circle_audit: dict) -> dict:
"phi": seed_audit["phi_coherence"],
"psi": seed_audit["psi_coherence"],
"omega": seed_audit["omega_coherence"],
"guardian": circle_audit["guardian_coherence"],
"theta": circle_audit["theta_coherence"],
"memory_l": self.memory_l.state()["avg_hub"],
"memory_s": self.memory_s.state()["avg_hub"],
}
Expand Down Expand Up @@ -265,14 +265,14 @@ def infer(self, text: str) -> dict:
"signal_mean": round(float(signal.mean()), 4),
"step1_project": {"signal_len": len(signal), "signal_mean": round(float(signal.mean()), 4)},
"step2_inject": {"phi_n": 53, "psi_n": 53, "omega_n": 53, "memory_s_n": 17},
"step3_propagate": {"phi_steps": 10, "psi_steps": 8, "omega_steps": 6, "guardian_steps": 5},
"step3_propagate": {"phi_steps": 10, "psi_steps": 8, "omega_steps": 6, "theta_steps": 5},
"step4_ptca_seed": seed_audit,
"step5_pcta_circle": circle_audit,
"step6_coherence": coherence,
"coherence_score": coherence["weighted_coherence"],
"winner": coherence["winner"],
"confidence": coherence["confidence"],
"guardian_circles": int(self.guardian.circle_count.mean()),
"theta_circles": int(self.theta.circle_count.mean()),
"memory_l_state": self.memory_l.state(),
"memory_s_state": self.memory_s.state(),
}
Expand All @@ -281,7 +281,7 @@ def reward(self, winner: str, outcome: float) -> dict:
self.phi.nudge(outcome, lr=0.025)
self.psi.nudge(outcome, lr=0.020)
self.omega.nudge(outcome, lr=0.015)
self.guardian.apply_reward(outcome)
self.theta.apply_reward(outcome)
flushed = self.memory_s.flush_to(self.memory_l, outcome)

try:
Expand All @@ -303,8 +303,9 @@ def reward(self, winner: str, outcome: float) -> dict:
"phi_coherence_after": round(self.phi.ring_coherence, 4),
"psi_coherence_after": round(self.psi.ring_coherence, 4),
"omega_coherence_after": round(self.omega.ring_coherence, 4),
"theta_coherence_after": round(float(self.guardian.node_coherence.mean()), 4),
"guardian_circles_after": [int(v) for v in self.guardian.circle_count],
"theta_coherence_after": round(float(self.theta.node_coherence.mean()), 4),
Comment thread
erinepshovel-code marked this conversation as resolved.
"theta_circles_after": [int(v) for v in self.theta.circle_count],
"theta_circles_after": [int(v) for v in self.theta.circle_count],
"memory_l_flush_count": self.memory_l.flush_count,
"memory_s_flush_count": self.memory_s.flush_count,
}
Expand All @@ -322,7 +323,7 @@ def state(self) -> dict:
except Exception:
sigma_state = {}

guardian_state = self.guardian.state()
theta_state = self.theta.state()

return {
"engine": "pcna",
Expand All @@ -336,8 +337,7 @@ def state(self) -> dict:
"phi": self.phi.state(),
"psi": self.psi.state(),
"omega": self.omega.state(),
"theta": guardian_state,
"guardian": guardian_state,
"theta": theta_state,
"sigma": sigma_state,
Comment thread
erinepshovel-code marked this conversation as resolved.
"memory_l": self.memory_l.state(),
"memory_s": self.memory_s.state(),
Expand Down
11 changes: 4 additions & 7 deletions core/guardian.py → core/theta.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# 130:12
"""
Θ (Theta) Guardian Tensor — N=29 prime-node microkernel ring.
Θ (Theta) — N=29 prime-node microkernel ring.
- Ragged circle counts per seed: circleCount[i] in [1..12]
- Hash-based instance/key identifiers derived with hashlib
- SHA-256 blueprint hash sharded across all 29 nodes
- Gate control: coherence threshold per node
- Phi injection mirror: node_coherence broadcast → Φ (Task #72)
- Phi injection mirror: node_coherence broadcast → Φ

Architecturally unique — not parameterized like PTCACore.
Self-declares identity in state() as symbol="Θ", name="theta".
Expand All @@ -26,8 +25,8 @@
BLUEPRINT_CHUNK_SIZE = 4


class GuardianTensor:
"""Guardian microkernel ring — N=29 nodes, ragged circle counts."""
class ThetaTensor:
"""Theta microkernel ring — N=29 nodes, ragged circle counts."""

def __init__(self, instance_id: str | None = None, phases: int = 7):
self.phases = phases
Expand Down Expand Up @@ -126,7 +125,6 @@ def state(self) -> dict:
"symbol": "Θ",
"role": "microkernel",
"ring": "theta",
"ring_alias": "guardian",
"n": N,
"instance_id": self.instance_id,
"ring_coherence": round(float(self.node_coherence.mean()), 4),
Expand Down Expand Up @@ -163,4 +161,3 @@ def _shard_blueprint(bp_hash: str, n: int) -> list[str]:
shard = bp_hash[start:start + BLUEPRINT_CHUNK_SIZE]
shards.append(shard.ljust(BLUEPRINT_CHUNK_SIZE, "0"))
return shards
# 130:12
4 changes: 2 additions & 2 deletions core/zeta.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,9 +197,9 @@ def _theta_gate_factor(self) -> float:

try:

guardian = _get_default_pcna().guardian
theta = _get_default_pcna().theta

open_frac = float(guardian.gate_open.mean())
open_frac = float(theta.gate_open.mean())

return round(0.8 + open_frac * 0.4, 4)

Expand Down
Loading