Skip to main content

batuta/recipes/
types.rs

1//! Recipe types and configuration structures.
2
3use crate::experiment::{ComputeDevice, CpuArchitecture, ModelParadigm, PlatformEfficiency};
4use serde::{Deserialize, Serialize};
5use std::collections::HashMap;
6
7/// Recipe execution result
8#[derive(Debug, Clone)]
9pub struct RecipeResult {
10    /// Recipe name
11    pub recipe_name: String,
12    /// Whether the recipe succeeded
13    pub success: bool,
14    /// Output artifacts
15    pub artifacts: Vec<String>,
16    /// Metrics collected
17    pub metrics: HashMap<String, f64>,
18    /// Error message if failed
19    pub error: Option<String>,
20}
21
22impl RecipeResult {
23    /// Create a successful result
24    pub fn success(name: impl Into<String>) -> Self {
25        Self {
26            recipe_name: name.into(),
27            success: true,
28            artifacts: Vec::new(),
29            metrics: HashMap::new(),
30            error: None,
31        }
32    }
33
34    /// Create a failed result
35    pub fn failure(name: impl Into<String>, error: impl Into<String>) -> Self {
36        Self {
37            recipe_name: name.into(),
38            success: false,
39            artifacts: Vec::new(),
40            metrics: HashMap::new(),
41            error: Some(error.into()),
42        }
43    }
44
45    /// Add an artifact
46    pub fn with_artifact(mut self, artifact: impl Into<String>) -> Self {
47        self.artifacts.push(artifact.into());
48        self
49    }
50
51    /// Add a metric
52    pub fn with_metric(mut self, name: impl Into<String>, value: f64) -> Self {
53        self.metrics.insert(name.into(), value);
54        self
55    }
56}
57
58/// Experiment tracking recipe configuration
59#[derive(Debug, Clone, Serialize, Deserialize)]
60pub struct ExperimentTrackingConfig {
61    /// Experiment name
62    pub experiment_name: String,
63    /// Model paradigm
64    pub paradigm: ModelParadigm,
65    /// Compute device configuration
66    pub device: ComputeDevice,
67    /// Platform type
68    pub platform: PlatformEfficiency,
69    /// Enable energy tracking
70    pub track_energy: bool,
71    /// Enable cost tracking
72    pub track_cost: bool,
73    /// Carbon intensity for CO2 calculation (g/kWh)
74    pub carbon_intensity: Option<f64>,
75    /// Tags for organization
76    pub tags: Vec<String>,
77}
78
79impl Default for ExperimentTrackingConfig {
80    fn default() -> Self {
81        Self {
82            experiment_name: "default-experiment".to_string(),
83            paradigm: ModelParadigm::DeepLearning,
84            device: ComputeDevice::Cpu {
85                cores: 8,
86                threads_per_core: 2,
87                architecture: CpuArchitecture::X86_64,
88            },
89            platform: PlatformEfficiency::Server,
90            track_energy: true,
91            track_cost: true,
92            carbon_intensity: Some(400.0), // Global average
93            tags: Vec::new(),
94        }
95    }
96}