/** * Neural Augmentation Simulation Tests * * Tests GNN-guided edge selection, RL navigation, embedding-topology * co-optimization, and attention-based layer routing. * * Target Metrics: * - GNN edge selection (adaptive M: 8-32) * - Memory reduction >15% (target: 18%) * - RL navigation convergence <500 episodes * - Hop reduction >20% (target: 26%) * - Joint optimization +9.1% * - Full pipeline improvement >25% (target: 29.4%) */ import { describe, it, expect, beforeAll } from 'vitest'; import { neuralAugmentationScenario } from '../../scenarios/latent-space/neural-augmentation'; import type { SimulationReport } from '../../types'; describe('NeuralAugmentation', () => { let report: SimulationReport; beforeAll(async () => { report = await neuralAugmentationScenario.run(neuralAugmentationScenario.config); }, 120000); // 120s timeout describe('Optimal Strategy', () => { it('should select full-neural or joint-opt', () => { const best = report.summary.bestStrategy; expect(['full-neural', 'joint-opt', 'gnn-edges']).toContain(best.strategy); }); it('should test baseline', () => { const strategies = neuralAugmentationScenario.config.strategies; const baseline = strategies.find(s => s.name === 'baseline'); expect(baseline).toBeDefined(); }); it('should test all neural components', () => { const strategies = neuralAugmentationScenario.config.strategies; expect(strategies.some(s => s.name === 'gnn-edges')).toBe(true); expect(strategies.some(s => s.name === 'rl-nav')).toBe(true); expect(strategies.some(s => s.name === 'joint-opt')).toBe(true); }); }); describe('GNN Edge Selection', () => { it('should reduce memory >15%', () => { const edgeMetrics = report.metrics.edgeSelection; expect(edgeMetrics.avgSparsityGain).toBeGreaterThan(15); }); it('should target 18% memory reduction', () => { const gnnResults = (report.detailedResults as any[]).filter( r => r.strategy === 'gnn-edges' || r.strategy === 'full-neural' ); gnnResults.forEach(r => { if (r.metrics.sparsityGain) { expect(r.metrics.sparsityGain).toBeCloseTo(18, 5); } }); }); it('should adapt M between 8-32', () => { const gnnResults = (report.detailedResults as any[]).filter( r => r.strategy === 'gnn-edges' || r.strategy === 'full-neural' ); gnnResults.forEach(r => { if (r.metrics.avgDegree) { expect(r.metrics.avgDegree).toBeGreaterThanOrEqual(8); expect(r.metrics.avgDegree).toBeLessThanOrEqual(32); } }); }); it('should maintain graph quality', () => { const gnnResults = (report.detailedResults as any[]).filter( r => r.strategy === 'gnn-edges' ); gnnResults.forEach(r => { expect(r.metrics.edgeSelectionQuality).toBeGreaterThan(0.8); }); }); }); describe('RL Navigation', () => { it('should reduce hops >20%', () => { const navMetrics = report.metrics.navigation; expect(navMetrics.avgHopsReduction).toBeGreaterThan(20); }); it('should target 26% hop reduction', () => { const rlResults = (report.detailedResults as any[]).filter( r => r.strategy === 'rl-nav' || r.strategy === 'full-neural' ); rlResults.forEach(r => { if (r.metrics.avgHopsReduction) { expect(r.metrics.avgHopsReduction).toBeCloseTo(26, 8); } }); }); it('should converge <500 episodes', () => { const rlResults = (report.detailedResults as any[]).filter( r => r.strategy === 'rl-nav' || r.strategy === 'full-neural' ); rlResults.forEach(r => { if (r.metrics.rlConvergenceEpochs) { expect(r.metrics.rlConvergenceEpochs).toBeLessThan(500); } }); }); it('should achieve high policy quality', () => { const rlResults = (report.detailedResults as any[]).filter( r => r.strategy === 'rl-nav' ); rlResults.forEach(r => { if (r.metrics.policyQuality) { expect(r.metrics.policyQuality).toBeGreaterThan(0.90); } }); }); }); describe('Joint Embedding-Topology Optimization', () => { it('should improve performance >9%', () => { const jointMetrics = report.metrics.coOptimization; expect(jointMetrics.avgJointGain).toBeGreaterThan(7); }); it('should target +9.1% improvement', () => { const jointResults = (report.detailedResults as any[]).filter( r => r.strategy === 'joint-opt' || r.strategy === 'full-neural' ); jointResults.forEach(r => { if (r.metrics.jointOptimizationGain) { expect(r.metrics.jointOptimizationGain).toBeCloseTo(9.1, 3); } }); }); it('should improve embedding quality', () => { const jointResults = (report.detailedResults as any[]).filter( r => r.strategy === 'joint-opt' ); jointResults.forEach(r => { expect(r.metrics.embeddingQuality).toBeGreaterThan(0.90); }); }); it('should improve topology quality', () => { const jointResults = (report.detailedResults as any[]).filter( r => r.strategy === 'joint-opt' ); jointResults.forEach(r => { expect(r.metrics.topologyQuality).toBeGreaterThan(0.85); }); }); }); describe('Attention-Based Layer Routing', () => { it('should skip layers efficiently', () => { const routingMetrics = report.metrics.layerRouting; expect(routingMetrics.avgLayerSkipRate).toBeGreaterThan(30); }); it('should target 35-50% layer skip rate', () => { const fullNeural = (report.detailedResults as any[]).filter( r => r.strategy === 'full-neural' ); fullNeural.forEach(r => { if (r.metrics.layerSkipRate) { expect(r.metrics.layerSkipRate).toBeGreaterThan(30); expect(r.metrics.layerSkipRate).toBeLessThan(60); } }); }); it('should maintain routing accuracy >85%', () => { const fullNeural = (report.detailedResults as any[]).filter( r => r.strategy === 'full-neural' ); fullNeural.forEach(r => { if (r.metrics.routingAccuracy) { expect(r.metrics.routingAccuracy).toBeGreaterThan(0.85); } }); }); it('should speed up search', () => { const fullNeural = (report.detailedResults as any[]).filter( r => r.strategy === 'full-neural' ); fullNeural.forEach(r => { if (r.metrics.speedupFromRouting) { expect(r.metrics.speedupFromRouting).toBeGreaterThan(1.2); } }); }); }); describe('Full Neural Pipeline', () => { it('should improve >25% end-to-end', () => { const avgImprovement = report.summary.avgNavigationImprovement; expect(avgImprovement).toBeGreaterThan(20); }); it('should target 29.4% improvement', () => { const fullNeural = (report.detailedResults as any[]).find( r => r.strategy === 'full-neural' ); if (fullNeural) { const totalGain = (fullNeural.metrics.navigationEfficiency || 0) + (fullNeural.metrics.sparsityGain || 0) / 2; expect(totalGain).toBeGreaterThan(25); } }); it('should combine all components', () => { const fullNeural = (report.detailedResults as any[]).filter( r => r.strategy === 'full-neural' ); fullNeural.forEach(r => { expect(r.metrics.sparsityGain).toBeDefined(); expect(r.metrics.navigationEfficiency).toBeDefined(); expect(r.metrics.jointOptimizationGain).toBeDefined(); }); }); }); describe('Component Integration', () => { it('should test GNN architecture', () => { const strategies = neuralAugmentationScenario.config.strategies; const gnn = strategies.find(s => s.name === 'gnn-edges'); if (gnn) { expect(gnn.parameters.gnnLayers).toBe(3); expect(gnn.parameters.hiddenDim).toBe(128); } }); it('should test RL parameters', () => { const strategies = neuralAugmentationScenario.config.strategies; const rl = strategies.find(s => s.name === 'rl-nav'); if (rl) { expect(rl.parameters.rlEpisodes).toBeGreaterThan(0); expect(rl.parameters.learningRate).toBeLessThan(0.01); } }); }); describe('Scalability', () => { it('should test at 100k nodes', () => { const sizes = neuralAugmentationScenario.config.graphSizes; expect(sizes).toContain(100000); }); it('should test multiple dimensions', () => { const dims = neuralAugmentationScenario.config.dimensions; expect(dims).toContain(128); expect(dims).toContain(768); }); it('should maintain quality at scale', () => { const large = (report.detailedResults as any[]).filter(r => r.size === 100000); large.forEach(r => { if (r.strategy !== 'baseline') { expect(r.metrics.navigationEfficiency).toBeGreaterThan(0); } }); }); }); describe('Baseline Comparison', () => { it('should outperform baseline', () => { const baseline = (report.detailedResults as any[]).filter(r => r.strategy === 'baseline'); const neural = (report.detailedResults as any[]).filter(r => r.strategy !== 'baseline'); if (baseline.length > 0 && neural.length > 0) { const avgNeuralGain = neural.reduce( (sum, r) => sum + (r.metrics.navigationEfficiency || 0), 0 ) / neural.length; expect(avgNeuralGain).toBeGreaterThan(0); } }); }); describe('Report Generation', () => { it('should generate analysis', () => { expect(report.analysis).toBeDefined(); expect(report.analysis).toContain('Neural'); }); it('should provide recommendations', () => { expect(report.recommendations).toBeDefined(); expect(report.recommendations.length).toBeGreaterThanOrEqual(4); }); it('should generate neural diagrams', () => { expect(report.artifacts.gnnArchitectures).toBeDefined(); expect(report.artifacts.navigationPolicies).toBeDefined(); expect(report.artifacts.optimizationCurves).toBeDefined(); }); it('should complete within timeout', () => { expect(report.executionTimeMs).toBeLessThan(120000); }); }); });