| import numpy as np |
| import time |
| import sys |
| import os |
| import random |
|
|
| |
| class Colors: |
| HEADER = '\033[95m' |
| BLUE = '\033[94m' |
| GREEN = '\033[92m' |
| WARNING = '\033[93m' |
| FAIL = '\033[91m' |
| ENDC = '\033[0m' |
| BOLD = '\033[1m' |
|
|
| def main(): |
| print(f"{Colors.HEADER}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{Colors.ENDC}") |
| print(f"{Colors.HEADER}β FUSION REACTOR SAFETY MONITOR - HYBRID AI SYSTEM β{Colors.ENDC}") |
| print(f"{Colors.HEADER}ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ{Colors.ENDC}") |
| print("Loading Neural Links...") |
| time.sleep(1) |
|
|
| |
| try: |
| q_data = np.load("qsvc_results/qsvc_results.npz") |
| q_preds = q_data['preds'] |
| y_test = q_data['targets'] |
| |
| |
| possible_paths = ['vG.0.1/qgan_data_optimized.npz', 'qgan_data_optimized.npz'] |
| data_path = next((p for p in possible_paths if os.path.exists(p)), None) |
| data = np.load(data_path) |
| |
| from sklearn.ensemble import RandomForestClassifier |
| rf = RandomForestClassifier(n_estimators=100, random_state=42) |
| rf.fit(data['X_train'], data['y_train']) |
| |
| |
| X_test_sub = data['X_test'][:len(q_preds)] |
| c_preds = rf.predict_proba(X_test_sub)[:, 1] |
|
|
| except Exception as e: |
| print(f"{Colors.FAIL}System Error: Could not load model history.{Colors.ENDC}") |
| print(e) |
| return |
|
|
| print(f"{Colors.GREEN}β System Online.{Colors.ENDC}\n") |
| print(f"{'SHOT ID':<10} | {'CLASSICAL GUARD':<20} | {'QUANTUM GUARD':<20} | {'STATUS'}") |
| print("-" * 75) |
|
|
| events_found = 0 |
| |
| for i in range(len(y_test)): |
| c_score = c_preds[i] |
| q_score = q_preds[i] |
| is_disruption = y_test[i] == 1 |
| |
| |
| c_status = f"{c_score:.2f} (SAFE)" if c_score < 0.5 else f"{c_score:.2f} {Colors.FAIL}(WARN){Colors.ENDC}" |
| q_status = f"{q_score:.2f} (SAFE)" if q_score < 0.5 else f"{q_score:.2f} {Colors.FAIL}(WARN){Colors.ENDC}" |
| |
| final_msg = "" |
| delay = 0.05 |
| |
| |
| |
| |
| if (c_score < 0.5 and q_score < 0.5): |
| final_msg = f"{Colors.GREEN}STABLE{Colors.ENDC}" |
| delay = 0.02 |
| |
| |
| elif (c_score > 0.5 and q_score > 0.5): |
| final_msg = f"{Colors.WARNING}MITIGATED{Colors.ENDC}" |
| delay = 0.1 |
|
|
| |
| elif (c_score < 0.5 and q_score > 0.5 and is_disruption): |
| events_found += 1 |
| print("-" * 75) |
| print(f"{Colors.BOLD}>>> ANOMALY DETECTED IN SHOT {i} <<<{Colors.ENDC}") |
| print(f" Classical AI: {Colors.GREEN}SAFE ({c_score:.2f}){Colors.ENDC} --> β FALSE NEGATIVE") |
| print(f" Quantum AI: {Colors.FAIL}DANGER ({q_score:.2f}){Colors.ENDC} --> β
TRUE POSITIVE") |
| print(f" ACTION: {Colors.WARNING}[TRIGGERING EMERGENCY SHUTDOWN]{Colors.ENDC}") |
| print("-" * 75) |
| time.sleep(1.5) |
| continue |
|
|
| |
| else: |
| final_msg = f"{Colors.BLUE}ANALYZING{Colors.ENDC}" |
| delay = 0.05 |
|
|
| |
| if delay == 0.02 and i % 10 != 0: |
| continue |
| |
| print(f"{i:<10} | {c_status:<29} | {q_status:<29} | {final_msg}") |
| time.sleep(delay) |
|
|
| if events_found >= 5: |
| print(f"\n{Colors.BOLD}Simulation Limit Reached. 5 Quantum Saves Demonstrated.{Colors.ENDC}") |
| break |
|
|
| if __name__ == "__main__": |
| main() |