trs_mlflow/
run.rs

1//! Contains everything that is related to mlflow run.
2use crate::experiment::KeyValue;
3use builder_pattern::Builder;
4use chrono::Utc;
5use serde::{Deserialize, Serialize};
6
7#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
8pub struct CreateRun {
9    #[into]
10    pub experiment_id: String,
11    #[into]
12    pub run_name: String,
13    #[default(Utc::now().timestamp_millis())]
14    pub start_time: i64,
15    #[default(vec![])]
16    #[serde(default)]
17    pub tags: Vec<KeyValue>,
18}
19
20#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
21pub struct UpdateRun {
22    #[into]
23    pub run_id: String,
24    #[into]
25    pub experiment_id: String,
26    pub status: RunStatus,
27    #[default(Utc::now().timestamp_millis())]
28    pub end_time: i64,
29    #[default(None)]
30    pub run_name: Option<String>,
31}
32
33#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
34pub struct Run {
35    pub info: RunInfo,
36    pub data: RunData,
37    #[serde(default)]
38    pub inputs: RunInputs,
39}
40
41#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
42pub struct RunInfo {
43    pub run_id: String,
44    pub run_name: String,
45    pub experiment_id: String,
46    pub status: RunStatus,
47    pub start_time: u64,
48    pub end_time: Option<u64>,
49    pub artifact_uri: String,
50    pub lifecycle_stage: String,
51}
52
53#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
54pub struct RunData {
55    #[serde(default)]
56    #[default(vec![])]
57    pub metrics: Vec<Metric>,
58    #[serde(default)]
59    #[default(vec![])]
60    pub params: Vec<KeyValue>,
61    #[serde(default)]
62    #[default(vec![])]
63    pub tags: Vec<KeyValue>,
64}
65
66#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
67#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
68pub enum RunStatus {
69    Running,
70    Scheduled,
71    Finished,
72    Failed,
73    Killed,
74}
75
76#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
77pub struct Metric {
78    #[into]
79    pub key: String,
80    #[into]
81    pub value: f64,
82    #[default(Utc::now().timestamp_millis())]
83    pub timestamp: i64,
84    pub step: u64,
85}
86
87#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
88pub struct RunInputs {
89    #[serde(rename = "dataset_inputs", default)]
90    pub inputs: Vec<DataSetInput>,
91}
92
93#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
94pub struct DataSetInput {
95    #[default(vec![])]
96    pub tags: Vec<KeyValue>,
97    pub dataset: DataSet,
98}
99
100#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
101pub struct DataSet {
102    #[into]
103    pub name: String,
104    #[into]
105    pub digest: String,
106    #[into]
107    pub source_type: String,
108    #[into]
109    pub source: String,
110    #[into]
111    pub schema: String,
112    #[into]
113    pub profile: String,
114}
115
116#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, Builder)]
117pub struct SearchRuns {
118    /// List of experiment IDs to search over.
119    #[into]
120    pub experiment_ids: Vec<String>,
121    /// A filter expression over params, metrics, and tags, that allows
122    /// returning a subset of runs. The syntax is a subset of SQL that supports
123    /// ANDing together binary operations between a param, metric, or tag and a
124    /// constant.
125    ///
126    /// Example: metrics.rmse < 1 and params.model_class = 'LogisticRegression'
127    #[into]
128    #[default("".to_owned())]
129    pub filter: String,
130    /// Whether to display only active, only deleted, or all runs. Defaults to
131    /// only active runs.
132    #[default(ViewType::default())]
133    pub view: ViewType,
134    /// Maximum number of runs desired. If unspecified, defaults to 1000. All
135    /// servers are guaranteed to support a max_results threshold of at least
136    /// 50,000 but may support more. Callers of this endpoint are encouraged to
137    /// pass max_results explicitly and leverage page_token to iterate through
138    /// experiments.
139    #[default(None)]
140    #[serde(skip_serializing_if = "Option::is_none")]
141    pub max_results: Option<u16>,
142    #[into]
143    #[default(vec![])]
144    /// List of columns to be ordered by, including attributes, params, metrics,
145    /// and tags with an optional “DESC” or “ASC” annotation, where “ASC” is the
146    /// default. Example: [“params.input DESC”, “metrics.alpha ASC”,
147    /// “metrics.rmse”] Tiebreaks are done by start_time DESC followed by run_id
148    /// for runs with the same start time (and this is the default ordering
149    /// criterion if order_by is not provided).
150    pub order_by: Vec<String>,
151    #[default(None)]
152    #[serde(skip_serializing_if = "Option::is_none")]
153    pub page_token: Option<String>,
154}
155
156#[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)]
157#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
158pub enum ViewType {
159    #[default]
160    ActiveOnly,
161    DeletedOnly,
162    All,
163}