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
This commit is contained in:
@@ -13,6 +13,7 @@ from optimizr.hmm import HMM
|
||||
from optimizr.core import (
|
||||
mcmc_sample,
|
||||
differential_evolution,
|
||||
parallel_differential_evolution_rust,
|
||||
grid_search,
|
||||
mutual_information,
|
||||
shannon_entropy,
|
||||
@@ -30,6 +31,12 @@ from optimizr.core import (
|
||||
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
|
||||
@@ -44,6 +51,7 @@ __all__ = [
|
||||
"HMM",
|
||||
"mcmc_sample",
|
||||
"differential_evolution",
|
||||
"parallel_differential_evolution_rust",
|
||||
"grid_search",
|
||||
"mutual_information",
|
||||
"shannon_entropy",
|
||||
@@ -61,5 +69,11 @@ __all__ = [
|
||||
"return_statistics_py",
|
||||
"create_lagged_features_py",
|
||||
"rolling_correlation_py",
|
||||
# Benchmark functions
|
||||
"Sphere",
|
||||
"Rosenbrock",
|
||||
"Rastrigin",
|
||||
"Ackley",
|
||||
"Griewank",
|
||||
"maths_toolkit",
|
||||
]
|
||||
|
||||
@@ -11,6 +11,7 @@ try:
|
||||
from optimizr._core import (
|
||||
mcmc_sample as _rust_mcmc_sample,
|
||||
differential_evolution as _rust_differential_evolution,
|
||||
parallel_differential_evolution_rust,
|
||||
grid_search as _rust_grid_search,
|
||||
mutual_information as _rust_mutual_information,
|
||||
shannon_entropy as _rust_shannon_entropy,
|
||||
@@ -28,6 +29,12 @@ try:
|
||||
return_statistics_py,
|
||||
create_lagged_features_py,
|
||||
rolling_correlation_py,
|
||||
# Benchmark functions
|
||||
Sphere,
|
||||
Rosenbrock,
|
||||
Rastrigin,
|
||||
Ackley,
|
||||
Griewank,
|
||||
)
|
||||
RUST_AVAILABLE = True
|
||||
except ImportError:
|
||||
|
||||
Reference in New Issue
Block a user