Spaces:
Sleeping
Sleeping
Update 1014ecaa4_scimind2_communicator.py
Browse files
1014ecaa4_scimind2_communicator.py
CHANGED
|
@@ -801,66 +801,6 @@ def main(stdscr):
|
|
| 801 |
interface.text_comm.messages.extend(history)
|
| 802 |
interface.run()
|
| 803 |
|
| 804 |
-
# ==============================================================================
|
| 805 |
-
# PERFORMANCE TUNER (REAL-WORLD SIMULATION)
|
| 806 |
-
# ==============================================================================
|
| 807 |
-
class AutoPerformanceTuner:
|
| 808 |
-
"""
|
| 809 |
-
Führt eine echte Simulation der Physik-Engine durch, um die Tick-Rate zu bestimmen.
|
| 810 |
-
"""
|
| 811 |
-
@staticmethod
|
| 812 |
-
def tune(N=40):
|
| 813 |
-
print(f"[INIT] Benchmarking Physics Core (N={N})...")
|
| 814 |
-
|
| 815 |
-
try:
|
| 816 |
-
# 1. Instanziieren der ECHTEN Physik-Engine
|
| 817 |
-
# Wir nutzen exakt die Klasse, die später läuft.
|
| 818 |
-
test_comm = SciMindCommunicator(N=N)
|
| 819 |
-
|
| 820 |
-
# 2. Synthetische Daten vorbereiten
|
| 821 |
-
# Rauschen wie im echten Betrieb
|
| 822 |
-
dummy_noise = torch.rand(N, N, dtype=torch.float32)
|
| 823 |
-
# Text-Feld (Braid) simulieren (wir tun so, als wäre Text da)
|
| 824 |
-
dummy_braid = torch.zeros(N, N, dtype=torch.float32)
|
| 825 |
-
|
| 826 |
-
# 3. Warm-Up (JIT Compiler & Caches aufwecken)
|
| 827 |
-
for _ in range(5):
|
| 828 |
-
test_comm.step(dummy_noise, dummy_braid, ntp_offset=0.0)
|
| 829 |
-
|
| 830 |
-
# 4. Messung (30 Frames simulieren)
|
| 831 |
-
iterations = 30
|
| 832 |
-
t_start = time.time()
|
| 833 |
-
|
| 834 |
-
for _ in range(iterations):
|
| 835 |
-
# Der exakte Aufruf, der auch in app.py passiert
|
| 836 |
-
test_comm.step(dummy_noise, dummy_braid, ntp_offset=0.001)
|
| 837 |
-
|
| 838 |
-
t_end = time.time()
|
| 839 |
-
avg_time_per_tick = (t_end - t_start) / iterations
|
| 840 |
-
|
| 841 |
-
print(f"[PERF] Average Tick Calculation Time: {avg_time_per_tick*1000:.2f} ms")
|
| 842 |
-
|
| 843 |
-
# 5. Berechnung des Delays (Die 50% Regel)
|
| 844 |
-
# Wir wollen, dass der Server maximal 50% der Zeit rechnet.
|
| 845 |
-
# Also muss Pause >= Rechenzeit sein.
|
| 846 |
-
|
| 847 |
-
# Sicherheitsfaktor 1.2 für Overhead (JSON Serialisierung, Websocket Netzwerk)
|
| 848 |
-
recommended_delay = avg_time_per_tick * 1.5
|
| 849 |
-
|
| 850 |
-
# Clamping (Grenzen setzen)
|
| 851 |
-
# Nicht schneller als 30 FPS (0.033s), um Browser nicht zu überhitzen
|
| 852 |
-
# Nicht langsamer als 2 FPS (0.5s), sonst sieht es kaputt aus
|
| 853 |
-
final_delay = max(0.033, min(recommended_delay, 0.5))
|
| 854 |
-
|
| 855 |
-
fps = 1.0 / final_delay
|
| 856 |
-
print(f"[PERF] Setting Tick Delay to {final_delay:.4f}s (~{fps:.1f} FPS) to manage CPU load.")
|
| 857 |
-
|
| 858 |
-
return final_delay
|
| 859 |
-
|
| 860 |
-
except Exception as e:
|
| 861 |
-
print(f"[PERF] Benchmark crash ({e}). Fallback to 10 Hz.")
|
| 862 |
-
return 0.10
|
| 863 |
-
|
| 864 |
if __name__ == "__main__":
|
| 865 |
try:
|
| 866 |
curses.wrapper(main)
|
|
|
|
| 801 |
interface.text_comm.messages.extend(history)
|
| 802 |
interface.run()
|
| 803 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 804 |
if __name__ == "__main__":
|
| 805 |
try:
|
| 806 |
curses.wrapper(main)
|