ahco-rust 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- ahco_rust-0.1.0/Cargo.lock +285 -0
- ahco_rust-0.1.0/Cargo.toml +25 -0
- ahco_rust-0.1.0/PKG-INFO +84 -0
- ahco_rust-0.1.0/README.md +75 -0
- ahco_rust-0.1.0/ahco.py +258 -0
- ahco_rust-0.1.0/ahco_rust/__init__.py +7 -0
- ahco_rust-0.1.0/dist/ahco_rust-0.1.0-cp311-cp311-win_amd64.whl +0 -0
- ahco_rust-0.1.0/pyproject.toml +16 -0
- ahco_rust-0.1.0/src/lib.rs +1035 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
# This file is automatically @generated by Cargo.
|
|
2
|
+
# It is not intended for manual editing.
|
|
3
|
+
version = 3
|
|
4
|
+
|
|
5
|
+
[[package]]
|
|
6
|
+
name = "ahco"
|
|
7
|
+
version = "0.1.0"
|
|
8
|
+
dependencies = [
|
|
9
|
+
"pyo3",
|
|
10
|
+
"rand",
|
|
11
|
+
"rand_chacha",
|
|
12
|
+
"rand_distr",
|
|
13
|
+
]
|
|
14
|
+
|
|
15
|
+
[[package]]
|
|
16
|
+
name = "autocfg"
|
|
17
|
+
version = "1.5.0"
|
|
18
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
19
|
+
checksum = "c08606f8c3cbf4ce6ec8e28fb0014a2c086708fe954eaa885384a6165172e7e8"
|
|
20
|
+
|
|
21
|
+
[[package]]
|
|
22
|
+
name = "cfg-if"
|
|
23
|
+
version = "1.0.4"
|
|
24
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
25
|
+
checksum = "9330f8b2ff13f34540b44e946ef35111825727b38d33286ef986142615121801"
|
|
26
|
+
|
|
27
|
+
[[package]]
|
|
28
|
+
name = "getrandom"
|
|
29
|
+
version = "0.2.17"
|
|
30
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
31
|
+
checksum = "ff2abc00be7fca6ebc474524697ae276ad847ad0a6b3faa4bcb027e9a4614ad0"
|
|
32
|
+
dependencies = [
|
|
33
|
+
"cfg-if",
|
|
34
|
+
"libc",
|
|
35
|
+
"wasi",
|
|
36
|
+
]
|
|
37
|
+
|
|
38
|
+
[[package]]
|
|
39
|
+
name = "heck"
|
|
40
|
+
version = "0.5.0"
|
|
41
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
42
|
+
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
|
43
|
+
|
|
44
|
+
[[package]]
|
|
45
|
+
name = "indoc"
|
|
46
|
+
version = "2.0.7"
|
|
47
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
48
|
+
checksum = "79cf5c93f93228cf8efb3ba362535fb11199ac548a09ce117c9b1adc3030d706"
|
|
49
|
+
dependencies = [
|
|
50
|
+
"rustversion",
|
|
51
|
+
]
|
|
52
|
+
|
|
53
|
+
[[package]]
|
|
54
|
+
name = "libc"
|
|
55
|
+
version = "0.2.183"
|
|
56
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
57
|
+
checksum = "b5b646652bf6661599e1da8901b3b9522896f01e736bad5f723fe7a3a27f899d"
|
|
58
|
+
|
|
59
|
+
[[package]]
|
|
60
|
+
name = "libm"
|
|
61
|
+
version = "0.2.16"
|
|
62
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
63
|
+
checksum = "b6d2cec3eae94f9f509c767b45932f1ada8350c4bdb85af2fcab4a3c14807981"
|
|
64
|
+
|
|
65
|
+
[[package]]
|
|
66
|
+
name = "memoffset"
|
|
67
|
+
version = "0.9.1"
|
|
68
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
69
|
+
checksum = "488016bfae457b036d996092f6cb448677611ce4449e970ceaf42695203f218a"
|
|
70
|
+
dependencies = [
|
|
71
|
+
"autocfg",
|
|
72
|
+
]
|
|
73
|
+
|
|
74
|
+
[[package]]
|
|
75
|
+
name = "num-traits"
|
|
76
|
+
version = "0.2.19"
|
|
77
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
78
|
+
checksum = "071dfc062690e90b734c0b2273ce72ad0ffa95f0c74596bc250dcfd960262841"
|
|
79
|
+
dependencies = [
|
|
80
|
+
"autocfg",
|
|
81
|
+
"libm",
|
|
82
|
+
]
|
|
83
|
+
|
|
84
|
+
[[package]]
|
|
85
|
+
name = "once_cell"
|
|
86
|
+
version = "1.21.4"
|
|
87
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
88
|
+
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
|
89
|
+
|
|
90
|
+
[[package]]
|
|
91
|
+
name = "portable-atomic"
|
|
92
|
+
version = "1.13.1"
|
|
93
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
94
|
+
checksum = "c33a9471896f1c69cecef8d20cbe2f7accd12527ce60845ff44c153bb2a21b49"
|
|
95
|
+
|
|
96
|
+
[[package]]
|
|
97
|
+
name = "ppv-lite86"
|
|
98
|
+
version = "0.2.21"
|
|
99
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
100
|
+
checksum = "85eae3c4ed2f50dcfe72643da4befc30deadb458a9b590d720cde2f2b1e97da9"
|
|
101
|
+
dependencies = [
|
|
102
|
+
"zerocopy",
|
|
103
|
+
]
|
|
104
|
+
|
|
105
|
+
[[package]]
|
|
106
|
+
name = "proc-macro2"
|
|
107
|
+
version = "1.0.106"
|
|
108
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
109
|
+
checksum = "8fd00f0bb2e90d81d1044c2b32617f68fcb9fa3bb7640c23e9c748e53fb30934"
|
|
110
|
+
dependencies = [
|
|
111
|
+
"unicode-ident",
|
|
112
|
+
]
|
|
113
|
+
|
|
114
|
+
[[package]]
|
|
115
|
+
name = "pyo3"
|
|
116
|
+
version = "0.23.5"
|
|
117
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
118
|
+
checksum = "7778bffd85cf38175ac1f545509665d0b9b92a198ca7941f131f85f7a4f9a872"
|
|
119
|
+
dependencies = [
|
|
120
|
+
"cfg-if",
|
|
121
|
+
"indoc",
|
|
122
|
+
"libc",
|
|
123
|
+
"memoffset",
|
|
124
|
+
"once_cell",
|
|
125
|
+
"portable-atomic",
|
|
126
|
+
"pyo3-build-config",
|
|
127
|
+
"pyo3-ffi",
|
|
128
|
+
"pyo3-macros",
|
|
129
|
+
"unindent",
|
|
130
|
+
]
|
|
131
|
+
|
|
132
|
+
[[package]]
|
|
133
|
+
name = "pyo3-build-config"
|
|
134
|
+
version = "0.23.5"
|
|
135
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
136
|
+
checksum = "94f6cbe86ef3bf18998d9df6e0f3fc1050a8c5efa409bf712e661a4366e010fb"
|
|
137
|
+
dependencies = [
|
|
138
|
+
"once_cell",
|
|
139
|
+
"target-lexicon",
|
|
140
|
+
]
|
|
141
|
+
|
|
142
|
+
[[package]]
|
|
143
|
+
name = "pyo3-ffi"
|
|
144
|
+
version = "0.23.5"
|
|
145
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
146
|
+
checksum = "e9f1b4c431c0bb1c8fb0a338709859eed0d030ff6daa34368d3b152a63dfdd8d"
|
|
147
|
+
dependencies = [
|
|
148
|
+
"libc",
|
|
149
|
+
"pyo3-build-config",
|
|
150
|
+
]
|
|
151
|
+
|
|
152
|
+
[[package]]
|
|
153
|
+
name = "pyo3-macros"
|
|
154
|
+
version = "0.23.5"
|
|
155
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
156
|
+
checksum = "fbc2201328f63c4710f68abdf653c89d8dbc2858b88c5d88b0ff38a75288a9da"
|
|
157
|
+
dependencies = [
|
|
158
|
+
"proc-macro2",
|
|
159
|
+
"pyo3-macros-backend",
|
|
160
|
+
"quote",
|
|
161
|
+
"syn",
|
|
162
|
+
]
|
|
163
|
+
|
|
164
|
+
[[package]]
|
|
165
|
+
name = "pyo3-macros-backend"
|
|
166
|
+
version = "0.23.5"
|
|
167
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
168
|
+
checksum = "fca6726ad0f3da9c9de093d6f116a93c1a38e417ed73bf138472cf4064f72028"
|
|
169
|
+
dependencies = [
|
|
170
|
+
"heck",
|
|
171
|
+
"proc-macro2",
|
|
172
|
+
"pyo3-build-config",
|
|
173
|
+
"quote",
|
|
174
|
+
"syn",
|
|
175
|
+
]
|
|
176
|
+
|
|
177
|
+
[[package]]
|
|
178
|
+
name = "quote"
|
|
179
|
+
version = "1.0.45"
|
|
180
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
181
|
+
checksum = "41f2619966050689382d2b44f664f4bc593e129785a36d6ee376ddf37259b924"
|
|
182
|
+
dependencies = [
|
|
183
|
+
"proc-macro2",
|
|
184
|
+
]
|
|
185
|
+
|
|
186
|
+
[[package]]
|
|
187
|
+
name = "rand"
|
|
188
|
+
version = "0.8.5"
|
|
189
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
190
|
+
checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
|
|
191
|
+
dependencies = [
|
|
192
|
+
"libc",
|
|
193
|
+
"rand_chacha",
|
|
194
|
+
"rand_core",
|
|
195
|
+
]
|
|
196
|
+
|
|
197
|
+
[[package]]
|
|
198
|
+
name = "rand_chacha"
|
|
199
|
+
version = "0.3.1"
|
|
200
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
201
|
+
checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
|
|
202
|
+
dependencies = [
|
|
203
|
+
"ppv-lite86",
|
|
204
|
+
"rand_core",
|
|
205
|
+
]
|
|
206
|
+
|
|
207
|
+
[[package]]
|
|
208
|
+
name = "rand_core"
|
|
209
|
+
version = "0.6.4"
|
|
210
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
211
|
+
checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
|
|
212
|
+
dependencies = [
|
|
213
|
+
"getrandom",
|
|
214
|
+
]
|
|
215
|
+
|
|
216
|
+
[[package]]
|
|
217
|
+
name = "rand_distr"
|
|
218
|
+
version = "0.4.3"
|
|
219
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
220
|
+
checksum = "32cb0b9bc82b0a0876c2dd994a7e7a2683d3e7390ca40e6886785ef0c7e3ee31"
|
|
221
|
+
dependencies = [
|
|
222
|
+
"num-traits",
|
|
223
|
+
"rand",
|
|
224
|
+
]
|
|
225
|
+
|
|
226
|
+
[[package]]
|
|
227
|
+
name = "rustversion"
|
|
228
|
+
version = "1.0.22"
|
|
229
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
230
|
+
checksum = "b39cdef0fa800fc44525c84ccb54a029961a8215f9619753635a9c0d2538d46d"
|
|
231
|
+
|
|
232
|
+
[[package]]
|
|
233
|
+
name = "syn"
|
|
234
|
+
version = "2.0.117"
|
|
235
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
236
|
+
checksum = "e665b8803e7b1d2a727f4023456bbbbe74da67099c585258af0ad9c5013b9b99"
|
|
237
|
+
dependencies = [
|
|
238
|
+
"proc-macro2",
|
|
239
|
+
"quote",
|
|
240
|
+
"unicode-ident",
|
|
241
|
+
]
|
|
242
|
+
|
|
243
|
+
[[package]]
|
|
244
|
+
name = "target-lexicon"
|
|
245
|
+
version = "0.12.16"
|
|
246
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
247
|
+
checksum = "61c41af27dd6d1e27b1b16b489db798443478cef1f06a660c96db617ba5de3b1"
|
|
248
|
+
|
|
249
|
+
[[package]]
|
|
250
|
+
name = "unicode-ident"
|
|
251
|
+
version = "1.0.24"
|
|
252
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
253
|
+
checksum = "e6e4313cd5fcd3dad5cafa179702e2b244f760991f45397d14d4ebf38247da75"
|
|
254
|
+
|
|
255
|
+
[[package]]
|
|
256
|
+
name = "unindent"
|
|
257
|
+
version = "0.2.4"
|
|
258
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
259
|
+
checksum = "7264e107f553ccae879d21fbea1d6724ac785e8c3bfc762137959b5802826ef3"
|
|
260
|
+
|
|
261
|
+
[[package]]
|
|
262
|
+
name = "wasi"
|
|
263
|
+
version = "0.11.1+wasi-snapshot-preview1"
|
|
264
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
265
|
+
checksum = "ccf3ec651a847eb01de73ccad15eb7d99f80485de043efb2f370cd654f4ea44b"
|
|
266
|
+
|
|
267
|
+
[[package]]
|
|
268
|
+
name = "zerocopy"
|
|
269
|
+
version = "0.8.42"
|
|
270
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
271
|
+
checksum = "f2578b716f8a7a858b7f02d5bd870c14bf4ddbbcf3a4c05414ba6503640505e3"
|
|
272
|
+
dependencies = [
|
|
273
|
+
"zerocopy-derive",
|
|
274
|
+
]
|
|
275
|
+
|
|
276
|
+
[[package]]
|
|
277
|
+
name = "zerocopy-derive"
|
|
278
|
+
version = "0.8.42"
|
|
279
|
+
source = "registry+https://github.com/rust-lang/crates.io-index"
|
|
280
|
+
checksum = "7e6cc098ea4d3bd6246687de65af3f920c430e236bee1e3bf2e441463f08a02f"
|
|
281
|
+
dependencies = [
|
|
282
|
+
"proc-macro2",
|
|
283
|
+
"quote",
|
|
284
|
+
"syn",
|
|
285
|
+
]
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
[package]
|
|
2
|
+
name = "ahco"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
edition = "2021"
|
|
5
|
+
rust-version = "1.82"
|
|
6
|
+
description = "AHCO-v3 continuous black-box optimization in Rust, with optional Python bindings"
|
|
7
|
+
readme = "README.md"
|
|
8
|
+
license = "MIT OR Apache-2.0"
|
|
9
|
+
documentation = "https://docs.rs/ahco"
|
|
10
|
+
keywords = ["optimization", "black-box", "continuous", "python"]
|
|
11
|
+
categories = ["science"]
|
|
12
|
+
|
|
13
|
+
[lib]
|
|
14
|
+
name = "ahco"
|
|
15
|
+
crate-type = ["rlib", "cdylib"]
|
|
16
|
+
|
|
17
|
+
[features]
|
|
18
|
+
default = []
|
|
19
|
+
python = ["dep:pyo3"]
|
|
20
|
+
|
|
21
|
+
[dependencies]
|
|
22
|
+
rand = "0.8.5"
|
|
23
|
+
rand_chacha = "0.3.1"
|
|
24
|
+
rand_distr = "0.4.3"
|
|
25
|
+
pyo3 = { version = "0.23.5", optional = true, features = ["extension-module"] }
|
ahco_rust-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: ahco-rust
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Rust implementation of AHCO-v3 continuous black-box optimization
|
|
5
|
+
License-Expression: MIT OR Apache-2.0
|
|
6
|
+
Requires-Python: >=3.8
|
|
7
|
+
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
|
|
8
|
+
|
|
9
|
+
# AHCO
|
|
10
|
+
|
|
11
|
+
AHCO is a Rust implementation of the AHCO strategy for maximizing a
|
|
12
|
+
continuous, bounded, black-box objective. It is published as the `ahco` Rust
|
|
13
|
+
crate and can also be built as a Python extension, the Rust implementation uses
|
|
14
|
+
native randomized-tree and feature-selection estimators, so it follows the
|
|
15
|
+
same optimization phases and proposal strategies but is not expected to
|
|
16
|
+
produce bit-for-bit identical results to the scikit-learn Python version.
|
|
17
|
+
|
|
18
|
+
## Rust
|
|
19
|
+
|
|
20
|
+
Add the crate to `Cargo.toml`:
|
|
21
|
+
|
|
22
|
+
```toml
|
|
23
|
+
[dependencies]
|
|
24
|
+
ahco = "0.1"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
Example:
|
|
28
|
+
|
|
29
|
+
```rust
|
|
30
|
+
use ahco::{optimize, AhcoConfig};
|
|
31
|
+
|
|
32
|
+
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
33
|
+
let result = optimize(
|
|
34
|
+
AhcoConfig::new(4, 100, 7),
|
|
35
|
+
|x| Ok(-x.iter().map(|value| (value - 0.7).powi(2)).sum::<f64>()),
|
|
36
|
+
)?;
|
|
37
|
+
|
|
38
|
+
println!("best score: {}", result.best_score);
|
|
39
|
+
println!("best point: {:?}", result.best_x);
|
|
40
|
+
Ok(())
|
|
41
|
+
}
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
Every objective receives a point in `[0, 1]^dimension` and returns a score to
|
|
45
|
+
maximize. Return `Err(AhcoError::Objective(...))` to stop on an objective
|
|
46
|
+
failure. Non-finite scores are treated as very poor scores. `history` contains
|
|
47
|
+
the best score so far after each evaluation.
|
|
48
|
+
|
|
49
|
+
The crate is dual-licensed under MIT or Apache-2.0.
|
|
50
|
+
|
|
51
|
+
## Python
|
|
52
|
+
|
|
53
|
+
Install the extension from this source directory with `pip install .` (a Rust
|
|
54
|
+
toolchain is required to build it):
|
|
55
|
+
|
|
56
|
+
```python
|
|
57
|
+
from ahco_rust import run_ahco3
|
|
58
|
+
|
|
59
|
+
result = run_ahco3(
|
|
60
|
+
lambda x: -sum((value - 0.7) ** 2 for value in x),
|
|
61
|
+
d=4,
|
|
62
|
+
budget=100,
|
|
63
|
+
seed=7,
|
|
64
|
+
)
|
|
65
|
+
|
|
66
|
+
print(result["best_x"], result["best_score"])
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
The Python function accepts the same `f`, `d`, `budget`, `seed`, and optional
|
|
70
|
+
`kmax` arguments as `ahco.py`'s `run_ahco3`. Its result has the same keys:
|
|
71
|
+
`method`, `best_score`, `best_x`, `evaluations`, `history`, and `seconds`.
|
|
72
|
+
The Python objective is called once per evaluation; exceptions raised by it
|
|
73
|
+
are propagated to the caller.
|
|
74
|
+
|
|
75
|
+
## Development
|
|
76
|
+
|
|
77
|
+
```text
|
|
78
|
+
cargo test
|
|
79
|
+
cargo build --features python
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
To publish the Rust crate, run `cargo publish` from this directory. The Python
|
|
83
|
+
extension is built separately from the same crate with maturin/pip.
|
|
84
|
+
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
# AHCO
|
|
2
|
+
|
|
3
|
+
AHCO is a Rust implementation of the AHCO strategy for maximizing a
|
|
4
|
+
continuous, bounded, black-box objective. It is published as the `ahco` Rust
|
|
5
|
+
crate and can also be built as a Python extension, the Rust implementation uses
|
|
6
|
+
native randomized-tree and feature-selection estimators, so it follows the
|
|
7
|
+
same optimization phases and proposal strategies but is not expected to
|
|
8
|
+
produce bit-for-bit identical results to the scikit-learn Python version.
|
|
9
|
+
|
|
10
|
+
## Rust
|
|
11
|
+
|
|
12
|
+
Add the crate to `Cargo.toml`:
|
|
13
|
+
|
|
14
|
+
```toml
|
|
15
|
+
[dependencies]
|
|
16
|
+
ahco = "0.1"
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Example:
|
|
20
|
+
|
|
21
|
+
```rust
|
|
22
|
+
use ahco::{optimize, AhcoConfig};
|
|
23
|
+
|
|
24
|
+
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|
25
|
+
let result = optimize(
|
|
26
|
+
AhcoConfig::new(4, 100, 7),
|
|
27
|
+
|x| Ok(-x.iter().map(|value| (value - 0.7).powi(2)).sum::<f64>()),
|
|
28
|
+
)?;
|
|
29
|
+
|
|
30
|
+
println!("best score: {}", result.best_score);
|
|
31
|
+
println!("best point: {:?}", result.best_x);
|
|
32
|
+
Ok(())
|
|
33
|
+
}
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
Every objective receives a point in `[0, 1]^dimension` and returns a score to
|
|
37
|
+
maximize. Return `Err(AhcoError::Objective(...))` to stop on an objective
|
|
38
|
+
failure. Non-finite scores are treated as very poor scores. `history` contains
|
|
39
|
+
the best score so far after each evaluation.
|
|
40
|
+
|
|
41
|
+
The crate is dual-licensed under MIT or Apache-2.0.
|
|
42
|
+
|
|
43
|
+
## Python
|
|
44
|
+
|
|
45
|
+
Install the extension from this source directory with `pip install .` (a Rust
|
|
46
|
+
toolchain is required to build it):
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from ahco_rust import run_ahco3
|
|
50
|
+
|
|
51
|
+
result = run_ahco3(
|
|
52
|
+
lambda x: -sum((value - 0.7) ** 2 for value in x),
|
|
53
|
+
d=4,
|
|
54
|
+
budget=100,
|
|
55
|
+
seed=7,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
print(result["best_x"], result["best_score"])
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
The Python function accepts the same `f`, `d`, `budget`, `seed`, and optional
|
|
62
|
+
`kmax` arguments as `ahco.py`'s `run_ahco3`. Its result has the same keys:
|
|
63
|
+
`method`, `best_score`, `best_x`, `evaluations`, `history`, and `seconds`.
|
|
64
|
+
The Python objective is called once per evaluation; exceptions raised by it
|
|
65
|
+
are propagated to the caller.
|
|
66
|
+
|
|
67
|
+
## Development
|
|
68
|
+
|
|
69
|
+
```text
|
|
70
|
+
cargo test
|
|
71
|
+
cargo build --features python
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
To publish the Rust crate, run `cargo publish` from this directory. The Python
|
|
75
|
+
extension is built separately from the same crate with maturin/pip.
|