OptiRS Core
Core optimization algorithms and utilities for the OptiRS machine learning optimization library.
Overview
OptiRS-Core provides the foundational optimization algorithms and mathematical utilities that power the entire OptiRS ecosystem. This crate integrates deeply with the SciRS2 scientific computing foundation and implements state-of-the-art optimization algorithms with high performance and numerical stability.
Features
- 26 Optimizer Implementations: 22 implement
optimizers::Optimizer(first-order methods, quasi-Newton L-BFGS, and meta-learning optimizers MAML/Reptile/Meta-SGD/NTM). 4 more live insecond_orderas a separate family: Newton and a second, independent L-BFGS implementSecondOrderOptimizer; Newton-CG and K-FAC expose their ownstepAPI instead - 100% SciRS2 Integration: Built exclusively on SciRS2's scientific computing primitives
- SIMD & Parallel: SIMD-accelerated (
SimdSGD) and multi-core (parallel_optimizer) paths via scirs2-core, measured by thesimd_benchmarks/parallel_benchmarksCriterion suites - Performance Monitoring: Built-in metrics via
optimizer_metrics, optionalscirs2-metricsintegration behind themetrics-integrationfeature - Serialization: Complete Serde support for checkpointing and model persistence
- Memory Efficient: Gradient accumulation, chunked processing for billion-parameter models
- Federated Optimization:
FedProxOptimizerwith proximal term (mu=0 degenerates to FedAvg) - Vision Transformer Support:
ViTLayerDecayscheduler for per-layer exponential LR decay - Attention-Aware Scheduling:
AttentionAwareScheduler- component-specific LR scaling for Transformer models - Gradient Flow Analysis:
GradientFlowAnalyzerwith vanishing/exploding detection and SVG visualization - Loss Landscape Analysis: 2D perturbation analysis, sharpness computation, saddle point detection
- 2202 Tests Passing: library + integration tests (
cargo nextest run -p optirs-core --all-features), plus 95 passing doc tests
Optimization Algorithms
Optimizers
Commonly used: SGD, Adam, AdamW, RMSprop, Adagrad, AdaDelta, AdaBound, LAMB, LARS, Lion, SAM,
RAdam, Ranger, Lookahead, SparseAdam, GroupedAdam, L-BFGS, Newton, Newton-CG, K-FAC, and the
meta-learning optimizers MAML, Reptile, Meta-SGD and NTM. second_order also has a second,
independent L-BFGS implementation (re-exported as SecondOrderLBFGS) alongside Newton.
See the crate documentation (cargo doc -p optirs-core --open) for the complete, categorized
list of all 26 optimizers.
Advanced Features
- Learning rate scheduling and decay (
optirs_core::schedulers- see the crate docs for the full list of schedulers) - Gradient clipping and normalization
- Warm-up and cooldown strategies
- Numerical stability guarantees
- Memory-efficient implementations
Dependencies
Required Dependencies (SciRS2 Ecosystem)
scirs2-core0.6.5: Foundation scientific primitives (REQUIRED)- Provides: arrays, random, numeric traits, SIMD, parallel ops, GPU abstractions
scirs2-optimize0.6.5: Base optimization interfaces (REQUIRED)scirs2-neural: Required by specific modules (e.g.neuromorphic)scirs2-stats: Required by distribution-based regularizers
Optional SciRS2 Dependencies
scirs2-metrics: Behind themetrics-integrationfeaturescirs2-datasets: Behind thecross-platform-testingfeature
External Dependencies
serde,serde_json,toml: Serialization / config parsingthiserror: Error handlingchrono,sha2,oxicode,x25519-dalek,log: checkpoint storage, hashing, and secure-aggregation supportrsa(optional, behind thecryptofeature): plugin signature verification- Dev-only:
approx,criterion,tempfile(testing and benchmarking)
Note: OptiRS does NOT use scirs2-autograd. OptiRS receives pre-computed gradients and does not perform automatic differentiation.
Usage
Add this to your Cargo.toml:
[]
= "0.3.2"
= "0.6.5" # Required foundation
Basic Example
use ;
use Array1; // ✅ CORRECT - Use scirs2_core
With Learning Rate Scheduling
use ;
use ;
use ;
Cargo Features
Default Features
std: Standard library support (enabled by default)
Optional Features
cross-platform-testing: Cross-platform compatibility testing (pulls inscirs2-datasets)metrics-integration: Re-exportsmetrics::*and pulls inscirs2-metricscrypto: Plugin signature verification (pulls inrsa)
Enable features in your Cargo.toml:
[]
= { = "0.3.2", = ["cross-platform-testing"] }
Note: SIMD and parallel processing are built-in via scirs2-core and automatically enabled when beneficial.
Architecture
OptiRS-Core is designed with modularity and performance in mind. Selected top-level modules
(see src/lib.rs for the complete list of 40 public modules):
optirs-core/
├── src/
│ ├── lib.rs # Public API and re-exports
│ ├── optimizers/ # Optimizer implementations (sgd.rs, adam.rs, adamw.rs, ...)
│ ├── second_order/ # Newton, Newton-CG, K-FAC
│ ├── schedulers/ # Learning rate scheduling
│ ├── distributed/ # Ring all-reduce, pipeline parallelism, elastic training
│ ├── privacy/ # Differential privacy, secure aggregation
│ └── utils/ # Mathematical utilities
Performance
OptiRS-Core is optimized for high-performance machine learning workloads:
- SIMD Acceleration: via
scirs2_core::simd_ops(optimizers::SimdSGD,simd_optimizer); measured bybenches/simd_benchmarks.rs, no fixed speedup ratio is asserted in these docs - Parallel Processing: via
scirs2_core::parallel_ops(parallel_optimizer, non-wasm32 targets); measured bybenches/parallel_benchmarks.rs - GPU Support: Backed by
scirs2_core::gpuabstractions (gpu_optimizer) - Memory Efficient: Gradient accumulation, chunked processing
- Vectorized Operations: Via scirs2_core::ndarray abstractions
- Numerical Stability: Validated on standard optimization benchmarks (Rosenbrock, Himmelblau)
Development Guidelines
Coding Standards
To ensure consistency across the OptiRS-Core codebase, all contributors must follow these guidelines:
Variable Naming
- Always use
snake_casefor variable names (e.g.,gradient_norm,parameter_count,learning_rate) - Avoid camelCase or other naming conventions (e.g.,
gradientNorm❌,parameterCount❌) - Use descriptive names that clearly indicate the variable's purpose
// ✅ Correct: snake_case
let gradient_norm = gradients.norm;
let parameter_count = model.parameter_count;
let learning_rate = optimizer.get_learning_rate;
// ❌ Incorrect: camelCase or other formats
let gradientNorm = gradients.norm;
let parameterCount = model.parameter_count;
let learningrate = optimizer.get_learning_rate;
Function and Method Names
- Use
snake_casefor function and method names - Use descriptive verbs that indicate the function's action
Type Names
- Use
PascalCasefor struct, enum, and trait names - Use
SCREAMING_SNAKE_CASEfor constants
General Guidelines
- Follow Rust's official naming conventions as specified in RFC 430
- Use
rustfmtandclippyto maintain code formatting and catch common issues - Write clear, self-documenting code with appropriate comments
Before Submitting Code
- Run
cargo fmtto format your code - Run
cargo clippyto check for lint issues - Ensure all tests pass with
cargo test - Verify compilation with
cargo check
Contributing
OptiRS follows the Cool Japan organization's development standards. See the main OptiRS repository for contribution guidelines.
License
This project is licensed under the Apache License, Version 2.0.