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— FSI_FELON v4.0"""
|
| 3 |
+
import sys, os, json, time, random
|
| 4 |
+
sys.path.insert(0, os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
|
| 5 |
+
|
| 6 |
+
from chimera.engine import ChimeraEngine
|
| 7 |
+
from chimera.organs import OrganType, ORGAN_DESCRIPTIONS
|
| 8 |
+
|
| 9 |
+
TASKS = [
|
| 10 |
+
"build a REST API with user authentication",
|
| 11 |
+
"remember the database schema for the user module",
|
| 12 |
+
"analyze this code for SQL injection vulnerabilities",
|
| 13 |
+
"plan the architecture for a distributed microservice system",
|
| 14 |
+
"imagine a world where code writes itself through pheromone trails",
|
| 15 |
+
"search for primary sources on the origin of the Creeper virus",
|
| 16 |
+
"generate a Python decorator that logs function calls",
|
| 17 |
+
"store the encryption key configuration for future reference",
|
| 18 |
+
"what if the nanobot swarm could communicate through dreams",
|
| 19 |
+
"check this payment gateway integration for security flaws",
|
| 20 |
+
"design a migration strategy from monolith to microservices",
|
| 21 |
+
"recall the JWT authentication implementation from last session",
|
| 22 |
+
"build a command-line tool for file encryption",
|
| 23 |
+
"simulate a network of 1000 nanobots processing tasks in parallel",
|
| 24 |
+
"audit the login system for race conditions",
|
| 25 |
+
"save the API endpoint configuration for the notification service",
|
| 26 |
+
"plan the implementation of a real-time collaborative editor",
|
| 27 |
+
"imagine an intelligence that emerges from decaying pheromone trails",
|
| 28 |
+
"search for evidence about the effectiveness of behavioral biometrics",
|
| 29 |
+
"generate unit tests for the payment processing module",
|
| 30 |
+
]
|
| 31 |
+
|
| 32 |
+
ROUTING_EXPECTATIONS = {
|
| 33 |
+
"build": ["prefrontal", "cerebellum", "spine"],
|
| 34 |
+
"remember": ["hippocampus"],
|
| 35 |
+
"analyze": ["spine", "prefrontal"],
|
| 36 |
+
"plan": ["prefrontal"],
|
| 37 |
+
"imagine": ["dream"],
|
| 38 |
+
"what if": ["dream", "prefrontal"],
|
| 39 |
+
"search": ["antennae", "spine"],
|
| 40 |
+
"generate": ["spine", "prefrontal"],
|
| 41 |
+
"store": ["hippocampus"],
|
| 42 |
+
"check": ["spine", "prefrontal"],
|
| 43 |
+
"design": ["prefrontal"],
|
| 44 |
+
"recall": ["hippocampus"],
|
| 45 |
+
"build": ["spine", "cerebellum"],
|
| 46 |
+
"simulate": ["dream", "prefrontal"],
|
| 47 |
+
"audit": ["spine", "prefrontal"],
|
| 48 |
+
"save": ["hippocampus"],
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
def determine_expected(input_text: str) -> list:
|
| 52 |
+
text_lower = input_text.lower()
|
| 53 |
+
for key, expected in ROUTING_EXPECTATIONS.items():
|
| 54 |
+
if text_lower.startswith(key):
|
| 55 |
+
return expected
|
| 56 |
+
return ["antennae"]
|
| 57 |
+
|
| 58 |
+
def run_benchmark():
|
| 59 |
+
print("╔══════════════════════════════════════════════════╗")
|
| 60 |
+
print("║ CHIMERA ENGINE — BENCHMARK v1.0 ║")
|
| 61 |
+
print("╚══════════════════════════════════════════════════╝")
|
| 62 |
+
|
| 63 |
+
print(f"\n Organs ({len(OrganType)}):")
|
| 64 |
+
for ot in OrganType:
|
| 65 |
+
print(f" • {ot.value:15s} — {ORGAN_DESCRIPTIONS[ot]}")
|
| 66 |
+
|
| 67 |
+
engine = ChimeraEngine(decay_rate=0.05)
|
| 68 |
+
print(f"\n Routing {len(TASKS)} tasks through Chimera Engine...")
|
| 69 |
+
print()
|
| 70 |
+
|
| 71 |
+
results = []
|
| 72 |
+
correct_routes = 0
|
| 73 |
+
organ_utilization = {ot.value: 0 for ot in OrganType}
|
| 74 |
+
|
| 75 |
+
for i, task_input in enumerate(TASKS):
|
| 76 |
+
t0 = time.time()
|
| 77 |
+
outcome = engine.route(task_input)
|
| 78 |
+
elapsed = time.time() - t0
|
| 79 |
+
|
| 80 |
+
routed_organ = outcome.get("routed_to", "unknown")
|
| 81 |
+
expected_organs = determine_expected(task_input)
|
| 82 |
+
is_correct = routed_organ in expected_organs
|
| 83 |
+
|
| 84 |
+
if is_correct:
|
| 85 |
+
correct_routes += 1
|
| 86 |
+
if routed_organ in organ_utilization:
|
| 87 |
+
organ_utilization[routed_organ] += 1
|
| 88 |
+
|
| 89 |
+
mark = "✅" if is_correct else "❌"
|
| 90 |
+
print(f" {mark} [{i+1:2d}/{len(TASKS)}] {routed_organ:15s} ← {task_input[:45]:45s} ({elapsed:.3f}s)")
|
| 91 |
+
results.append({
|
| 92 |
+
"task": task_input, "routed_to": routed_organ,
|
| 93 |
+
"expected": expected_organs, "correct": is_correct,
|
| 94 |
+
"time": round(elapsed, 4), "scores": outcome.get("all_scores", {}),
|
| 95 |
+
})
|
| 96 |
+
|
| 97 |
+
routing_accuracy = correct_routes / len(TASKS)
|
| 98 |
+
print(f"\n{'='*60}")
|
| 99 |
+
print(f" RESULTS")
|
| 100 |
+
print(f"{'='*60}")
|
| 101 |
+
print(f" Total tasks: {len(TASKS)}")
|
| 102 |
+
print(f" Correct routes: {correct_routes}")
|
| 103 |
+
print(f" Routing accuracy: {routing_accuracy:.1%}")
|
| 104 |
+
print(f" Organs functional: {sum(1 for s in engine.organ_stats().values() if s['tasks_processed'] > 0)}/{len(OrganType)}")
|
| 105 |
+
|
| 106 |
+
print(f"\n ── Organ Utilization ──")
|
| 107 |
+
for ot in OrganType:
|
| 108 |
+
count = organ_utilization[ot.value]
|
| 109 |
+
pct = count / len(TASKS) * 100
|
| 110 |
+
bar = "█" * int(pct / 2) + "░" * (50 - int(pct / 2))
|
| 111 |
+
print(f" {ot.value:15s} │{bar}│ {count:3d} tasks ({pct:.0f}%)")
|
| 112 |
+
|
| 113 |
+
print(f"\n ── Organ Stats ──")
|
| 114 |
+
for name, stats in engine.organ_stats().items():
|
| 115 |
+
sr = stats.get("success_rate", 0)
|
| 116 |
+
print(f" {name:15s} processed={stats['tasks_processed']} success_rate={sr:.0%} energy={stats['energy']}")
|
| 117 |
+
|
| 118 |
+
print(f"\n ── Pheromone Stats ──")
|
| 119 |
+
ps = engine.pheromones.stats()
|
| 120 |
+
print(f" Active trails: {ps['active_trails']}")
|
| 121 |
+
print(f" Total lays: {ps['total_lays']}")
|
| 122 |
+
print(f" Total reinforcements: {ps['total_reinforcements']}")
|
| 123 |
+
print(f" Decay rate: {ps['decay_rate']}")
|
| 124 |
+
|
| 125 |
+
verdict = "✅ PASS" if routing_accuracy >= 0.85 and sum(1 for s in engine.organ_stats().values() if s['tasks_processed'] > 0) >= 6 else "❌ NEEDS WORK"
|
| 126 |
+
print(f"\n VERDICT: {verdict}")
|
| 127 |
+
print(f" Target: >85% routing accuracy, 6/6 organs active")
|
| 128 |
+
print(f" Actual: {routing_accuracy:.1%} accuracy, {sum(1 for s in engine.organ_stats().values() if s['tasks_processed'] > 0)}/6 organs active")
|
| 129 |
+
|
| 130 |
+
report = {
|
| 131 |
+
"timestamp": time.strftime("%Y-%m-%dT%H:%M:%S"),
|
| 132 |
+
"benchmark": "Chimera Engine v1.0",
|
| 133 |
+
"total_tasks": len(TASKS),
|
| 134 |
+
"correct_routes": correct_routes,
|
| 135 |
+
"routing_accuracy": round(routing_accuracy, 3),
|
| 136 |
+
"organs_functional": sum(1 for s in engine.organ_stats().values() if s['tasks_processed'] > 0),
|
| 137 |
+
"organ_utilization": organ_utilization,
|
| 138 |
+
"organ_stats": engine.organ_stats(),
|
| 139 |
+
"pheromone_stats": ps,
|
| 140 |
+
"results": results,
|
| 141 |
+
"verdict": "PASS" if routing_accuracy >= 0.85 else "NEEDS_WORK",
|
| 142 |
+
}
|
| 143 |
+
with open("/tmp/fsi_felon/chimera/benchmark_results.json", "w") as f:
|
| 144 |
+
json.dump(report, f, indent=2)
|
| 145 |
+
print(f"\n Report saved: /tmp/fsi_felon/chimera/benchmark_results.json")
|
| 146 |
+
return routing_accuracy
|
| 147 |
+
|
| 148 |
+
if __name__ == "__main__":
|
| 149 |
+
run_benchmark()
|