Skip to content

Commit

Permalink
docker image for app
Browse files Browse the repository at this point in the history
  • Loading branch information
joglekara committed Nov 12, 2024
1 parent 6508e8b commit 3421e8a
Show file tree
Hide file tree
Showing 8 changed files with 115 additions and 30 deletions.
47 changes: 47 additions & 0 deletions .github/workflows/deploy.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# This is a basic workflow to help you get started with Actions

name: deploy

# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the master branch
push:
branches:
- main
- add-data

# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:

# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
deploy-tsadar:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v1
with:
aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
aws-region: us-east-1

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v1

- name: Build and tag api request image to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: continuum
IMAGE_TAG: latest-tsadar-runner
run: |
docker build -f Dockerfile -t $ECR_REGISTRY/$ECR_REPOSITORY:$IMAGE_TAG .
- name: Push all images to Amazon ECR
env:
ECR_REGISTRY: ${{ steps.login-ecr.outputs.registry }}
ECR_REPOSITORY: continuum
run: |
docker push --all-tags $ECR_REGISTRY/$ECR_REPOSITORY
11 changes: 11 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# base image
FROM mambaorg/micromamba:latest

WORKDIR /app

COPY --chown=$MAMBA_USER:$MAMBA_USER tsadar /app/tsadar
COPY --chown=$MAMBA_USER:$MAMBA_USER env_gpu.yml docker/fit_for_app.py docker/run.sh /app/
RUN chmod +x run.sh

RUN micromamba install -y -n base -f /app/env_gpu.yml && \
micromamba clean --all --yes
5 changes: 5 additions & 0 deletions docker/fit_for_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import sys
from tsadar.runner import run_for_app

if __name__ == "__main__":
run_for_app(sys.argv[1])
2 changes: 2 additions & 0 deletions docker/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/bin/bash
micromamba run -n base python3 fit_for_app.py $1
44 changes: 19 additions & 25 deletions env_gpu.yml
Original file line number Diff line number Diff line change
@@ -1,30 +1,24 @@
name: tsadar-gpu
channels:
- conda-forge
dependencies:
- python=3.10
- ipython
- ipykernel
- python=3.12
- pyhdf
- pip
- jax[cuda12]
- jaxopt
- numpy<2
- scipy
- matplotlib
- pyyaml
- mlflow
- boto3
- flatten-dict
- typing-extensions
- optax
- tqdm
- xarray
- pandas
- pip:
# works for regular pip packages
- --find-links https://storage.googleapis.com/jax-releases/jax_cuda_releases.html
- jaxlib==0.4.26+cuda12.cudnn89
- jax==0.4.26
- jaxopt
- numpy
- scipy
- matplotlib
- pyhdf
- xlrd
- pyyaml
- mlflow
- boto3
- flatten-dict
- typing-extensions
- optax
- tqdm
- xarray
- mlflow_export_import
- pandas
- interpax
- mlflow_export_import
- interpax

4 changes: 3 additions & 1 deletion tsadar/data_handleing/load_ts_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
BASE_FILES_PATH = os.path.join(os.path.dirname(__file__), "..", "aux")


def loadData(sNum, sDay, loadspecs):
def loadData(sNum, sDay, loadspecs, custom_path=False):
"""
This function loads the appropriate data based off the provided shot number (sNum) automatically determining the
type of data in the file. The flag sDay changes the default path to the temporary archive on the redwood server and
Expand All @@ -35,6 +35,8 @@ def loadData(sNum, sDay, loadspecs):
"""
if sDay:
folder = r"\\redwood\archive\tmp\thomson"
elif custom_path:
folder = custom_path
else:
folder = join(BASE_FILES_PATH, "data")

Expand Down
8 changes: 7 additions & 1 deletion tsadar/process/prepare.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
from typing import Dict

import numpy as np
import os

from tsadar.process.evaluate_background import get_shot_bg
from tsadar.data_handleing.load_ts_data import loadData
from tsadar.process.correct_throughput import correctThroughput
Expand All @@ -20,8 +22,12 @@ def prepare_data(config: Dict) -> Dict:
"""
# load data
custom_path = (config["data"]["filenames"]["epw"] is not None) | (config["data"]["filenames"]["iaw"] is not None)
if custom_path:
custom_path = os.path.dirname(config["data"]["filenames"]["epw"])

[elecData, ionData, xlab, config["other"]["extraoptions"]["spectype"]] = loadData(
config["data"]["shotnum"], config["data"]["shotDay"], config["other"]["extraoptions"]
config["data"]["shotnum"], config["data"]["shotDay"], config["other"]["extraoptions"], custom_path=custom_path
)

# get scattering angles and weights
Expand Down
24 changes: 21 additions & 3 deletions tsadar/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,9 +81,27 @@ def run(cfg_path: str, mode: str) -> str:
return run_id


def run_for_app(cfg: Dict, mode: str) -> str:
with mlflow.start_run(run_name=cfg["mlflow"]["run"], log_system_metrics=True) as mlflow_run:
_run_(cfg, mode=mode)
def run_for_app(run_id: str) -> str:
with mlflow.start_run(run_id=run_id, log_system_metrics=True) as mlflow_run:
# download config
with tempfile.TemporaryDirectory(dir=BASE_TEMPDIR) as temp_path:

dest_file_path = utils.download_file(f"config.yaml", mlflow_run.info.artifact_uri, temp_path)
with open(dest_file_path, "r") as fi:
config = yaml.safe_load(fi)

if config["data"]["filenames"]["epw"] is not None:
config["data"]["filenames"]["epw"] = utils.download_file(
config["data"]["filenames"]["epw"], mlflow_run.info.artifact_uri, temp_path
)

if config["data"]["filenames"]["iaw"] is not None:
config["data"]["filenames"]["iaw"] = utils.download_file(
config["data"]["filenames"]["iaw"], mlflow_run.info.artifact_uri, temp_path
)

_run_(config, mode="fit")

return mlflow_run.info.run_id


Expand Down

0 comments on commit 3421e8a

Please sign in to comment.