1use serde::{Deserialize, Serialize};
6
7#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
13pub enum StackLayer {
14 Primitives,
16 MlAlgorithms,
18 MlPipeline,
20 Transpilers,
22 Orchestration,
24 Quality,
26 Data,
28 Media,
30}
31
32impl StackLayer {
33 pub fn index(&self) -> u8 {
35 match self {
36 StackLayer::Primitives => 0,
37 StackLayer::MlAlgorithms => 1,
38 StackLayer::MlPipeline => 2,
39 StackLayer::Transpilers => 3,
40 StackLayer::Orchestration => 4,
41 StackLayer::Quality => 5,
42 StackLayer::Data => 6,
43 StackLayer::Media => 7,
44 }
45 }
46
47 pub fn all() -> Vec<StackLayer> {
49 vec![
50 StackLayer::Primitives,
51 StackLayer::MlAlgorithms,
52 StackLayer::MlPipeline,
53 StackLayer::Transpilers,
54 StackLayer::Orchestration,
55 StackLayer::Quality,
56 StackLayer::Data,
57 StackLayer::Media,
58 ]
59 }
60}
61
62impl std::fmt::Display for StackLayer {
63 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
64 match self {
65 StackLayer::Primitives => write!(f, "Compute Primitives"),
66 StackLayer::MlAlgorithms => write!(f, "ML Algorithms"),
67 StackLayer::MlPipeline => write!(f, "Training & Inference"),
68 StackLayer::Transpilers => write!(f, "Transpilers"),
69 StackLayer::Orchestration => write!(f, "Orchestration"),
70 StackLayer::Quality => write!(f, "Quality & Profiling"),
71 StackLayer::Data => write!(f, "Data Loading"),
72 StackLayer::Media => write!(f, "Media Production"),
73 }
74 }
75}
76
77#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
83pub enum CapabilityCategory {
84 Compute,
85 Storage,
86 MachineLearning,
87 Transpilation,
88 Validation,
89 Profiling,
90 Distribution,
91 Media,
92 ContentGeneration,
93}
94
95#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
97pub struct Capability {
98 pub name: String,
99 pub category: CapabilityCategory,
100 pub description: Option<String>,
101}
102
103impl Capability {
104 pub fn new(name: impl Into<String>, category: CapabilityCategory) -> Self {
105 Self { name: name.into(), category, description: None }
106 }
107
108 pub fn with_description(mut self, desc: impl Into<String>) -> Self {
109 self.description = Some(desc.into());
110 self
111 }
112}
113
114#[derive(Debug, Clone, Serialize, Deserialize)]
120pub struct StackComponent {
121 pub name: String,
123 pub version: String,
125 pub layer: StackLayer,
127 pub description: String,
129 pub capabilities: Vec<Capability>,
131 pub crate_name: Option<String>,
133 pub references: Vec<Citation>,
135}
136
137impl StackComponent {
138 pub fn new(
139 name: impl Into<String>,
140 version: impl Into<String>,
141 layer: StackLayer,
142 description: impl Into<String>,
143 ) -> Self {
144 Self {
145 name: name.into(),
146 version: version.into(),
147 layer,
148 description: description.into(),
149 capabilities: Vec::new(),
150 crate_name: None,
151 references: Vec::new(),
152 }
153 }
154
155 pub fn with_capability(mut self, cap: Capability) -> Self {
156 self.capabilities.push(cap);
157 self
158 }
159
160 pub fn with_capabilities(mut self, caps: Vec<Capability>) -> Self {
161 self.capabilities.extend(caps);
162 self
163 }
164
165 pub fn has_capability(&self, name: &str) -> bool {
166 self.capabilities.iter().any(|c| c.name == name)
167 }
168}
169
170#[derive(Debug, Clone, Serialize, Deserialize)]
172pub struct Citation {
173 pub id: u32,
174 pub authors: String,
175 pub year: u16,
176 pub title: String,
177 pub venue: Option<String>,
178}
179
180#[derive(Debug, Clone, Default, Serialize, Deserialize)]
186pub struct HardwareSpec {
187 pub has_gpu: bool,
188 pub gpu_memory_gb: Option<f32>,
189 pub cpu_cores: Option<u32>,
190 pub ram_gb: Option<f32>,
191 pub is_distributed: bool,
192 pub node_count: Option<u32>,
193}
194
195impl HardwareSpec {
196 pub fn cpu_only() -> Self {
197 Self { has_gpu: false, ..Default::default() }
198 }
199
200 pub fn with_gpu(memory_gb: f32) -> Self {
201 Self { has_gpu: true, gpu_memory_gb: Some(memory_gb), ..Default::default() }
202 }
203
204 pub fn has_gpu(&self) -> bool {
205 self.has_gpu
206 }
207}
208
209#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
211pub enum DataSize {
212 Samples(u64),
214 Bytes(u64),
216 Unknown,
218}
219
220impl DataSize {
221 pub fn samples(n: u64) -> Self {
222 DataSize::Samples(n)
223 }
224
225 pub fn bytes(n: u64) -> Self {
226 DataSize::Bytes(n)
227 }
228
229 pub fn as_samples(&self) -> Option<u64> {
231 match self {
232 DataSize::Samples(n) => Some(*n),
233 _ => None,
234 }
235 }
236
237 pub fn is_large(&self) -> bool {
239 match self {
240 DataSize::Samples(n) => *n > 100_000,
241 DataSize::Bytes(n) => *n > 1_000_000_000,
242 DataSize::Unknown => false,
243 }
244 }
245}
246
247#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
249pub enum OptimizationTarget {
250 #[default]
252 Speed,
253 Memory,
255 Power,
257 Balanced,
259}
260
261#[derive(Debug, Clone, Default, Serialize, Deserialize)]
263pub struct QueryConstraints {
264 pub max_latency_ms: Option<u64>,
266 pub data_size: Option<DataSize>,
268 pub sovereign_only: bool,
270 pub eu_compliant: bool,
272 pub hardware: HardwareSpec,
274}
275
276#[derive(Debug, Clone, Default, Serialize, Deserialize)]
278pub struct QueryPreferences {
279 pub optimize_for: OptimizationTarget,
281 pub simplicity_weight: f32,
283 pub existing_components: Vec<String>,
285}
286
287#[derive(Debug, Clone, Serialize, Deserialize)]
289pub struct OracleQuery {
290 pub description: String,
292 pub constraints: QueryConstraints,
294 pub preferences: QueryPreferences,
296}
297
298impl OracleQuery {
299 pub fn new(description: impl Into<String>) -> Self {
300 Self {
301 description: description.into(),
302 constraints: QueryConstraints::default(),
303 preferences: QueryPreferences::default(),
304 }
305 }
306
307 pub fn with_constraints(mut self, constraints: QueryConstraints) -> Self {
308 self.constraints = constraints;
309 self
310 }
311
312 pub fn with_preferences(mut self, preferences: QueryPreferences) -> Self {
313 self.preferences = preferences;
314 self
315 }
316
317 pub fn with_data_size(mut self, size: DataSize) -> Self {
318 self.constraints.data_size = Some(size);
319 self
320 }
321
322 pub fn with_hardware(mut self, hardware: HardwareSpec) -> Self {
323 self.constraints.hardware = hardware;
324 self
325 }
326
327 pub fn sovereign_only(mut self) -> Self {
328 self.constraints.sovereign_only = true;
329 self
330 }
331
332 pub fn eu_compliant(mut self) -> Self {
333 self.constraints.eu_compliant = true;
334 self
335 }
336}
337
338#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
344#[allow(clippy::upper_case_acronyms)]
345pub enum Backend {
346 Scalar,
347 SIMD,
348 GPU,
349 Distributed,
350}
351
352impl std::fmt::Display for Backend {
353 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
354 match self {
355 Backend::Scalar => write!(f, "Scalar"),
356 Backend::SIMD => write!(f, "SIMD"),
357 Backend::GPU => write!(f, "GPU"),
358 Backend::Distributed => write!(f, "Distributed"),
359 }
360 }
361}
362
363#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
365pub enum OpComplexity {
366 Low,
368 Medium,
370 High,
372}
373
374#[derive(Debug, Clone, Serialize, Deserialize)]
376pub struct ComputeRecommendation {
377 pub backend: Backend,
378 pub rationale: String,
379}
380
381#[derive(Debug, Clone, Serialize, Deserialize)]
383pub struct DistributionRecommendation {
384 pub tool: Option<String>,
385 pub needed: bool,
386 pub rationale: String,
387 pub node_count: Option<u32>,
388}
389
390impl DistributionRecommendation {
391 pub fn not_needed(rationale: impl Into<String>) -> Self {
392 Self { tool: None, needed: false, rationale: rationale.into(), node_count: None }
393 }
394}
395
396#[derive(Debug, Clone, Serialize, Deserialize)]
398pub struct ComponentRecommendation {
399 pub component: String,
401 pub path: Option<String>,
403 pub confidence: f32,
405 pub rationale: String,
407}
408
409impl ComponentRecommendation {
410 pub fn new(
411 component: impl Into<String>,
412 confidence: f32,
413 rationale: impl Into<String>,
414 ) -> Self {
415 Self { component: component.into(), confidence, rationale: rationale.into(), path: None }
416 }
417
418 pub fn with_path(
419 component: impl Into<String>,
420 confidence: f32,
421 rationale: impl Into<String>,
422 path: String,
423 ) -> Self {
424 Self {
425 component: component.into(),
426 confidence,
427 rationale: rationale.into(),
428 path: Some(path),
429 }
430 }
431}
432
433#[derive(Debug, Clone, Serialize, Deserialize)]
435pub struct OracleResponse {
436 pub problem_class: String,
438 pub algorithm: Option<String>,
440 pub primary: ComponentRecommendation,
442 pub supporting: Vec<ComponentRecommendation>,
444 pub compute: ComputeRecommendation,
446 pub distribution: DistributionRecommendation,
448 pub code_example: Option<String>,
450 pub related_queries: Vec<String>,
452}
453
454impl OracleResponse {
455 pub fn new(problem_class: impl Into<String>, primary: ComponentRecommendation) -> Self {
456 Self {
457 problem_class: problem_class.into(),
458 algorithm: None,
459 primary,
460 supporting: Vec::new(),
461 compute: ComputeRecommendation {
462 backend: Backend::SIMD,
463 rationale: "Default SIMD backend".into(),
464 },
465 distribution: DistributionRecommendation {
466 tool: None,
467 needed: false,
468 rationale: "Single-node sufficient".into(),
469 node_count: None,
470 },
471 code_example: None,
472 related_queries: Vec::new(),
473 }
474 }
475
476 pub fn with_algorithm(mut self, algo: impl Into<String>) -> Self {
477 self.algorithm = Some(algo.into());
478 self
479 }
480
481 pub fn with_supporting(mut self, rec: ComponentRecommendation) -> Self {
482 self.supporting.push(rec);
483 self
484 }
485
486 pub fn with_compute(mut self, compute: ComputeRecommendation) -> Self {
487 self.compute = compute;
488 self
489 }
490
491 pub fn with_distribution(mut self, dist: DistributionRecommendation) -> Self {
492 self.distribution = dist;
493 self
494 }
495
496 pub fn with_code_example(mut self, code: impl Into<String>) -> Self {
497 self.code_example = Some(code.into());
498 self
499 }
500}
501
502#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
508pub enum ProblemDomain {
509 SupervisedLearning,
511 UnsupervisedLearning,
512 DeepLearning,
513 Inference,
514 SpeechRecognition,
515 LinearAlgebra,
517 VectorSearch,
518 GraphAnalytics,
519 PythonMigration,
521 CMigration,
522 ShellMigration,
523 DistributedCompute,
525 DataPipeline,
526 ModelServing,
527 Testing,
529 Profiling,
530 Validation,
531 MediaProduction,
533}
534
535impl std::fmt::Display for ProblemDomain {
536 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
537 match self {
538 ProblemDomain::SupervisedLearning => write!(f, "Supervised Learning"),
539 ProblemDomain::UnsupervisedLearning => write!(f, "Unsupervised Learning"),
540 ProblemDomain::DeepLearning => write!(f, "Deep Learning"),
541 ProblemDomain::Inference => write!(f, "Model Inference"),
542 ProblemDomain::SpeechRecognition => write!(f, "Speech Recognition"),
543 ProblemDomain::LinearAlgebra => write!(f, "Linear Algebra"),
544 ProblemDomain::VectorSearch => write!(f, "Vector Search"),
545 ProblemDomain::GraphAnalytics => write!(f, "Graph Analytics"),
546 ProblemDomain::PythonMigration => write!(f, "Python Migration"),
547 ProblemDomain::CMigration => write!(f, "C/C++ Migration"),
548 ProblemDomain::ShellMigration => write!(f, "Shell Migration"),
549 ProblemDomain::DistributedCompute => write!(f, "Distributed Computing"),
550 ProblemDomain::DataPipeline => write!(f, "Data Pipeline"),
551 ProblemDomain::ModelServing => write!(f, "Model Serving"),
552 ProblemDomain::Testing => write!(f, "Testing"),
553 ProblemDomain::Profiling => write!(f, "Profiling"),
554 ProblemDomain::Validation => write!(f, "Validation"),
555 ProblemDomain::MediaProduction => write!(f, "Media Production"),
556 }
557 }
558}
559
560#[derive(Debug, Clone, Serialize, Deserialize)]
566pub struct IntegrationPattern {
567 pub from: String,
568 pub to: String,
569 pub pattern_name: String,
570 pub description: String,
571 pub code_template: Option<String>,
572}
573
574#[cfg(test)]
579#[path = "types_tests.rs"]
580mod tests;