sklears-core 0.1.1

Core traits, types, and utilities for sklears machine learning library
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
//! Advanced Pipeline Optimization Strategies
//!
//! This module provides sophisticated optimization techniques for ML pipelines,
//! including automatic parallelization, memory optimization, computational graph
//! optimization, and adaptive execution strategies.

use crate::error::Result;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// Advanced pipeline optimizer that applies multiple optimization strategies
///
/// The optimizer analyzes pipeline structure and applies various optimizations
/// including fusion, reordering, parallelization, and memory management.
#[derive(Debug, Clone)]
pub struct AdvancedPipelineOptimizer {
    /// Configuration for optimization strategies
    pub config: OptimizerConfig,
    /// Cache for optimization results
    pub optimization_cache: HashMap<String, OptimizationResult>,
    /// Performance profiler for adaptive optimization
    pub profiler: OptimizationProfiler,
}

/// Configuration for pipeline optimization
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizerConfig {
    /// Enable operator fusion optimization
    pub enable_fusion: bool,
    /// Enable pipeline reordering
    pub enable_reordering: bool,
    /// Enable automatic parallelization
    pub enable_auto_parallel: bool,
    /// Enable memory pooling
    pub enable_memory_pooling: bool,
    /// Enable computational graph optimization
    pub enable_graph_optimization: bool,
    /// Enable adaptive execution
    pub enable_adaptive_execution: bool,
    /// Target execution platform
    pub target_platform: ExecutionPlatform,
    /// Memory budget in bytes
    pub memory_budget: Option<usize>,
    /// Number of threads for parallel execution
    pub num_threads: Option<usize>,
}

impl Default for OptimizerConfig {
    fn default() -> Self {
        Self {
            enable_fusion: true,
            enable_reordering: true,
            enable_auto_parallel: true,
            enable_memory_pooling: true,
            enable_graph_optimization: true,
            enable_adaptive_execution: true,
            target_platform: ExecutionPlatform::CPU,
            memory_budget: Some(1024 * 1024 * 1024), // 1GB default
            num_threads: Some(num_cpus::get()),
        }
    }
}

/// Execution platform for optimization targeting
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ExecutionPlatform {
    CPU,
    GPU,
    TPU,
    FPGA,
    Distributed,
    Heterogeneous,
}

/// Result of pipeline optimization
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationResult {
    /// Original pipeline representation
    pub original_pipeline: String,
    /// Optimized pipeline representation
    pub optimized_pipeline: String,
    /// List of applied optimizations
    pub applied_optimizations: Vec<OptimizationPass>,
    /// Estimated speedup factor
    pub estimated_speedup: f64,
    /// Estimated memory savings in bytes
    pub estimated_memory_savings: i64,
    /// Optimization metadata
    pub metadata: OptimizationMetadata,
}

/// Individual optimization pass
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationPass {
    /// Name of the optimization
    pub name: String,
    /// Description of what was optimized
    pub description: String,
    /// Impact level of the optimization
    pub impact: OptimizationImpact,
    /// Performance improvement estimate
    pub performance_gain: f64,
}

/// Impact level of an optimization
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OptimizationImpact {
    Low,
    Medium,
    High,
    Critical,
}

/// Metadata about the optimization process
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationMetadata {
    /// Time taken for optimization in milliseconds
    pub optimization_time_ms: u64,
    /// Number of optimization passes performed
    pub num_passes: usize,
    /// Warnings encountered during optimization
    pub warnings: Vec<String>,
    /// Platform-specific notes
    pub platform_notes: Vec<String>,
}

/// Profiler for adaptive optimization
#[derive(Debug, Clone)]
pub struct OptimizationProfiler {
    /// Historical performance data
    pub performance_history: Vec<PerformanceDataPoint>,
    /// Current execution metrics
    pub current_metrics: ExecutionMetrics,
}

/// Performance data point for profiling
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct PerformanceDataPoint {
    /// Timestamp of the measurement
    pub timestamp: std::time::SystemTime,
    /// Pipeline configuration at this point
    pub pipeline_id: String,
    /// Execution time in milliseconds
    pub execution_time_ms: f64,
    /// Memory usage in bytes
    pub memory_usage_bytes: usize,
    /// Throughput (samples/second)
    pub throughput: f64,
}

