Skip to content

Commit

Permalink
Merge branch 'tax-day-experiment' of https://github.com/NSLS-II-PDF/p…
Browse files Browse the repository at this point in the history
…df-agents into tax-day-experiment
  • Loading branch information
AdamCorrao committed Apr 10, 2024
2 parents c2d6aae + 7785df1 commit 55c6721
Show file tree
Hide file tree
Showing 7 changed files with 82 additions and 16 deletions.
40 changes: 35 additions & 5 deletions containers/mmm5-tax-day-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,26 +3,53 @@ version: '3'


services:
gsas:
gsas-agent:
image: gsas:conda
build:
context: ../gsas
dockerfile: Containerfile-conda
command: /bin/bash -c "export BS_AGENT_STARTUP_SCRIPT_PATH=/src/pdf-agents/pdf_agents/startup_scripts/mmm5-tax-day/gsas.py && exec conda run -n GSASII --no-capture-output uvicorn bluesky_adaptive.server:app"
command: conda run -n GSASII --no-capture-output uvicorn bluesky_adaptive.server:app --host 0.0.0.0 --root-path /gsas-agent
environment:
- TILED_API_KEY=$TILED_API_KEY
- BS_AGENT_STARTUP_SCRIPT_PATH=/src/pdf-agents/pdf_agents/startup_scripts/mmm5-tax-day/gsas.py
volumes:
- type: bind
source: ../pdf_agents
target: /src/pdf-agents/pdf_agents
read_only: true
- type: bind
source: /etc/bluesky/kafka.yml
target: /etc/bluesky/kafka.yml
read_only: true

gsas-ui:
image: ghcr.io/maffettone/bluesky-adaptive-ui:latest
entrypoint: /modify_dns.sh
command: python3 /src/bluesky-adaptive-ui/bluesky_adaptive_ui/default_dash_app/app.py --agent-address gsas-agent --agent-port 8000
environment:
- DASH_REQUEST_PATHNAME_PREFIX="/gsas/"
volumes:
- ./modify_dns.sh:/modify_dns.sh
- type: bind
source: ../../bluesky-adaptive-ui
target: /src/bluesky-adaptive-ui
read_only: true

kmeans-gsas:
kmeans-gsas-agent:
image: bluesky:latest
command: /bin/bash -c "BS_AGENT_STARTUP_SCRIPT_PATH=/src/pdf-agents/pdf_agents/startup_scripts/mmm5-tax-day/kmeans-gsas.py uvicorn bluesky_adaptive.server:app"
command: uvicorn bluesky_adaptive.server:app --host 0.0.0.0 --root-path /kmeans-gsas-agent
environment:
- TILED_API_KEY=$TILED_API_KEY
- BS_AGENT_STARTUP_SCRIPT_PATH=/src/pdf-agents/pdf_agents/startup_scripts/mmm5-tax-day/gsas.py
volumes:
- type: bind
source: ../pdf_agents
target: /src/pdf-agents/pdf_agents
read_only: true
- type: bind
source: /etc/bluesky/kafka.yml
target: /etc/bluesky/kafka.yml
read_only: true
depends_on:
gsas:
condition: service_started
Expand All @@ -46,8 +73,11 @@ services:
target: /var/www/html
read_only: true
depends_on:
gsas:
gsas-agent:
condition: service_started
gsas-ui:
condition: service_started
kmeans-gsas:
condition: service_started


13 changes: 13 additions & 0 deletions containers/modify_dns.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# Extract the first nameserver entry
nameserver=$(grep -m 1 'nameserver' /etc/resolv.conf)

# Recreate resolv.conf with the desired content
{
echo "search dns.podman"
echo "$nameserver"
} > /etc/resolv.conf

# Execute the original CMD passed to the script
exec "$@"
20 changes: 15 additions & 5 deletions containers/nginx/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -57,16 +57,26 @@

<body>
<div class="container">
<h1>Welcome!</h1>
<p>This is the default landing page for our service. Please check back soon for updates.</p>
<h1>Landing Page for Agent Services!</h1>
<p>This is the default landing page for the agent services.</p>

<!-- Links to your services -->
<h2>Our Services</h2>
<h2>Available Agents</h2>
<ul>
<!-- Link to the GSAS service -->
<li><a href="/gsas/">GSAS Service</a></li>
<li><a href="/gsas-agent/docs">GSAS Service (FastAPI)</a></li>
<!-- Link to the KMeans-GSAS service -->
<li><a href="/kmeans-gsas/">KMeans-GSAS Service</a></li>
<li><a href="/kmeans-gsas-agent/docs">KMeans-GSAS (FastAPI)</a></li>
<!-- Add more services here -->
<!-- Example: <li><a href="/your-service/">Your Service Name</a></li> -->
</ul>

<h2>Available Agent User Interfaces</h2>
<ul>
<!-- Link to the GSAS service -->
<li><a href="/gsas/">GSAS UI</a></li>
<!-- Link to the KMeans-GSAS service -->
<li><a href="/kmeans-gsas/">KMeans-GSAS UI</a></li>
<!-- Add more services here -->
<!-- Example: <li><a href="/your-service/">Your Service Name</a></li> -->
</ul>
Expand Down
11 changes: 10 additions & 1 deletion containers/nginx/locs.d/gsas.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@

location /gsas/ {
proxy_pass http://gsas:8000/;
proxy_pass http://gsas-ui:8050/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_read_timeout 60s;
}

location /gsas-agent/ {
proxy_pass http://gsas-agent:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
4 changes: 2 additions & 2 deletions containers/nginx/locs.d/kmeans-gsas.conf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
location /kmeans-gsas/ {
proxy_pass http://kmeans-gsas:8000/;
location /kmeans-gsas-agent/ {
proxy_pass http://kmeans-gsas-agent:8000/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
Expand Down
5 changes: 2 additions & 3 deletions pdf_agents/agents.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,13 +370,12 @@ def generate_report(self, **kwargs):
self.close_and_restart(clear_tell_cache=False, retell_all=False, reason="Per-Run Subscribers")

@classmethod
def get_beamline_objects(cls) -> dict:
ret = super().get_beamline_objects()
def get_default_producer(cls) -> Publisher:
beamline_tla = "pdf"
kafka_config = nslsii.kafka_utils._read_bluesky_kafka_config_file(
config_file_path="/etc/bluesky/kafka.yml"
)
ret["report_producer"] = Publisher(
ret = Publisher(
topic=f"{beamline_tla}.mmm.bluesky.agents",
bootstrap_servers=",".join(kafka_config["bootstrap_servers"]),
key="{beamline_tla}.key",
Expand Down
5 changes: 5 additions & 0 deletions pdf_agents/startup_scripts/mmm5-tax-day/gsas.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,16 @@
}
}

report_producer = RefinementAgent.get_default_producer()


agent = RefinementAgent(
# GSAS Args
cif_paths=["/src/pdf-agents/assets/fcc.cif"],
refinement_params=[param_dict_phase1],
inst_param_path="/src/pdf-agents/assets/LaB6_IPF.instprm",
# Required report producer
report_producer=report_producer,
# BS Adaptive Args
ask_on_tell=False,
report_on_tell=True,
Expand Down

0 comments on commit 55c6721

Please sign in to comment.