Skip to content

Coiled account for Fast-cGAN software environment and doing forecast inference #1

@nishadhka

Description

@nishadhka

Overview

This issue documents the setup process for running the Fast-CGAN model entirely on a cloud-based environment using Coiled and Docker. The goal is to containerize the software environment, push the container to Google Artifact Registry, and configure a Coiled software environment to run Fast-CGAN seamlessly.


Steps to Build and Push the Docker Image

The following commands build the Fast-CGAN Docker image and push it to Google Artifact Registry:

docker build -t us-east1-docker.pkg.dev/sewaa-416306/coiled/fast-cgan:v0 -f coiled-dockerfile .
docker push us-east1-docker.pkg.dev/sewaa-416306/coiled/fast-cgan:v0

Authentication and Configuration

To authenticate with Google Cloud and configure Docker for pushing images:

export GOOGLE_APPLICATION_CREDENTIALS="/path/to/key.json"
gcloud auth activate-service-account --key-file=$GOOGLE_APPLICATION_CREDENTIALS
gcloud auth configure-docker us-east1-docker.pkg.dev

Verify the authentication:

gcloud auth list --filter=status:ACTIVE --format="value(account)" | grep iam.gserviceaccount.com

Setting Up Coiled Environment

Once the Docker image is built and pushed, we define a Coiled software environment to use this container:

import coiled

coiled.create_software_environment(
    name="fast-cgan-v0",
    container="us-east1-docker.pkg.dev/sewaa-416306/coiled/fast-cgan:v0",
)

To start a Jupyter notebook in Coiled using this environment:

coiled notebook start --name fast-cgan-notebook --vm-type n2-standard-2 --software fast-cgan-v0

Dockerfile for Fast-CGAN Environment

The coiled-dockerfile below details the Fast-CGAN setup, including dependencies, model files, and integration with Coiled.

ARG PYTHON_VERSION=3.10

FROM alpine/git AS builder
ARG API_REPO=https://github.com/icpac-igad/fast-cgan.git
ARG GAN_REPO=https://github.com/jaysnm/ensemble-cgan.git
ARG GAN_BRANCH=Jurre_brishti

RUN git clone --depth 1 ${API_REPO} /tmp/api && \
    git clone --depth 1 -b ${GAN_BRANCH} ${GAN_REPO} /tmp/cgan

FROM python:${PYTHON_VERSION}-slim AS runner

ARG USER_NAME=cgan
ARG USER_ID=1000
ARG GROUP_ID=1000
ARG WORK_HOME=/opt/cgan

# Install system libraries
RUN apt-get update -y && \
    apt-get install -y --no-install-recommends git rsync ssh ca-certificates pkg-config wget \
    libgdal-dev libgeos-dev libproj-dev gdal-bin libcgal-dev libxml2-dev libsqlite3-dev  \
    gcc g++ dvipng libfontconfig-dev libjpeg-dev libspng-dev libx11-dev libgbm-dev \
    libeccodes-dev libeccodes-tools && \
    mkdir -p ${WORK_HOME}/.local/bin ${WORK_HOME}/.ssh

RUN groupadd --gid ${GROUP_ID} ${USER_NAME} && \
    useradd --home-dir ${WORK_HOME} --uid ${USER_ID} --gid ${GROUP_ID} ${USER_NAME} && \
    chown -Rf ${USER_NAME}:${USER_NAME} ${WORK_HOME}

USER ${USER_NAME}
WORKDIR ${WORK_HOME}
ENV PATH=${WORK_HOME}/.local/bin:$PATH

# Download and extract model initialization data
RUN mkdir -p ${WORK_HOME}/data/models-config/jurre-brishti && \
    mkdir -p ${WORK_HOME}/data/models-config/mvua-kubwa && \
    wget -v https://cgan.icpac.net/ftp/models-config/jurre-brishti.tar.gz -P /tmp && \
    wget -v https://cgan.icpac.net/ftp/models-config/mvua-kubwa.tar.gz -P /tmp && \
    tar -xvzf /tmp/jurre-brishti.tar.gz -C ${WORK_HOME}/data/models-config/jurre-brishti && \
    tar -xvzf /tmp/mvua-kubwa.tar.gz -C ${WORK_HOME}/data/models-config/mvua-kubwa && \
    rm /tmp/jurre-brishti.tar.gz /tmp/mvua-kubwa.tar.gz

# Copy cloned repositories
COPY --from=builder --chown=${USER_NAME}:root /tmp/cgan ${WORK_HOME}/ensemble-cgan
RUN cd ${WORK_HOME}/ensemble-cgan && pip install --upgrade pip && pip install --no-cache-dir -e .

COPY --from=builder --chown=${USER_NAME}:root /tmp/api/pyproject.toml /tmp/api/poetry.lock /tmp/api/README.md ${WORK_HOME}/
COPY --from=builder --chown=${USER_NAME}:root /tmp/api/fastcgan ${WORK_HOME}/fastcgan

# Install Fast-CGAN API and dependencies
RUN cd ${WORK_HOME} && pip install --no-cache-dir -e . && \
    pip install eccodes cfgrib && \
    pip install coiled dask distributed dask-kubernetes google-cloud-storage && \
    touch ${WORK_HOME}/.env

# Create directories for data storage
RUN mkdir -p ${WORK_HOME}/jobs ${WORK_HOME}/forecasts ${WORK_HOME}/logs

# Set environment variables
ENV WORK_HOME=${WORK_HOME}
ENV JOBS_DATA_DIR=${WORK_HOME}/jobs
ENV FORECASTS_DATA_DIR=${WORK_HOME}/forecasts
ENV LOGS_DIR=${WORK_HOME}/logs

Guide for New Members: Setting Up Coiled and Running Fast-CGAN

1. Coiled Setup and Login

Step 1: Install Coiled Library

Ensure you have Python 3.8+ installed, then install Coiled:

pip install coiled

Step 2: Log into Coiled

Each user needs to log in to Coiled using the following command:

coiled login

This will open a browser window prompting you to authenticate with Coiled. After logging in, you’ll be connected to the shared workspace.

Step 3: Verify Workspace Access

Ensure that you are part of the correct Coiled workspace:

coiled whoami

If needed, switch to the workspace assigned for Fast-CGAN (replace workspace-name with the actual name: gcp-sewaa-nka):

coiled set workspace workspace-name

2. Creating a Jupyter Notebook in Coiled

Once logged in, each member can create their own notebook environment in Coiled.

Step 4: Start a Notebook

To start a Jupyter notebook using the pre-built Fast-CGAN software environment:

coiled notebook start --name fast-cgan-notebook --vm-type n2-standard-2 --software fast-cgan-v0

This will:

  • Spin up a Jupyter Notebook on Coiled Cloud
  • Use the pre-configured fast-cgan-v0 software environment
  • Assign a n2-standard-2 VM for execution

Once the notebook is started, Coiled will display a URL. Open this in your browser to access the notebook.


6. Shutting Down the Notebook

When finished, members should stop their notebook session to free up resources:

coiled notebook stop --name fast-cgan-notebook

Troubleshooting

  • If Coiled authentication fails, re-run:

    coiled login
  • If the notebook doesn't start, check workspace permissions:

    coiled whoami
  • If packages are missing inside the notebook:

    pip install --user <package_name>

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions