1use crate::{
2 storage::{errors::StorageError, primitive},
3 Experiment,
4};
5
6pub struct Run<'a> {
12 experiment: &'a Experiment<'a>,
13 id: String,
14}
15
16impl<'a> Run<'a> {
17 pub(crate) fn new(experiment: &'a Experiment, run: primitive::Run) -> Self {
18 Run {
19 experiment,
20 id: run.info.run_id,
21 }
22 }
23}
24
25impl Run<'_> {
27 pub fn log_param(&self, name: &str, value: &str) {
28 self.try_log_param(name, value).unwrap();
29 }
30
31 pub fn log_metric(&self, name: &str, value: f64, time_stamp: u64, step: u64) {
32 self.try_log_metric(name, value, time_stamp, step).unwrap();
33 }
34
35 pub fn terminate(self) {
36 self.try_terminate().unwrap()
37 }
38}
39
40impl Run<'_> {
42 pub fn try_log_param(&self, name: &str, value: &str) -> Result<(), StorageError> {
43 self.experiment
44 .client
45 .storage
46 .log_param(&self.id, name, value)
47 }
48
49 pub fn try_log_metric(
50 &self,
51 name: &str,
52 value: f64,
53 time_stamp: u64,
54 step: u64,
55 ) -> Result<(), StorageError> {
56 self.experiment
57 .client
58 .storage
59 .log_metric(&self.id, name, value, time_stamp, step)
60 }
61
62 pub fn try_terminate(self) -> Result<(), StorageError> {
63 let end_time = crate::timestamp();
64 self.experiment
65 .client
66 .storage
67 .terminate_run(&self.id, end_time)
68 }
69}