l2co-optimizers 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.
- l2co_optimizers-0.1.0/LICENSE +28 -0
- l2co_optimizers-0.1.0/MANIFEST.in +3 -0
- l2co_optimizers-0.1.0/PKG-INFO +173 -0
- l2co_optimizers-0.1.0/README.md +127 -0
- l2co_optimizers-0.1.0/pyproject.toml +123 -0
- l2co_optimizers-0.1.0/setup.cfg +4 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/__init__.py +256 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/__init__.py +1 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/evosax_implementations.py +603 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/experimentdata.py +71 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/handshake_policy.py +288 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/lbfgs.py +506 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/loss.py +88 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/mapping.py +100 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/menu_eval.py +387 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/opt_history.py +200 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/optax_implementations.py +542 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/optimizer_schedule.py +363 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/popsize.py +149 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/random_search.py +252 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/rbf_trust_region.py +585 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/sampler.py +290 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/shade.py +667 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/state_transfer.py +1364 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/stopping_criteria.py +156 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/sub_optimizer.py +852 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/turbo.py +525 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/typing.py +147 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/update_class.py +177 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/_src/utils.py +24 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/__init__.py +5 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/__init__.py +0 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/adam.yaml +24 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/all.yaml +183 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/contrast.yaml +32 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/gaussian_classification.yaml +10 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/headroom4.yaml +26 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/lr_sweep_pde.yaml +20 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/medium.yaml +13 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/pde.yaml +22 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/sepcmaes.yaml +10 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/small.yaml +7 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/standard.yaml +34 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/standard_no_stopping.yaml +14 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/supercompressible.yaml +7 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers/conf/optimizers/two_functions.yaml +14 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers.egg-info/PKG-INFO +173 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers.egg-info/SOURCES.txt +62 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers.egg-info/dependency_links.txt +1 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers.egg-info/requires.txt +30 -0
- l2co_optimizers-0.1.0/src/l2co_optimizers.egg-info/top_level.txt +1 -0
- l2co_optimizers-0.1.0/tests/test_conf_optimizers.py +83 -0
- l2co_optimizers-0.1.0/tests/test_even_popsize.py +68 -0
- l2co_optimizers-0.1.0/tests/test_handshake_policy.py +112 -0
- l2co_optimizers-0.1.0/tests/test_l2co_tasks_integration.py +65 -0
- l2co_optimizers-0.1.0/tests/test_lbfgs.py +331 -0
- l2co_optimizers-0.1.0/tests/test_menu_loss_and_grad.py +333 -0
- l2co_optimizers-0.1.0/tests/test_optimizers_facade.py +111 -0
- l2co_optimizers-0.1.0/tests/test_rbf_trust_region.py +302 -0
- l2co_optimizers-0.1.0/tests/test_schedule_namer.py +45 -0
- l2co_optimizers-0.1.0/tests/test_shade.py +419 -0
- l2co_optimizers-0.1.0/tests/test_state_transfer.py +1113 -0
- l2co_optimizers-0.1.0/tests/test_sub_optimizer_dispatch.py +176 -0
- l2co_optimizers-0.1.0/tests/test_turbo.py +214 -0
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
BSD 3-Clause License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026, Martin van der Schelling
|
|
4
|
+
|
|
5
|
+
Redistribution and use in source and binary forms, with or without
|
|
6
|
+
modification, are permitted provided that the following conditions are met:
|
|
7
|
+
|
|
8
|
+
1. Redistributions of source code must retain the above copyright notice, this
|
|
9
|
+
list of conditions and the following disclaimer.
|
|
10
|
+
|
|
11
|
+
2. Redistributions in binary form must reproduce the above copyright notice,
|
|
12
|
+
this list of conditions and the following disclaimer in the documentation
|
|
13
|
+
and/or other materials provided with the distribution.
|
|
14
|
+
|
|
15
|
+
3. Neither the name of the copyright holder nor the names of its
|
|
16
|
+
contributors may be used to endorse or promote products derived from
|
|
17
|
+
this software without specific prior written permission.
|
|
18
|
+
|
|
19
|
+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
|
20
|
+
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
21
|
+
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
|
22
|
+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
|
23
|
+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
24
|
+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
|
25
|
+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
|
26
|
+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
|
27
|
+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
28
|
+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: l2co-optimizers
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Bare optimizers compatible with the L2CO library
|
|
5
|
+
Author-email: Martin van der Schelling <m.p.vanderschelling@tudelft.nl>
|
|
6
|
+
Maintainer-email: Martin van der Schelling <m.p.vanderschelling@tudelft.nl>
|
|
7
|
+
License-Expression: BSD-3-Clause
|
|
8
|
+
Project-URL: bugs, https://github.com/bessagroup/l2co-optimizers/issues
|
|
9
|
+
Project-URL: homepage, https://github.com/bessagroup/l2co-optimizers
|
|
10
|
+
Keywords: optimization,optimizers,jax,evolution-strategies
|
|
11
|
+
Classifier: Intended Audience :: Science/Research
|
|
12
|
+
Classifier: Topic :: Scientific/Engineering :: Artificial Intelligence
|
|
13
|
+
Classifier: Topic :: Software Development :: Libraries :: Python Modules
|
|
14
|
+
Classifier: Programming Language :: Python :: 3
|
|
15
|
+
Requires-Python: >=3.12
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
License-File: LICENSE
|
|
18
|
+
Requires-Dist: equinox<0.14,>=0.13.0
|
|
19
|
+
Requires-Dist: evosax<0.3,>=0.2.0
|
|
20
|
+
Requires-Dist: f3dasm
|
|
21
|
+
Requires-Dist: flax>=0.12.0
|
|
22
|
+
Requires-Dist: hydra-core>=1.3.2
|
|
23
|
+
Requires-Dist: jax<=0.9.1,>=0.4.30
|
|
24
|
+
Requires-Dist: jaxtyping>=0.3.2
|
|
25
|
+
Requires-Dist: omegaconf
|
|
26
|
+
Requires-Dist: optax>=0.2.5
|
|
27
|
+
Provides-Extra: dev
|
|
28
|
+
Requires-Dist: setuptools>=77.0.0; extra == "dev"
|
|
29
|
+
Requires-Dist: build; extra == "dev"
|
|
30
|
+
Requires-Dist: wheel; extra == "dev"
|
|
31
|
+
Requires-Dist: pre-commit>=4.4.0; extra == "dev"
|
|
32
|
+
Requires-Dist: ruff>=0.14.10; extra == "dev"
|
|
33
|
+
Provides-Extra: docs
|
|
34
|
+
Requires-Dist: mkdocs>=1.6.0; extra == "docs"
|
|
35
|
+
Requires-Dist: mkdocs-gen-files>=0.5.0; extra == "docs"
|
|
36
|
+
Requires-Dist: mkdocs-include-exclude-files>=0.1.0; extra == "docs"
|
|
37
|
+
Requires-Dist: mkdocs-ipynb>=0.1.1; extra == "docs"
|
|
38
|
+
Requires-Dist: mkdocs-material>=9.6.20; extra == "docs"
|
|
39
|
+
Requires-Dist: mkdocstrings>=0.30.1; extra == "docs"
|
|
40
|
+
Requires-Dist: mkdocstrings-python>=1.18.2; extra == "docs"
|
|
41
|
+
Requires-Dist: pymdown-extensions>=10.16.1; extra == "docs"
|
|
42
|
+
Provides-Extra: tests
|
|
43
|
+
Requires-Dist: pytest>=8.4.1; extra == "tests"
|
|
44
|
+
Requires-Dist: pytest-cov>=6.2.1; extra == "tests"
|
|
45
|
+
Dynamic: license-file
|
|
46
|
+
|
|
47
|
+

