Skip to content

Commit

Permalink
Merge pull request #21 from johnaohara/grpc
Browse files Browse the repository at this point in the history
Added gRPC endpoint and python client
  • Loading branch information
dinogun authored Apr 28, 2022
2 parents 2408431 + a640591 commit a6fd02e
Show file tree
Hide file tree
Showing 16 changed files with 1,160 additions and 168 deletions.
5 changes: 3 additions & 2 deletions Dockerfile.hpo
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ WORKDIR /opt/app

# Install packages needed for python to function correctly
# Create the non root user, same as the one used in the build phase.
RUN microdnf install -y python3 \
RUN microdnf install -y python3 gcc-c++ python3-devel \
&& microdnf update -y \
&& microdnf -y install shadow-utils \
&& adduser -u 1001 -G root -s /usr/sbin/nologin default \
Expand All @@ -38,7 +38,7 @@ RUN microdnf install -y python3 \
USER 1001

# Install optuna to the default user
RUN python3 -m pip install --user optuna requests scikit-optimize jsonschema
RUN python3 -m pip install --user optuna requests scikit-optimize jsonschema click grpcio protobuf

LABEL name="Kruize HPO" \
vendor="Red Hat" \
Expand All @@ -54,5 +54,6 @@ COPY --chown=1001:0 index.html /opt/app/


EXPOSE 8085
EXPOSE 50051

ENTRYPOINT python3 -u src/service.py
5 changes: 4 additions & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
optuna
requests
scikit-optimize
jsonschema
jsonschema
grpcio
click
protobuf
2 changes: 1 addition & 1 deletion scripts/cluster-helpers.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ function docker_start() {

check_prereq running ${SERVICE_STATUS_DOCKER}

${CONTAINER_RUNTIME} run -d --name hpo_docker_container -p 8085:8085 ${HPO_CONTAINER_IMAGE} >/dev/null 2>&1
${CONTAINER_RUNTIME} run -d --name hpo_docker_container -p 8085:8085 -p 50051:50051 ${HPO_CONTAINER_IMAGE} >/dev/null 2>&1
check_err "Unexpected error occured. Service Stopped!"

echo
Expand Down
49 changes: 49 additions & 0 deletions src/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,52 @@ The criteria for setting the experiment status is:
| `success` | The experiment runs successfully without any error. |
| `failure` | The experiment fails due to reason such as OOMKilled. |
| `prune` | The experiment terminates due to reasons such as insufficient cpu and memory. |


## gRPC Client

[`grpc_client.py`](./grpc_client.py) is a command line client that allows users to interact with the gRPC service.

### Usage

```shell
$ python3 ./grpc_client.py
Usage: grpc_client.py [OPTIONS] COMMAND [ARGS]...

A HPO command line tool to allow interaction with HPO service

Options:
--help Show this message and exit.

Commands:
config Obtain a configuration set for a particular experiment trial
count Return a count of experiments currently running
list List names of all experiments currently running
new Create a new experiment
next Generate next configuration set for running experiment
result Update results for a particular experiment trial
show Show details of running experiment

```

Commands provide interactive input for params or allow users to set params on the command line for scripted use;

e.g.

```shell
$ python3 ./grpc_client.py new
Experiment configuration file path:
```

or

```shell
$ python3 ./grpc_client.py new --file=/tmp/hpo/newExperiment.json
```

> **_NOTE:_** The default host and port for the client is `localhost` and `50051`. If you wish to connect to a remote machine, or via a diferent port, please set the following environment variables, `HPO_HOST` and `HPO_PORT`.
> e.g.
> ```shell
> $ export HPO_HOST=remoteMachine.com
> $ export HPO_PORT=9191
> ```
Empty file added src/__init__.py
Empty file.
23 changes: 23 additions & 0 deletions src/exceptions.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
"""
Copyright (c) 2020, 2022 Red Hat, IBM Corporation and others.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
"""

class Error(Exception):
"""Base class for other exceptions"""
pass

class ExperimentNotFoundError(Error):
"""Raised when the input value is too small"""
pass
Empty file added src/gRPC/__init__.py
Empty file.
162 changes: 162 additions & 0 deletions src/gRPC/hpo_pb2.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit a6fd02e

Please sign in to comment.