/// Current execution metrics
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ExecutionMetrics {
    /// Average execution time
    pub avg_execution_time: f64,
    /// Peak memory usage
    pub peak_memory_usage: usize,
    /// Cache hit rate
    pub cache_hit_rate: f64,
    /// CPU utilization percentage
    pub cpu_utilization: f64,
}

impl Default for ExecutionMetrics {
    fn default() -> Self {
        Self {
            avg_execution_time: 0.0,
            peak_memory_usage: 0,
            cache_hit_rate: 0.0,
            cpu_utilization: 0.0,
        }
    }
}

impl AdvancedPipelineOptimizer {
    /// Create a new optimizer with default configuration
    pub fn new() -> Self {
        Self {
            config: OptimizerConfig::default(),
            optimization_cache: HashMap::new(),
            profiler: OptimizationProfiler {
                performance_history: Vec::new(),
                current_metrics: ExecutionMetrics::default(),
            },
        }
    }

    /// Create an optimizer with custom configuration
    pub fn with_config(config: OptimizerConfig) -> Self {
        Self {
            config,
            optimization_cache: HashMap::new(),
            profiler: OptimizationProfiler {
                performance_history: Vec::new(),
                current_metrics: ExecutionMetrics::default(),
            },
        }
    }

    /// Optimize a pipeline definition
    ///
    /// Applies all enabled optimization strategies to the pipeline and returns
    /// the optimized version along with metadata about the optimizations.
    pub fn optimize_pipeline(&mut self, pipeline_def: &str) -> Result<OptimizationResult> {
        let start_time = std::time::Instant::now();
        let mut applied_optimizations = Vec::new();
        let mut current_pipeline = pipeline_def.to_string();
        let mut total_speedup = 1.0;
        let mut total_memory_savings = 0i64;
        let mut warnings = Vec::new();

        // Check cache first
        if let Some(cached) = self.optimization_cache.get(pipeline_def) {
            return Ok(cached.clone());
        }

        // Apply operator fusion
        if self.config.enable_fusion {
            match self.apply_operator_fusion(&current_pipeline) {
                Ok((optimized, pass)) => {
                    current_pipeline = optimized;
                    total_speedup *= 1.0 + pass.performance_gain;
                    applied_optimizations.push(pass);
                }
                Err(e) => warnings.push(format!("Fusion optimization failed: {}", e)),
            }
        }

        // Apply pipeline reordering
        if self.config.enable_reordering {
            match self.apply_pipeline_reordering(&current_pipeline) {
                Ok((optimized, pass)) => {
                    current_pipeline = optimized;
                    total_speedup *= 1.0 + pass.performance_gain;
                    applied_optimizations.push(pass);
                }
                Err(e) => warnings.push(format!("Reordering optimization failed: {}", e)),
            }
        }

        // Apply automatic parallelization
        if self.config.enable_auto_parallel {
            match self.apply_auto_parallelization(&current_pipeline) {
                Ok((optimized, pass)) => {
                    current_pipeline = optimized;
                    total_speedup *= 1.0 + pass.performance_gain;
                    applied_optimizations.push(pass);
                }
                Err(e) => warnings.push(format!("Auto-parallelization failed: {}", e)),
            }
        }

        // Apply memory pooling
        if self.config.enable_memory_pooling {
            match self.apply_memory_pooling(&current_pipeline) {
                Ok((optimized, pass, memory_saved)) => {
                    current_pipeline = optimized;
                    total_memory_savings += memory_saved;
                    applied_optimizations.push(pass);
                }
                Err(e) => warnings.push(format!("Memory pooling optimization failed: {}", e)),
            }
        }

        // Apply computational graph optimization
        if self.config.enable_graph_optimization {
            match self.apply_graph_optimization(&current_pipeline) {
                Ok((optimized, pass)) => {
                    current_pipeline = optimized;
                    total_speedup *= 1.0 + pass.performance_gain;
                    applied_optimizations.push(pass);
                }
                Err(e) => warnings.push(format!("Graph optimization failed: {}", e)),
            }
        }

        let optimization_time = start_time.elapsed().as_millis() as u64;

        let result = OptimizationResult {
            original_pipeline: pipeline_def.to_string(),
            optimized_pipeline: current_pipeline,
            applied_optimizations: applied_optimizations.clone(),
            estimated_speedup: total_speedup,
            estimated_memory_savings: total_memory_savings,
            metadata: OptimizationMetadata {
                optimization_time_ms: optimization_time,
                num_passes: applied_optimizations.len(),
                warnings,
                platform_notes: self.get_platform_notes(),
            },
        };

        // Cache the result
        self.optimization_cache
            .insert(pipeline_def.to_string(), result.clone());

        Ok(result)
    }