|
|
48
|
+
|
|
49
|
+
# L2CO Optimizers
|
|
50
|
+
|
|
51
|
+
| [**GitHub**](https://github.com/bessagroup/l2co-optimizers)
|
|
52
|
+
|
|
53
|
+
Bare optimizers compatible with the L2CO library
|
|
54
|
+
|
|
55
|
+
***
|
|
56
|
+
|
|
57
|
+
## Summary
|
|
58
|
+
|
|
59
|
+
`l2co-optimizers` is the optimizer half of the [L2CO](https://github.com/bessagroup/l2co) ecosystem, as [`l2co-tasks`](https://github.com/bessagroup/l2co-tasks) is the task half. It provides:
|
|
60
|
+
- **a name registry** of ready-to-run optimizers: the optax gradient methods, the evosax distribution- and population-based algorithms, plus SHADE, TuRBO, an RBF trust region, per-evaluation-key L-BFGS and random search;
|
|
61
|
+
- **the `UpdateClass` container** every registry factory returns;
|
|
62
|
+
- **the `OptimizationStep` spec** that names an optimizer with its hyperparameters and stopping criteria;
|
|
63
|
+
- **ready-made Hydra optimizer configs**.
|
|
64
|
+
|
|
65
|
+
It also ships the *strategy-facing* layer meta-optimizers dispatch through: the `SubOpt` adapter, the per-optimizer handshake policy and state transfer, and menu-dispatched loss evaluation. The meta-optimization strategies themselves (`l2co`, `rl2co`, `agentic-l2co`) and the loop that runs an optimizer on a task stay in [`l2co`](https://github.com/bessagroup/l2co).
|
|
66
|
+
|
|
67
|
+
## Statement of need
|
|
68
|
+
|
|
69
|
+
Learning-to-optimize and optimizer-selection research needs many optimizers behind one calling convention, so that a selector can switch between them mid-run. `l2co-optimizers` provides that convention without the meta-learning stack:
|
|
70
|
+
- every optimizer is built by `optimizer_mapping(name)(task=..., opt_hash=..., bounded=..., stop_fn=...)`;
|
|
71
|
+
- every one steps through the same `(params, opt_state, key)` carry;
|
|
72
|
+
- every one reports into the same `OptHistory`.
|
|
73
|
+
|
|
74
|
+
It depends on neither `l2co` nor `l2co-tasks`. A task reaches it only through `TaskLike`, a structural protocol (`model`, `loss_fn`, `pass_rng`) that `l2co_tasks.Task` satisfies unchanged. `l2co` is the bridge that runs one on the other.
|
|
75
|
+
|
|
76
|
+
## Authorship
|
|
77
|
+
|
|
78
|
+
**Authors**:
|
|
79
|
+
- Martin van der Schelling ([m.p.vanderschelling@tudelft.nl](mailto:m.p.vanderschelling@tudelft.nl))
|
|
80
|
+
|
|
81
|
+
**Authors affiliation:**
|
|
82
|
+
- Delft University of Technology (Bessa Research Group)
|
|
83
|
+
|
|
84
|
+
**Maintainer:**
|
|
85
|
+
- Martin van der Schelling ([m.p.vanderschelling@tudelft.nl](mailto:m.p.vanderschelling@tudelft.nl))
|
|
86
|
+
|
|
87
|
+
**Maintainer affiliation:**
|
|
88
|
+
- Delft University of Technology (Bessa Research Group)
|
|
89
|
+
|
|
90
|
+
## Getting started
|
|
91
|
+
|
|
92
|
+
`l2co-optimizers` is `uv`-managed and depends on an editable install of a sibling [`f3dasm`](https://github.com/bessagroup/f3dasm) checkout, so lay the repositories out side by side before syncing:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git clone https://github.com/bessagroup/f3dasm.git
|
|
96
|
+
git clone https://github.com/bessagroup/l2co-optimizers.git
|
|
97
|
+
cd l2co-optimizers
|
|
98
|
+
uv sync
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
Build an optimizer from the registry and step it. Any object with `model`, `loss_fn` and `pass_rng` is a task:
|
|
102
|
+
|
|
103
|
+
```python
|
|
104
|
+
from dataclasses import dataclass
|
|
105
|
+
import jax.numpy as jnp, jax.random as jr
|
|
106
|
+
from l2co_optimizers import optimizer_mapping, TaskLike
|
|
107
|
+
|
|
108
|
+
@dataclass
|
|
109
|
+
class Sphere:
|
|
110
|
+
model = jnp.zeros(4)
|
|
111
|
+
pass_rng = False
|
|
112
|
+
def loss_fn(self, x, **sample):
|
|
113
|
+
return jnp.sum((x - 0.5) ** 2)
|
|
114
|
+
|
|
115
|
+
task = Sphere()
|
|
116
|
+
assert isinstance(task, TaskLike)
|
|
117
|
+
|
|
118
|
+
cmaes = optimizer_mapping("cmaes")(task=task, opt_hash=1)
|
|
119
|
+
params = jnp.repeat(task.model[None], cmaes.popsize, axis=0)
|
|
120
|
+
state = cmaes.init_fn(params, jr.key(0))
|
|
121
|
+
(params, state, key), history = cmaes.step_fn((params, state, jr.key(0)), sample={})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
To run an optimizer on an `l2co_tasks.Task` over a full budget, with batching, realizations and the history reduction, use `l2co.RunState` / `l2co.RolloutWrapper`. To add your own optimizer, see [Register your own optimizer](./docs/register_optimizer.ipynb).
|
|
125
|
+
|
|
126
|
+
## Hydra optimizer configurations
|
|
127
|
+
|
|
128
|
+
The package ships ready-made `optimizers` config groups under `l2co_optimizers/conf/optimizers/`, installed as package data. Each YAML is a list of `OptimizationStep` specs:
|
|
129
|
+
- **single-optimizer sweeps:** `adam`, `sepcmaes`, `lr_sweep_pde`;
|
|
130
|
+
- **the portfolios used across the L2CO studies:** `small`, `medium`, `standard`, `standard_no_stopping`, `all`;
|
|
131
|
+
- **curated menus:** `headroom4`, `contrast`, `two_functions`, `gaussian_classification`, `pde`, `supercompressible`.
|
|
132
|
+
|
|
133
|
+
Add the package to a Hydra application's search path and select a group:
|
|
134
|
+
|
|
135
|
+
```yaml
|
|
136
|
+
hydra:
|
|
137
|
+
searchpath:
|
|
138
|
+
- pkg://l2co_optimizers.conf
|
|
139
|
+
|
|
140
|
+
defaults:
|
|
141
|
+
- optimizers: medium # any file in l2co_optimizers/conf/optimizers/
|
|
142
|
+
```
|
|
143
|
+
|
|
144
|
+
Hydra merges a group's options across search paths. So an application can keep its own `conf/optimizers/*.yaml` next to these, as `l2co_experiments` does for its meta-optimizer configs. `create_schedules_experimentdata` turns a composed group into an `f3dasm.ExperimentData` with one `OptimizationStep` per row.
|
|
145
|
+
|
|
146
|
+
## Releases
|
|
147
|
+
|
|
148
|
+
Sibling packages in this ecosystem declare each other unpinned, so nothing enforces compatibility between releases. **`l2co-optimizers` 0.1.0 must be released before, or together with, `l2co` 1.6.0**, which is the first `l2co` to depend on it.
|
|
149
|
+
|
|
150
|
+
## Community Support
|
|
151
|
+
|
|
152
|
+
If you find any **issues, bugs or problems** with this package, please use the [GitHub issue tracker](https://github.com/bessagroup/l2co-optimizers/issues) to report them.
|
|
153
|
+
|
|
154
|
+
## License
|
|
155
|
+
|
|
156
|
+
Copyright (c) 2026, Martin van der Schelling
|
|
157
|
+
|
|
158
|
+
All rights reserved.
|
|
159
|
+
|
|
160
|
+
This project is licensed under the BSD 3-Clause License. See [LICENSE](https://github.com/bessagroup/l2co-optimizers/blob/main/LICENSE) for the full license text.
|
|
161
|
+
|
|
162
|
+
## Related repositories
|
|
163
|
+
|
|
164
|
+
This package is part of the L2CO ecosystem developed in the [Bessa Research Group](https://github.com/bessagroup). The repositories below work together:
|
|
165
|
+
|
|
166
|
+
- [l2co](https://github.com/bessagroup/L2CO) — Learning to Choose Optimizers: a meta-learner that selects an optimizer from problem features before any evaluations, then reassesses that choice from the observed optimization trajectory.
|
|
167
|
+
- [rl2co](https://github.com/bessagroup/rl2co) — Reinforcement Learning to Choose Optimizers: a JAX-based RL agent that dynamically switches between optimizers during a run.
|
|
168
|
+
- [l2co-tasks](https://github.com/bessagroup/l2co-tasks) — Optimization task definitions (BBOB, CEC 2005, PDE, spiral, …) compatible with the L2CO library.
|
|
169
|
+
- [l2co-optimizers](https://github.com/bessagroup/l2co-optimizers) — Bare optimizers (registry, `UpdateClass`, `OptimizationStep`, handshake and state transfer) compatible with the L2CO library.
|
|
170
|
+
- [l2co_experiments](https://github.com/bessagroup/l2co_experiments) — Hydra + f3dasm experiment pipelines (dataset creation, training, rollouts, figures) for the L2CO studies.
|
|
171
|
+
- [agentic-l2co](https://github.com/bessagroup/agentic-l2co) — An LLM-agent drop-in replacement for `l2co.L2COModel`, driving two-stage optimizer selection with an Ollama-hosted LLM.
|
|
172
|
+
- [bbob-jax](https://github.com/bessagroup/bbob-jax) — JAX implementations of the BBOB (noiseless and noisy), CEC 2005 and CEC 2017 black-box optimization benchmark functions.
|
|
173
|
+
- [f3dasm](https://github.com/bessagroup/f3dasm) — Framework for Data-Driven Design and Analysis of Structures and Materials; provides `ExperimentData`, pipelines, and SLURM orchestration.
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+

|
|
2
|
+
|
|
3
|
+
# L2CO Optimizers
|
|
4
|
+
|
|
5
|
+
| [**GitHub**](https://github.com/bessagroup/l2co-optimizers)
|
|
6
|
+
|
|
7
|
+
Bare optimizers compatible with the L2CO library
|
|
8
|
+
|
|
9
|
+
***
|
|
10
|
+
|
|
11
|
+
## Summary
|
|
12
|
+
|
|
13
|
+
`l2co-optimizers` is the optimizer half of the [L2CO](https://github.com/bessagroup/l2co) ecosystem, as [`l2co-tasks`](https://github.com/bessagroup/l2co-tasks) is the task half. It provides:
|
|
14
|
+
- **a name registry** of ready-to-run optimizers: the optax gradient methods, the evosax distribution- and population-based algorithms, plus SHADE, TuRBO, an RBF trust region, per-evaluation-key L-BFGS and random search;
|
|
15
|
+
- **the `UpdateClass` container** every registry factory returns;
|
|
16
|
+
- **the `OptimizationStep` spec** that names an optimizer with its hyperparameters and stopping criteria;
|
|
17
|
+
- **ready-made Hydra optimizer configs**.
|
|
18
|
+
|
|
19
|
+
It also ships the *strategy-facing* layer meta-optimizers dispatch through: the `SubOpt` adapter, the per-optimizer handshake policy and state transfer, and menu-dispatched loss evaluation. The meta-optimization strategies themselves (`l2co`, `rl2co`, `agentic-l2co`) and the loop that runs an optimizer on a task stay in [`l2co`](https://github.com/bessagroup/l2co).
|
|
20
|
+
|
|
21
|
+
## Statement of need
|
|
22
|
+
|
|
23
|
+
Learning-to-optimize and optimizer-selection research needs many optimizers behind one calling convention, so that a selector can switch between them mid-run. `l2co-optimizers` provides that convention without the meta-learning stack:
|
|
24
|
+
- every optimizer is built by `optimizer_mapping(name)(task=..., opt_hash=..., bounded=..., stop_fn=...)`;
|
|
25
|
+
- every one steps through the same `(params, opt_state, key)` carry;
|
|
26
|
+
- every one reports into the same `OptHistory`.
|
|
27
|
+
|
|
28
|
+
It depends on neither `l2co` nor `l2co-tasks`. A task reaches it only through `TaskLike`, a structural protocol (`model`, `loss_fn`, `pass_rng`) that `l2co_tasks.Task` satisfies unchanged. `l2co` is the bridge that runs one on the other.
|
|
29
|
+
|
|
30
|
+
## Authorship
|
|
31
|
+
|
|
32
|
+
**Authors**:
|
|
33
|
+
- Martin van der Schelling ([m.p.vanderschelling@tudelft.nl](mailto:m.p.vanderschelling@tudelft.nl))
|
|
34
|
+
|
|
35
|
+
**Authors affiliation:**
|
|
36
|
+
- Delft University of Technology (Bessa Research Group)
|
|
37
|
+
|
|
38
|
+
**Maintainer:**
|
|
39
|
+
- Martin van der Schelling ([m.p.vanderschelling@tudelft.nl](mailto:m.p.vanderschelling@tudelft.nl))
|
|
40
|
+
|
|
41
|
+
**Maintainer affiliation:**
|
|
42
|
+
- Delft University of Technology (Bessa Research Group)
|
|
43
|
+
|
|
44
|
+
## Getting started
|
|
45
|
+
|
|
46
|
+
`l2co-optimizers` is `uv`-managed and depends on an editable install of a sibling [`f3dasm`](https://github.com/bessagroup/f3dasm) checkout, so lay the repositories out side by side before syncing:
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
git clone https://github.com/bessagroup/f3dasm.git
|
|
50
|
+
git clone https://github.com/bessagroup/l2co-optimizers.git
|
|
51
|
+
cd l2co-optimizers
|
|
52
|
+
uv sync
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
Build an optimizer from the registry and step it. Any object with `model`, `loss_fn` and `pass_rng` is a task:
|
|
56
|
+
|
|
57
|
+
```python
|
|
58
|
+
from dataclasses import dataclass
|
|
59
|
+
import jax.numpy as jnp, jax.random as jr
|
|
60
|
+
from l2co_optimizers import optimizer_mapping, TaskLike
|
|
61
|
+
|
|
62
|
+
@dataclass
|
|
63
|
+
class Sphere:
|
|
64
|
+
model = jnp.zeros(4)
|
|
65
|
+
pass_rng = False
|
|
66
|
+
def loss_fn(self, x, **sample):
|
|
67
|
+
return jnp.sum((x - 0.5) ** 2)
|
|
68
|
+
|
|
69
|
+
task = Sphere()
|
|
70
|
+
assert isinstance(task, TaskLike)
|
|
71
|
+
|
|
72
|
+
cmaes = optimizer_mapping("cmaes")(task=task, opt_hash=1)
|
|
73
|
+
params = jnp.repeat(task.model[None], cmaes.popsize, axis=0)
|
|
74
|
+
state = cmaes.init_fn(params, jr.key(0))
|
|
75
|
+
(params, state, key), history = cmaes.step_fn((params, state, jr.key(0)), sample={})
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
To run an optimizer on an `l2co_tasks.Task` over a full budget, with batching, realizations and the history reduction, use `l2co.RunState` / `l2co.RolloutWrapper`. To add your own optimizer, see [Register your own optimizer](./docs/register_optimizer.ipynb).
|
|
79
|
+
|
|
80
|
+
## Hydra optimizer configurations
|
|
81
|
+
|
|
82
|
+
The package ships ready-made `optimizers` config groups under `l2co_optimizers/conf/optimizers/`, installed as package data. Each YAML is a list of `OptimizationStep` specs:
|
|
83
|
+
- **single-optimizer sweeps:** `adam`, `sepcmaes`, `lr_sweep_pde`;
|
|
84
|
+
- **the portfolios used across the L2CO studies:** `small`, `medium`, `standard`, `standard_no_stopping`, `all`;
|
|
85
|
+
- **curated menus:** `headroom4`, `contrast`, `two_functions`, `gaussian_classification`, `pde`, `supercompressible`.
|
|
86
|
+
|
|
87
|
+
Add the package to a Hydra application's search path and select a group:
|
|
88
|
+
|
|
89
|
+
```yaml
|
|
90
|
+
hydra:
|
|
91
|
+
searchpath:
|
|
92
|
+
- pkg://l2co_optimizers.conf
|
|
93
|
+
|
|
94
|
+
defaults:
|
|
95
|
+
- optimizers: medium # any file in l2co_optimizers/conf/optimizers/
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Hydra merges a group's options across search paths. So an application can keep its own `conf/optimizers/*.yaml` next to these, as `l2co_experiments` does for its meta-optimizer configs. `create_schedules_experimentdata` turns a composed group into an `f3dasm.ExperimentData` with one `OptimizationStep` per row.
|
|
99
|
+
|
|
100
|
+
## Releases
|
|
101
|
+
|
|
102
|
+
Sibling packages in this ecosystem declare each other unpinned, so nothing enforces compatibility between releases. **`l2co-optimizers` 0.1.0 must be released before, or together with, `l2co` 1.6.0**, which is the first `l2co` to depend on it.
|
|
103
|
+
|
|
104
|
+
## Community Support
|
|
105
|
+
|
|
106
|
+
If you find any **issues, bugs or problems** with this package, please use the [GitHub issue tracker](https://github.com/bessagroup/l2co-optimizers/issues) to report them.
|
|
107
|
+
|
|
108
|
+
## License
|
|
109
|
+
|
|
110
|
+
Copyright (c) 2026, Martin van der Schelling
|
|
111
|
+
|
|
112
|
+
All rights reserved.
|
|
113
|
+
|
|
114
|
+
This project is licensed under the BSD 3-Clause License. See [LICENSE](https://github.com/bessagroup/l2co-optimizers/blob/main/LICENSE) for the full license text.
|
|
115
|
+
|
|
116
|
+
## Related repositories
|
|
117
|
+
|
|
118
|
+
This package is part of the L2CO ecosystem developed in the [Bessa Research Group](https://github.com/bessagroup). The repositories below work together:
|
|
119
|
+
|
|
120
|
+
- [l2co](https://github.com/bessagroup/L2CO) — Learning to Choose Optimizers: a meta-learner that selects an optimizer from problem features before any evaluations, then reassesses that choice from the observed optimization trajectory.
|
|
121
|
+
- [rl2co](https://github.com/bessagroup/rl2co) — Reinforcement Learning to Choose Optimizers: a JAX-based RL agent that dynamically switches between optimizers during a run.
|
|
122
|
+
- [l2co-tasks](https://github.com/bessagroup/l2co-tasks) — Optimization task definitions (BBOB, CEC 2005, PDE, spiral, …) compatible with the L2CO library.
|
|
123
|
+
- [l2co-optimizers](https://github.com/bessagroup/l2co-optimizers) — Bare optimizers (registry, `UpdateClass`, `OptimizationStep`, handshake and state transfer) compatible with the L2CO library.
|
|
124
|
+
- [l2co_experiments](https://github.com/bessagroup/l2co_experiments) — Hydra + f3dasm experiment pipelines (dataset creation, training, rollouts, figures) for the L2CO studies.
|
|
125
|
+
- [agentic-l2co](https://github.com/bessagroup/agentic-l2co) — An LLM-agent drop-in replacement for `l2co.L2COModel`, driving two-stage optimizer selection with an Ollama-hosted LLM.
|
|
126
|
+
- [bbob-jax](https://github.com/bessagroup/bbob-jax) — JAX implementations of the BBOB (noiseless and noisy), CEC 2005 and CEC 2017 black-box optimization benchmark functions.
|
|
127
|
+
- [f3dasm](https://github.com/bessagroup/f3dasm) — Framework for Data-Driven Design and Analysis of Structures and Materials; provides `ExperimentData`, pipelines, and SLURM orchestration.
|
|
@@ -0,0 +1,123 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
build-backend = "setuptools.build_meta"
|
|
3
|
+
requires = ["setuptools>=77.0.0", "wheel"]
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
authors = [
|
|
7
|
+
{email = "m.p.vanderschelling@tudelft.nl", name = "Martin van der Schelling"}
|
|
8
|
+
]
|
|
9
|
+
classifiers = [
|
|
10
|
+
"Intended Audience :: Science/Research",
|
|
11
|
+
"Topic :: Scientific/Engineering :: Artificial Intelligence",
|
|
12
|
+
"Topic :: Software Development :: Libraries :: Python Modules",
|
|
13
|
+
"Programming Language :: Python :: 3"
|
|
14
|
+
]
|
|
15
|
+
dependencies = [
|
|
16
|
+
"equinox>=0.13.0,<0.14",
|
|
17
|
+
"evosax>=0.2.0,<0.3",
|
|
18
|
+
"f3dasm",
|
|
19
|
+
"flax>=0.12.0",
|
|
20
|
+
"hydra-core>=1.3.2",
|
|
21
|
+
"jax>=0.4.30,<=0.9.1",
|
|
22
|
+
"jaxtyping>=0.3.2",
|
|
23
|
+
"omegaconf",
|
|
24
|
+
"optax>=0.2.5"
|
|
25
|
+
]
|
|
26
|
+
description = "Bare optimizers compatible with the L2CO library"
|
|
27
|
+
keywords = ["optimization", "optimizers", "jax", "evolution-strategies"]
|
|
28
|
+
license = "BSD-3-Clause"
|
|
29
|
+
maintainers = [
|
|
30
|
+
{email = "m.p.vanderschelling@tudelft.nl", name = "Martin van der Schelling"}
|
|
31
|
+
]
|
|
32
|
+
name = "l2co-optimizers"
|
|
33
|
+
readme = "README.md"
|
|
34
|
+
requires-python = ">= 3.12"
|
|
35
|
+
version = "0.1.0"
|
|
36
|
+
|
|
37
|
+
[project.optional-dependencies]
|
|
38
|
+
dev = [
|
|
39
|
+
"setuptools>=77.0.0",
|
|
40
|
+
"build",
|
|
41
|
+
"wheel",
|
|
42
|
+
"pre-commit>=4.4.0",
|
|
43
|
+
"ruff>=0.14.10"
|
|
44
|
+
]
|
|
45
|
+
docs = [
|
|
46
|
+
"mkdocs>=1.6.0",
|
|
47
|
+
"mkdocs-gen-files>=0.5.0",
|
|
48
|
+
"mkdocs-include-exclude-files>=0.1.0",
|
|
49
|
+
"mkdocs-ipynb>=0.1.1",
|
|
50
|
+
"mkdocs-material>=9.6.20",
|
|
51
|
+
"mkdocstrings>=0.30.1",
|
|
52
|
+
"mkdocstrings-python>=1.18.2",
|
|
53
|
+
"pymdown-extensions>=10.16.1"
|
|
54
|
+
]
|
|
55
|
+
tests = [
|
|
56
|
+
"pytest>=8.4.1",
|
|
57
|
+
"pytest-cov>=6.2.1"
|
|
58
|
+
]
|
|
59
|
+
|
|
60
|
+
[project.urls]
|
|
61
|
+
bugs = "https://github.com/bessagroup/l2co-optimizers/issues"
|
|
62
|
+
homepage = "https://github.com/bessagroup/l2co-optimizers"
|
|
63
|
+
|
|
64
|
+
[tool.pytest.ini_options]
|
|
65
|
+
filterwarnings = [
|
|
66
|
+
"error::DeprecationWarning:l2co_optimizers"
|
|
67
|
+
]
|
|
68
|
+
markers = [
|
|
69
|
+
"slow: test runs a long optimization loop",
|
|
70
|
+
"requires_f3dasm: test constructs an f3dasm.ExperimentData",
|
|
71
|
+
"requires_l2co_tasks: drives real l2co_tasks.Task objects (skipped unless l2co_tasks imports)"
|
|
72
|
+
]
|
|
73
|
+
testpaths = ["tests"]
|
|
74
|
+
|
|
75
|
+
[tool.ruff]
|
|
76
|
+
line-length = 79
|
|
77
|
+
|
|
78
|
+
[tool.ruff.lint]
|
|
79
|
+
exclude = [
|
|
80
|
+
"__pycache__",
|
|
81
|
+
"dist",
|
|
82
|
+
"*.egg",
|
|
83
|
+
"tests",
|
|
84
|
+
".git"
|
|
85
|
+
]
|
|
86
|
+
ignore = [
|
|
87
|
+
"E226",
|
|
88
|
+
"E3",
|
|
89
|
+
"E731",
|
|
90
|
+
"C901",
|
|
91
|
+
"F722",
|
|
92
|
+
"UP045",
|
|
93
|
+
"B027",
|
|
94
|
+
"B012"
|
|
95
|
+
]
|
|
96
|
+
select = [
|
|
97
|
+
"E", # pycodestyle errors
|
|
98
|
+
"W", # pycodestyle warnings
|
|
99
|
+
"F", # Pyflakes
|
|
100
|
+
"I", # isort
|
|
101
|
+
"B", # flake8-bugbear
|
|
102
|
+
"UP", # pyupgrade
|
|
103
|
+
"TID251" # flake8-tidy-imports banned-api
|
|
104
|
+
]
|
|
105
|
+
|
|
106
|
+
[tool.ruff.lint.flake8-tidy-imports.banned-api]
|
|
107
|
+
"l2co".msg = "l2co-optimizers must not import l2co (l2co depends on this package)."
|
|
108
|
+
"l2co_tasks".msg = "l2co-optimizers must not import l2co_tasks; take a TaskLike instead."
|
|
109
|
+
|
|
110
|
+
[tool.ruff.lint.per-file-ignores]
|
|
111
|
+
"__init__.py" = ["F401", "E402"]
|
|
112
|
+
|
|
113
|
+
[tool.ruff.lint.pydocstyle]
|
|
114
|
+
convention = "numpy"
|
|
115
|
+
|
|
116
|
+
[tool.setuptools.package-data]
|
|
117
|
+
"l2co_optimizers.conf" = ["**/*.yaml"]
|
|
118
|
+
|
|
119
|
+
[tool.uv]
|
|
120
|
+
package = true
|
|
121
|
+
|
|
122
|
+
[tool.uv.sources]
|
|
123
|
+
f3dasm = {editable = true, path = "../f3dasm"}
|