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
//! # OptiRS NAS - Neural Architecture Search
//!
//! **Version:** 0.3.2
//! **Status:** Research-grade implementations; APIs may still change between releases
//!
//! ⚠️ **Warning:** Architecture search is compute-heavy and the search-space / objective
//! APIs are still evolving. Validate a discovered architecture against your own baselines
//! before relying on it in production.
//!
//! `optirs-nas` provides neural architecture search and automated optimizer discovery
//! built on [SciRS2](https://github.com/cool-japan/scirs).
//!
//! ## Dependencies
//!
//! - `scirs2-core` 0.6.5 - required foundation (arrays, RNG, numeric traits)
//!
//! This crate has **no intra-workspace dependencies**: `optirs-core` and
//! `optirs-learned` were declared once but never referenced, and were removed so
//! `optirs-nas` builds and tests standalone. The benchmark harness in
//! [`evaluation::BenchmarkSuite`] implements its optimizer update rules directly, which
//! also makes NAS scores reproducible independently of sibling-crate changes.
//!
//! ## Implementation Status (v0.3.2)
//!
//! - ✅ Bayesian optimization ([`search_strategies::bayesian`] - Gaussian-process surrogate search)
//! - ✅ Hyperparameter search ([`hyperparameter`] - grid enumeration, TPE, a GP-free
//! kernel-regression surrogate, and evolutionary search)
//! - ✅ Evolutionary algorithms ([`search_strategies::evolutionary`] - population-based search)
//! - ✅ RL-based search ([`search_strategies::rl_search`] - neural-controller sampling)
//! - ✅ Differentiable search ([`search_strategies::differentiable`] - DARTS-style gradient search)
//! - ✅ Multi-objective optimization ([`multi_objective`] - NSGA-II, NSGA-III, MOEA/D,
//! weighted-sum, Pareto frontier, exact hypervolume)
//! - ✅ Hardware-aware cost modeling ([`hardware_cost`] - latency/memory/energy estimation)
//! - ✅ AutoML pipeline coordination ([`automl_pipeline`]), cross-domain transfer, few-shot and
//! progressive search
//! - 📝 Real, tested algorithms throughout - still labeled research-grade because search-space
//! and objective APIs may change across releases
//!
//! ## Features
//!
//! ### Search Strategies
//! - **Bayesian Optimization** - Gaussian processes for efficient search
//! - **Evolutionary Algorithms** - Population-based architecture evolution
//! - **Reinforcement Learning** - Neural controller for architecture sampling
//! - **Gradient-Based** - DARTS and differentiable NAS
//!
//! ### Multi-Objective Optimization
//! - **Pareto Frontier** - Balance accuracy, speed, memory
//! - **Weighted Sum** - Customizable objective functions
//! - **NSGA-II** - Non-dominated sorting genetic algorithm
//! - **NSGA-III** - Reference-point-based many-objective sorting
//! - **MOEA/D** - Decomposition-based optimization (Tchebycheff/PBI/ASF/weighted-sum)
//! - Interactive preference articulation and Pareto-level constraint handling
//! (`MultiObjectiveConfig::user_preferences`/`constraint_handling`) are declared
//! but not yet consulted by any optimizer; hard resource limits are enforced
//! separately by [`nas_engine::resources::ResourceMonitor`], not by the
//! multi-objective layer.
//!
//! ### Progressive Search
//! - **Start Simple** - Begin with small architectures
//! - **Gradual Complexity** - Incrementally increase depth/width
//! - **Early Stopping** - Prune unpromising architectures
//! - **Transfer Learning** - Reuse knowledge from previous searches
//!
//! ### Hardware-Aware NAS
//! - **Latency Prediction** - Model inference time on target hardware
//! - **Memory Estimation** - Predict GPU/TPU memory usage
//! - **Energy Consumption** - Optimize for mobile/edge devices
//! - **Cost Optimization** - Minimize cloud compute costs
//!
//! ## Example Usage
//!
//! The engine type is [`nas_engine::NeuralArchitectureSearch`], configured with a
//! [`nas_engine::NASConfig`]. This example compiles and runs as a doctest, so it
//! cannot drift away from the real API.
//!
//! ```rust
//! use optirs_nas::nas_engine::resources::SystemResourceTracker;
//! use optirs_nas::nas_engine::telemetry::{FixedTelemetry, TelemetrySample};
//! use optirs_nas::nas_engine::{
//! create_minimal_nas_config, NeuralArchitectureSearch, SearchStrategyType,
//! };
//! use std::time::Duration;
//!
//! # fn main() -> Result<(), optirs_nas::error::OptimError> {
//! // A small, ready-made configuration: a populated search space, a Random
//! // strategy and a tiny budget.
//! let mut config = create_minimal_nas_config::<f64>();
//! config.search_strategy = SearchStrategyType::Evolutionary;
//! config.search_budget = 2;
//! config.population_size = 4;
//!
//! let mut engine = NeuralArchitectureSearch::new(config)?;
//! // The engine reports which strategy is *actually* running, not just what was
//! // requested.
//! assert_eq!(engine.search_strategy_name(), "EvolutionaryStrategy");
//!
//! // Pin the telemetry so this example's outcome does not depend on how much
//! // memory the host happens to have free. `resource_monitor_mut` is the supported
//! // injection point for real telemetry too.
//! engine.resource_monitor_mut().set_trackers(vec![Box::new(
//! SystemResourceTracker::with_telemetry(
//! "example".to_string(),
//! Duration::from_secs(5),
//! Box::new(FixedTelemetry::new("example", TelemetrySample::unknown())),
//! ),
//! )]);
//!
//! // A short search: two generations against the built-in evaluator.
//! let results = engine.run_search()?;
//! assert!(!results.search_history.is_empty());
//! # Ok(())
//! # }
//! ```
//!
//! Hyperparameter search is independent of the engine and can be driven directly:
//!
//! ```rust
//! use optirs_nas::hyperparameter::{
//! DistributionType, HyperparameterOptimizer, HyperparameterSpace,
//! OptimizationStrategy, ParameterRange,
//! };
//!
//! # fn main() -> Result<(), optirs_nas::error::OptimError> {
//! let mut space: HyperparameterSpace<f64> = HyperparameterSpace::new();
//! space.add_parameter(
//! "learning_rate".to_string(),
//! ParameterRange {
//! name: "learning_rate".to_string(),
//! min_value: 1e-5,
//! max_value: 1e-1,
//! distribution: DistributionType::Uniform,
//! log_scale: true,
//! discrete_values: None,
//! },
//! );
//!
//! // Grid search enumerates the grid; it does not sample at random.
//! let mut optimizer =
//! HyperparameterOptimizer::with_seed(space, OptimizationStrategy::Grid, 7);
//! optimizer.set_grid_resolution(4);
//! assert_eq!(optimizer.grid_size(), Some(4));
//!
//! let suggestion = optimizer.suggest_configuration()?;
//! let learning_rate = suggestion.parameters["learning_rate"];
//! assert!((1e-5..=1e-1).contains(&learning_rate));
//! # Ok(())
//! # }
//! ```
//!
//! ## Supported Search Spaces
//!
//! - **Optimizer Selection** - Choose between SGD, Adam, RMSprop, etc.
//! - **Hyperparameters** - Learning rates, momentum, weight decay
//! - **Learning Rate Schedules** - Warmup, decay, cosine annealing
//! - **Regularization** - L1/L2, dropout rates, gradient clipping
//! - **Architecture Components** - Optimizer composition and ensembles
//!
//! ## Architecture
//!
//! Every algorithm in this crate is implemented here; `scirs2-core` supplies the
//! numeric substrate only:
//!
//! - **Arrays**: `scirs2_core::ndarray` ([`scirs2_core::ndarray::Array1`] / `Array2` / `Array3`)
//! - **Numeric traits**: `scirs2_core::numeric` ([`scirs2_core::numeric::Float`], `NumCast`)
//! - **RNG**: `scirs2_core::random` (`Random`, `Rng`)
//!
//! The search machinery itself lives in this crate:
//! - **Search space**: [`nas_engine::SearchSpaceConfig`]
//! - **Engine**: [`nas_engine::NeuralArchitectureSearch`]
//! - **Strategies**: [`search_strategies`]
//! - **Multi-objective**: [`multi_objective`]
//!
//! (Earlier revisions of this document referenced
//! `scirs2_core::neural_architecture_search` and
//! `scirs2_core::quantum_optimization`; neither module exists.)
//!
//! ## References
//!
//! - DARTS: Differentiable Architecture Search (Liu et al., 2019)
//! - EfficientNet: Rethinking Model Scaling for CNNs (Tan & Le, 2019)
//! - Once-for-All: Train One Network and Specialize it for Efficient Deployment (Cai et al., 2020)
//!
//! ## Contributing
//!
//! Research contributions welcome! Follow SciRS2 integration guidelines.
/// Compiles and runs every `rust` code block in `README.md` as a doctest, so the
/// README cannot drift away from the API.
///
/// The previous README documented roughly twenty types that do not exist
/// (`NASEngine`, `BayesianOptimizer`, `ProgressiveNAS::new().with_initial_depth(..)`,
/// `HardwareAwareNAS`, `DistributedNAS`, ...) and `.await`ed every call in a crate
/// with no `async fn` at all. Nothing caught it because nothing compiled it.
///
/// `#[cfg(doctest)]` keeps this out of the published documentation and out of
/// normal builds; it exists only so `cargo test --doc` picks the file up.
;
pub
pub use ArchitectureSpace;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ;
pub use SearchStrategy;
pub use ;
// Re-export key types
use ;
/// Evaluation configuration for architecture search
/// Evaluation metrics for architectures
// ---------------------------------------------------------------------------
// Canonical result / architecture types
// ---------------------------------------------------------------------------
//
// The generic, element-type-parameterised definitions in
// [`nas_engine::results`] are the single source of truth for architectures,
// evaluation results and resource accounting. They are re-exported here so
// `optirs_nas::OptimizerArchitecture<T>` and
// `nas_engine::results::OptimizerArchitecture<T>` name the *same* type. Earlier
// releases carried a second, `f64`-only copy of each of these structs at the
// crate root; those duplicates are gone.
pub use NASConfig;
pub use ;