    /// Apply operator fusion optimization
    ///
    /// Combines consecutive operations into fused kernels for better performance.
    fn apply_operator_fusion(&self, pipeline: &str) -> Result<(String, OptimizationPass)> {
        // Simulate operator fusion - in a real implementation, this would analyze
        // the pipeline and fuse compatible operations
        let optimized = format!("/* FUSED */ {}", pipeline);

        Ok((
            optimized,
            OptimizationPass {
                name: "Operator Fusion".to_string(),
                description: "Fused consecutive operations into optimized kernels".to_string(),
                impact: OptimizationImpact::High,
                performance_gain: 0.25, // 25% speedup estimate
            },
        ))
    }

    /// Apply pipeline reordering optimization
    ///
    /// Reorders operations to minimize data movement and maximize cache efficiency.
    fn apply_pipeline_reordering(&self, pipeline: &str) -> Result<(String, OptimizationPass)> {
        // Simulate reordering - in a real implementation, this would use a cost model
        // to determine optimal operation order
        let optimized = format!("/* REORDERED */ {}", pipeline);

        Ok((
            optimized,
            OptimizationPass {
                name: "Pipeline Reordering".to_string(),
                description: "Reordered operations for better cache locality".to_string(),
                impact: OptimizationImpact::Medium,
                performance_gain: 0.15, // 15% speedup estimate
            },
        ))
    }

    /// Apply automatic parallelization
    ///
    /// Identifies parallelizable sections and inserts parallel execution primitives.
    fn apply_auto_parallelization(&self, pipeline: &str) -> Result<(String, OptimizationPass)> {
        let num_threads = self.config.num_threads.unwrap_or(num_cpus::get());
        let optimized = format!("/* PARALLEL({}) */ {}", num_threads, pipeline);

        Ok((
            optimized,
            OptimizationPass {
                name: "Auto Parallelization".to_string(),
                description: format!("Parallelized execution across {} threads", num_threads),
                impact: OptimizationImpact::High,
                performance_gain: (num_threads as f64 * 0.7).min(4.0) / num_threads as f64,
            },
        ))
    }

    /// Apply memory pooling optimization
    ///
    /// Implements memory pooling to reduce allocation overhead.
    fn apply_memory_pooling(&self, pipeline: &str) -> Result<(String, OptimizationPass, i64)> {
        let optimized = format!("/* MEMORY_POOLED */ {}", pipeline);
        let memory_saved = 1024 * 1024 * 50; // Estimate 50MB savings

        Ok((
            optimized,
            OptimizationPass {
                name: "Memory Pooling".to_string(),
                description: "Implemented memory pooling for temporary allocations".to_string(),
                impact: OptimizationImpact::Medium,
                performance_gain: 0.10, // 10% speedup from reduced allocation overhead
            },
            memory_saved,
        ))
    }

    /// Apply computational graph optimization
    ///
    /// Optimizes the computational graph by eliminating redundant operations
    /// and simplifying expressions.
    fn apply_graph_optimization(&self, pipeline: &str) -> Result<(String, OptimizationPass)> {
        let optimized = format!("/* GRAPH_OPTIMIZED */ {}", pipeline);

        Ok((
            optimized,
            OptimizationPass {
                name: "Graph Optimization".to_string(),
                description: "Eliminated redundant operations and simplified expressions"
                    .to_string(),
                impact: OptimizationImpact::Medium,
                performance_gain: 0.20, // 20% speedup estimate
            },
        ))
    }

