Skip to content

Commit f9a4aa5

Browse files
committed
Writes the chapter on isolating black box functions
1 parent 1c51f43 commit f9a4aa5

File tree

2 files changed

+3
-3
lines changed

2 files changed

+3
-3
lines changed

docs/protein-optimization/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,13 +136,13 @@ An evolutionary strategy for continuous problems
136136
:::{grid-item-card} Bayesian Optimization
137137
:link: ./using_poli_baselines/latent_space_bo.html
138138
:columns: 6
139-
Learning continuous representations and optimizing in latent space. [WIP]
139+
A vanilla implementation of Bayesian Optimization using `botorch`.
140140
:::
141141

142142
:::{grid-item-card} Line Bayesian Optimization
143143
:link: ./using_poli_baselines/latent_space_bo.html
144144
:columns: 6
145-
Learning continuous representations and optimizing in latent space. [WIP]
145+
A version of Bayesian Optimization where the acquisition is optimized over a line.
146146
:::
147147

148148
::::
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Isolating black box objective functions"]},{"cell_type":"code","execution_count":null,"metadata":{"vscode":{"languageId":"plaintext"}},"outputs":[],"source":["TODO: write"]},{"cell_type":"code","execution_count":null,"metadata":{"vscode":{"languageId":"plaintext"}},"outputs":[],"source":[]}],"metadata":{"language_info":{"name":"python"}},"nbformat":4,"nbformat_minor":2}
1+
{"cells":[{"cell_type":"markdown","metadata":{},"source":["# Isolating black box objective functions"]},{"cell_type":"markdown","metadata":{"vscode":{"languageId":"plaintext"}},"source":["Each black-box objective function in `poli` lives inside a `conda` environment. For example:\n","- the `foldx` stability objective lives inside `poli__protein`, which has `biopython`, `pdb-tools` and other libraries that are required to interface well with proteins and their representations.\n","- the `dockstring` objective lives inside `poli__dockstring`, which includes babel as part of its installation.\n","\n","There are two ways of running objective functions: **having the right dependencies**, or **in isolation**.\n","\n","[TODO: add diagram]"]},{"cell_type":"markdown","metadata":{},"source":["## Running objective functions in isolation"]},{"cell_type":"markdown","metadata":{},"source":["Let's say that your current environment doesn't have the package `dockstring` installed. You can still run the objective function:"]},{"cell_type":"code","execution_count":3,"metadata":{},"outputs":[],"source":["# No output: we don't have it installed.\n","!pip freeze | grep dockstring"]},{"cell_type":"code","execution_count":7,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["poli 🧪: creating an isolated black box function.\n","poli 🧪: starting the isolated objective process.\n"]},{"name":"stderr","output_type":"stream","text":["/Users/sjt972/anaconda3/envs/poli__dockstring/lib/python3.9/site-packages/dockstring/utils.py:77: DockstringWarning: Although Mac use is supported, docking scores on Mac do not always perfectly match scores from Linux. Therefore, extra care should be taken when comparing results to other platforms. In particular, the baselines in the DOCKSTRING paper were computed on Linux, so please do not directly compare your docking scores to the scores reported on the paper.\n"," warnings.warn(\n"]}],"source":["from poli import create\n","\n","problem_info, f, x0, y0, _ = create(\n"," name=\"dockstring\",\n"," target_name=\"drd2\" # The target protein.\n",")"]},{"cell_type":"markdown","metadata":{},"source":["As you can see, `poli` warns us that it is creating the conda environment associated with the black box function, and it is creating an isolated process where the objective can be run.\n","\n","This can be verified by checking the type of `f`:"]},{"cell_type":"code","execution_count":8,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["ExternalBlackBox(L=inf, num_evaluations=0)\n"]}],"source":["print(f)"]},{"cell_type":"markdown","metadata":{},"source":["This black box is an `ExternalBlackBox`, meaning that it is listening to an isolated process running `python` inside the `poli__dockstring` environment."]},{"cell_type":"markdown","metadata":{},"source":["We can still evaluate `f` like normal:"]},{"cell_type":"code","execution_count":10,"metadata":{},"outputs":[{"name":"stderr","output_type":"stream","text":["/Users/sjt972/anaconda3/envs/poli__dockstring/lib/python3.9/site-packages/dockstring/utils.py:77: DockstringWarning: Although Mac use is supported, docking scores on Mac do not always perfectly match scores from Linux. Therefore, extra care should be taken when comparing results to other platforms. In particular, the baselines in the DOCKSTRING paper were computed on Linux, so please do not directly compare your docking scores to the scores reported on the paper.\n"," warnings.warn(\n"]},{"data":{"text/plain":["array([[11.9]])"]},"execution_count":10,"metadata":{},"output_type":"execute_result"}],"source":["f(x0)"]},{"cell_type":"code","execution_count":11,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["ExternalBlackBox(L=inf, num_evaluations=1)\n"]}],"source":["print(f)"]},{"cell_type":"markdown","metadata":{},"source":["## When you have the right dependencies..."]},{"cell_type":"markdown","metadata":{},"source":["However, when you have the right dependencies, the `create` method returns the actual objective function. Let's use for example `rdkit_logp`:"]},{"cell_type":"code","execution_count":12,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["poli 🧪: Creating the objective from the repository.\n"]}],"source":["problem_info, f_logp, x0_logp, y0_logp, _ = create(\n"," name=\"rdkit_logp\"\n",")"]},{"cell_type":"markdown","metadata":{},"source":["Now, if we print `f_logp`, we can see that the create method returned the actual objective black box."]},{"cell_type":"code","execution_count":13,"metadata":{},"outputs":[{"name":"stdout","output_type":"stream","text":["LogPBlackBox(L=inf, num_evaluations=1)\n"]}],"source":["print(f_logp)"]},{"cell_type":"markdown","metadata":{},"source":["## Conclusions"]},{"cell_type":"markdown","metadata":{},"source":["- `poli` is able to instantiate objective functions inside isolated environments.\n","- If the dependencies are met, the objective function is created directly instead."]},{"cell_type":"markdown","metadata":{},"source":["## Read more"]},{"cell_type":"markdown","metadata":{},"source":["You can check the individual dependencies of each black box inside their implementation, or in [their documentation](../objective_repository/all_objectives.md)."]}],"metadata":{"kernelspec":{"display_name":"poli-docs","language":"python","name":"python3"},"language_info":{"codemirror_mode":{"name":"ipython","version":3},"file_extension":".py","mimetype":"text/x-python","name":"python","nbconvert_exporter":"python","pygments_lexer":"ipython3","version":"3.9.18"}},"nbformat":4,"nbformat_minor":2}

0 commit comments

Comments
 (0)