Skip to content

Commit

Permalink
Move server into module
Browse files Browse the repository at this point in the history
  • Loading branch information
langdal committed Feb 10, 2021
1 parent 77d4f1f commit a646a13
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 10 deletions.
2 changes: 1 addition & 1 deletion Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ RUN chown -R user:user /code && chmod -R 755 /code

USER user

COPY src/ /code
COPY optimizerapi/ /code

ENV PATH=/opt/venv/bin:${PATH}

Expand Down
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,12 @@ If you have Docker installed the API can be started locally by running the scrip

Alternatively the project can be build and run with the following commands:

python3 -m venv env
source env/bin/activate
pip install --upgrade pip

pip install -r requirements.txt
python src/server.py
python optimizerapi/server.py

Now open [http://localhost:9090/v1.0/ui/](http://localhost:9090/v1.0/ui/) in a browser to explore the API through Swagger UI

Empty file added optimizerapi/__init__.py
Empty file.
File renamed without changes.
13 changes: 6 additions & 7 deletions src/optimizer.py → optimizerapi/optimizer.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,25 @@
from ProcessOptimizer.plots import plot_objective, plot_convergence
from ProcessOptimizer.utils import cook_estimator
from ProcessOptimizer.learning.gaussian_process.kernels import Matern
from numbers import Number
import numpy
numpy.random.seed(42)

def post_hyperparams(hyperparams: str) -> str:
return 'Hello {name}'.format(name=name)
return 'Hello {name}'.format(name=hyperparams)


def run(params: str = None, xi: float = 0.01, yi: float = 1, kappa: float = 1.96) -> str:
def run(params: str = None, Xi: [float] = [0.01], yi: [Number] = [1], kappa: float = 1.96) -> str:
# TODO generate space, i.e., an array of either options for categories or tuples of (min, max) for value types
space = [(0,1), (0,1)]
space = [(0,1)]
hyperparams = {
'base_estimator': 'GP',
'acq_func': 'gp_hedge',
'n_initial_points': 3,
'acq_func_kwargs': {'kappa': kappa, 'xi': xi}
'acq_func_kwargs': {'kappa': kappa, 'Xi': Xi, 'yi': yi}
}
optimizer = Optimizer(space, **hyperparams)
# TODO call optimizer with proper Xi and Yi values
# result = optimizer.tell(Xi, Xi)
result = 0
result = optimizer.tell(Xi, yi)
if params:
return 'Run with {params} = {result}'.format(params=params, result=result)
else:
Expand Down
2 changes: 1 addition & 1 deletion src/server.py → optimizerapi/server.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import connexion

if __name__ == '__main__':
app = connexion.FlaskApp(__name__, port=9090, specification_dir='openapi/')
app = connexion.FlaskApp(__name__, port=9090, specification_dir='./openapi/')
app.add_api('specification.yml', arguments={'title': 'Hello World Example'})
app.run()

0 comments on commit a646a13

Please sign in to comment.