Skip to content

Commit

Permalink
fix: update docker naming and offline mode
Browse files Browse the repository at this point in the history
  • Loading branch information
maffettone committed Dec 11, 2023
1 parent e97a202 commit 9538455
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 22 deletions.
19 changes: 6 additions & 13 deletions docker/clustering_service/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,22 +1,15 @@
# docker build -t kmeans_service:latest .
FROM fedora
# Lock in a python version because of some backward compatability issues
RUN dnf update -y \
&& dnf install -y \
python3.9 \
g++ \
gcc \
git \
&& dnf clean all
FROM python:3.10

RUN python3.9 -m ensurepip --upgrade
RUN pip3 install 'bluesky-adaptive[all]'
RUN pip3 install bluesky-adaptive
RUN pip3 install uvicorn fastapi caproto nslsii
RUN pip3 install git+https://github.com/NSLS-II-PDF/pdf-agents.git@main
RUN pip3 install git+https://github.com/NSLS-II-PDF/pdf-agents.git@enh-container-service
RUN pip3 install git+https://github.com/bluesky/[email protected]#egg=databroker
RUN pip3 install scikit-learn

COPY kmeans_service.py /src/kmeans_service.py

ENV BS_AGENT_STARTUP_SCRIPT_PATH=/src/kmeans_service.py
ENV OFFLINE_MODE="TRUE"

CMD uvicorn bluesky_adaptive.server:app --host 127.0.0.1 --port 60610
CMD uvicorn bluesky_adaptive.server:app --host 127.0.0.1 --port 60610
4 changes: 2 additions & 2 deletions docker/clustering_service/build_and_run.sh
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
docker build -t kmeans_service:latest .
docker-compose up
docker build -t kmeans-service:pdf .
docker-compose up
6 changes: 3 additions & 3 deletions docker/clustering_service/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
version: '3'
services:
your-service:
image: kmeans_service:latest
kmeans-service:
image: kmeans-service:pdf
ports:
- 60281:60610
volumes:
- /etc/bluesky:/etc/bluesky
- /etc/bluesky:/etc/bluesky
8 changes: 6 additions & 2 deletions docker/clustering_service/kmeans_service.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import os

from bluesky_adaptive.server import register_variable, shutdown_decorator, startup_decorator

from pdf_agents.sklearn import PassiveKmeansAgent
Expand All @@ -14,7 +16,7 @@ def __init__(self, *args, **kwargs):

@property
def name(self):
return "KmeansAgent"
return "KmeansAgentService"

@property
def running(self):
Expand Down Expand Up @@ -63,7 +65,9 @@ def server_registrations(self) -> None:
return super().server_registrations()


agent = Agent(k_clusters=3, report_on_tell=True, ask_on_tell=False, direct_to_queue=False)
offline_mode = str(os.getenv("OFFLINE_MODE", "False")).lower() in ["true", "1", "yes"]
print(offline_mode)
agent = Agent(k_clusters=3, report_on_tell=True, ask_on_tell=False, direct_to_queue=False, offline=offline_mode)


@startup_decorator
Expand Down
2 changes: 0 additions & 2 deletions pdf_agents/sklearn.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,6 @@
class PassiveKmeansAgent(PDFBaseAgent, ClusterAgentBase):
def __init__(self, k_clusters, *args, **kwargs):
estimator = KMeans(k_clusters)
_default_kwargs = self.get_beamline_objects()
_default_kwargs.update(kwargs)
super().__init__(*args, estimator=estimator, **kwargs)

def clear_caches(self):
Expand Down

0 comments on commit 9538455

Please sign in to comment.