You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It installs an `openjdk` that will be added to the path when the environment is active. Moreover, you can also hack your way around installing conda and creating conda environments inside Colab.
211
+
It installs an `openjdk` that will be added to the path when the environment is active. Moreover, [`conda` is also installable in Google Colab, allowing you to use `poli` there](https://colab.research.google.com/drive/1-IISCebWYfu0QhuCJ11wOag8aKOiPtls?usp=sharing).
199
212
200
213
:::
201
214
@@ -208,18 +221,11 @@ If you
208
221
209
222
then you should be set!
210
223
211
-
You can test that your problem is registerable by creating a fresh environment that includes poli, and running
224
+
You can test that your problem is registerable by running
your_keyword_1=..., # <-- Keywords you (maybe) needed
234
-
your_keyword_2=... # <-- at your_factory.create(...)
235
-
# For now, only string kwargs are
236
-
# supported.
239
+
your_arg_1=..., # <-- Keywords you (maybe) needed
240
+
your_arg_2=..., # <-- at your_factory.create(...)
241
+
your_kwarg=..., # <--
242
+
# For now, only certain types are
243
+
# supported: str, int, bool, float,
244
+
# None, and lists thereof.
237
245
)
238
246
```
239
247
240
-
`poli`will ask you to confirm that you want to register your problem (you can force the registration by passing `force_register=True` to `objective_factory.create`).
241
-
242
248
## (Optional) Making your problem be available if dependencies are met
243
249
244
-
At this point, you can run your objective function in an isolated process (which will literally import the factory and the black box function from the `register.py` you wrote). A better alternative is to get direct access to the object itself. Having access to the actual class makes your life easy, especially when it comes to using debugging tools like the ones in VSCode.
250
+
At this point, you can run your objective function in an isolated process (which will literally import the factory and the black box function from the `register.py` you wrote).
251
+
252
+
A better alternative is to get direct access to the object itself. Having access to the actual class makes your life easy, especially when it comes to using debugging tools like the ones in VSCode.
245
253
246
254
If you want to make your problem available if it can be imported, take a look at `src/poli/objective_repository/__init__.py`. Add a block like this one at the end of it:
247
255
@@ -263,4 +271,4 @@ except ImportError: # Maybe you'll need to check for other errors.
263
271
264
272
## Submitting a pull request
265
273
266
-
If you want to share your problem with us, feel free to create a pull request in our repository: https://github.com/MachineLearningLifeScience/poli
274
+
If you want to share your problem with us, feel free to create a pull request in our repository following the instructions in our `CONTRIBUTING.md`: https://github.com/MachineLearningLifeScience/poli
[TODO: write] For now, check [the chapter on creating solvers](../using_poli/the_basics/defining_a_problem_solver.md).
3
+
The main use-case for `poli_baselines` is **defining optimizers for objective functions**.
4
+
5
+
The main design objective of `poli` is for it to be almost trivial to **query** complicated black box objective functions; likewise, the design objective of `poli_baselines` is to allow developers of black-box optimization algorithms to test them on said objective functions.
6
+
7
+
This chapter explains how to define a "solver", or a black-box optimization algorithm.
8
+
9
+
:::{note}
10
+
11
+
By default, all our optimizers **maximize**.
12
+
13
+
:::
14
+
15
+
## An abstract problem solver
16
+
17
+
All problem solvers in `poli_baselines` inherit from an `AbstractSolver`, which is implemented as follows:
18
+
19
+
```python
20
+
# poli_baselines/core/abstract_solver.py
21
+
classAbstractSolver:
22
+
def__init__(
23
+
self,
24
+
black_box: AbstractBlackBox,
25
+
x0: np.ndarray,
26
+
y0: np.ndarray,
27
+
):
28
+
self.black_box = black_box
29
+
self.x0 = x0
30
+
self.y0 = y0
31
+
32
+
self.history = {
33
+
"x": [x0_i.reshape(1, -1) for x0_i in x0],
34
+
"y": [y0_i.reshape(1, -1) for y0_i in y0],
35
+
}
36
+
37
+
self.iteration =0
38
+
```
39
+
40
+
i.e. the minimal ingredients required to instantiate a solver are a black-box function defined through `poli`, the initial design `x0`, and its evaluation `y0`.
41
+
42
+
**The only abstract method required** is a `next_candidate() -> np.ndarray`, which uses the `self.history` to propose a new candidate. Using this method, the abstract solver implements a `.solve(max_iter: int)` as follows:
43
+
44
+
```python
45
+
# poli_baselines/core/abstract_solver.py
46
+
classAbstractSolver:
47
+
...
48
+
49
+
defnext_candidate(self) -> np.ndarray:
50
+
"""
51
+
Returns the next candidate solution
52
+
after checking the history.
53
+
"""
54
+
raiseNotImplementedError(
55
+
"This method is abstract, and should be implemented by a subclass."
56
+
)
57
+
58
+
defsolve(self, max_iter: int=100):
59
+
"""
60
+
Runs the solver for the given number of iterations.
61
+
"""
62
+
for i inrange(max_iter):
63
+
# Call the pre-step callbacks
64
+
if pre_step_callbacks isnotNone:
65
+
for callback in pre_step_callbacks:
66
+
callback(self)
67
+
68
+
# Take a step, which in turn updates the local history.
69
+
_, y =self.step()
70
+
71
+
# Call the post-step callbacks
72
+
if post_step_callbacks isnotNone:
73
+
for callback in post_step_callbacks:
74
+
callback(self)
75
+
76
+
if verbose:
77
+
print(f"Iteration {i}: {y}, best so far: {self.get_best_performance()}")
78
+
79
+
if break_at_performance isnotNone:
80
+
if y >= break_at_performance:
81
+
break
82
+
```
83
+
84
+
## An example: `RandomMutations`
85
+
86
+
Leveraging the fact that we are usually working with discrete sequences, we can implement the simplest version of an optimizer: one that takes the best performing sequence, and randomly mutates one of its positions.
87
+
88
+
The following is an implementation of exactly this:
Pretty lean! Notice how **the `next_candidate` method could perform all sorts of complicated logic** like latent space Bayesian Optimization, evolutionary algorithms... Moreover, the conda environment where you do the optimization has nothing to do with the enviroment where the objective function was defined: `poli` is set up in such a way that you can query the objective functions without having to worry!
126
+
127
+
:::{note}
128
+
Our implementation of `RandomMutation` is slightly different, since we allow users to query e.g. integer indices instead of strings.
129
+
130
+
[Take a look at the exact implementation on `poli_baselines/solvers/simple/random_mutation.py`](https://github.com/MachineLearningLifeScience/poli-baselines/blob/main/src/poli_baselines/solvers/simple/random_mutation.py).
131
+
:::
132
+
133
+
## Submitting a pull request
134
+
135
+
If you want to share your problem with us, feel free to create a pull request in our repository following the instructions in our `CONTRIBUTING.md`: https://github.com/MachineLearningLifeScience/poli-baselines
Copy file name to clipboardExpand all lines: docs/protein-optimization/index.md
+11-7Lines changed: 11 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -5,10 +5,20 @@ This page contains documentation on how to use `poli`, a library of discrete obj
5
5
A core feature of `poli` is isolating calls to complicated objective functions which might, for example, depend on simulators, binaries, and highly specific package requirements.
6
6
Our promise is: if you can run your objective function reliably in a `conda` environment, then you can register it and call it from other projects and environments without having to worry about re-installing all the dependencies.
7
7
8
-
## Get started!
8
+
## Getting started
9
9
10
10
A good place to start is the next chapter! [Go to Getting Started](./getting_started/getting_started.md).
11
11
12
+
To install `poli` and `poli-baselines`, we recommend creating a fresh conda environment
0 commit comments