1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
// use core::f64;
// use std::path::PathBuf;
// use trellis_runner::{prelude::*, ErrorEstimate};
// struct DummyCalculation {}
// struct DummyProblem {}
// #[derive(Default)]
// struct DummyState {
// param: Option<Vec<f64>>,
// cost: f64,
// is_initialised: bool,
// iter: usize,
// }
// impl UserState for DummyState {
// type Float = f64;
// type Param = Vec<f64>;
// fn new() -> Self {
// Self {
// param: None,
// cost: f64::MAX,
// is_initialised: true,
// iter: 0,
// }
// }
// fn is_initialised(&self) -> bool {
// self.is_initialised
// }
// fn get_param(&self) -> Option<&Self::Param> {
// self.param.as_ref()
// }
// fn update(&mut self) -> ErrorEstimate<Self::Float> {
// self.iter += 1;
// ErrorEstimate(self.cost)
// }
// fn last_was_best(&mut self) {}
// }
// #[derive(Debug)]
// enum DummyError {
// TypeA,
// }
// impl std::fmt::Display for DummyError {
// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
// write!(f, "{:?}", self)
// }
// }
// impl std::error::Error for DummyError {}
// impl Calculation<DummyProblem, DummyState> for DummyCalculation {
// type Error = DummyError;
// type Output = bool;
// const NAME: &'static str = "My dumb calculation";
// fn initialise(
// &mut self,
// _problem: &mut Problem<DummyProblem>,
// state: DummyState,
// ) -> Result<DummyState, Self::Error> {
// println!("initialising");
// Ok(state)
// }
// fn next(
// &mut self,
// _problem: &mut Problem<DummyProblem>,
// mut state: DummyState,
// ) -> Result<DummyState, Self::Error> {
// std::thread::sleep(std::time::Duration::from_millis(100));
// state.cost = (-((state.iter as f64) / 100.0)).exp();
// Ok(state)
// }
// fn finalise(
// &mut self,
// _problem: &mut Problem<DummyProblem>,
// _state: DummyState,
// ) -> Result<Self::Output, Self::Error> {
// Ok(true)
// }
// }
// #[tokio::test]
// #[cfg(feature = "tokio")]
// async fn problems_run_successfully() {
// let calculation = DummyCalculation {};
// let problem = DummyProblem {};
// // let iden = "calculation_time".to_string();
// // let outdir = PathBuf::from(r"/Users/cgubbin/sensorium/tooling/runner/out/");
// //
// // let config = PlotConfig {
// // x_limits: 0.0..100.0,
// // y_limits: None,
// // x_label: "Iteration".into(),
// // y_label: "Measure".into(),
// // title: "Optimisation Progress".into(),
// // };
// //
// let cancellation_token = tokio_util::sync::CancellationToken::new();
// let runner = calculation
// .build_for(problem)
// .with_cancellation_token(cancellation_token.clone())
// .configure(|state| state.max_iters(100))
// // .attach_observer(
// // FileWriter::new(
// // outdir.clone(),
// // iden.clone(),
// // WriteToFileSerializer::JSON,
// // Target::Measure,
// // ),
// // Frequency::Always,
// // )
// // .attach_observer(
// // PlotGenerator::measure(outdir, iden, config),
// // Frequency::Always,
// // )
// .finalise()
// .expect("failed to build problem");
// // tokio::task::spawn_blocking(move || runner.run());
// let result = runner.run();
// dbg!(result);
// std::thread::sleep(std::time::Duration::from_millis(10000));
// cancellation_token.cancel();
// }