use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum StackLayer {
Primitives,
MlAlgorithms,
MlPipeline,
Transpilers,
Orchestration,
Quality,
Data,
Media,
}
impl StackLayer {
pub fn index(&self) -> u8 {
match self {
StackLayer::Primitives => 0,
StackLayer::MlAlgorithms => 1,
StackLayer::MlPipeline => 2,
StackLayer::Transpilers => 3,
StackLayer::Orchestration => 4,
StackLayer::Quality => 5,
StackLayer::Data => 6,
StackLayer::Media => 7,
}
}
pub fn all() -> Vec<StackLayer> {
vec![
StackLayer::Primitives,
StackLayer::MlAlgorithms,
StackLayer::MlPipeline,
StackLayer::Transpilers,
StackLayer::Orchestration,
StackLayer::Quality,
StackLayer::Data,
StackLayer::Media,
]
}
}
impl std::fmt::Display for StackLayer {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
StackLayer::Primitives => write!(f, "Compute Primitives"),
StackLayer::MlAlgorithms => write!(f, "ML Algorithms"),
StackLayer::MlPipeline => write!(f, "Training & Inference"),
StackLayer::Transpilers => write!(f, "Transpilers"),
StackLayer::Orchestration => write!(f, "Orchestration"),
StackLayer::Quality => write!(f, "Quality & Profiling"),
StackLayer::Data => write!(f, "Data Loading"),
StackLayer::Media => write!(f, "Media Production"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum CapabilityCategory {
Compute,
Storage,
MachineLearning,
Transpilation,
Validation,
Profiling,
Distribution,
Media,
ContentGeneration,
}
#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub struct Capability {
pub name: String,
pub category: CapabilityCategory,
pub description: Option<String>,
}
impl Capability {
pub fn new(name: impl Into<String>, category: CapabilityCategory) -> Self {
Self { name: name.into(), category, description: None }
}
pub fn with_description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(desc.into());
self
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct StackComponent {
pub name: String,
pub version: String,
pub layer: StackLayer,
pub description: String,
pub capabilities: Vec<Capability>,
pub crate_name: Option<String>,
pub references: Vec<Citation>,
}
impl StackComponent {
pub fn new(
name: impl Into<String>,
version: impl Into<String>,
layer: StackLayer,
description: impl Into<String>,
) -> Self {
Self {
name: name.into(),
version: version.into(),
layer,
description: description.into(),
capabilities: Vec::new(),
crate_name: None,
references: Vec::new(),
}
}
pub fn with_capability(mut self, cap: Capability) -> Self {
self.capabilities.push(cap);
self
}
pub fn with_capabilities(mut self, caps: Vec<Capability>) -> Self {
self.capabilities.extend(caps);
self
}
pub fn has_capability(&self, name: &str) -> bool {
self.capabilities.iter().any(|c| c.name == name)
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Citation {
pub id: u32,
pub authors: String,
pub year: u16,
pub title: String,
pub venue: Option<String>,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct HardwareSpec {
pub has_gpu: bool,
pub gpu_memory_gb: Option<f32>,
pub cpu_cores: Option<u32>,
pub ram_gb: Option<f32>,
pub is_distributed: bool,
pub node_count: Option<u32>,
}
impl HardwareSpec {
pub fn cpu_only() -> Self {
Self { has_gpu: false, ..Default::default() }
}
pub fn with_gpu(memory_gb: f32) -> Self {
Self { has_gpu: true, gpu_memory_gb: Some(memory_gb), ..Default::default() }
}
pub fn has_gpu(&self) -> bool {
self.has_gpu
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum DataSize {
Samples(u64),
Bytes(u64),
Unknown,
}
impl DataSize {
pub fn samples(n: u64) -> Self {
DataSize::Samples(n)
}
pub fn bytes(n: u64) -> Self {
DataSize::Bytes(n)
}
pub fn as_samples(&self) -> Option<u64> {
match self {
DataSize::Samples(n) => Some(*n),
_ => None,
}
}
pub fn is_large(&self) -> bool {
match self {
DataSize::Samples(n) => *n > 100_000,
DataSize::Bytes(n) => *n > 1_000_000_000,
DataSize::Unknown => false,
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub enum OptimizationTarget {
#[default]
Speed,
Memory,
Power,
Balanced,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct QueryConstraints {
pub max_latency_ms: Option<u64>,
pub data_size: Option<DataSize>,
pub sovereign_only: bool,
pub eu_compliant: bool,
pub hardware: HardwareSpec,
}
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct QueryPreferences {
pub optimize_for: OptimizationTarget,
pub simplicity_weight: f32,
pub existing_components: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleQuery {
pub description: String,
pub constraints: QueryConstraints,
pub preferences: QueryPreferences,
}
impl OracleQuery {
pub fn new(description: impl Into<String>) -> Self {
Self {
description: description.into(),
constraints: QueryConstraints::default(),
preferences: QueryPreferences::default(),
}
}
pub fn with_constraints(mut self, constraints: QueryConstraints) -> Self {
self.constraints = constraints;
self
}
pub fn with_preferences(mut self, preferences: QueryPreferences) -> Self {
self.preferences = preferences;
self
}
pub fn with_data_size(mut self, size: DataSize) -> Self {
self.constraints.data_size = Some(size);
self
}
pub fn with_hardware(mut self, hardware: HardwareSpec) -> Self {
self.constraints.hardware = hardware;
self
}
pub fn sovereign_only(mut self) -> Self {
self.constraints.sovereign_only = true;
self
}
pub fn eu_compliant(mut self) -> Self {
self.constraints.eu_compliant = true;
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[allow(clippy::upper_case_acronyms)]
pub enum Backend {
Scalar,
SIMD,
GPU,
Distributed,
}
impl std::fmt::Display for Backend {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Backend::Scalar => write!(f, "Scalar"),
Backend::SIMD => write!(f, "SIMD"),
Backend::GPU => write!(f, "GPU"),
Backend::Distributed => write!(f, "Distributed"),
}
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum OpComplexity {
Low,
Medium,
High,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComputeRecommendation {
pub backend: Backend,
pub rationale: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DistributionRecommendation {
pub tool: Option<String>,
pub needed: bool,
pub rationale: String,
pub node_count: Option<u32>,
}
impl DistributionRecommendation {
pub fn not_needed(rationale: impl Into<String>) -> Self {
Self { tool: None, needed: false, rationale: rationale.into(), node_count: None }
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ComponentRecommendation {
pub component: String,
pub path: Option<String>,
pub confidence: f32,
pub rationale: String,
}
impl ComponentRecommendation {
pub fn new(
component: impl Into<String>,
confidence: f32,
rationale: impl Into<String>,
) -> Self {
Self { component: component.into(), confidence, rationale: rationale.into(), path: None }
}
pub fn with_path(
component: impl Into<String>,
confidence: f32,
rationale: impl Into<String>,
path: String,
) -> Self {
Self {
component: component.into(),
confidence,
rationale: rationale.into(),
path: Some(path),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OracleResponse {
pub problem_class: String,
pub algorithm: Option<String>,
pub primary: ComponentRecommendation,
pub supporting: Vec<ComponentRecommendation>,
pub compute: ComputeRecommendation,
pub distribution: DistributionRecommendation,
pub code_example: Option<String>,
pub related_queries: Vec<String>,
}
impl OracleResponse {
pub fn new(problem_class: impl Into<String>, primary: ComponentRecommendation) -> Self {
Self {
problem_class: problem_class.into(),
algorithm: None,
primary,
supporting: Vec::new(),
compute: ComputeRecommendation {
backend: Backend::SIMD,
rationale: "Default SIMD backend".into(),
},
distribution: DistributionRecommendation {
tool: None,
needed: false,
rationale: "Single-node sufficient".into(),
node_count: None,
},
code_example: None,
related_queries: Vec::new(),
}
}
pub fn with_algorithm(mut self, algo: impl Into<String>) -> Self {
self.algorithm = Some(algo.into());
self
}
pub fn with_supporting(mut self, rec: ComponentRecommendation) -> Self {
self.supporting.push(rec);
self
}
pub fn with_compute(mut self, compute: ComputeRecommendation) -> Self {
self.compute = compute;
self
}
pub fn with_distribution(mut self, dist: DistributionRecommendation) -> Self {
self.distribution = dist;
self
}
pub fn with_code_example(mut self, code: impl Into<String>) -> Self {
self.code_example = Some(code.into());
self
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
pub enum ProblemDomain {
SupervisedLearning,
UnsupervisedLearning,
DeepLearning,
Inference,
SpeechRecognition,
LinearAlgebra,
VectorSearch,
GraphAnalytics,
PythonMigration,
CMigration,
ShellMigration,
DistributedCompute,
DataPipeline,
ModelServing,
Testing,
Profiling,
Validation,
MediaProduction,
}
impl std::fmt::Display for ProblemDomain {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
ProblemDomain::SupervisedLearning => write!(f, "Supervised Learning"),
ProblemDomain::UnsupervisedLearning => write!(f, "Unsupervised Learning"),
ProblemDomain::DeepLearning => write!(f, "Deep Learning"),
ProblemDomain::Inference => write!(f, "Model Inference"),
ProblemDomain::SpeechRecognition => write!(f, "Speech Recognition"),
ProblemDomain::LinearAlgebra => write!(f, "Linear Algebra"),
ProblemDomain::VectorSearch => write!(f, "Vector Search"),
ProblemDomain::GraphAnalytics => write!(f, "Graph Analytics"),
ProblemDomain::PythonMigration => write!(f, "Python Migration"),
ProblemDomain::CMigration => write!(f, "C/C++ Migration"),
ProblemDomain::ShellMigration => write!(f, "Shell Migration"),
ProblemDomain::DistributedCompute => write!(f, "Distributed Computing"),
ProblemDomain::DataPipeline => write!(f, "Data Pipeline"),
ProblemDomain::ModelServing => write!(f, "Model Serving"),
ProblemDomain::Testing => write!(f, "Testing"),
ProblemDomain::Profiling => write!(f, "Profiling"),
ProblemDomain::Validation => write!(f, "Validation"),
ProblemDomain::MediaProduction => write!(f, "Media Production"),
}
}
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct IntegrationPattern {
pub from: String,
pub to: String,
pub pattern_name: String,
pub description: String,
pub code_template: Option<String>,
}
#[cfg(test)]
#[path = "types_tests.rs"]
mod tests;