Skip to content

Commit e7aa1ce

Browse files
authored
Renaming hotstart option and hist fields of optimization result (#191)
* Renaming hot into warm start Hot start would correspond to argmin checkpointing (not implemented) while warm start is the optimizer starting from existing DOE file * Renaming x_hist/y_hist inx_doe/y_doe * Fix py test
1 parent 954d24a commit e7aa1ce

File tree

8 files changed

+42
-42
lines changed

8 files changed

+42
-42
lines changed

ego/examples/mopta08.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -276,7 +276,7 @@ fn main() -> anyhow::Result<()> {
276276
.infill_optimizer(InfillOptimizer::Slsqp)
277277
.kpls_dim(kpls_dim)
278278
.outdir(outdir)
279-
.hot_start(true)
279+
.warm_start(true)
280280
})
281281
.min_within(&xlimits)
282282
.run()

ego/src/egor.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -223,8 +223,8 @@ impl<O: GroupFunc, SB: SurrogateBuilder> Egor<O, SB> {
223223
OptimResult {
224224
x_opt: result.state.get_best_param().unwrap().to_owned(),
225225
y_opt: result.state.get_full_best_cost().unwrap().to_owned(),
226-
x_hist: x_data,
227-
y_hist: y_data,
226+
x_doe: x_data,
227+
y_doe: y_data,
228228
state: result.state,
229229
}
230230
} else {
@@ -241,8 +241,8 @@ impl<O: GroupFunc, SB: SurrogateBuilder> Egor<O, SB> {
241241
OptimResult {
242242
x_opt: x_opt.row(0).to_owned(),
243243
y_opt: result.state.get_full_best_cost().unwrap().to_owned(),
244-
x_hist: x_data,
245-
y_hist: y_data,
244+
x_doe: x_data,
245+
y_doe: y_data,
246246
state: result.state,
247247
}
248248
};
@@ -413,8 +413,8 @@ mod tests {
413413

414414
#[test]
415415
#[serial]
416-
fn test_xsinx_with_hotstart_egor_builder() {
417-
let outdir = "target/test_hotstart_01";
416+
fn test_xsinx_with_warmstart_egor_builder() {
417+
let outdir = "target/test_warmstart_01";
418418
let _ = std::fs::remove_file(format!("{outdir}/{DOE_INITIAL_FILE}"));
419419
let _ = std::fs::remove_file(format!("{outdir}/{DOE_FILE}"));
420420
let xlimits = array![[0.0, 25.0]];
@@ -430,7 +430,7 @@ mod tests {
430430
let doe: Array2<f64> = read_npy(&filepath).expect("file read");
431431

432432
let res = EgorBuilder::optimize(xsinx)
433-
.configure(|config| config.max_iters(3).outdir(outdir).hot_start(true).seed(42))
433+
.configure(|config| config.max_iters(3).outdir(outdir).warm_start(true).seed(42))
434434
.min_within(&xlimits)
435435
.run()
436436
.expect("Egor should minimize xsinx");
@@ -720,13 +720,13 @@ mod tests {
720720

721721
#[test]
722722
#[serial]
723-
fn test_mixobj_mixint_hotstart_egor_builder() {
723+
fn test_mixobj_mixint_warmstart_egor_builder() {
724724
let env = env_logger::Env::new().filter_or("EGOBOX_LOG", "info");
725725
let mut builder = env_logger::Builder::from_env(env);
726726
let builder = builder.target(env_logger::Target::Stdout);
727727
builder.try_init().ok();
728728

729-
let outdir = "target/test_hotstart_02";
729+
let outdir = "target/test_warmstart_02";
730730
let outfile = format!("{outdir}/{DOE_INITIAL_FILE}");
731731
let _ = std::fs::remove_file(format!("{outdir}/{DOE_INITIAL_FILE}"));
732732
let _ = std::fs::remove_file(format!("{outdir}/{DOE_FILE}"));
@@ -752,7 +752,7 @@ mod tests {
752752
// Check that with no iteration, obj function is never called
753753
// as the DOE does not need to be evaluated!
754754
EgorBuilder::optimize(|_x| panic!("Should not call objective function!"))
755-
.configure(|config| config.outdir(outdir).hot_start(true).max_iters(0).seed(42))
755+
.configure(|config| config.outdir(outdir).warm_start(true).max_iters(0).seed(42))
756756
.min_within_mixint_space(&xtypes)
757757
.run()
758758
.unwrap();

ego/src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
//! * specify the initial doe,
1212
//! * parameterize internal optimization,
1313
//! * parameterize mixture of experts,
14-
//! * save intermediate results and allow hot restart,
14+
//! * save intermediate results and allow warm restart,
1515
//!
1616
//! # Examples
1717
//!

ego/src/solver/egor_config.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ pub struct EgorConfig {
7979
/// Directory to save intermediate results: inital doe + evalutions at each iteration
8080
pub(crate) outdir: Option<String>,
8181
/// If true use `outdir` to retrieve and start from previous results
82-
pub(crate) hot_start: bool,
82+
pub(crate) warm_start: bool,
8383
/// List of x types allowing the handling of discrete input variables
8484
pub(crate) xtypes: Vec<XType>,
8585
/// A random generator seed used to get reproductible results.
@@ -108,7 +108,7 @@ impl Default for EgorConfig {
108108
n_clusters: 1,
109109
target: f64::NEG_INFINITY,
110110
outdir: None,
111-
hot_start: false,
111+
warm_start: false,
112112
xtypes: vec![],
113113
seed: None,
114114
trego: TregoConfig::default(),
@@ -248,7 +248,7 @@ impl EgorConfig {
248248
self
249249
}
250250

251-
/// Sets a directory to write optimization history and used as search path for hot start doe
251+
/// Sets a directory to write optimization history and used as search path for warm start doe
252252
pub fn outdir(mut self, outdir: impl Into<String>) -> Self {
253253
self.outdir = Some(outdir.into());
254254
self
@@ -260,8 +260,8 @@ impl EgorConfig {
260260
}
261261

262262
/// Whether we start by loading last DOE saved in `outdir` as initial DOE
263-
pub fn hot_start(mut self, hot_start: bool) -> Self {
264-
self.hot_start = hot_start;
263+
pub fn warm_start(mut self, warm_start: bool) -> Self {
264+
self.warm_start = warm_start;
265265
self
266266
}
267267

ego/src/solver/egor_solver.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ where
174174
let sampling = Lhs::new(&self.xlimits).with_rng(rng).kind(LhsKind::Maximin);
175175

176176
let hstart_doe: Option<Array2<f64>> =
177-
if self.config.hot_start && self.config.outdir.is_some() {
177+
if self.config.warm_start && self.config.outdir.is_some() {
178178
let path: &String = self.config.outdir.as_ref().unwrap();
179179
let filepath = std::path::Path::new(&path).join(DOE_FILE);
180180
if filepath.is_file() {

ego/src/types.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ pub struct OptimResult<F: Float> {
1717
/// Optimum y value (e.g. f(x_opt))
1818
pub y_opt: Array1<F>,
1919
/// History of successive x values
20-
pub x_hist: Array2<F>,
21-
/// History of successive y values (e.g f(x_hist))
22-
pub y_hist: Array2<F>,
20+
pub x_doe: Array2<F>,
21+
/// History of successive y values (e.g f(x_doe))
22+
pub y_doe: Array2<F>,
2323
/// EgorSolver final state
2424
pub state: EgorState<F>,
2525
}

python/egobox/tests/test_egor.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_xsinx_with_reclustering(self):
8686
self.assertAlmostEqual(-15.125, res.y_opt[0], delta=1e-3)
8787
self.assertAlmostEqual(18.935, res.x_opt[0], delta=1e-3)
8888

89-
def test_xsinx_with_hotstart(self):
89+
def test_xsinx_with_warmstart(self):
9090
if os.path.exists("./test_dir/egor_initial_doe.npy"):
9191
os.remove("./test_dir/egor_initial_doe.npy")
9292
if os.path.exists("./test_dir/egor_doe.npy"):
@@ -99,7 +99,7 @@ def test_xsinx_with_hotstart(self):
9999
self.assertAlmostEqual(-15.125, res.y_opt[0], delta=1e-3)
100100
self.assertAlmostEqual(18.935, res.x_opt[0], delta=1e-3)
101101

102-
egor = egx.Egor(xlimits, outdir="./test_dir", hot_start=True)
102+
egor = egx.Egor(xlimits, outdir="./test_dir", warm_start=True)
103103
res = egor.minimize(xsinx, max_iters=5)
104104
print(f"Optimization f={res.y_opt} at {res.x_opt}")
105105
self.assertAlmostEqual(-15.125, res.y_opt[0], delta=1e-2)
@@ -129,8 +129,8 @@ def test_g24(self):
129129
self.assertAlmostEqual(-5.5080, res.y_opt[0], delta=1e-2)
130130
self.assertAlmostEqual(2.3295, res.x_opt[0], delta=1e-2)
131131
self.assertAlmostEqual(3.1785, res.x_opt[1], delta=1e-2)
132-
self.assertEqual((n_doe + max_iters, 2), res.x_hist.shape)
133-
self.assertEqual((n_doe + max_iters, 1 + n_cstr), res.y_hist.shape)
132+
self.assertEqual((n_doe + max_iters, 2), res.x_doe.shape)
133+
self.assertEqual((n_doe + max_iters, 1 + n_cstr), res.y_doe.shape)
134134

135135
def test_g24_kpls(self):
136136
egor = egx.Egor(

src/egor.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -133,9 +133,9 @@ pub(crate) fn to_specs(py: Python, xlimits: Vec<Vec<f64>>) -> PyResult<PyObject>
133133
/// Known optimum used as stopping criterion.
134134
///
135135
/// outdir (String)
136-
/// Directory to write optimization history and used as search path for hot start doe
136+
/// Directory to write optimization history and used as search path for warm start doe
137137
///
138-
/// hot_start (bool)
138+
/// warm_start (bool)
139139
/// Start by loading initial doe from <outdir> directory
140140
///
141141
/// seed (int >= 0)
@@ -161,7 +161,7 @@ pub(crate) struct Egor {
161161
pub n_optmod: usize,
162162
pub target: f64,
163163
pub outdir: Option<String>,
164-
pub hot_start: bool,
164+
pub warm_start: bool,
165165
pub seed: Option<u64>,
166166
}
167167

@@ -172,9 +172,9 @@ pub(crate) struct OptimResult {
172172
#[pyo3(get)]
173173
y_opt: Py<PyArray1<f64>>,
174174
#[pyo3(get)]
175-
x_hist: Py<PyArray2<f64>>,
175+
x_doe: Py<PyArray2<f64>>,
176176
#[pyo3(get)]
177-
y_hist: Py<PyArray2<f64>>,
177+
y_doe: Py<PyArray2<f64>>,
178178
}
179179

180180
#[pymethods]
@@ -199,7 +199,7 @@ impl Egor {
199199
n_optmod = 1,
200200
target = f64::NEG_INFINITY,
201201
outdir = None,
202-
hot_start = false,
202+
warm_start = false,
203203
seed = None
204204
))]
205205
#[allow(clippy::too_many_arguments)]
@@ -223,7 +223,7 @@ impl Egor {
223223
n_optmod: usize,
224224
target: f64,
225225
outdir: Option<String>,
226-
hot_start: bool,
226+
warm_start: bool,
227227
seed: Option<u64>,
228228
) -> Self {
229229
let doe = doe.map(|x| x.to_owned_array());
@@ -246,7 +246,7 @@ impl Egor {
246246
n_optmod,
247247
target,
248248
outdir,
249-
hot_start,
249+
warm_start,
250250
seed,
251251
}
252252
}
@@ -286,13 +286,13 @@ impl Egor {
286286
});
287287
let x_opt = res.x_opt.into_pyarray_bound(py).to_owned();
288288
let y_opt = res.y_opt.into_pyarray_bound(py).to_owned();
289-
let x_hist = res.x_hist.into_pyarray_bound(py).to_owned();
290-
let y_hist = res.y_hist.into_pyarray_bound(py).to_owned();
289+
let x_doe = res.x_doe.into_pyarray_bound(py).to_owned();
290+
let y_doe = res.y_doe.into_pyarray_bound(py).to_owned();
291291
Ok(OptimResult {
292292
x_opt: x_opt.into(),
293293
y_opt: y_opt.into(),
294-
x_hist: x_hist.into(),
295-
y_hist: y_hist.into(),
294+
x_doe: x_doe.into(),
295+
y_doe: y_doe.into(),
296296
})
297297
}
298298

@@ -367,13 +367,13 @@ impl Egor {
367367
let idx = find_best_result_index(&y_doe, &self.cstr_tol());
368368
let x_opt = x_doe.row(idx).to_pyarray_bound(py).into();
369369
let y_opt = y_doe.row(idx).to_pyarray_bound(py).into();
370-
let x_hist = x_doe.to_pyarray_bound(py).into();
371-
let y_hist = y_doe.to_pyarray_bound(py).into();
370+
let x_doe = x_doe.to_pyarray_bound(py).into();
371+
let y_doe = y_doe.to_pyarray_bound(py).into();
372372
OptimResult {
373373
x_opt,
374374
y_opt,
375-
x_hist,
376-
y_hist,
375+
x_doe,
376+
y_doe,
377377
}
378378
}
379379
}
@@ -462,7 +462,7 @@ impl Egor {
462462
.trego(self.trego)
463463
.n_optmod(self.n_optmod)
464464
.target(self.target)
465-
.hot_start(self.hot_start); // when used as a service no hotstart
465+
.warm_start(self.warm_start); // when used as a service no warmstart
466466
if let Some(doe) = doe {
467467
config = config.doe(doe);
468468
};

0 commit comments

Comments
 (0)