hone-python 0.12.1__tar.gz → 0.12.2__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.
- hone_python-0.12.1/README.md → hone_python-0.12.2/PKG-INFO +43 -0
- hone_python-0.12.1/PKG-INFO → hone_python-0.12.2/README.md +18 -22
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/config/bayesian_config.py +5 -2
- hone_python-0.12.2/hone/config/cmaes_config.py +15 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/config/genetic_optimizer_config.py +23 -15
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/config/multi_objective_config.py +19 -8
- hone_python-0.12.2/hone/config/optimizer_config.py +57 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/pyproject.toml +17 -2
- hone_python-0.12.1/hone/config/cmaes_config.py +0 -11
- hone_python-0.12.1/hone/config/optimizer_config.py +0 -48
- {hone_python-0.12.1 → hone_python-0.12.2}/LICENSE +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/__main__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/conditional.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/constrained.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/ml.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/multi.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/problems.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/benchmarks/runner.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/config/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/objective_function/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/objective_function/objective_function.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/_gp.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/_pool.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/base.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/bayesian.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/choice.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/cmaes.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/core.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/breeding.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/nsga2.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/optimizer.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/selection.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/genetic/variation.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/multi.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/multi_bayesian.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/optimizers/random_search.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/parameters/__init__.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/parameters/conditions.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/parameters/constraints.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/parameters/parameters.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/pareto.py +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/py.typed +0 -0
- {hone_python-0.12.1 → hone_python-0.12.2}/hone/result.py +0 -0
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hone-python
|
|
3
|
+
Version: 0.12.2
|
|
4
|
+
Summary: A python-based optimization engine/library.
|
|
5
|
+
License-Expression: BSD-3-Clause
|
|
6
|
+
License-File: LICENSE
|
|
7
|
+
Author: David Beare
|
|
8
|
+
Author-email: rnbeare@gmail.com
|
|
9
|
+
Requires-Python: >=3.12
|
|
10
|
+
Classifier: Programming Language :: Python :: 3
|
|
11
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
+
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
+
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
+
Requires-Dist: numpy (>=1.26.2)
|
|
16
|
+
Requires-Dist: pydantic (>=2.7,<3.0.0)
|
|
17
|
+
Requires-Dist: pyyaml (>=6.0.3,<7.0.0)
|
|
18
|
+
Requires-Dist: scipy (>=1.13)
|
|
19
|
+
Requires-Dist: threadpoolctl (>=3.5)
|
|
20
|
+
Project-URL: Changelog, https://github.com/GreatEmuWar/hone/blob/main/CHANGELOG.md
|
|
21
|
+
Project-URL: Documentation, https://hone-python.dev/
|
|
22
|
+
Project-URL: Source, https://github.com/GreatEmuWar/hone
|
|
23
|
+
Description-Content-Type: text/markdown
|
|
24
|
+
|
|
1
25
|
# hone
|
|
2
26
|
Python-based optimization engine.
|
|
3
27
|
|
|
28
|
+
Documentation: https://hone-python.dev/
|
|
29
|
+
|
|
4
30
|
## Install
|
|
5
31
|
|
|
6
32
|
```
|
|
@@ -413,6 +439,8 @@ Requires Python 3.12 or later and [Poetry](https://python-poetry.org/) 2.
|
|
|
413
439
|
| --- | --- |
|
|
414
440
|
| `make test` | Install the dependencies and run the tests with coverage |
|
|
415
441
|
| `make lint` | Run ruff, then mypy to check types |
|
|
442
|
+
| `make docs` | Serve the documentation site at http://127.0.0.1:8000, rebuilding as files change (see [Docs](#docs)) |
|
|
443
|
+
| `make docs-build` | Build the documentation site into `site/`, failing on any warning, as CI does |
|
|
416
444
|
| `make docker-test` | Build the Docker image and run the tests inside it (see [Running in Docker](#running-in-docker)) |
|
|
417
445
|
| `make benchmark` | Run the full benchmark suite and update `benchmarks/results.md` |
|
|
418
446
|
| `make benchmark-noisy` | Run the noisy problems and update `benchmarks/noisy-results.md` |
|
|
@@ -421,6 +449,20 @@ Requires Python 3.12 or later and [Poetry](https://python-poetry.org/) 2.
|
|
|
421
449
|
| `make benchmark-conditional` | Run the conditional problems and update `benchmarks/conditional-results.md` |
|
|
422
450
|
| `make benchmark-multi` | Run the multi-objective problems and update `benchmarks/multi-results.md` |
|
|
423
451
|
|
|
452
|
+
### Docs
|
|
453
|
+
|
|
454
|
+
The documentation site is built with [MkDocs Material](https://squidfunk.github.io/mkdocs-material/) from `mkdocs.yml` and the pages in `docs/`. Most pages hold no text of their own: a line such as `<!-- include README.md#constraints level=2 -->` pulls in a section of this README, and others pull in `CHANGELOG.md`, the benchmark results and the examples, so each is written once. `docs/hooks.py` does the including and points links at the site's own pages. The API reference is generated from docstrings by mkdocstrings; a config field is documented by a docstring on the line after it. `docs/design/` holds design notes and isn't published.
|
|
455
|
+
|
|
456
|
+
On every push to `main`, CI builds the site and publishes it to the `gh-pages` branch with [mike](https://github.com/jimporter/mike), as the version `latest`, which GitHub Pages serves at https://hone-python.dev. The repository's Pages settings publish from the `gh-pages` branch with `hone-python.dev` as the custom domain, which GitHub keeps in a `CNAME` file on that branch; mike leaves it in place when it deploys. The domain's DNS is at Cloudflare.
|
|
457
|
+
|
|
458
|
+
Only `latest` is kept for now. To keep the docs of each release once that's needed:
|
|
459
|
+
|
|
460
|
+
1. Add `extra: {version: {provider: mike}}` to `mkdocs.yml`, for the version menu.
|
|
461
|
+
2. Change the deploy step to publish each release as its own version, with `latest` as an alias: `mike deploy --update-aliases 0.13 latest`, run when a version is released.
|
|
462
|
+
3. The first time, run `mike delete latest` just before that deploy, in the same job, since a version and an alias can't share a name.
|
|
463
|
+
|
|
464
|
+
Links to `/latest/...` keep working throughout, now pointing at the newest release.
|
|
465
|
+
|
|
424
466
|
### Running in Docker
|
|
425
467
|
|
|
426
468
|
With [Docker](https://docs.docker.com/get-docker/) installed you can run hone without Python or Poetry on your machine. The image holds hone with its development dependencies, the tests, the examples and the saved benchmark summaries, on Python 3.14.
|
|
@@ -459,3 +501,4 @@ Please report vulnerabilities privately, not as issues: see [SECURITY.md](SECURI
|
|
|
459
501
|
## License
|
|
460
502
|
|
|
461
503
|
BSD 3-Clause. See [LICENSE](LICENSE).
|
|
504
|
+
|
|
@@ -1,27 +1,8 @@
|
|
|
1
|
-
Metadata-Version: 2.4
|
|
2
|
-
Name: hone-python
|
|
3
|
-
Version: 0.12.1
|
|
4
|
-
Summary: A python-based optimization engine/library.
|
|
5
|
-
License-Expression: BSD-3-Clause
|
|
6
|
-
License-File: LICENSE
|
|
7
|
-
Author: David Beare
|
|
8
|
-
Author-email: rnbeare@gmail.com
|
|
9
|
-
Requires-Python: >=3.12
|
|
10
|
-
Classifier: Programming Language :: Python :: 3
|
|
11
|
-
Classifier: Programming Language :: Python :: 3.12
|
|
12
|
-
Classifier: Programming Language :: Python :: 3.13
|
|
13
|
-
Classifier: Programming Language :: Python :: 3.14
|
|
14
|
-
Classifier: Programming Language :: Python :: 3.15
|
|
15
|
-
Requires-Dist: numpy (>=1.26.2)
|
|
16
|
-
Requires-Dist: pydantic (>=2.7,<3.0.0)
|
|
17
|
-
Requires-Dist: pyyaml (>=6.0.1,<7.0.0)
|
|
18
|
-
Requires-Dist: scipy (>=1.13)
|
|
19
|
-
Requires-Dist: threadpoolctl (>=3.5)
|
|
20
|
-
Description-Content-Type: text/markdown
|
|
21
|
-
|
|
22
1
|
# hone
|
|
23
2
|
Python-based optimization engine.
|
|
24
3
|
|
|
4
|
+
Documentation: https://hone-python.dev/
|
|
5
|
+
|
|
25
6
|
## Install
|
|
26
7
|
|
|
27
8
|
```
|
|
@@ -434,6 +415,8 @@ Requires Python 3.12 or later and [Poetry](https://python-poetry.org/) 2.
|
|
|
434
415
|
| --- | --- |
|
|
435
416
|
| `make test` | Install the dependencies and run the tests with coverage |
|
|
436
417
|
| `make lint` | Run ruff, then mypy to check types |
|
|
418
|
+
| `make docs` | Serve the documentation site at http://127.0.0.1:8000, rebuilding as files change (see [Docs](#docs)) |
|
|
419
|
+
| `make docs-build` | Build the documentation site into `site/`, failing on any warning, as CI does |
|
|
437
420
|
| `make docker-test` | Build the Docker image and run the tests inside it (see [Running in Docker](#running-in-docker)) |
|
|
438
421
|
| `make benchmark` | Run the full benchmark suite and update `benchmarks/results.md` |
|
|
439
422
|
| `make benchmark-noisy` | Run the noisy problems and update `benchmarks/noisy-results.md` |
|
|
@@ -442,6 +425,20 @@ Requires Python 3.12 or later and [Poetry](https://python-poetry.org/) 2.
|
|
|
442
425
|
| `make benchmark-conditional` | Run the conditional problems and update `benchmarks/conditional-results.md` |
|
|
443
426
|
| `make benchmark-multi` | Run the multi-objective problems and update `benchmarks/multi-results.md` |
|
|
444
427
|
|
|
428
|
+
### Docs
|
|
429
|
+
|
|
430
|
+
The documentation site is built with [MkDocs Material](https://squidfunk.github.io/mkdocs-material/) from `mkdocs.yml` and the pages in `docs/`. Most pages hold no text of their own: a line such as `<!-- include README.md#constraints level=2 -->` pulls in a section of this README, and others pull in `CHANGELOG.md`, the benchmark results and the examples, so each is written once. `docs/hooks.py` does the including and points links at the site's own pages. The API reference is generated from docstrings by mkdocstrings; a config field is documented by a docstring on the line after it. `docs/design/` holds design notes and isn't published.
|
|
431
|
+
|
|
432
|
+
On every push to `main`, CI builds the site and publishes it to the `gh-pages` branch with [mike](https://github.com/jimporter/mike), as the version `latest`, which GitHub Pages serves at https://hone-python.dev. The repository's Pages settings publish from the `gh-pages` branch with `hone-python.dev` as the custom domain, which GitHub keeps in a `CNAME` file on that branch; mike leaves it in place when it deploys. The domain's DNS is at Cloudflare.
|
|
433
|
+
|
|
434
|
+
Only `latest` is kept for now. To keep the docs of each release once that's needed:
|
|
435
|
+
|
|
436
|
+
1. Add `extra: {version: {provider: mike}}` to `mkdocs.yml`, for the version menu.
|
|
437
|
+
2. Change the deploy step to publish each release as its own version, with `latest` as an alias: `mike deploy --update-aliases 0.13 latest`, run when a version is released.
|
|
438
|
+
3. The first time, run `mike delete latest` just before that deploy, in the same job, since a version and an alias can't share a name.
|
|
439
|
+
|
|
440
|
+
Links to `/latest/...` keep working throughout, now pointing at the newest release.
|
|
441
|
+
|
|
445
442
|
### Running in Docker
|
|
446
443
|
|
|
447
444
|
With [Docker](https://docs.docker.com/get-docker/) installed you can run hone without Python or Poetry on your machine. The image holds hone with its development dependencies, the tests, the examples and the saved benchmark summaries, on Python 3.14.
|
|
@@ -480,4 +477,3 @@ Please report vulnerabilities privately, not as issues: see [SECURITY.md](SECURI
|
|
|
480
477
|
## License
|
|
481
478
|
|
|
482
479
|
BSD 3-Clause. See [LICENSE](LICENSE).
|
|
483
|
-
|
|
@@ -11,9 +11,12 @@ class BayesianConfig(OptimizerConfig):
|
|
|
11
11
|
Each generation is a batch of candidates chosen together. When max_evaluations is set and
|
|
12
12
|
generations isn't, generations defaults to the budget, so the run ends when the budget is spent.
|
|
13
13
|
"""
|
|
14
|
-
population_size: int | None = Field(default=None, ge=1) # type: ignore[assignment]
|
|
14
|
+
population_size: int | None = Field(default=None, ge=1) # type: ignore[assignment]
|
|
15
|
+
"""Candidates per batch. None: 1, or the number of workers."""
|
|
15
16
|
generations: int = Field(default=100, ge=1)
|
|
16
|
-
|
|
17
|
+
"""Batches to run, unless the run stops sooner."""
|
|
18
|
+
initial_samples: int | None = Field(default=None, ge=1)
|
|
19
|
+
"""Spread-out candidates evaluated before the model is used. None: 2 × (variables + 1)."""
|
|
17
20
|
|
|
18
21
|
@model_validator(mode="before")
|
|
19
22
|
@classmethod
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
from pydantic import Field
|
|
2
|
+
|
|
3
|
+
from .optimizer_config import OptimizerConfig
|
|
4
|
+
|
|
5
|
+
|
|
6
|
+
class CMAESConfig(OptimizerConfig):
|
|
7
|
+
"""Configuration for CMA-ES. The defaults suit most problems; usually only the budget needs setting."""
|
|
8
|
+
population_size: int | None = Field(default=None, ge=2) # type: ignore[assignment]
|
|
9
|
+
"""Candidates per generation. None: 4 + 3 ln(n) for n variables, or twice the workers if more."""
|
|
10
|
+
generations: int = Field(default=1000, ge=1)
|
|
11
|
+
"""An upper bound; max_evaluations is the usual way to set a budget."""
|
|
12
|
+
initial_step: float = Field(default=0.3, gt=0, le=1)
|
|
13
|
+
"""Starting step size, as a fraction of each range."""
|
|
14
|
+
restarts: bool = True
|
|
15
|
+
"""Restart with double the population when a run converges or stalls (IPOP-CMA-ES)."""
|
|
@@ -27,30 +27,38 @@ class GeneticOptimizerConfig(OptimizerConfig):
|
|
|
27
27
|
population to about a twentieth of the budget, between 16 and 50, and generations to
|
|
28
28
|
as many as the budget allows. Without a budget they default to 100 and 25.
|
|
29
29
|
"""
|
|
30
|
-
# Chance each gene of a child is mutated. None: 1 / the number of variables, at least 0.1;
|
|
31
|
-
# with noise, 0.1, which the benchmark's noisy problems favour at large budgets.
|
|
32
30
|
mutation_rate: float | None = Field(default=None, ge=0, le=1)
|
|
33
|
-
|
|
34
|
-
|
|
31
|
+
"""Chance each gene of a child is mutated. None: 1 / the number of variables, at least 0.1;
|
|
32
|
+
with noise, 0.1, which the benchmark's noisy problems favour at large budgets."""
|
|
35
33
|
mutation_scale: float = Field(default=0.1, gt=0)
|
|
36
|
-
|
|
37
|
-
|
|
34
|
+
"""Size of a range mutation, as a fraction of the range width: the starting size when
|
|
35
|
+
mutation adapts, and the size throughout when it doesn't."""
|
|
38
36
|
adaptive_mutation: bool | None = None
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
"""Each individual carries its own mutation size, which its children inherit and vary, so
|
|
38
|
+
selection tunes it as the run goes. None: on, except with noise, where it didn't help."""
|
|
39
|
+
crossover_rate: float = Field(default=0.8, ge=0, le=1)
|
|
40
|
+
"""Chance each gene of a child comes from its first parent."""
|
|
42
41
|
blend_crossover: bool = True
|
|
42
|
+
"""Draw each range value of a child from between its parents' values, widened by blend_alpha
|
|
43
|
+
times their distance on each side, rather than copying one."""
|
|
43
44
|
blend_alpha: float = Field(default=0.1, ge=0)
|
|
45
|
+
"""How far beyond its parents' values a blended range value may fall, as a multiple of
|
|
46
|
+
their distance."""
|
|
44
47
|
elitism: bool = True
|
|
45
|
-
|
|
48
|
+
"""Carry the fittest individuals over to the next generation unchanged."""
|
|
49
|
+
elitism_rate: float = Field(default=0.1, ge=0, lt=1)
|
|
50
|
+
"""Share of each generation carried over unchanged, at most all but one individual."""
|
|
46
51
|
selection_method: SelectionMethod = SelectionMethod.TOURNAMENT
|
|
52
|
+
"""How parents are chosen."""
|
|
47
53
|
tournament_size: int = Field(default=4, ge=2)
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
# late, on large budgets; costs on small ones. 0 turns niches off. None, the default, means
|
|
52
|
-
# 0.5 for a search space with conditions, where each branch is a niche, and 0 otherwise.
|
|
54
|
+
"""Individuals drawn for each tournament; the fittest of them becomes a parent."""
|
|
55
|
+
tournament_p: float = Field(default=1.0, ge=0, le=1)
|
|
56
|
+
"""Chance a tournament picks its best rather than its worst."""
|
|
53
57
|
niche_share: float | None = Field(default=None, ge=0, lt=1)
|
|
58
|
+
"""Share of children bred within niches of parents with the same choice parameter values, so
|
|
59
|
+
each option keeps tuning its own numbers. Helps problems where the best choice is found
|
|
60
|
+
late, on large budgets; costs on small ones. 0 turns niches off. None, the default, means
|
|
61
|
+
0.5 for a search space with conditions, where each branch is a niche, and 0 otherwise."""
|
|
54
62
|
|
|
55
63
|
@model_validator(mode="before")
|
|
56
64
|
@classmethod
|
|
@@ -18,9 +18,10 @@ class MultiObjectiveConfig(OptimizerConfig):
|
|
|
18
18
|
don't apply.
|
|
19
19
|
"""
|
|
20
20
|
objectives: dict[str, Direction] = Field(min_length=2)
|
|
21
|
-
|
|
22
|
-
# the worst value of each objective in the first generation, a tenth of its range further out.
|
|
21
|
+
"""Each objective's name, and whether to minimize or maximize it."""
|
|
23
22
|
reference: dict[str, float] | None = None
|
|
23
|
+
"""A point every objective must be better than to count toward hypervolume, by objective. None:
|
|
24
|
+
the worst value of each objective in the first generation, a tenth of its range further out."""
|
|
24
25
|
|
|
25
26
|
@model_validator(mode="after")
|
|
26
27
|
def _check_objectives(self):
|
|
@@ -42,13 +43,20 @@ class NSGA2Config(MultiObjectiveConfig):
|
|
|
42
43
|
are NSGA-II's own. With max_evaluations set, population_size and generations default as
|
|
43
44
|
for the genetic optimizer.
|
|
44
45
|
"""
|
|
45
|
-
mutation_rate: float | None = Field(default=None, ge=0, le=1)
|
|
46
|
+
mutation_rate: float | None = Field(default=None, ge=0, le=1)
|
|
47
|
+
"""As in GeneticOptimizerConfig: chance each gene of a child is mutated."""
|
|
46
48
|
mutation_scale: float = Field(default=0.1, gt=0)
|
|
49
|
+
"""As in GeneticOptimizerConfig: size of a range mutation, as a fraction of the range width."""
|
|
47
50
|
adaptive_mutation: bool | None = None
|
|
51
|
+
"""As in GeneticOptimizerConfig: each individual carries its own mutation size."""
|
|
48
52
|
crossover_rate: float = Field(default=0.8, ge=0, le=1)
|
|
53
|
+
"""As in GeneticOptimizerConfig: chance each gene of a child comes from its first parent."""
|
|
49
54
|
blend_crossover: bool = True
|
|
55
|
+
"""As in GeneticOptimizerConfig: draw each range value of a child from between its parents' values."""
|
|
50
56
|
blend_alpha: float = Field(default=0.1, ge=0)
|
|
57
|
+
"""As in GeneticOptimizerConfig: how far beyond its parents' values a blended value may fall."""
|
|
51
58
|
niche_share: float | None = Field(default=None, ge=0, lt=1)
|
|
59
|
+
"""As in GeneticOptimizerConfig: share of children bred within niches of parents with the same choices."""
|
|
52
60
|
|
|
53
61
|
@model_validator(mode="before")
|
|
54
62
|
@classmethod
|
|
@@ -70,13 +78,16 @@ class MultiObjectiveBayesianConfig(MultiObjectiveConfig):
|
|
|
70
78
|
As with BayesianConfig, each generation is a batch of candidates chosen together, and with
|
|
71
79
|
max_evaluations set, generations defaults to the budget.
|
|
72
80
|
"""
|
|
73
|
-
population_size: int | None = Field(default=None, ge=1) # type: ignore[assignment]
|
|
81
|
+
population_size: int | None = Field(default=None, ge=1) # type: ignore[assignment]
|
|
82
|
+
"""Candidates per batch. None: 1, or the number of workers."""
|
|
74
83
|
generations: int = Field(default=100, ge=1)
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
# with the weighting applied to their predictions.
|
|
84
|
+
"""Batches to run, unless the run stops sooner."""
|
|
85
|
+
initial_samples: int | None = Field(default=None, ge=1)
|
|
86
|
+
"""Spread-out candidates evaluated before the models are used. None: 2 × (variables + 1)."""
|
|
79
87
|
method: Literal["parego", "models"] = "parego"
|
|
88
|
+
"""How candidates are chosen. "parego": a random weighting of the scaled objectives per
|
|
89
|
+
candidate, scored by one Gaussian process. "models": one Gaussian process per objective,
|
|
90
|
+
with the weighting applied to their predictions."""
|
|
80
91
|
|
|
81
92
|
@model_validator(mode="before")
|
|
82
93
|
@classmethod
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
from pathlib import Path
|
|
2
|
+
from typing import Self
|
|
3
|
+
|
|
4
|
+
import yaml
|
|
5
|
+
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
6
|
+
|
|
7
|
+
|
|
8
|
+
class OptimizerConfig(BaseModel):
|
|
9
|
+
"""Settings shared by every optimizer."""
|
|
10
|
+
# use_attribute_docstrings makes each field's docstring its description, in the JSON schema
|
|
11
|
+
# and in the documentation.
|
|
12
|
+
model_config = ConfigDict(extra="forbid", frozen=True, use_attribute_docstrings=True)
|
|
13
|
+
|
|
14
|
+
population_size: int = Field(default=100, ge=2)
|
|
15
|
+
"""Individuals evaluated per generation."""
|
|
16
|
+
generations: int = Field(default=25, ge=1)
|
|
17
|
+
"""Generations to run, unless the run stops sooner."""
|
|
18
|
+
max_evaluations: int | None = Field(default=None, ge=1)
|
|
19
|
+
"""Stop after this many evaluations, even partway through a generation."""
|
|
20
|
+
maximize: bool = False
|
|
21
|
+
"""Maximize the objective instead of minimizing it."""
|
|
22
|
+
threshold: float | None = None
|
|
23
|
+
"""Stop once the best fitness reaches this."""
|
|
24
|
+
seed: int | None = None
|
|
25
|
+
"""Fixes the random number generator, so runs can be repeated."""
|
|
26
|
+
noise: bool = False
|
|
27
|
+
"""The objective is noisy: evaluating the same point twice can give different values."""
|
|
28
|
+
final_evaluations: int = Field(default=0, ge=0)
|
|
29
|
+
"""With noise, evaluations kept back to re-evaluate the most promising points at the end, so
|
|
30
|
+
the result is chosen, and its value reported, from averages rather than single lucky values."""
|
|
31
|
+
min_finished: float = Field(default=1.0, gt=0, le=1)
|
|
32
|
+
"""The share of each generation's evaluations that must finish before the next generation is
|
|
33
|
+
bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background,
|
|
34
|
+
and their results join the generation under way when they arrive. Results then depend on
|
|
35
|
+
timing, so runs are no longer exactly repeatable."""
|
|
36
|
+
|
|
37
|
+
@model_validator(mode="after")
|
|
38
|
+
def _check_final_evaluations(self):
|
|
39
|
+
if self.final_evaluations and self.max_evaluations is not None and self.final_evaluations >= self.max_evaluations:
|
|
40
|
+
raise ValueError(
|
|
41
|
+
f"final_evaluations {self.final_evaluations} leaves nothing of max_evaluations {self.max_evaluations} for the search"
|
|
42
|
+
)
|
|
43
|
+
return self
|
|
44
|
+
|
|
45
|
+
@property
|
|
46
|
+
def reserved_evaluations(self) -> int:
|
|
47
|
+
"""Evaluations kept back for the final re-evaluation: none without noise."""
|
|
48
|
+
return self.final_evaluations if self.noise else 0
|
|
49
|
+
|
|
50
|
+
@classmethod
|
|
51
|
+
def from_file(cls, filepath: str | Path) -> Self:
|
|
52
|
+
"""Create a config from a JSON or YAML file."""
|
|
53
|
+
filepath = Path(filepath)
|
|
54
|
+
text = filepath.read_text()
|
|
55
|
+
if filepath.suffix.lower() in {".yaml", ".yml"}:
|
|
56
|
+
return cls.model_validate(yaml.safe_load(text) or {})
|
|
57
|
+
return cls.model_validate_json(text)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
[project]
|
|
2
2
|
name = "hone-python"
|
|
3
|
-
version = "0.12.
|
|
3
|
+
version = "0.12.2"
|
|
4
4
|
description = "A python-based optimization engine/library."
|
|
5
5
|
authors = [{ name = "David Beare", email = "rnbeare@gmail.com" }]
|
|
6
6
|
readme = "README.md"
|
|
@@ -9,7 +9,7 @@ license-files = ["LICENSE"]
|
|
|
9
9
|
requires-python = ">=3.12"
|
|
10
10
|
dependencies = [
|
|
11
11
|
"numpy (>=1.26.2)",
|
|
12
|
-
"pyyaml (>=6.0.
|
|
12
|
+
"pyyaml (>=6.0.3,<7.0.0)",
|
|
13
13
|
"pydantic (>=2.7,<3.0.0)",
|
|
14
14
|
"scipy (>=1.13)",
|
|
15
15
|
"threadpoolctl (>=3.5)",
|
|
@@ -19,6 +19,15 @@ dependencies = [
|
|
|
19
19
|
[tool.poetry]
|
|
20
20
|
packages = [{ include = "hone" }]
|
|
21
21
|
|
|
22
|
+
# Only for building the docs site: poetry install --with docs
|
|
23
|
+
[tool.poetry.group.docs]
|
|
24
|
+
optional = true
|
|
25
|
+
|
|
26
|
+
[project.urls]
|
|
27
|
+
Documentation = "https://hone-python.dev/"
|
|
28
|
+
Source = "https://github.com/GreatEmuWar/hone"
|
|
29
|
+
Changelog = "https://github.com/GreatEmuWar/hone/blob/main/CHANGELOG.md"
|
|
30
|
+
|
|
22
31
|
[build-system]
|
|
23
32
|
requires = ["poetry-core>=2.0.0,<3.0.0"]
|
|
24
33
|
build-backend = "poetry.core.masonry.api"
|
|
@@ -34,6 +43,12 @@ dev = [
|
|
|
34
43
|
"scipy-stubs (>=1.18.1.1,<2.0.0.0)",
|
|
35
44
|
"hypothesis (>=6.170,<7.0)"
|
|
36
45
|
]
|
|
46
|
+
docs = [
|
|
47
|
+
"mkdocs-material (>=9.8.0,<10.0.0)",
|
|
48
|
+
"mkdocstrings-python (>=2.0.10,<3.0.0)",
|
|
49
|
+
"griffe-pydantic (>=1.3.2,<2.0.0)",
|
|
50
|
+
"mike (>=2.2.0,<3.0.0)"
|
|
51
|
+
]
|
|
37
52
|
|
|
38
53
|
[tool.pytest.ini_options]
|
|
39
54
|
testpaths = ["tests", "pbt/tests"]
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
from pydantic import Field
|
|
2
|
-
|
|
3
|
-
from .optimizer_config import OptimizerConfig
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
class CMAESConfig(OptimizerConfig):
|
|
7
|
-
"""Configuration for CMA-ES. The defaults suit most problems; usually only the budget needs setting."""
|
|
8
|
-
population_size: int | None = Field(default=None, ge=2) # type: ignore[assignment] # None: 4 + 3 ln(n) for n variables, or twice the workers if more
|
|
9
|
-
generations: int = Field(default=1000, ge=1) # an upper bound; max_evaluations is the usual way to set a budget
|
|
10
|
-
initial_step: float = Field(default=0.3, gt=0, le=1) # starting step size, as a fraction of each range
|
|
11
|
-
restarts: bool = True # restart with double the population when a run converges or stalls (IPOP-CMA-ES)
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
from pathlib import Path
|
|
2
|
-
from typing import Self
|
|
3
|
-
|
|
4
|
-
import yaml
|
|
5
|
-
from pydantic import BaseModel, ConfigDict, Field, model_validator
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
class OptimizerConfig(BaseModel):
|
|
9
|
-
"""Settings shared by every optimizer."""
|
|
10
|
-
model_config = ConfigDict(extra="forbid", frozen=True)
|
|
11
|
-
|
|
12
|
-
population_size: int = Field(default=100, ge=2) # individuals evaluated per generation
|
|
13
|
-
generations: int = Field(default=25, ge=1)
|
|
14
|
-
max_evaluations: int | None = Field(default=None, ge=1) # stop after this many evaluations, even mid-generation
|
|
15
|
-
maximize: bool = False
|
|
16
|
-
threshold: float | None = None # stop once the best fitness reaches this
|
|
17
|
-
seed: int | None = None # fixes the random number generator, so runs can be repeated
|
|
18
|
-
noise: bool = False # the objective is noisy: evaluating the same point twice can give different values
|
|
19
|
-
# With noise, evaluations kept back to re-evaluate the most promising points at the end, so
|
|
20
|
-
# the result is chosen, and its value reported, from averages rather than single lucky values
|
|
21
|
-
final_evaluations: int = Field(default=0, ge=0)
|
|
22
|
-
# The share of each generation's evaluations that must finish before the next generation is
|
|
23
|
-
# bred. Below 1, the slowest evaluations don't hold up the run: they finish in the background,
|
|
24
|
-
# and their results join the generation under way when they arrive. Results then depend on
|
|
25
|
-
# timing, so runs are no longer exactly repeatable.
|
|
26
|
-
min_finished: float = Field(default=1.0, gt=0, le=1)
|
|
27
|
-
|
|
28
|
-
@model_validator(mode="after")
|
|
29
|
-
def _check_final_evaluations(self):
|
|
30
|
-
if self.final_evaluations and self.max_evaluations is not None and self.final_evaluations >= self.max_evaluations:
|
|
31
|
-
raise ValueError(
|
|
32
|
-
f"final_evaluations {self.final_evaluations} leaves nothing of max_evaluations {self.max_evaluations} for the search"
|
|
33
|
-
)
|
|
34
|
-
return self
|
|
35
|
-
|
|
36
|
-
@property
|
|
37
|
-
def reserved_evaluations(self) -> int:
|
|
38
|
-
"""Evaluations kept back for the final re-evaluation: none without noise."""
|
|
39
|
-
return self.final_evaluations if self.noise else 0
|
|
40
|
-
|
|
41
|
-
@classmethod
|
|
42
|
-
def from_file(cls, filepath: str | Path) -> Self:
|
|
43
|
-
"""Create a config from a JSON or YAML file."""
|
|
44
|
-
filepath = Path(filepath)
|
|
45
|
-
text = filepath.read_text()
|
|
46
|
-
if filepath.suffix.lower() in {".yaml", ".yml"}:
|
|
47
|
-
return cls.model_validate(yaml.safe_load(text) or {})
|
|
48
|
-
return cls.model_validate_json(text)
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|