|
| 1 | +# Getting started |
| 2 | + |
| 3 | +In this chapter, we share with you how to install `poli`, and get started with registering objective functions. |
| 4 | + |
| 5 | +## Installing locally |
| 6 | + |
| 7 | +Unfortunately, we only support **Linux** and **MacOS** for now. |
| 8 | + |
| 9 | +### Installing conda |
| 10 | + |
| 11 | +`poli` is built on top of manipulating `conda` environments. It is therefore important for you to **install conda**. [Follow the documentation of Anaconda itself](https://conda.io/projects/conda/en/latest/user-guide/install/index.html). |
| 12 | + |
| 13 | +Test that your installation went through by writing |
| 14 | + |
| 15 | +```bash |
| 16 | +$ conda --version |
| 17 | +conda 23.7.2 |
| 18 | +``` |
| 19 | + |
| 20 | +It's okay if you have another version. Read more about [supported versions of `conda` (TODO:ADD)](). |
| 21 | + |
| 22 | +### Installing `poli` |
| 23 | + |
| 24 | +We recommend creating an environment called `poli-base`. **The only dependency `poli` has is `numpy`**: |
| 25 | + |
| 26 | +```bash |
| 27 | +$ conda create -n poli-base python=3.9 |
| 28 | +$ conda activate poli-base |
| 29 | +$ pip install numpy |
| 30 | +``` |
| 31 | + |
| 32 | +Right now, we only support two ways of installing `poli`: by cloning the repo and installing, or using `pip` and `git+`. [TODO: change from my fork to MLLS repo after merging] |
| 33 | + |
| 34 | +::::{tab-set} |
| 35 | + |
| 36 | +:::{tab-item} Installing using `pip +git` |
| 37 | + |
| 38 | +If you are not interested in debugging, you can simply run |
| 39 | + |
| 40 | +```bash |
| 41 | +# in the poli-base env |
| 42 | +pip install git+https://github.com/miguelgondu/poli.git |
| 43 | +``` |
| 44 | + |
| 45 | +::: |
| 46 | + |
| 47 | +:::{tab-item} Installing for debugging |
| 48 | + |
| 49 | +If you are interested in debugging locally, clone and install as follows: |
| 50 | + |
| 51 | +```bash |
| 52 | +# in the `poli-base` env. |
| 53 | +$ git clone [email protected]:miguelgondu/poli.git |
| 54 | +$ cd ./poli |
| 55 | +$ pip install -e . |
| 56 | +``` |
| 57 | + |
| 58 | +::: |
| 59 | + |
| 60 | +:::: |
| 61 | + |
| 62 | +### Testing your installation |
| 63 | + |
| 64 | +To make sure everything went well, you can test your `poli` installation by running |
| 65 | + |
| 66 | +```bash |
| 67 | +$ python -c "from poli.core.registry import get_problems ; print(get_problems())" |
| 68 | +[] |
| 69 | +``` |
| 70 | + |
| 71 | +If the installation isn't fresh/the only one in your system, you might actually get some registered problems. |
| 72 | + |
| 73 | +## Running `poli` in Colab |
| 74 | + |
| 75 | +With a little effort, you can run `poli` in Colab. [Check this example](https://colab.research.google.com/drive/1-IISCebWYfu0QhuCJ11wOag8aKOiPtls). |
| 76 | + |
| 77 | + |
| 78 | +## Your first `poli` script |
| 79 | + |
| 80 | +As you might have noticed, you can get a list of the registered problems using the `get_problems` method inside `poli.core.registry`. You can also get a list of objective functions available for installing/registration using `from poli.objective_repository import AVAILABLE_OBJECTIVES`: |
| 81 | + |
| 82 | +```bash |
| 83 | +$ python -c "from poli.objective_repository import AVAILABLE_OBJECTIVES ; print(AVAILABLE_OBJECTIVES)" |
| 84 | +[..., 'white_noise'] |
| 85 | +``` |
| 86 | + |
| 87 | +Let's write a small script that installs `white_noise` from the repository: |
| 88 | + |
| 89 | +```python |
| 90 | +# see examples/minimal_working_example.py |
| 91 | +from poli import objective_factory |
| 92 | + |
| 93 | +problem_info, f, x0, y0, run_info = objective_factory.create(name="white_noise") |
| 94 | + |
| 95 | +x = np.array([[1]]) # must be of shape [b, d], in this case [1, 1]. |
| 96 | +for _ in range(5): |
| 97 | + print(f"f(x) = {f(x)}") |
| 98 | +``` |
| 99 | + |
| 100 | +If we run this script, `poli` will ask us to confirm that we want to register/install `"white_noise"` as an objective function (you can deactivate this confirmation step by passing the flag `force_register=True` to `.create`). Afterwards, it will print 5 evaluations of the objective function on the same input. |
| 101 | + |
| 102 | + |
0 commit comments