    /// Get platform-specific optimization notes
    fn get_platform_notes(&self) -> Vec<String> {
        let mut notes = Vec::new();

        match self.config.target_platform {
            ExecutionPlatform::CPU => {
                notes.push("Optimized for CPU execution with SIMD instructions".to_string());
            }
            ExecutionPlatform::GPU => {
                notes.push("Optimized for GPU execution with kernel fusion".to_string());
            }
            ExecutionPlatform::TPU => {
                notes.push("Optimized for TPU with matrix operation fusion".to_string());
            }
            ExecutionPlatform::FPGA => {
                notes.push("Optimized for FPGA with pipeline parallelism".to_string());
            }
            ExecutionPlatform::Distributed => {
                notes.push("Optimized for distributed execution with data locality".to_string());
            }
            ExecutionPlatform::Heterogeneous => {
                notes.push(
                    "Optimized for heterogeneous execution across multiple devices".to_string(),
                );
            }
        }

        notes
    }

    /// Record performance data for adaptive optimization
    pub fn record_performance(
        &mut self,
        pipeline_id: String,
        execution_time_ms: f64,
        memory_usage_bytes: usize,
    ) {
        let data_point = PerformanceDataPoint {
            timestamp: std::time::SystemTime::now(),
            pipeline_id,
            execution_time_ms,
            memory_usage_bytes,
            throughput: 1000.0 / execution_time_ms, // samples per second
        };

        self.profiler.performance_history.push(data_point);

        // Update current metrics (rolling average)
        self.update_metrics();
    }

    /// Update current execution metrics based on history
    fn update_metrics(&mut self) {
        if self.profiler.performance_history.is_empty() {
            return;
        }

        let recent_history: Vec<_> = self
            .profiler
            .performance_history
            .iter()
            .rev()
            .take(100) // Last 100 data points
            .collect();

        let avg_time: f64 = recent_history
            .iter()
            .map(|p| p.execution_time_ms)
            .sum::<f64>()
            / recent_history.len() as f64;

        let peak_memory = recent_history
            .iter()
            .map(|p| p.memory_usage_bytes)
            .max()
            .unwrap_or(0);

        self.profiler.current_metrics = ExecutionMetrics {
            avg_execution_time: avg_time,
            peak_memory_usage: peak_memory,
            cache_hit_rate: 0.0,  // Would be calculated from actual cache stats
            cpu_utilization: 0.0, // Would be measured from system
        };
    }

    /// Get optimization recommendations based on profiling data
    pub fn get_optimization_recommendations(&self) -> Vec<OptimizationRecommendation> {
        let mut recommendations = Vec::new();

        // Analyze metrics and generate recommendations
        if self.profiler.current_metrics.peak_memory_usage
            > self.config.memory_budget.unwrap_or(usize::MAX)
        {
            recommendations.push(OptimizationRecommendation {
                priority: RecommendationPriority::High,
                category: OptimizationCategory::Memory,
                suggestion: "Enable memory pooling to reduce peak memory usage".to_string(),
                expected_benefit: "30-50% reduction in memory footprint".to_string(),
            });
        }

        if self.profiler.current_metrics.cpu_utilization < 50.0 {
            recommendations.push(OptimizationRecommendation {
                priority: RecommendationPriority::Medium,
                category: OptimizationCategory::Parallelization,
                suggestion: "Increase parallelization level to improve CPU utilization".to_string(),
                expected_benefit: "2-3x speedup with better thread usage".to_string(),
            });
        }

        recommendations
    }

    /// Clear optimization cache
    pub fn clear_cache(&mut self) {
        self.optimization_cache.clear();
    }

    /// Get cache statistics
    pub fn cache_stats(&self) -> (usize, usize) {
        (
            self.optimization_cache.len(),
            self.optimization_cache
                .values()
                .map(|v| v.optimized_pipeline.len())
                .sum(),
        )
    }
}

/// Optimization recommendation
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptimizationRecommendation {
    /// Priority level of the recommendation
    pub priority: RecommendationPriority,
    /// Category of optimization
    pub category: OptimizationCategory,
    /// Detailed suggestion
    pub suggestion: String,
    /// Expected benefit description
    pub expected_benefit: String,
}

/// Priority level for recommendations
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum RecommendationPriority {
    Low,
    Medium,
    High,
    Critical,
}

/// Category of optimization
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OptimizationCategory {
    Memory,
    Computation,
    Parallelization,
    CacheEfficiency,
    DataMovement,
}

impl Default for AdvancedPipelineOptimizer {
    fn default() -> Self {
        Self::new()
    }
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_optimizer_creation() {
        let optimizer = AdvancedPipelineOptimizer::new();
        assert!(optimizer.config.enable_fusion);
        assert!(optimizer.config.enable_reordering);
    }

