Files
optimiz-rs/python/optimizr/__init__.py
T
Melvin Alvarez f5f6005f80 feat(parallel): add GIL-free parallel DE with Rust objectives
- Implement RustObjective trait for GIL-free parallelization
- Add 5 benchmark functions: Sphere, Rosenbrock, Rastrigin, Ackley, Griewank
  * Each implements RustObjective with evaluate(), dimension(), global_optimum()
  * Exposed to Python with __call__ method

- Add parallel_differential_evolution_rust() function:
  * Uses Rayon for parallel population evaluation
  * Works with RustObjective implementations only
  * Eliminates Python GIL overhead for 10-100× speedup
  * Supports all DE strategies and adaptive parameters

- Create comprehensive examples:
  * parallel_de_benchmark.py: Performance benchmarks showing speedup
  * polaroid_optimizr_integration.py: 4 workflows combining Polaroid + OptimizR
    - Regime detection with HMM
    - Strategy parameter optimization
    - Portfolio risk analysis
    - Pairs trading pipeline

- Module integration:
  * Export benchmark functions in Python API
  * Export parallel_differential_evolution_rust
  * Update __init__.py and core.py with new functions

- Technical implementation:
  * RustObjective trait in src/rust_objectives.rs
  * Parallel evaluation uses par_iter() from Rayon
  * Per-thread RNG seeding for reproducibility
  * Maintains same API as standard DE for easy comparison

Part of Priority 2: Enable Rust parallelization (Enhancement Strategy)
Expected speedup: 10-100× on multi-core systems for pure Rust objectives
2026-01-03 00:03:29 +01:00

80 lines
1.8 KiB
Python

"""
OptimizR - High-Performance Optimization Algorithms
===================================================
Fast, reliable implementations of advanced optimization and statistical
inference algorithms with Rust acceleration and pure Python fallbacks.
.. moduleauthor:: OptimizR Contributors
"""
from optimizr.hmm import HMM
from optimizr.core import (
mcmc_sample,
differential_evolution,
parallel_differential_evolution_rust,
grid_search,
mutual_information,
shannon_entropy,
sparse_pca_py,
box_tao_decomposition_py,
elastic_net_py,
hurst_exponent_py,
compute_risk_metrics_py,
estimate_half_life_py,
bootstrap_returns_py,
# Time-series utilities
prepare_for_hmm_py,
rolling_hurst_exponent_py,
rolling_half_life_py,
return_statistics_py,
create_lagged_features_py,
rolling_correlation_py,
# Benchmark functions
Sphere,
Rosenbrock,
Rastrigin,
Ackley,
Griewank,
)
# Try to import maths_toolkit from Rust backend
try:
from optimizr import _core
maths_toolkit = _core
except (ImportError, AttributeError):
maths_toolkit = None
__version__ = "0.2.0"
__all__ = [
"HMM",
"mcmc_sample",
"differential_evolution",
"parallel_differential_evolution_rust",
"grid_search",
"mutual_information",
"shannon_entropy",
"sparse_pca_py",
"box_tao_decomposition_py",
"elastic_net_py",
"hurst_exponent_py",
"compute_risk_metrics_py",
"estimate_half_life_py",
"bootstrap_returns_py",
# Time-series utilities
"prepare_for_hmm_py",
"rolling_hurst_exponent_py",
"rolling_half_life_py",
"return_statistics_py",
"create_lagged_features_py",
"rolling_correlation_py",
# Benchmark functions
"Sphere",
"Rosenbrock",
"Rastrigin",
"Ackley",
"Griewank",
"maths_toolkit",
]