Skip to main content

axonml/
lib.rs

1//! Axonml — Umbrella Crate
2//!
3//! # File
4//! `crates/axonml/src/lib.rs`
5//!
6//! # Author
7//! Andrew Jewell Sr. — AutomataNexus LLC
8//! ORCID: 0009-0005-2158-7060
9//!
10//! # Updated
11//! April 14, 2026 11:15 PM EST
12//!
13//! # Overview
14//!
15//! `axonml` is a thin umbrella crate that re-exports the full AxonML deep
16//! learning framework under a single unified namespace. It also hosts the
17//! **live browser training monitor** (`TrainingMonitor`), which is small,
18//! dependency-light, and used by essentially every training script in the
19//! workspace.
20//!
21//! Domain-specific models (e.g. HVAC diagnostics) and training infrastructure
22//! (trainer, hub, benchmark, adversarial) live in dedicated sibling crates:
23//!
24//! - `axonml-hvac`  — HVAC fault-detection models (Apollo, Panoptes, etc.)
25//! - `axonml-train` — `TrainingConfig`, `EarlyStopping`, `AdversarialTrainer`,
26//!   `benchmark_model`, unified model hub
27//!
28//! This separation was made in April 2026 to keep the umbrella crate focused
29//! on re-exports and the live training dashboard.
30//!
31//! # Disclaimer
32//! Use at own risk. This software is provided "as is", without warranty of any
33//! kind, express or implied. The author and AutomataNexus shall not be held
34//! liable for any damages arising from the use of this software.
35
36#![warn(clippy::all)]
37#![allow(clippy::cast_possible_truncation)]
38#![allow(clippy::cast_sign_loss)]
39#![allow(clippy::cast_precision_loss)]
40#![allow(clippy::cast_possible_wrap)]
41#![allow(clippy::missing_errors_doc)]
42#![allow(clippy::missing_panics_doc)]
43#![allow(clippy::must_use_candidate)]
44#![allow(clippy::module_name_repetitions)]
45#![allow(clippy::similar_names)]
46#![allow(clippy::doc_markdown)]
47#![allow(clippy::uninlined_format_args)]
48
49// =============================================================================
50// Core Re-exports
51// =============================================================================
52
53#[cfg(feature = "core")]
54pub use axonml_core as core;
55
56#[cfg(feature = "core")]
57pub use axonml_tensor as tensor;
58
59#[cfg(feature = "core")]
60pub use axonml_autograd as autograd;
61
62// =============================================================================
63// Neural Network Re-exports
64// =============================================================================
65
66#[cfg(feature = "nn")]
67pub use axonml_nn as nn;
68
69#[cfg(feature = "nn")]
70pub use axonml_optim as optim;
71
72// =============================================================================
73// Data Re-exports
74// =============================================================================
75
76#[cfg(feature = "data")]
77pub use axonml_data as data;
78
79// =============================================================================
80// Domain-Specific Re-exports
81// =============================================================================
82
83#[cfg(feature = "vision")]
84pub use axonml_vision as vision;
85
86#[cfg(feature = "text")]
87pub use axonml_text as text;
88
89#[cfg(feature = "audio")]
90pub use axonml_audio as audio;
91
92#[cfg(feature = "distributed")]
93pub use axonml_distributed as distributed;
94
95#[cfg(feature = "profile")]
96pub use axonml_profile as profile;
97
98#[cfg(feature = "llm")]
99pub use axonml_llm as llm;
100
101#[cfg(feature = "jit")]
102pub use axonml_jit as jit;
103
104#[cfg(feature = "onnx")]
105pub use axonml_onnx as onnx;
106
107#[cfg(feature = "serialize")]
108pub use axonml_serialize as serialize;
109
110#[cfg(feature = "quant")]
111pub use axonml_quant as quant;
112
113#[cfg(feature = "fusion")]
114pub use axonml_fusion as fusion;
115
116#[cfg(feature = "hvac")]
117pub use axonml_hvac as hvac;
118
119#[cfg(feature = "train")]
120pub use axonml_train as train;
121
122// =============================================================================
123// Training Monitor — stays in the umbrella crate
124// =============================================================================
125
126/// Live browser-based training monitor — opens Chromium with real-time charts.
127pub mod monitor;
128pub use monitor::TrainingMonitor;
129
130// =============================================================================
131// Prelude
132// =============================================================================
133
134/// Common imports for machine learning tasks.
135///
136/// ```ignore
137/// use axonml::prelude::*;
138/// ```
139pub mod prelude {
140    // Core types
141    #[cfg(feature = "core")]
142    pub use axonml_core::{DType, Device, Error, Result};
143
144    // Tensor operations
145    #[cfg(feature = "core")]
146    pub use axonml_tensor::Tensor;
147
148    // Autograd
149    #[cfg(feature = "core")]
150    pub use axonml_autograd::{Variable, no_grad};
151
152    // Neural network modules
153    #[cfg(feature = "nn")]
154    pub use axonml_nn::{
155        AvgPool2d, BCELoss, BatchNorm1d, BatchNorm2d, Conv2d, CrossEntropyLoss, Dropout, Embedding,
156        GELU, GRU, L1Loss, LSTM, LayerNorm, LeakyReLU, Linear, MSELoss, MaxPool2d, Module,
157        MultiHeadAttention, Parameter, RNN, ReLU, Sequential, SiLU, Sigmoid, Softmax, Tanh,
158    };
159
160    // Optimizers
161    #[cfg(feature = "nn")]
162    pub use axonml_optim::{
163        Adam, AdamW, CosineAnnealingLR, ExponentialLR, LRScheduler, Optimizer, RMSprop, SGD, StepLR,
164    };
165
166    // Data loading
167    #[cfg(feature = "data")]
168    pub use axonml_data::{DataLoader, Dataset, RandomSampler, SequentialSampler, Transform};
169
170    // Vision
171    #[cfg(feature = "vision")]
172    pub use axonml_vision::{
173        CenterCrop, ImageNormalize, LeNet, RandomHorizontalFlip, Resize, SimpleCNN, SyntheticCIFAR,
174        SyntheticMNIST,
175    };
176
177    // Text
178    #[cfg(feature = "text")]
179    pub use axonml_text::{
180        BasicBPETokenizer, CharTokenizer, LanguageModelDataset, SyntheticSentimentDataset,
181        TextDataset, Tokenizer, Vocab, WhitespaceTokenizer,
182    };
183
184    // Audio
185    #[cfg(feature = "audio")]
186    pub use axonml_audio::{
187        AddNoise, MFCC, MelSpectrogram, NormalizeAudio, Resample, SyntheticCommandDataset,
188        SyntheticMusicDataset,
189    };
190
191    // Distributed
192    #[cfg(feature = "distributed")]
193    pub use axonml_distributed::{
194        DDP, DistributedDataParallel, ProcessGroup, World, all_reduce_mean, all_reduce_sum,
195        barrier, broadcast,
196    };
197
198    // Profiling
199    #[cfg(feature = "profile")]
200    pub use axonml_profile::{
201        Bottleneck, BottleneckAnalyzer, ComputeProfiler, MemoryProfiler, ProfileGuard,
202        ProfileReport, Profiler, TimelineProfiler,
203    };
204
205    // LLM architectures — all nine models
206    #[cfg(feature = "llm")]
207    pub use axonml_llm::{
208        Bert, BertConfig, BertForMaskedLM, BertForSequenceClassification, GPT2, GPT2Config,
209        GPT2LMHead, GenerationConfig, TextGenerator,
210    };
211
212    // Training infrastructure
213    #[cfg(feature = "train")]
214    pub use axonml_train::{
215        AdversarialTrainer, Callback, EarlyStopping, ProgressLogger, TrainingConfig,
216        TrainingHistory, TrainingMetrics,
217    };
218
219    // JIT compilation
220    #[cfg(feature = "jit")]
221    pub use axonml_jit::{
222        CompiledFunction, Graph, JitCompiler, Optimizer as JitOptimizer, TracedValue, trace,
223    };
224}
225
226// =============================================================================
227// Version Information
228// =============================================================================
229
230/// Returns the version of the Axonml framework.
231#[must_use]
232pub fn version() -> &'static str {
233    env!("CARGO_PKG_VERSION")
234}
235
236/// Returns a string describing the enabled features.
237#[must_use]
238pub fn features() -> String {
239    let mut features = Vec::new();
240
241    #[cfg(feature = "core")]
242    features.push("core");
243
244    #[cfg(feature = "nn")]
245    features.push("nn");
246
247    #[cfg(feature = "data")]
248    features.push("data");
249
250    #[cfg(feature = "vision")]
251    features.push("vision");
252
253    #[cfg(feature = "text")]
254    features.push("text");
255
256    #[cfg(feature = "audio")]
257    features.push("audio");
258
259    #[cfg(feature = "distributed")]
260    features.push("distributed");
261
262    #[cfg(feature = "profile")]
263    features.push("profile");
264
265    #[cfg(feature = "llm")]
266    features.push("llm");
267
268    #[cfg(feature = "jit")]
269    features.push("jit");
270
271    #[cfg(feature = "onnx")]
272    features.push("onnx");
273
274    #[cfg(feature = "serialize")]
275    features.push("serialize");
276
277    #[cfg(feature = "quant")]
278    features.push("quant");
279
280    #[cfg(feature = "fusion")]
281    features.push("fusion");
282
283    #[cfg(feature = "hvac")]
284    features.push("hvac");
285
286    #[cfg(feature = "train")]
287    features.push("train");
288
289    if features.is_empty() {
290        "none".to_string()
291    } else {
292        features.join(", ")
293    }
294}
295
296// =============================================================================
297// Tests
298// =============================================================================
299
300#[cfg(test)]
301mod tests {
302    use super::*;
303
304    #[test]
305    fn test_version() {
306        let v = version();
307        assert!(!v.is_empty());
308    }
309
310    #[test]
311    fn test_features() {
312        let f = features();
313        assert!(f.contains("core"));
314    }
315
316    #[cfg(feature = "core")]
317    #[test]
318    fn test_tensor_creation() {
319        use tensor::Tensor;
320        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0, 4.0], &[2, 2]).unwrap();
321        assert_eq!(t.shape(), &[2, 2]);
322    }
323
324    #[cfg(feature = "core")]
325    #[test]
326    fn test_variable_creation() {
327        use autograd::Variable;
328        use tensor::Tensor;
329        let t = Tensor::from_vec(vec![1.0, 2.0, 3.0], &[3]).unwrap();
330        let v = Variable::new(t, true);
331        assert_eq!(v.data().shape(), &[3]);
332    }
333
334    #[cfg(feature = "nn")]
335    #[test]
336    fn test_linear_layer() {
337        use autograd::Variable;
338        use nn::Linear;
339        use nn::Module;
340        use tensor::Tensor;
341
342        let layer = Linear::new(4, 2);
343        let input = Variable::new(Tensor::from_vec(vec![1.0; 4], &[1, 4]).unwrap(), false);
344        let output = layer.forward(&input);
345        assert_eq!(output.data().shape(), &[1, 2]);
346    }
347}