From 987e5e6ac266b14bca11e6ccdb6eaaaa7001e7fa Mon Sep 17 00:00:00 2001 From: jgrusewski Date: Fri, 20 Feb 2026 19:43:47 +0100 Subject: [PATCH] refactor(ml): remove 797 lines of commented-out code and disabled imports Removed across 66 files: - 49 instances of "// use crate::safe_operations; // DISABLED" - 11 instances of "// use error_handling::{...}; // crate doesn't exist" - 2 instances of "// use crate::Optimizer; // not available" - 5 disabled test placeholder blocks (/* ... */) in ensemble/ - 1 disabled From impl in lib.rs (38 lines) - 1 disabled test module in model.rs (113 lines) - 1 disabled code block in integration/distillation.rs (41 lines) - Various other disabled imports with explanation comments All of this code references modules/crates that were removed during prior refactoring waves and is preserved in git history. Removing it reduces noise and makes the codebase easier to navigate. 1922 lib tests passing, compilation clean. Co-Authored-By: Claude Opus 4.6 --- ml/src/checkpoint/compression.rs | 2 +- ml/src/checkpoint/mod.rs | 2 +- ml/src/checkpoint/validation.rs | 2 +- ml/src/checkpoint/versioning.rs | 2 +- ml/src/dqn/agent.rs | 1 - ml/src/dqn/dqn.rs | 3 +- ml/src/dqn/network.rs | 2 +- ml/src/dqn/performance_validation.rs | 2 +- ml/src/dqn/replay_buffer.rs | 2 +- ml/src/dqn/reward.rs | 2 +- ml/src/dqn/self_supervised_pretraining.rs | 2 +- ml/src/ensemble/confidence.rs | 136 -------------- ml/src/ensemble/model.rs | 171 ------------------ ml/src/ensemble/voting.rs | 161 ----------------- ml/src/ensemble/weights.rs | 104 ----------- ml/src/error.rs | 3 - ml/src/examples.rs | 6 - ml/src/flash_attention/block_sparse.rs | 2 +- ml/src/flash_attention/causal_masking.rs | 2 +- ml/src/integration/distillation.rs | 41 ----- ml/src/lib.rs | 38 ---- ml/src/liquid/activation.rs | 2 +- ml/src/liquid/cells.rs | 2 +- ml/src/liquid/network.rs | 2 +- ml/src/liquid/ode_solvers.rs | 2 +- ml/src/liquid/training.rs | 2 +- ml/src/microstructure/advanced_models.rs | 3 +- .../advanced_models_extended.rs | 3 +- ml/src/microstructure/amihud.rs | 2 +- ml/src/microstructure/benchmarks.rs | 2 +- ml/src/microstructure/hasbrouck.rs | 2 +- ml/src/microstructure/integration.rs | 2 +- ml/src/microstructure/kyle_lambda.rs | 2 +- ml/src/microstructure/ml_integration.rs | 1 - ml/src/microstructure/mod.rs | 2 - .../microstructure/portfolio_integration.rs | 3 +- ml/src/microstructure/roll_spread.rs | 2 +- ml/src/microstructure/training_pipeline.rs | 3 +- ml/src/microstructure/vpin.rs | 2 +- ml/src/model.rs | 114 ------------ ml/src/performance.rs | 2 +- ml/src/ppo/gae.rs | 2 +- ml/src/ppo/trajectories.rs | 2 +- ml/src/production.rs | 2 - ml/src/risk/advanced_risk_engine.rs | 2 - ml/src/risk/circuit_breakers.rs | 2 +- ml/src/risk/extreme_value_models.rs | 2 +- ml/src/risk/kelly_optimizer.rs | 2 +- ml/src/risk/lstm_gan_scenarios.rs | 2 +- ml/src/risk/monitor.rs | 2 +- ml/src/risk/position_sizing.rs | 4 +- ml/src/risk/var_models.rs | 2 +- ml/src/tft/gated_residual.rs | 2 +- ml/src/tft/hft_optimizations.rs | 2 +- ml/src/tft/quantile_outputs.rs | 2 +- ml/src/tft/variable_selection.rs | 2 +- ml/src/tlob/transformer.rs | 2 +- ml/src/training/dqn_trainer.rs | 1 - ml/src/training/transformer_trainer.rs | 1 - ml/src/training/unified_data_loader.rs | 3 +- ml/src/training_pipeline.rs | 2 - ml/src/transformers/attention.rs | 2 +- ml/src/transformers/features.rs | 2 +- ml/src/transformers/financial_transformer.rs | 2 +- ml/src/transformers/hft_transformer.rs | 2 - ml/src/transformers/quantization.rs | 3 +- 66 files changed, 48 insertions(+), 845 deletions(-) diff --git a/ml/src/checkpoint/compression.rs b/ml/src/checkpoint/compression.rs index e2283f33a..9c255485d 100644 --- a/ml/src/checkpoint/compression.rs +++ b/ml/src/checkpoint/compression.rs @@ -282,7 +282,7 @@ impl CompressionStats { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_compression_manager() -> Result<(), MLError> { diff --git a/ml/src/checkpoint/mod.rs b/ml/src/checkpoint/mod.rs index 660994465..921be828d 100644 --- a/ml/src/checkpoint/mod.rs +++ b/ml/src/checkpoint/mod.rs @@ -872,7 +872,7 @@ impl CheckpointManager { mod tests { use super::*; use std::sync::atomic::AtomicBool; - // use crate::safe_operations; // DISABLED - module not found + // Mock model for testing struct MockModel { diff --git a/ml/src/checkpoint/validation.rs b/ml/src/checkpoint/validation.rs index 53c243bf9..89387439e 100644 --- a/ml/src/checkpoint/validation.rs +++ b/ml/src/checkpoint/validation.rs @@ -375,7 +375,7 @@ impl Default for ValidationReport { mod tests { use super::*; use chrono::Utc; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_checksum_validation() { diff --git a/ml/src/checkpoint/versioning.rs b/ml/src/checkpoint/versioning.rs index 4b9f9c565..1beb135e4 100644 --- a/ml/src/checkpoint/versioning.rs +++ b/ml/src/checkpoint/versioning.rs @@ -452,7 +452,7 @@ pub type MigrationHandler = fn(&[u8]) -> Result, MLError>; #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_semantic_version_parsing() -> Result<(), MLError> { diff --git a/ml/src/dqn/agent.rs b/ml/src/dqn/agent.rs index 5a6e87697..7674f8ca4 100644 --- a/ml/src/dqn/agent.rs +++ b/ml/src/dqn/agent.rs @@ -9,7 +9,6 @@ use crate::Adam; use candle_core::Tensor; use candle_nn::{ops::leaky_relu, Module, VarBuilder}; use candle_optimisers::adam::ParamsAdam; // Use our Adam wrapper from lib.rs - // use crate::Optimizer; // Optimizer trait not available in candle v0.9 use serde::{Deserialize, Serialize}; use tracing::debug; diff --git a/ml/src/dqn/dqn.rs b/ml/src/dqn/dqn.rs index 70593f485..56d1cfa27 100644 --- a/ml/src/dqn/dqn.rs +++ b/ml/src/dqn/dqn.rs @@ -20,7 +20,6 @@ use candle_nn::ops::leaky_relu; use candle_nn::Module; use candle_nn::{Linear, VarBuilder, VarMap}; use candle_optimisers::adam::ParamsAdam; -// use crate::Optimizer; // Optimizer trait not available in candle v0.9 use rand::{thread_rng, Rng}; use serde::{Deserialize, Serialize}; use tracing::debug; @@ -2589,7 +2588,7 @@ impl DQN { mod tests { use super::*; use crate::dqn::Experience; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_working_dqn_creation() -> anyhow::Result<()> { diff --git a/ml/src/dqn/network.rs b/ml/src/dqn/network.rs index e2dc97bc5..e42cdeea0 100644 --- a/ml/src/dqn/network.rs +++ b/ml/src/dqn/network.rs @@ -423,7 +423,7 @@ impl QNetwork { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_qnetwork_creation() -> anyhow::Result<()> { diff --git a/ml/src/dqn/performance_validation.rs b/ml/src/dqn/performance_validation.rs index 7af87d644..ba2e63ce5 100644 --- a/ml/src/dqn/performance_validation.rs +++ b/ml/src/dqn/performance_validation.rs @@ -105,7 +105,7 @@ impl DQNPerformanceValidator { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_performance_validator_creation() { diff --git a/ml/src/dqn/replay_buffer.rs b/ml/src/dqn/replay_buffer.rs index 6d48f5631..f5d29bf5c 100644 --- a/ml/src/dqn/replay_buffer.rs +++ b/ml/src/dqn/replay_buffer.rs @@ -211,7 +211,7 @@ impl ReplayBuffer { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + fn create_test_experience(reward: f32) -> Experience { Experience::new(vec![1.0, 2.0, 3.0], 1, reward, vec![1.1, 2.1, 3.1], false) diff --git a/ml/src/dqn/reward.rs b/ml/src/dqn/reward.rs index e03f27948..3b4dbeda8 100644 --- a/ml/src/dqn/reward.rs +++ b/ml/src/dqn/reward.rs @@ -1041,7 +1041,7 @@ pub fn calculate_batch_rewards( #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + /// Create test state with proper 128-dim structure /// diff --git a/ml/src/dqn/self_supervised_pretraining.rs b/ml/src/dqn/self_supervised_pretraining.rs index 458b03736..f61ce6c8f 100644 --- a/ml/src/dqn/self_supervised_pretraining.rs +++ b/ml/src/dqn/self_supervised_pretraining.rs @@ -229,7 +229,7 @@ impl FinancialDatasetBuilder { mod tests { use super::*; use candle_core::{DType, Device}; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_financial_dataset_builder() { diff --git a/ml/src/ensemble/confidence.rs b/ml/src/ensemble/confidence.rs index 57ca33a20..19e745418 100644 --- a/ml/src/ensemble/confidence.rs +++ b/ml/src/ensemble/confidence.rs @@ -11,139 +11,3 @@ impl ConfidenceCalculator { Self {} } } - -/* -// DISABLED: Tests require missing types (ConfidenceConfig, SignalStatistics, etc.) -// Fix after implementing proper confidence calculation API -#[cfg(test)] -mod tests { - use super::*; - use std::collections::HashMap; - use crate::ensemble::{ModelSignal, SignalMetadata}; - - fn create_test_signal( - model_id: &str, - signal: f32, - confidence: f32, - model_type: &str, - ) -> ModelSignal { - ModelSignal { - model_id: model_id.to_string(), - signal, - confidence, - timestamp: std::time::SystemTime::now() - .duration_since(std::time::UNIX_EPOCH) - .map(|d| d.as_nanos() as u64) - .unwrap_or(0), - metadata: SignalMetadata { - model_version: model_type.to_string(), - features_used: vec![], - prediction_horizon: 0, - }, - } - } - - #[test] - fn test_confidence_calculation() { - let config = ConfidenceConfig::default(); - let calculator = ConfidenceCalculator::new(config); - - let signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", 0.7, 0.8, "lstm"), - ]; - - let statistics = SignalStatistics { - model_count: 2, - variance: 0.05, - agreement_ratio: 1.0, - avg_confidence: 0.85, - ..SignalStatistics::default() - }; - - let confidence = calculator.calculate_ensemble_confidence(&signals, 0.75, &statistics)?; - - assert!(confidence > 0.0); - assert!(confidence <= 1.0); - } - - #[test] - fn test_agreement_score() { - let config = ConfidenceConfig::default(); - let calculator = ConfidenceCalculator::new(config); - - // All signals agree (same direction) - let agreeing_signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", 0.6, 0.8, "lstm"), - ]; - - let agreement_score = calculator.calculate_agreement_score(&agreeing_signals, 0.7); - assert!(agreement_score > 0.8); // Should be high - - // Conflicting signals - let conflicting_signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", -0.6, 0.8, "lstm"), - ]; - - let conflict_score = calculator.calculate_agreement_score(&conflicting_signals, 0.1); - assert!(conflict_score < 0.6); // Should be lower - } - - #[test] - fn test_diversity_score() { - let config = ConfidenceConfig::default(); - let calculator = ConfidenceCalculator::new(config); - - // High diversity (different model types) - let diverse_signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", 0.6, 0.8, "lstm"), - create_test_signal("model3", 0.7, 0.85, "transformer"), - ]; - - let diversity_score = calculator.calculate_diversity_score(&diverse_signals); - assert!(diversity_score > 0.5); - - // Low diversity (same model type) - let similar_signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", 0.6, 0.8, "dqn"), - create_test_signal("model3", 0.7, 0.85, "dqn"), - ]; - - let similar_score = calculator.calculate_diversity_score(&similar_signals); - assert!(similar_score < diversity_score); - } - - #[test] - fn test_model_performance_update() { - let config = ConfidenceConfig::default(); - let mut calculator = ConfidenceCalculator::new(config); - - calculator.update_model_performance("model1", 0.8, 0.1, 1.5); - let performance = calculator.get_model_performance("model1")?; - - assert_eq!(performance.accuracy, 0.08); // 0.0 * 0.9 + 0.8 * 0.1 - assert_eq!(performance.prediction_count, 1); - } - - #[test] - fn test_confidence_bounds() { - let config = ConfidenceConfig::default(); - let calculator = ConfidenceCalculator::new(config); - - let signals = vec![ - create_test_signal("model1", 0.8, 0.9, "dqn"), - create_test_signal("model2", 0.6, 0.8, "lstm"), - ]; - - let (lower, upper) = calculator.calculate_confidence_bounds(&signals, 0.7); - - assert!(lower < upper); - assert!(lower >= -1.0); - assert!(upper <= 1.0); - } -} -*/ diff --git a/ml/src/ensemble/model.rs b/ml/src/ensemble/model.rs index 442895e00..692dae43f 100644 --- a/ml/src/ensemble/model.rs +++ b/ml/src/ensemble/model.rs @@ -386,174 +386,3 @@ fn current_timestamp() -> u64 { .unwrap_or_default() .as_millis() as u64 } - -/* -// DISABLED: Tests require proper ensemble API implementation -// Fix after completing ensemble model infrastructure -#[cfg(test)] -mod tests { - use super::*; - - fn create_test_ensemble() -> EnsembleModel { - let config = EnsembleConfig::default(); - EnsembleModel::new(config)? - } - - fn create_test_signal(model_id: &str, signal: f32, confidence: f32) -> ModelSignal { - ModelSignal { - model_id: model_id.to_string(), - signal, - confidence, - timestamp: current_timestamp(), - metadata: SignalMetadata { - model_version: "1.0".to_string(), - features_used: vec!["test_feature".to_string()], - prediction_horizon: 50, - }, - } - } - - #[test] - fn test_ensemble_creation() { - let ensemble = create_test_ensemble(); - let metrics = ensemble.get_metrics()?; - - assert_eq!(metrics.total_models, 0); - assert_eq!(metrics.active_models, 0); - } - - #[test] - fn test_model_registration() { - let ensemble = create_test_ensemble(); - - let result = ensemble.register_model( - "test_model", - "momentum", - "1.0", - vec!["price".to_string(), "volume".to_string()], - 100, - ); - - assert!(result.is_ok()); - assert_eq!(ensemble.list_models().len(), 1); - assert_eq!(ensemble.list_models()[0], "test_model"); - } - - #[test] - fn test_signal_submission_and_aggregation() { - let ensemble = create_test_ensemble(); - - // Register models - ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?; - ensemble.register_model( - "model2", - "mean_reversion", - "1.0", - vec!["price".to_string()], - 60, - )?; - - // Submit signals - let signal1 = create_test_signal("model1", 0.8, 0.9); - let signal2 = create_test_signal("model2", 0.6, 0.8); - - ensemble.submit_signal(signal1)?; - ensemble.submit_signal(signal2)?; - - // Aggregate signals - let result = ensemble.aggregate_signals(); - assert!(result.is_ok()); - - let ensemble_signal = result?; - assert!(ensemble_signal.value > 0.0); - assert!(ensemble_signal.confidence > 0.0); - assert_eq!(ensemble_signal.contributing_models, 2); - } - - #[test] - fn test_insufficient_models() { - let mut config = EnsembleConfig::default(); - config.min_models = 3; - let ensemble = EnsembleModel::new(config)?; - - // Register only 2 models - ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?; - ensemble.register_model( - "model2", - "mean_reversion", - "1.0", - vec!["price".to_string()], - 60, - )?; - - let signal1 = create_test_signal("model1", 0.8, 0.9); - let signal2 = create_test_signal("model2", 0.6, 0.8); - - ensemble.submit_signal(signal1)?; - ensemble.submit_signal(signal2)?; - - // Should fail due to insufficient models - let result = ensemble.aggregate_signals(); - assert!(result.is_err()); - } - - #[test] - fn test_health_check() { - let ensemble = create_test_ensemble(); - - // Initially should be critical (no models) - let health = ensemble.health_check(); - assert_eq!(health.status, HealthStatus::Critical); - - // Register enough models - ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?; - ensemble.register_model( - "model2", - "mean_reversion", - "1.0", - vec!["price".to_string()], - 60, - )?; - ensemble.register_model("model3", "momentum", "1.0", vec!["volume".to_string()], 70)?; - - let health = ensemble.health_check(); - assert_eq!(health.status, HealthStatus::Healthy); - assert_eq!(health.total_models, 3); - } - - #[test] - fn test_model_unregistration() { - let ensemble = create_test_ensemble(); - - ensemble.register_model("model1", "momentum", "1.0", vec!["price".to_string()], 50)?; - assert_eq!(ensemble.list_models().len(), 1); - - ensemble.unregister_model("model1")?; - assert_eq!(ensemble.list_models().len(), 0); - - // Should fail to unregister non-existent model - let result = ensemble.unregister_model("nonexistent"); - assert!(result.is_err()); - } - - #[test] - fn test_market_regime_update() { - let ensemble = create_test_ensemble(); - - ensemble.register_model("momentum", "momentum", "1.0", vec!["price".to_string()], 50)?; - ensemble.register_model( - "mean_rev", - "mean_reversion", - "1.0", - vec!["price".to_string()], - 60, - )?; - - // Update regime and check that it's reflected in metrics - ensemble.update_market_regime(MarketRegime::Trending); - - let metrics = ensemble.get_metrics()?; - assert_eq!(metrics.current_regime, MarketRegime::Trending); - } -} -*/ diff --git a/ml/src/ensemble/voting.rs b/ml/src/ensemble/voting.rs index 17db6e0f3..b872b921a 100644 --- a/ml/src/ensemble/voting.rs +++ b/ml/src/ensemble/voting.rs @@ -83,164 +83,3 @@ pub struct VotingResult { pub strategy_used: VotingStrategy, pub excluded_models: usize, } - -/* -// DISABLED: Tests require proper voting API implementation -// Fix after completing voting system infrastructure -#[cfg(test)] -mod tests { - use super::*; - use std::collections::HashMap; - - fn create_test_signals() -> Vec { - vec![ - ModelSignal { - model_id: "model1".to_string(), - signal: 0.8, - confidence: 0.9, - timestamp: 1000, - metadata: SignalMetadata { - model_version: "1.0".to_string(), - features_used: vec!["price".to_string(), "volume".to_string()], - prediction_horizon: 50, - }, - }, - ModelSignal { - model_id: "model2".to_string(), - signal: 0.6, - confidence: 0.8, - timestamp: 1001, - metadata: SignalMetadata { - model_version: "1.1".to_string(), - features_used: vec!["price".to_string()], - prediction_horizon: 30, - }, - }, - ModelSignal { - model_id: "model3".to_string(), - signal: 0.9, - confidence: 0.95, - timestamp: 1002, - metadata: SignalMetadata { - model_version: "2.0".to_string(), - features_used: vec![ - "price".to_string(), - "volume".to_string(), - "volatility".to_string(), - ], - prediction_horizon: 80, - }, - }, - ] - } - - #[test] - fn test_weighted_average_voting() -> Result<(), MLError> { - let config = VotingConfig::default(); - let mut voter = EnsembleVoter::new(config); - let signals = create_test_signals(); - - let mut weights = HashMap::new(); - weights.insert("model1".to_string(), 0.4); - weights.insert("model2".to_string(), 0.3); - weights.insert("model3".to_string(), 0.3); - - let result = voter.aggregate_signals(&signals, &weights)?; - - assert!(result.signal > 0.0); - assert!(result.confidence > 0.0); - assert_eq!(result.participating_models, 1); - assert_eq!(result.strategy_used, VotingStrategy::WeightedAverage); - Ok(()) - } - - #[test] - fn test_confidence_weighted_voting() -> Result<(), MLError> { - let mut config = VotingConfig::default(); - config.strategy = VotingStrategy::ConfidenceWeighted; - config.dynamic_strategy = false; - - let mut voter = EnsembleVoter::new(config); - let signals = create_test_signals(); - let weights = HashMap::new(); // Empty weights for confidence-weighted - - let result = voter.aggregate_signals(&signals, &weights)?; - - // Model3 has highest confidence, so result should be closer to 0.9 - assert!(result.signal > 0.0); - assert_eq!(result.strategy_used, VotingStrategy::ConfidenceWeighted); - Ok(()) - } - - #[test] - fn test_outlier_rejection() -> Result<(), MLError> { - let mut config = VotingConfig::default(); - config.strategy = VotingStrategy::Robust; - config.dynamic_strategy = false; - config.outlier_threshold = 1.0; // Tight threshold - - let mut voter = EnsembleVoter::new(config); - - // Create signals with one outlier - let mut signals = create_test_signals(); - signals.push(ModelSignal { - model_id: "outlier".to_string(), - signal: 5.0, // Clear outlier - confidence: 0.9, - timestamp: 1003, - metadata: SignalMetadata { - model_version: "2.0".to_string(), - features_used: vec!["experimental".to_string()], - prediction_horizon: 100, - }, - }); - - let weights = HashMap::new(); - let result = voter.aggregate_signals(&signals, &weights)?; - - // Should exclude the outlier - // excluded_models is usize, so >= 0 is always true - assert!(result.signal < 2.0); // Should not be influenced by outlier - Ok(()) - } - - #[test] - fn test_dynamic_strategy_selection() -> Result<(), MLError> { - let mut config = VotingConfig::default(); - config.dynamic_strategy = true; - - let mut voter = EnsembleVoter::new(config); - let signals = create_test_signals(); - let weights = HashMap::new(); - - let result = voter.aggregate_signals(&signals, &weights)?; - - // Strategy should be selected automatically - assert!(matches!( - result.strategy_used, - VotingStrategy::WeightedAverage - | VotingStrategy::ConfidenceWeighted - | VotingStrategy::Adaptive - | VotingStrategy::Robust - )); - Ok(()) - } - - #[test] - fn test_minimum_confidence_threshold() -> Result<(), MLError> { - let mut config = VotingConfig::default(); - config.minimum_confidence = 0.85; // High threshold - config.dynamic_strategy = false; - - let mut voter = EnsembleVoter::new(config); - let signals = create_test_signals(); - let weights = HashMap::new(); - - let result = voter.aggregate_signals(&signals, &weights)?; - - // Should exclude model2 (confidence 0.8) and possibly model1 (confidence 0.9) - // excluded_models and participating_models are usize, so >= 0 is always true - Ok(()) - } -} -*/ diff --git a/ml/src/ensemble/weights.rs b/ml/src/ensemble/weights.rs index d8817bd14..a49f3c7b6 100644 --- a/ml/src/ensemble/weights.rs +++ b/ml/src/ensemble/weights.rs @@ -134,107 +134,3 @@ pub fn calculate_entropy(weights: &HashMap) -> f64 { } entropy } - -/* -// DISABLED: Tests require proper weight management API implementation -// Fix after completing weight management infrastructure -#[cfg(test)] -mod tests { - use super::*; - use std::collections::HashMap; - - #[test] - fn test_model_weights_initialization() { - let weights = ModelWeights::new(); - let model_ids = vec![ - "model1".to_string(), - "model2".to_string(), - "model3".to_string(), - ]; - - weights.initialize_equal_weights(&model_ids); - - assert_eq!(weights.model_count(), 3); - assert!((weights.get_weight("model1") - 1.0 / 3.0).abs() < 1e-10); - assert!((weights.get_weight("model2") - 1.0 / 3.0).abs() < 1e-10); - assert!((weights.get_weight("model3") - 1.0 / 3.0).abs() < 1e-10); - } - - #[test] - fn test_performance_metrics_update() { - let mut metrics = ModelPerformanceMetrics::new("test_model".to_string()); - let config = WeightConfig::default(); - - // Update with good performance - metrics.update_performance(0.1, 100.0, &config); - assert!(metrics.accuracy > 0.5); - assert!(metrics.recent_pnl > 0.0); - - // Update with bad performance - metrics.update_performance(2.0, -50.0, &config); - assert!(metrics.performance_score() > 0.0); // Should still be positive but lower - } - - #[test] - fn test_dynamic_weight_manager() { - let config = WeightConfig::default(); - let manager = DynamicWeightManager::new(config); - - // Register models - manager.register_model("momentum", "momentum")?; - manager.register_model("mean_reversion", "mean_reversion")?; - - // Update performance - manager.update_model_performance("momentum", 0.1, 100.0)?; - manager.update_model_performance("mean_reversion", 0.5, -20.0)?; - - let weights = manager.get_weights(); - assert_eq!(weights.len(), 2); - - // Momentum should have higher weight due to better performance - assert!(weights["momentum"] >= weights["mean_reversion"]); - } - - #[test] - fn test_regime_adaptation() { - let mut config = WeightConfig::default(); - config.regime_adaptation = true; - let manager = DynamicWeightManager::new(config); - - manager.register_model("momentum", "momentum")?; - manager.register_model("mean_reversion", "mean_reversion")?; - - // Set trending regime - should favor momentum - manager.update_market_regime(MarketRegime::Trending); - let weights_trending = manager.get_weights(); - - // Set sideways regime - should favor mean reversion - manager.update_market_regime(MarketRegime::Sideways); - let weights_sideways = manager.get_weights(); - - // In trending markets, momentum models should get higher weights - // In sideways markets, mean reversion models should get higher weights - // (This test assumes the models have similar base performance) - assert_ne!(weights_trending, weights_sideways); - } - - #[test] - fn test_entropy_calculation() { - let mut weights = HashMap::new(); - weights.insert("model1".to_string(), 1.0); - weights.insert("model2".to_string(), 0.0); - weights.insert("model3".to_string(), 0.0); - - let entropy_concentrated = calculate_entropy(&weights); - - weights.insert("model1".to_string(), 1.0 / 3.0); - weights.insert("model2".to_string(), 1.0 / 3.0); - weights.insert("model3".to_string(), 1.0 / 3.0); - - let entropy_uniform = calculate_entropy(&weights); - - // Uniform distribution should have higher entropy - assert!(entropy_uniform > entropy_concentrated); - } -} -*/ diff --git a/ml/src/error.rs b/ml/src/error.rs index c186bbc49..2e45f8c6d 100644 --- a/ml/src/error.rs +++ b/ml/src/error.rs @@ -53,17 +53,14 @@ mod tests { let error_str = inference_error.to_string(); assert!(error_str.contains("Test inference error")); assert!(error_str.contains("test_model")); - // assert_eq!(inference_error.severity(), ErrorSeverity::High); // Commented out - ErrorSeverity not available let training_error = ml_training_error("Test training error", None); let error_str = training_error.to_string(); assert!(error_str.contains("Test training error")); - // assert_eq!(training_error.severity(), ErrorSeverity::High); // Commented out - ErrorSeverity not available let validation_error = ml_validation_error("input", "Invalid input shape"); let error_str = validation_error.to_string(); assert!(error_str.contains("input")); assert!(error_str.contains("Invalid input shape")); - // assert_eq!(validation_error.severity(), ErrorSeverity::Medium); // Commented out - ErrorSeverity not available } } diff --git a/ml/src/examples.rs b/ml/src/examples.rs index 73d6df574..4d59748a7 100644 --- a/ml/src/examples.rs +++ b/ml/src/examples.rs @@ -237,9 +237,6 @@ async fn run_basic_dqn_example(config: &ExampleConfig) -> Result Result { - // TEMPORARILY COMMENTED OUT - Rainbow types not yet available - // use crate::dqn::{RainbowDQNConfig, RainbowDQNAgent}; - // Configure Rainbow DQN with all advanced features #[derive(Debug, Clone)] struct RainbowDQNConfig { @@ -397,9 +394,6 @@ async fn run_rainbow_dqn_example(config: &ExampleConfig) -> Result Result { - // TEMPORARILY COMMENTED OUT - TLOB transformer types not available - // use crate::tlob::{TLOBTransformer, TlobTransformerConfig}; - // PLACEHOLDER IMPLEMENTATION - Transformer types not yet available Ok(ExampleMetrics { score: Decimal::try_from(0.85).unwrap_or(Decimal::ZERO), diff --git a/ml/src/flash_attention/block_sparse.rs b/ml/src/flash_attention/block_sparse.rs index 04ce10b62..f7dc6e5c4 100644 --- a/ml/src/flash_attention/block_sparse.rs +++ b/ml/src/flash_attention/block_sparse.rs @@ -13,7 +13,7 @@ use candle_core::{Device, Tensor, DType, Result as CandleResult}; use crate::error::ModelError; use super::*; use super::{FlashAttention3Config, SparsePatternType}; -// use crate::safe_operations; // DISABLED - module not found + //[test] fn test_block_sparse_pattern_creation() -> Result<(), ModelError> { diff --git a/ml/src/flash_attention/causal_masking.rs b/ml/src/flash_attention/causal_masking.rs index a2f66d8f2..a39ed4ed8 100644 --- a/ml/src/flash_attention/causal_masking.rs +++ b/ml/src/flash_attention/causal_masking.rs @@ -12,7 +12,7 @@ use candle_core::{Device, Tensor, DType, Result as CandleResult}; use crate::error::ModelError; use super::*; use super::FlashAttention3Config; -// use crate::safe_operations; // DISABLED - module not found + //[test] fn test_causal_mask_optimizer_creation() -> Result<(), ModelError> { diff --git a/ml/src/integration/distillation.rs b/ml/src/integration/distillation.rs index 897a38026..a090fcd10 100644 --- a/ml/src/integration/distillation.rs +++ b/ml/src/integration/distillation.rs @@ -10,57 +10,16 @@ mod tests { #[tokio::test] async fn test_distillation_manager_creation() { - // let config = IntegrationHubConfig::default(); - // let manager = DistillationManager::new(&config); - // - // let models = manager.list_student_models().await; - // assert!(models.is_empty()); assert!(true); // Production test } #[tokio::test] async fn test_random_feature_generator() { - // let generator = RandomFeatureGenerator::new(5); - // let features = generator.generate_features().await?; - // assert_eq!(features.len(), 5); - // - // for &feature in &features { - // assert!(feature >= -1.0 && feature <= 1.0); - // } - // - // let names = generator.get_feature_names(); - // assert_eq!(names.len(), 5); - // assert_eq!(names[0], "feature_0"); assert!(true); // Production test } #[test] fn test_dataset_statistics() { - // let samples = vec![ - // TrainingSample { - // features: vec![1.0, 2.0], - // teacher_predictions: vec![0.5], - // teacher_confidence: 0.8, - // hard_target: None, - // sample_weight: 1.0, - // }, - // TrainingSample { - // features: vec![3.0, 4.0], - // teacher_predictions: vec![0.7], - // teacher_confidence: 0.9, - // hard_target: None, - // sample_weight: 1.0, - // }, - // ]; - // - // let config = IntegrationHubConfig::default(); - // let manager = DistillationManager::new(&config); - // let stats = manager.calculate_dataset_statistics(&samples); - // - // assert_eq!(stats.num_samples, 2); - // assert_eq!(stats.num_features, 2); - // assert_eq!(stats.feature_means, vec![2.0, 3.0]); // (1+3)/2, (2+4)/2 - // assert!((stats.target_mean - 0.6).abs() < 1e-6); // (0.5+0.7)/2 assert!(true); // Production test } } diff --git a/ml/src/lib.rs b/ml/src/lib.rs index ffb5d3ec1..a16562143 100644 --- a/ml/src/lib.rs +++ b/ml/src/lib.rs @@ -686,44 +686,6 @@ impl From for MLError { } } -// NOTE: Commented out workspace dependency - will be re-enabled when workspace is available -// impl From for MLError { -// fn from(err: error_handling::TradingError) -> Self { -// match err { -// error_handling::TradingError::InvalidPrice { value, reason } => { -// MLError::ValidationError { -// message: format!("Invalid price {}: {}", value, reason), -// } -// } -// error_handling::TradingError::InvalidQuantity { value, reason } => { -// MLError::ValidationError { -// message: format!("Invalid quantity {}: {}", value, reason), -// } -// } -// error_handling::TradingError::FinancialSafety { message, .. } => { -// MLError::ValidationError { -// message: format!("Financial safety error: {}", message), -// } -// } -// error_handling::TradingError::DivisionByZero { operation } => { -// MLError::ValidationError { -// message: format!("Division by zero in {}", operation), -// } -// } -// error_handling::TradingError::ModelInference { reason, model } => { -// MLError::InferenceError(format!("Model inference error for {}: {}", model, reason)) -// } -// error_handling::TradingError::GpuComputation { reason, operation } => { -// let msg = match operation { -// Some(op) => format!("GPU computation error ({}): {}", op, reason), -// None => format!("GPU computation error: {}", reason), -// }; -// MLError::ModelError(msg) -// } -// other => MLError::ModelError(format!("Trading error: {}", other)), -// } -// } -// } // Implement From trait for anyhow::Error impl From for MLError { fn from(err: anyhow::Error) -> Self { diff --git a/ml/src/liquid/activation.rs b/ml/src/liquid/activation.rs index 2b2888f6e..0497c52f4 100644 --- a/ml/src/liquid/activation.rs +++ b/ml/src/liquid/activation.rs @@ -191,7 +191,7 @@ pub mod derivatives { mod tests { use super::*; use crate::liquid::PRECISION; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_sigmoid() -> Result<()> { diff --git a/ml/src/liquid/cells.rs b/ml/src/liquid/cells.rs index 1af146a26..2140a59ae 100644 --- a/ml/src/liquid/cells.rs +++ b/ml/src/liquid/cells.rs @@ -426,7 +426,7 @@ mod tests { use crate::liquid::activation::ActivationType; use crate::liquid::ode_solvers::SolverType; use crate::liquid::PRECISION; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_ltc_cell_creation() -> Result<()> { diff --git a/ml/src/liquid/network.rs b/ml/src/liquid/network.rs index bd5e89b0a..24661a6cb 100644 --- a/ml/src/liquid/network.rs +++ b/ml/src/liquid/network.rs @@ -373,7 +373,7 @@ mod tests { use crate::liquid::ode_solvers::SolverType; use crate::liquid::PRECISION; use common::trading::MarketRegime; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_liquid_network_creation() -> Result<()> { diff --git a/ml/src/liquid/ode_solvers.rs b/ml/src/liquid/ode_solvers.rs index bc60b6a0d..f58827308 100644 --- a/ml/src/liquid/ode_solvers.rs +++ b/ml/src/liquid/ode_solvers.rs @@ -332,7 +332,7 @@ mod tests { use super::*; use crate::liquid::PRECISION; use common::trading::MarketRegime; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_euler_solver() -> Result<()> { diff --git a/ml/src/liquid/training.rs b/ml/src/liquid/training.rs index 911cb110a..2473c985f 100644 --- a/ml/src/liquid/training.rs +++ b/ml/src/liquid/training.rs @@ -535,7 +535,7 @@ impl TrainingUtils { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_training_batch_creation() -> Result<()> { diff --git a/ml/src/microstructure/advanced_models.rs b/ml/src/microstructure/advanced_models.rs index 6ab920bf7..f385242f9 100644 --- a/ml/src/microstructure/advanced_models.rs +++ b/ml/src/microstructure/advanced_models.rs @@ -20,14 +20,13 @@ use std::time::{Duration, Instant}; use candle_core::Device; use candle_core::{Tensor, Device, DType, Result as CandleResult}; use candle_nn::{Linear, LayerNorm, Dropout, Module, VarBuilder}; -// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist use ndarray::{Array1, Array2, Array3, ArrayView1, ArrayView2, s!}; use serde::{Deserialize, Serialize}; use crate::{MLAppResult, InferenceResult, ModelMetadata}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_feature_extractor_creation() { diff --git a/ml/src/microstructure/advanced_models_extended.rs b/ml/src/microstructure/advanced_models_extended.rs index cccbc5878..af6587701 100644 --- a/ml/src/microstructure/advanced_models_extended.rs +++ b/ml/src/microstructure/advanced_models_extended.rs @@ -13,7 +13,6 @@ use std::time::{Duration, Instant}; use candle_core::{Tensor, Device, DType, Result as CandleResult}; use candle_nn::{Linear, LayerNorm, Dropout, Module, VarBuilder}; -// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist use ndarray::{Array1, Array2, Array3, ArrayView1, ArrayView2, s!}; use serde::{Deserialize, Serialize}; @@ -21,7 +20,7 @@ use crate::{MLAppResult, InferenceResult, ModelMetadata}; use super::*; use super::advanced_models::{ use super::{MicrostructureResult, MarketDataUpdate, TradeDirection, MAX_CALCULATION_LATENCY_US}; -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_market_regime_encoding() { diff --git a/ml/src/microstructure/amihud.rs b/ml/src/microstructure/amihud.rs index f2e5dcc32..7819f1c94 100644 --- a/ml/src/microstructure/amihud.rs +++ b/ml/src/microstructure/amihud.rs @@ -24,7 +24,7 @@ use serde::{Deserialize, Serialize}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_amihud_measure_creation() { diff --git a/ml/src/microstructure/benchmarks.rs b/ml/src/microstructure/benchmarks.rs index a7de6d459..690b756ba 100644 --- a/ml/src/microstructure/benchmarks.rs +++ b/ml/src/microstructure/benchmarks.rs @@ -13,7 +13,7 @@ use tokio; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + /// Generate realistic market data for testing (replaces synthetic generation) /// Based on realistic market microstructure patterns diff --git a/ml/src/microstructure/hasbrouck.rs b/ml/src/microstructure/hasbrouck.rs index 9bf694454..e518046b5 100644 --- a/ml/src/microstructure/hasbrouck.rs +++ b/ml/src/microstructure/hasbrouck.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_hasbrouck_creation() { diff --git a/ml/src/microstructure/integration.rs b/ml/src/microstructure/integration.rs index e3d3458cf..5230ae14d 100644 --- a/ml/src/microstructure/integration.rs +++ b/ml/src/microstructure/integration.rs @@ -13,7 +13,7 @@ use tokio; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[tokio::test] async fn test_microstructure_engine_creation() { diff --git a/ml/src/microstructure/kyle_lambda.rs b/ml/src/microstructure/kyle_lambda.rs index 516b57305..3477acae7 100644 --- a/ml/src/microstructure/kyle_lambda.rs +++ b/ml/src/microstructure/kyle_lambda.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_kyle_lambda_estimator_creation() { diff --git a/ml/src/microstructure/ml_integration.rs b/ml/src/microstructure/ml_integration.rs index 5df59cb9f..ef0d86238 100644 --- a/ml/src/microstructure/ml_integration.rs +++ b/ml/src/microstructure/ml_integration.rs @@ -10,7 +10,6 @@ use std::time::Instant; use candle_core::Device; use candle_core::{Device, VarBuilder}; -// use error_handling::{FoxhuntError, ErrorSeverity, AppResult}; // Commented out - crate doesn't exist use serde::{Deserialize, Serialize}; use tokio::sync::{RwLock, Mutex}; diff --git a/ml/src/microstructure/mod.rs b/ml/src/microstructure/mod.rs index 4dd0a4eaf..127dcde94 100644 --- a/ml/src/microstructure/mod.rs +++ b/ml/src/microstructure/mod.rs @@ -37,8 +37,6 @@ //! - Memory efficiency: Zero-allocation hot paths //! - Integer arithmetic: 10,000x scaling for financial precision -// use error_handling::{AppResult, ErrorSeverity, FoxhuntError}; // Commented out - crate doesn't exist - // VPIN Implementation Module pub mod vpin_implementation; diff --git a/ml/src/microstructure/portfolio_integration.rs b/ml/src/microstructure/portfolio_integration.rs index 35d3e2d8d..851c2ff09 100644 --- a/ml/src/microstructure/portfolio_integration.rs +++ b/ml/src/microstructure/portfolio_integration.rs @@ -16,7 +16,6 @@ use std::{ use candle_core::Device; use candle_core::{Device, Tensor}; use chrono::{DateTime, Utc}; -// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist use portfolio_management::advanced_black_litterman::{ use serde::{Serialize, Deserialize}; use tokio::sync::RwLock; @@ -26,7 +25,7 @@ use crate::portfolio_transformer::{PortfolioTransformer, PortfolioState, Portfol use crate::portfolio_transformer::{PortfolioTransformerConfig}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + async fn create_test_integrator() -> Result> { let portfolio_config = PortfolioTransformerConfig::nano(); diff --git a/ml/src/microstructure/roll_spread.rs b/ml/src/microstructure/roll_spread.rs index e01173ccf..cf9e5d8e8 100644 --- a/ml/src/microstructure/roll_spread.rs +++ b/ml/src/microstructure/roll_spread.rs @@ -25,7 +25,7 @@ use common::types::Price; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_roll_spread_estimator_creation() { diff --git a/ml/src/microstructure/training_pipeline.rs b/ml/src/microstructure/training_pipeline.rs index 77ec3ec2b..0477fc523 100644 --- a/ml/src/microstructure/training_pipeline.rs +++ b/ml/src/microstructure/training_pipeline.rs @@ -16,7 +16,6 @@ use std::{ use candle_core::{Device, Tensor, DType}; use candle_nn::{VarBuilder, VarMap}; use chrono::{DateTime, Duration, Duration as ChronoDuration, NaiveDate, Utc}; -// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist use ndarray::Array2; // REMOVED: Polygon imports - replaced with Databento{ use serde::{Serialize, Deserialize}; @@ -25,7 +24,7 @@ use tracing::{debug, info, warn, error, instrument}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[tokio::test] async fn test_training_pipeline_creation() { diff --git a/ml/src/microstructure/vpin.rs b/ml/src/microstructure/vpin.rs index ab528413b..a152ed126 100644 --- a/ml/src/microstructure/vpin.rs +++ b/ml/src/microstructure/vpin.rs @@ -23,7 +23,7 @@ use serde::{Deserialize, Serialize}; use super::*; use super::{ -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_vpin_calculator_creation() { diff --git a/ml/src/model.rs b/ml/src/model.rs index 421905068..cec4fc179 100644 --- a/ml/src/model.rs +++ b/ml/src/model.rs @@ -2,117 +2,3 @@ //! //! This module provides actual neural network implementations using the Candle framework //! for production-ready HFT models. - -// DISABLED: Tests require ModelConfig, RealMLModel, Device, TrainingConfig types not available -// #[cfg(test)] -// mod tests { -// use super::*; -// use anyhow::anyhow; -// -// #[tokio::test] -// async fn test_real_model_creation() { -// let config = ModelConfig::default(); -// let model = -// RealMLModel::new(config).map_err(|e| anyhow!("Failed to create model: {:?}", e))?; -// -// assert!(!model.is_trained); -// assert_eq!( -// model.metadata.model_type, -// MLModelType::Custom("MLP".to_string()) -// ); -// assert_eq!(model.network.config.input_dim, 16); -// } -// -// #[tokio::test] -// async fn test_synthetic_data_generation() { -// let device = Device::Cpu; -// let (inputs, targets) = create_synthetic_training_data(&device, 100, 16, 1) -// .map_err(|e| anyhow!("Failed to create synthetic data: {:?}", e))?; -// -// assert_eq!(inputs.dims(), &[100, 16]); -// assert_eq!(targets.dims(), &[1, 100]); -// } -// -// #[tokio::test] -// async fn test_model_training() { -// let config = ModelConfig { -// input_dim: 8, -// hidden_dims: vec![16, 8], -// output_dim: 1, -// learning_rate: 0.01, -// batch_size: 32, -// }; -// -// let mut model = -// RealMLModel::new(config).map_err(|e| anyhow!("Failed to create model: {:?}", e))?; -// let device = model.device.clone(); -// -// // Create small dataset for quick test -// let (train_x, train_y) = create_synthetic_training_data(&device, 64, 8, 1) -// .map_err(|e| anyhow!("Failed to create training data: {:?}", e))?; -// -// // Train for few epochs -// let metrics = model -// .train(&train_x, &train_y, 10) -// .await -// .map_err(|e| anyhow!("Training failed: {:?}", e))?; -// -// assert!(model.is_trained); -// assert_eq!(metrics.epochs_trained, 10); -// assert!(metrics.train_loss >= 0.0); -// assert!(metrics.training_time_seconds > 0.0); -// } -// -// #[tokio::test] -// async fn test_real_training_pipeline() { -// let training_config = TrainingConfig { -// epochs: 5, -// learning_rate: 0.01, -// ..Default::default() -// }; -// -// let mut pipeline = RealTrainingPipeline::new(training_config); -// -// // Add two models -// let model1 = RealMLModel::new(ModelConfig { -// input_dim: 4, -// hidden_dims: vec![8], -// output_dim: 1, -// ..Default::default() -// }) -// .map_err(|e| anyhow!("Failed to create model 1: {:?}", e))?; -// -// let model2 = RealMLModel::new(ModelConfig { -// input_dim: 4, -// hidden_dims: vec![8, 4], -// output_dim: 1, -// ..Default::default() -// }) -// .map_err(|e| anyhow!("Failed to create model 2: {:?}", e))?; -// -// pipeline.add_model("model1".to_string(), model1); -// pipeline.add_model("model2".to_string(), model2); -// -// // Create training data -// let device = Device::Cpu; -// let (train_x, train_y) = create_synthetic_training_data(&device, 32, 4, 1) -// .map_err(|e| anyhow!("Failed to create training data: {:?}", e))?; -// -// // Train all models -// let results = pipeline -// .train_all(&train_x, &train_y) -// .await -// .map_err(|e| anyhow!("Pipeline training failed: {:?}", e))?; -// -// assert_eq!(results.len(), 2); -// assert!(results.contains_key("model1")); -// assert!(results.contains_key("model2")); -// -// // Test predictions -// let predictions = pipeline -// .predict_all(&train_x) -// .map_err(|e| anyhow!("Prediction failed: {:?}", e))?; -// -// assert_eq!(predictions.len(), 2); -// } -// } diff --git a/ml/src/performance.rs b/ml/src/performance.rs index d93619813..8e2a789e5 100644 --- a/ml/src/performance.rs +++ b/ml/src/performance.rs @@ -405,7 +405,7 @@ impl ZeroCopyOps { mod tests { use super::*; use std::mem::align_of; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_aligned_buffer() -> Result<(), MLError> { diff --git a/ml/src/ppo/gae.rs b/ml/src/ppo/gae.rs index 443a86e1f..c5d70826b 100644 --- a/ml/src/ppo/gae.rs +++ b/ml/src/ppo/gae.rs @@ -289,7 +289,7 @@ mod tests { use super::*; use crate::dqn::TradingAction; use crate::ppo::trajectories::{Trajectory, TrajectoryStep}; - // use crate::safe_operations; // DISABLED - module not found + fn create_test_trajectory() -> Trajectory { let mut trajectory = Trajectory::new(); diff --git a/ml/src/ppo/trajectories.rs b/ml/src/ppo/trajectories.rs index 892b8cbbe..b6da007c8 100644 --- a/ml/src/ppo/trajectories.rs +++ b/ml/src/ppo/trajectories.rs @@ -527,7 +527,7 @@ where #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_trajectory_creation() { diff --git a/ml/src/production.rs b/ml/src/production.rs index 88e8afe4d..0f890a5a7 100644 --- a/ml/src/production.rs +++ b/ml/src/production.rs @@ -8,8 +8,6 @@ //! - Performance monitoring and rollback //! - Sub-100μs inference optimization -// use crate::safe_operations; // DISABLED - module not found - #[cfg(test)] mod tests { use anyhow::Result; diff --git a/ml/src/risk/advanced_risk_engine.rs b/ml/src/risk/advanced_risk_engine.rs index 4d2168e31..687455740 100644 --- a/ml/src/risk/advanced_risk_engine.rs +++ b/ml/src/risk/advanced_risk_engine.rs @@ -18,8 +18,6 @@ use thiserror::Error; use tokio::sync::mpsc; use crate::{MLResult, MLError}; -// use crate::safe_operations; // DISABLED - module not found - /// Monte Carlo simulation for VaR calculation pub fn simulate_random_shock(volatility: f64) -> f64 { let mut rng = rand::thread_rng(); diff --git a/ml/src/risk/circuit_breakers.rs b/ml/src/risk/circuit_breakers.rs index c370717f2..62273c29b 100644 --- a/ml/src/risk/circuit_breakers.rs +++ b/ml/src/risk/circuit_breakers.rs @@ -357,7 +357,7 @@ impl MLCircuitBreaker { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_circuit_breaker_creation() -> Result<()> { diff --git a/ml/src/risk/extreme_value_models.rs b/ml/src/risk/extreme_value_models.rs index 836e40038..522b7f89b 100644 --- a/ml/src/risk/extreme_value_models.rs +++ b/ml/src/risk/extreme_value_models.rs @@ -25,7 +25,7 @@ use chrono::{DateTime, Utc}; use serde::{Deserialize, Serialize}; use super::*; -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_neural_evt_model_creation() { diff --git a/ml/src/risk/kelly_optimizer.rs b/ml/src/risk/kelly_optimizer.rs index 864671c63..bf203dee3 100644 --- a/ml/src/risk/kelly_optimizer.rs +++ b/ml/src/risk/kelly_optimizer.rs @@ -210,7 +210,7 @@ impl KellyCriterionOptimizer { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_basic_kelly_calculation() -> Result<()> { diff --git a/ml/src/risk/lstm_gan_scenarios.rs b/ml/src/risk/lstm_gan_scenarios.rs index 940b330b3..d548f69a4 100644 --- a/ml/src/risk/lstm_gan_scenarios.rs +++ b/ml/src/risk/lstm_gan_scenarios.rs @@ -24,7 +24,7 @@ use super::*; #[cfg(test)] mod tests { use super::*; -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_lstm_layer_creation() { diff --git a/ml/src/risk/monitor.rs b/ml/src/risk/monitor.rs index 60cd583b1..010989130 100644 --- a/ml/src/risk/monitor.rs +++ b/ml/src/risk/monitor.rs @@ -137,7 +137,7 @@ impl RealTimeMonitor { mod tests { use super::*; use tokio::test; -// use crate::safe_operations; // DISABLED - module not found + #[test] async fn test_monitor_creation() { diff --git a/ml/src/risk/position_sizing.rs b/ml/src/risk/position_sizing.rs index 47118b21f..525951f71 100644 --- a/ml/src/risk/position_sizing.rs +++ b/ml/src/risk/position_sizing.rs @@ -7,9 +7,7 @@ use ndarray::Array1; use crate::MLResult as Result; -// Import and re-export canonical types -// pub use common::position_sizing::PositionSizingRecommendation; // Commented out - module not available -// Using placeholder type +// Using placeholder type for PositionSizingRecommendation #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct PositionSizingRecommendation { pub recommended_size: f64, diff --git a/ml/src/risk/var_models.rs b/ml/src/risk/var_models.rs index c13b7cdfe..774336f5a 100644 --- a/ml/src/risk/var_models.rs +++ b/ml/src/risk/var_models.rs @@ -308,7 +308,7 @@ impl FeatureScaler { #[cfg(test)] mod tests { use super::*; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_neural_var_model_creation() -> Result<()> { diff --git a/ml/src/tft/gated_residual.rs b/ml/src/tft/gated_residual.rs index 747e3e9cf..0b9820c05 100644 --- a/ml/src/tft/gated_residual.rs +++ b/ml/src/tft/gated_residual.rs @@ -213,7 +213,7 @@ impl GRNStack { mod tests { use super::*; use candle_core::{DType, Device}; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_grn_creation() -> Result<(), MLError> { diff --git a/ml/src/tft/hft_optimizations.rs b/ml/src/tft/hft_optimizations.rs index 90fc11e87..1e7926b81 100644 --- a/ml/src/tft/hft_optimizations.rs +++ b/ml/src/tft/hft_optimizations.rs @@ -779,7 +779,7 @@ pub struct LatencyPercentiles { mod tests { use super::*; use candle_core::DType; - // use crate::safe_operations; // DISABLED - module not found + //[test] fn test_memory_pool_allocation() { diff --git a/ml/src/tft/quantile_outputs.rs b/ml/src/tft/quantile_outputs.rs index f13a78df1..0b53beb79 100644 --- a/ml/src/tft/quantile_outputs.rs +++ b/ml/src/tft/quantile_outputs.rs @@ -252,7 +252,7 @@ impl QuantileLayer { mod tests { use super::*; use candle_core::{DType, Device}; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_quantile_layer_creation() -> Result<(), MLError> { diff --git a/ml/src/tft/variable_selection.rs b/ml/src/tft/variable_selection.rs index fe72d450f..54ca2be5d 100644 --- a/ml/src/tft/variable_selection.rs +++ b/ml/src/tft/variable_selection.rs @@ -198,7 +198,7 @@ impl VariableSelectionNetwork { mod tests { use super::*; use candle_core::DType; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_variable_selection_network_creation() -> Result<(), MLError> { diff --git a/ml/src/tlob/transformer.rs b/ml/src/tlob/transformer.rs index a94b0ef06..b4fd252f6 100644 --- a/ml/src/tlob/transformer.rs +++ b/ml/src/tlob/transformer.rs @@ -316,7 +316,7 @@ impl TLOBTransformer { mod tests { use super::*; use std::thread; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_tlob_transformer_creation() -> Result<(), MLError> { diff --git a/ml/src/training/dqn_trainer.rs b/ml/src/training/dqn_trainer.rs index 487745662..ae8c6d62e 100644 --- a/ml/src/training/dqn_trainer.rs +++ b/ml/src/training/dqn_trainer.rs @@ -7,7 +7,6 @@ use std::collections::{HashMap, VecDeque}; use std::sync::Arc; use chrono::{DateTime, Utc}; -// use error_handling::{FoxhuntError, AppResult, ErrorSeverity}; // Commented out - crate doesn't exist use rand::prelude::*; // Replace common::rng with standard rand use ndarray::{Array1, Array2, Axis, s}; use serde::{Serialize, Deserialize}; diff --git a/ml/src/training/transformer_trainer.rs b/ml/src/training/transformer_trainer.rs index bc8865b6b..377e5e746 100644 --- a/ml/src/training/transformer_trainer.rs +++ b/ml/src/training/transformer_trainer.rs @@ -7,7 +7,6 @@ use std::collections::{HashMap, VecDeque}; use std::sync::Arc; use chrono::{DateTime, Utc}; -// use error_handling::{FoxhuntError, AppResult, ErrorSeverity}; // Commented out - crate doesn't exist use rand::prelude::*; // Replace common::rng with standard rand use ndarray::{Array1, Array2, Array3, Axis, s}; use serde::{Serialize, Deserialize}; diff --git a/ml/src/training/unified_data_loader.rs b/ml/src/training/unified_data_loader.rs index 6b04965d3..d419e0f70 100644 --- a/ml/src/training/unified_data_loader.rs +++ b/ml/src/training/unified_data_loader.rs @@ -23,8 +23,7 @@ use tracing::{debug, info}; use crate::safety::MLSafetyManager; use crate::{MLError, MLResult}; use common::types::{Price, Symbol, Volume}; -// use adaptive_strategy::microstructure::OrderLevel; // Commented out - crate not available -// Using placeholder OrderLevel type instead +// Using placeholder OrderLevel type #[derive(Debug, Clone, serde::Serialize, serde::Deserialize)] pub struct OrderLevel { pub price: f64, diff --git a/ml/src/training_pipeline.rs b/ml/src/training_pipeline.rs index 32ee0113f..325a9433e 100644 --- a/ml/src/training_pipeline.rs +++ b/ml/src/training_pipeline.rs @@ -21,8 +21,6 @@ use tokio::sync::{Mutex, RwLock}; use tracing::{error, info, warn}; use uuid::Uuid; -// use error_handling::{AppResult, TradingError}; // Commented out - crate doesn't exist - use crate::safety::{ GradientSafetyConfig, GradientSafetyManager, GradientStatistics, MLSafetyConfig, MLSafetyManager, SafetyResult, diff --git a/ml/src/transformers/attention.rs b/ml/src/transformers/attention.rs index eb7a5c156..768766b7a 100644 --- a/ml/src/transformers/attention.rs +++ b/ml/src/transformers/attention.rs @@ -5,7 +5,7 @@ #[cfg(test)] mod tests { use crate::tft::temporal_attention::AttentionConfig; - // use crate::safe_operations; // DISABLED - module not found + #[test] fn test_attention_config() { diff --git a/ml/src/transformers/features.rs b/ml/src/transformers/features.rs index 54b1c9dae..20f670629 100644 --- a/ml/src/transformers/features.rs +++ b/ml/src/transformers/features.rs @@ -26,7 +26,7 @@ use chrono::{DateTime, Datelike, Timelike, Utc}; use serde::{Deserialize, Serialize}; use super::*; -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_feature_config_default() { diff --git a/ml/src/transformers/financial_transformer.rs b/ml/src/transformers/financial_transformer.rs index 8379fe676..456b7faed 100644 --- a/ml/src/transformers/financial_transformer.rs +++ b/ml/src/transformers/financial_transformer.rs @@ -10,7 +10,7 @@ use serde::{Deserialize, Serialize}; use crate::{MLAppResult, TrainingMetrics}; use super::*; -// use crate::safe_operations; // DISABLED - module not found + #[tokio::test] async fn test_financial_transformer_creation() { diff --git a/ml/src/transformers/hft_transformer.rs b/ml/src/transformers/hft_transformer.rs index 6457692b4..d43dd15f9 100644 --- a/ml/src/transformers/hft_transformer.rs +++ b/ml/src/transformers/hft_transformer.rs @@ -21,13 +21,11 @@ use async_trait::async_trait; use candle_core::Device; use candle_core::{Device, Tensor, DType, Result as CandleResult, Module}; use candle_nn::{Linear, LayerNorm, Activation, VarBuilder, VarMap}; -// use error_handling::{FoxhuntError, AppResult}; // Commented out - crate doesn't exist use serde::{Serialize, Deserialize}; use tracing::{info, debug, warn, error}; use crate::{traits::MLModel, ModelMetadata, InferenceResult, TrainingMetrics, ValidationMetrics}; use super::*; -// use crate::safe_operations; // DISABLED - module not found #[tokio::test] async fn test_hft_transformer_creation() { diff --git a/ml/src/transformers/quantization.rs b/ml/src/transformers/quantization.rs index b0a382024..ea32ab37d 100644 --- a/ml/src/transformers/quantization.rs +++ b/ml/src/transformers/quantization.rs @@ -5,14 +5,13 @@ use candle_core::Device; use candle_core::{Device, Result as CandleResult, Tensor}; -// use error_handling::AppResult; // Commented out - crate doesn't exist use serde::{Deserialize, Serialize}; use tracing::{info, warn}; use tracing::{info, warn}; use tracing::{info, warn}; use super::*; -// use crate::safe_operations; // DISABLED - module not found + #[test] fn test_quantization_config() {