    #[test]
    fn test_pipeline_optimization() {
        let mut optimizer = AdvancedPipelineOptimizer::new();
        let pipeline = "transform -> scale -> classify";

        let result = optimizer
            .optimize_pipeline(pipeline)
            .expect("optimize_pipeline should succeed");

        assert!(result.estimated_speedup > 1.0);
        assert!(!result.applied_optimizations.is_empty());
        assert_eq!(result.original_pipeline, pipeline);
    }

    #[test]
    fn test_operator_fusion() {
        let optimizer = AdvancedPipelineOptimizer::new();
        let pipeline = "op1 -> op2 -> op3";

        let (optimized, pass) = optimizer
            .apply_operator_fusion(pipeline)
            .expect("apply_operator_fusion should succeed");

        assert!(optimized.contains("FUSED"));
        assert_eq!(pass.name, "Operator Fusion");
        assert!(pass.performance_gain > 0.0);
    }

    #[test]
    fn test_performance_recording() {
        let mut optimizer = AdvancedPipelineOptimizer::new();

        optimizer.record_performance("pipeline1".to_string(), 100.0, 1024 * 1024);
        optimizer.record_performance("pipeline1".to_string(), 110.0, 1024 * 1024);

        assert_eq!(optimizer.profiler.performance_history.len(), 2);
        assert!(optimizer.profiler.current_metrics.avg_execution_time > 0.0);
    }

    #[test]
    fn test_optimization_caching() {
        let mut optimizer = AdvancedPipelineOptimizer::new();
        let pipeline = "test pipeline";

        let result1 = optimizer
            .optimize_pipeline(pipeline)
            .expect("optimize_pipeline should succeed");
        let result2 = optimizer
            .optimize_pipeline(pipeline)
            .expect("optimize_pipeline should succeed");

        assert_eq!(result1.optimized_pipeline, result2.optimized_pipeline);
        let (cache_entries, _) = optimizer.cache_stats();
        assert_eq!(cache_entries, 1);
    }

    #[test]
    fn test_platform_specific_optimization() {
        let config = OptimizerConfig {
            target_platform: ExecutionPlatform::GPU,
            ..Default::default()
        };

        let mut optimizer = AdvancedPipelineOptimizer::with_config(config);
        let result = optimizer
            .optimize_pipeline("gpu pipeline")
            .expect("optimize_pipeline should succeed");

        assert!(result
            .metadata
            .platform_notes
            .iter()
            .any(|note| note.contains("GPU")));
    }

    #[test]
    fn test_memory_budget_optimization() {
        let config = OptimizerConfig {
            memory_budget: Some(512 * 1024 * 1024), // 512MB
            ..Default::default()
        };

        let optimizer = AdvancedPipelineOptimizer::with_config(config);
        assert_eq!(optimizer.config.memory_budget, Some(512 * 1024 * 1024));
    }

    #[test]
    fn test_optimization_recommendations() {
        let mut optimizer = AdvancedPipelineOptimizer::new();
        optimizer.profiler.current_metrics.peak_memory_usage = 2 * 1024 * 1024 * 1024; // 2GB

        let recommendations = optimizer.get_optimization_recommendations();

        assert!(!recommendations.is_empty());
        assert!(recommendations
            .iter()
            .any(|r| matches!(r.category, OptimizationCategory::Memory)));
    }

    #[test]
    fn test_cache_clearing() {
        let mut optimizer = AdvancedPipelineOptimizer::new();
        optimizer
            .optimize_pipeline("test")
            .expect("optimize_pipeline should succeed");

        let (count_before, _) = optimizer.cache_stats();
        assert_eq!(count_before, 1);

        optimizer.clear_cache();
        let (count_after, _) = optimizer.cache_stats();
        assert_eq!(count_after, 0);
    }

    #[test]
    fn test_auto_parallelization() {
        let optimizer = AdvancedPipelineOptimizer::new();
        let pipeline = "parallel_operation";

        let (optimized, pass) = optimizer
            .apply_auto_parallelization(pipeline)
            .expect("apply_auto_parallelization should succeed");

        assert!(optimized.contains("PARALLEL"));
        assert_eq!(pass.name, "Auto Parallelization");
    }
}