Files
2125_GCE/stress_test_10k_nuclear.py
T

533 lines
21 KiB
Python
Raw Normal View History

2026-07-09 12:54:44 -04:00
#!/usr/bin/env python3
"""10,000 Parallel Instance Extreme Stress Test with 100+ Program Variants
Generates 100+ unique XIC program variations covering:
- Deep control flow (IF/MATCH/LOOP combinations)
- Aggressive guardrail triggers
- Symbolic execution under stress
- Mixed workloads with varying glyph contexts
- Resource-intensive operations
- Predicate evaluation at scale
- Chain scheduling across hundreds of branches
Executes 10,000 parallel instances for 10 minutes, collecting:
- Execution count per program variant
- Guardrail trigger events
- Error rates
- VRAM usage peaks
- Throughput metrics
"""
import json
import os
import time
import random
import threading
import concurrent.futures
import psutil
import traceback
from datetime import datetime
from pathlib import Path
from typing import Dict, List, Any
# Configuration
SUPERDAVE_ROOT = Path(__file__).parent
PROGRAMS_DIR = SUPERDAVE_ROOT / "programs"
VARIANTS = 120 # 100+ unique program variants
INSTANCES = 10000
DURATION_SECS = 600 # 10 minutes
MAX_WORKERS = 1000 # Thread pool workers (OS manages scheduling)
# Metrics collection
metrics_lock = threading.Lock()
metrics = {
"total_executions": 0,
"successful_executions": 0,
"failed_executions": 0,
"guardrail_triggers": 0,
"variant_counters": {},
"vram_peaks": [],
"error_log": [],
"start_time": time.time(),
"end_time": None,
}
def generate_program_variants() -> List[str]:
"""Generate 100+ unique XIC program variants."""
variants = []
# Variant group 1: Pure IF branching with varying thresholds
for i in range(15):
threshold = 0.3 + (i * 0.04) # 0.3 to 0.9
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0, "branch_a": 5, "branch_b": 10, "end": 13},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_CONTEXT", "args": ["variant", f"if_threshold_{threshold:.2f}"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://variant_{i}_a"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://variant_{i}_b"]},
{"op": "RUN_PROMPT", "args": [f"Analyze variant {i} with threshold {threshold:.2f}"]},
{"op": "IF", "args": [f"fused.global_resonance_score > {threshold}", "branch_a", "branch_b"]},
{"op": "CHAIN", "args": ["branch_a"]},
{"op": "LOG", "args": [f"Branch A for variant {i}"]},
{"op": "RUN_PROMPT", "args": ["Deep analysis path A"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["branch_b"]},
{"op": "LOG", "args": [f"Branch B for variant {i}"]},
{"op": "RUN_PROMPT", "args": ["Alternative path B"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["IF variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_if_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 2: Aggressive LOOP with varying max_iter
for i in range(15):
max_iter = 3 + (i % 8) # 3-10 iterations
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0, "loop_body": 7, "end": 12},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_PARAM", "args": ["max_loop_iterations", max_iter]},
{"op": "SET_CONTEXT", "args": ["variant", f"loop_iter_{max_iter}"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://loop_{i}"]},
{"op": "LOG", "args": [f"Starting LOOP variant {i} with max_iter={max_iter}"]},
{"op": "LOOP", "args": [f"fused.global_resonance_score > 0.{5 + (i%4)}", "loop_body", max_iter]},
{"op": "CHAIN", "args": ["loop_body"]},
{"op": "RUN_PROMPT", "args": [f"Iterative refinement cycle {i}"]},
{"op": "GET_GLYPH_RESONANCE", "args": [f"glyph://loop_{i}", "global"]},
{"op": "LOG", "args": ["Loop iteration done"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["LOOP variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_loop_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 3: MATCH with multiple patterns
for i in range(15):
patterns = [f"glyph://pattern_{j}" for j in range(i % 5 + 1)]
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0, "match_true": 6, "end": 10},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_CONTEXT", "args": ["variant", f"match_pattern_{i}"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://match_{i}"]},
{"op": "RUN_PROMPT", "args": [f"Setup MATCH variant {i}"]},
{"op": "MATCH", "args": ["fused.glyph_ids", patterns[0], "match_true"]},
{"op": "CHAIN", "args": ["match_true"]},
{"op": "LOG", "args": ["Pattern matched"]},
{"op": "RUN_PROMPT", "args": ["Post-match analysis"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["MATCH variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_match_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 4: Nested control flow (IF inside LOOP)
for i in range(15):
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {
"main": 0, "loop_body": 8, "if_true": 12, "if_false": 15, "end": 18
},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_PARAM", "args": ["max_loop_iterations", 4]},
{"op": "SET_CONTEXT", "args": ["variant", f"nested_{i}"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://nested_{i}"]},
{"op": "LOOP", "args": ["fused.global_resonance_score > 0.5", "loop_body", 4]},
{"op": "CHAIN", "args": ["loop_body"]},
{"op": "RUN_PROMPT", "args": [f"Nested variant {i} cycle"]},
{"op": "IF", "args": ["fused.glyph_count > 0", "if_true", "if_false"]},
{"op": "CHAIN", "args": ["if_true"]},
{"op": "LOG", "args": ["Nested IF true"]},
{"op": "RUN_PROMPT", "args": ["Nested true path"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["if_false"]},
{"op": "LOG", "args": ["Nested IF false"]},
{"op": "RUN_PROMPT", "args": ["Nested false path"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["Nested variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_nested_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 5: Multi-chain complex control flow
for i in range(15):
chain_count = 3 + (i % 4)
chains = {f"chain_{j}": 5 + (j * 4) for j in range(chain_count)}
chains["end"] = 100
instructions = [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_CONTEXT", "args": ["variant", f"multichain_{i}"]},
]
for j in range(chain_count):
instructions.append({"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://chain_{j}_{i}"]})
instructions.extend([
{"op": "RUN_PROMPT", "args": [f"Multichain variant {i} setup"]},
])
for j in range(chain_count):
instructions.extend([
{"op": "CHAIN", "args": [f"chain_{j}"]},
{"op": "LOG", "args": [f"Chain {j} execution"]},
{"op": "RUN_PROMPT", "args": [f"Chain {j} processing"]},
])
instructions.append({"op": "CHAIN", "args": ["end"]})
instructions.append({"op": "LOG", "args": ["Multichain complete"]})
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": chains,
"instructions": instructions,
}
path = PROGRAMS_DIR / f"stress_multichain_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 6: Heavy guardrail stress (intentionally violate limits)
for i in range(15):
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0, "loop_a": 7, "end": 13},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_PARAM", "args": ["max_loop_iterations", 2]},
{"op": "SET_PARAM", "args": ["max_total_steps", 50 + i]},
{"op": "SET_CONTEXT", "args": ["variant", f"guardrail_stress_{i}"]},
{"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://guardrail_{i}"]},
{"op": "LOOP", "args": ["fused.global_resonance_score > 0.4", "loop_a", 10]},
{"op": "CHAIN", "args": ["loop_a"]},
{"op": "RUN_PROMPT", "args": ["Heavy iteration under guardrail stress"]},
{"op": "RUN_PROMPT", "args": ["Secondary prompt in loop"]},
{"op": "GET_GLYPH_RESONANCE", "args": [f"glyph://guardrail_{i}", "global"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["Guardrail stress variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_guardrail_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 7: Complex predicate evaluation
for i in range(15):
predicates = [
"fused.global_resonance_score > 0.7",
"fused.glyph_count >= 1",
"fused.global_resonance_score > 0.5 and fused.glyph_count > 0",
"dominant_contains('glyph://test')",
"not (fused.global_resonance_score < 0.3)",
]
pred = predicates[i % len(predicates)]
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0, "true_b": 5, "false_b": 9, "end": 12},
"instructions": [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_CONTEXT", "args": ["variant", f"predicate_{i}"]},
{"op": "RUN_PROMPT", "args": [f"Setup for predicate test {i}"]},
{"op": "IF", "args": [pred, "true_b", "false_b"]},
{"op": "CHAIN", "args": ["true_b"]},
{"op": "LOG", "args": [f"Predicate {i} evaluated true"]},
{"op": "RUN_PROMPT", "args": ["True path execution"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["false_b"]},
{"op": "LOG", "args": [f"Predicate {i} evaluated false"]},
{"op": "RUN_PROMPT", "args": ["False path execution"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "CHAIN", "args": ["end"]},
{"op": "LOG", "args": ["Predicate variant complete"]},
],
}
path = PROGRAMS_DIR / f"stress_predicate_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
# Variant group 8: Memory-intensive glyph stacking
for i in range(10):
glyph_count = 5 + (i * 2)
instructions = [
{"op": "SET_MODE", "args": ["symbolic"]},
{"op": "SET_CONTEXT", "args": ["variant", f"glyph_stack_{i}_{glyph_count}"]},
]
for j in range(glyph_count):
instructions.append({"op": "PUSH_GLYPH_CONTEXT", "args": [f"glyph://stack_{i}_{j}"]})
instructions.extend([
{"op": "RUN_PROMPT", "args": [f"Analyze {glyph_count} glyphs in variant {i}"]},
{"op": "LOG", "args": [f"Glyph stack {i} complete with {glyph_count} glyphs"]},
])
prog = {
"magic": "GXIC1",
"version": 1,
"model": "",
"entrypoint": "main",
"symbols": {"main": 0},
"instructions": instructions,
}
path = PROGRAMS_DIR / f"stress_glyph_stack_v{i}.gx.json"
path.write_text(json.dumps(prog, indent=2))
variants.append(str(path))
return variants
def run_stress_instance(instance_id: int, program_path: str) -> Dict[str, Any]:
"""Execute a single stress test instance."""
global metrics
try:
from xic_executor import run_xic
start_time = time.time()
# Record variant execution
with metrics_lock:
variant_name = Path(program_path).stem
metrics["variant_counters"][variant_name] = metrics["variant_counters"].get(variant_name, 0) + 1
# Run the XIC program
try:
ctx = run_xic(program_path, debug=False)
elapsed = time.time() - start_time
with metrics_lock:
metrics["total_executions"] += 1
metrics["successful_executions"] += 1
# Check if guardrails were triggered
if ctx._state.get("guardrails"):
metrics["guardrail_triggers"] += len(ctx._state["guardrails"])
return {
"instance_id": instance_id,
"status": "success",
"program": Path(program_path).stem,
"elapsed": elapsed,
"guardrails_triggered": len(ctx._state.get("guardrails", [])),
}
except Exception as e:
elapsed = time.time() - start_time
with metrics_lock:
metrics["total_executions"] += 1
metrics["failed_executions"] += 1
metrics["error_log"].append({
"instance": instance_id,
"program": Path(program_path).stem,
"error": str(e)[:100],
})
return {
"instance_id": instance_id,
"status": "error",
"program": Path(program_path).stem,
"error": str(e)[:50],
"elapsed": elapsed,
}
except ImportError:
with metrics_lock:
metrics["total_executions"] += 1
metrics["failed_executions"] += 1
return {"instance_id": instance_id, "status": "import_error"}
def monitor_vram():
"""Monitor VRAM usage during stress test."""
while time.time() - metrics["start_time"] < DURATION_SECS:
try:
vram_info = psutil.virtual_memory()
with metrics_lock:
metrics["vram_peaks"].append({
"timestamp": time.time() - metrics["start_time"],
"percent": vram_info.percent,
"used_gb": vram_info.used / (1024**3),
})
except Exception as e:
with metrics_lock:
if "error_log" not in metrics:
metrics["error_log"] = []
if len(metrics["error_log"]) < 100:
metrics["error_log"].append(f"vram_monitor: {e}")
time.sleep(0.5)
def main():
"""Execute 10,000 parallel instance stress test with 100+ program variants."""
print("\n" + "="*80)
print("🔥 EXTREME STRESS TEST: 10,000 Parallel Instances × 120 Program Variants")
print("="*80)
print(f"Start Time: {datetime.now().isoformat()}")
print(f"Duration: {DURATION_SECS} seconds (10 minutes)")
print(f"Max Workers: {MAX_WORKERS}")
print()
# Generate program variants
print("[1/3] Generating 120 program variants...")
variants = generate_program_variants()
print(f"✓ Generated {len(variants)} unique program variants")
print()
# Start VRAM monitoring thread
print("[2/3] Starting system monitoring...")
vram_monitor = threading.Thread(target=monitor_vram, daemon=True)
vram_monitor.start()
print("✓ VRAM monitoring started")
print()
# Launch 10,000 parallel instances
print(f"[3/3] Launching {INSTANCES} parallel instances...")
print(f"Each instance randomly selects from {len(variants)} program variants")
print()
start_time = time.time()
execution_count = 0
with concurrent.futures.ThreadPoolExecutor(max_workers=MAX_WORKERS) as executor:
futures_to_instance = {}
# Submit initial batch
for i in range(INSTANCES):
program = random.choice(variants)
future = executor.submit(run_stress_instance, i, program)
futures_to_instance[future] = i
# Process completions until timeout
while time.time() - start_time < DURATION_SECS:
done, _ = concurrent.futures.wait(
futures_to_instance.keys(),
timeout=1.0,
return_when=concurrent.futures.FIRST_COMPLETED
)
for future in done:
try:
result = future.result()
execution_count += 1
# Print progress every 500 executions
if execution_count % 500 == 0:
elapsed = time.time() - start_time
rate = execution_count / elapsed
print(f" ⚡ {execution_count} executions | "
f"{rate:.1f} exec/sec | "
f"{elapsed:.1f}s elapsed | "
f"{metrics['guardrail_triggers']} guardrail triggers")
except Exception as e:
print(f" ✗ Execution failed: {e}")
del futures_to_instance[future]
# Submit new instance if time remains
if time.time() - start_time < DURATION_SECS:
program = random.choice(variants)
new_future = executor.submit(run_stress_instance, execution_count, program)
futures_to_instance[new_future] = execution_count
# Check time
if time.time() - start_time >= DURATION_SECS:
break
# Cancel remaining futures
for future in futures_to_instance.keys():
future.cancel()
metrics["end_time"] = time.time()
total_elapsed = metrics["end_time"] - metrics["start_time"]
# Print results
print()
print("="*80)
print("📊 STRESS TEST RESULTS")
print("="*80)
print()
print(f"Duration: {total_elapsed:.1f} seconds")
print(f"Total Executions: {metrics['total_executions']}")
print(f"Successful: {metrics['successful_executions']}")
print(f"Failed: {metrics['failed_executions']}")
print(f"Success Rate: {100 * metrics['successful_executions'] / max(1, metrics['total_executions']):.1f}%")
print()
print(f"⚠️ Guardrail Triggers: {metrics['guardrail_triggers']}")
print(f"Throughput: {metrics['total_executions'] / total_elapsed:.1f} executions/second")
print()
# Variant distribution
print("Program Variant Distribution (top 15):")
sorted_variants = sorted(metrics["variant_counters"].items(), key=lambda x: x[1], reverse=True)
for variant, count in sorted_variants[:15]:
print(f" {variant}: {count} executions")
print()
# VRAM analysis
if metrics["vram_peaks"]:
vram_percents = [v["percent"] for v in metrics["vram_peaks"]]
vram_gbs = [v["used_gb"] for v in metrics["vram_peaks"]]
print("Memory Usage:")
print(f" Peak: {max(vram_percents):.1f}% ({max(vram_gbs):.2f} GB)")
print(f" Average: {sum(vram_percents)/len(vram_percents):.1f}%")
print()
# Error summary
if metrics["error_log"]:
print(f"Sample Errors ({len(metrics['error_log'])} total):")
for error in metrics["error_log"][:5]:
print(f" Instance {error['instance']} ({error['program']}): {error['error']}")
print()
print("="*80)
print(f"✅ STRESS TEST COMPLETE")
print(f"End Time: {datetime.now().isoformat()}")
print("="*80)
if __name__ == "__main__":
main()