Skip to content

Commit 5c00d7d

Browse files
authored
Merge pull request #9 from AIComputing101/coketaste/docker
Add unified docker
2 parents 530d9c3 + 0c5927f commit 5c00d7d

18 files changed

+949
-1572
lines changed

docker/Dockerfile

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Quantum Computing 101 - Unified Multi-Architecture Dockerfile
2+
# Supports CPU, NVIDIA GPU (CUDA), and AMD GPU (ROCm)
3+
# Best practices: Multi-stage build, build args, minimal layers
4+
5+
# Build arguments for variant selection
6+
ARG VARIANT=cpu
7+
ARG PYTORCH_VERSION=2.8.0
8+
ARG CUDA_VERSION=12.9
9+
ARG CUDNN_VERSION=9
10+
11+
# =============================================================================
12+
# Stage 1: Base Image Selection
13+
# =============================================================================
14+
FROM pytorch/pytorch:${PYTORCH_VERSION}-cuda${CUDA_VERSION}-cudnn${CUDNN_VERSION}-devel AS base-nvidia
15+
FROM rocm/pytorch:latest AS base-amd
16+
FROM python:3.12-slim AS base-cpu
17+
18+
# Select appropriate base based on variant
19+
FROM base-${VARIANT} AS base
20+
21+
# =============================================================================
22+
# Stage 2: Common Setup - System Dependencies
23+
# =============================================================================
24+
FROM base AS system-deps
25+
26+
# Metadata
27+
LABEL maintainer="Quantum Computing 101"
28+
LABEL version="3.0"
29+
LABEL description="Quantum computing educational platform with multi-GPU support"
30+
31+
# Environment variables
32+
ENV DEBIAN_FRONTEND=noninteractive \
33+
PYTHONUNBUFFERED=1 \
34+
PYTHONDONTWRITEBYTECODE=1 \
35+
MPLBACKEND=Agg \
36+
QC101_CONTAINER=1 \
37+
PIP_NO_CACHE_DIR=1 \
38+
PIP_DISABLE_PIP_VERSION_CHECK=1
39+
40+
# Install common system dependencies
41+
RUN apt-get update && apt-get install -y --no-install-recommends \
42+
gcc \
43+
g++ \
44+
make \
45+
git \
46+
curl \
47+
wget \
48+
vim \
49+
htop \
50+
ca-certificates \
51+
&& rm -rf /var/lib/apt/lists/*
52+
53+
# =============================================================================
54+
# Stage 3: Python Environment Setup
55+
# =============================================================================
56+
FROM system-deps AS python-setup
57+
58+
# Upgrade pip and install build tools
59+
RUN pip install --upgrade pip setuptools wheel
60+
61+
# Create non-root user for security
62+
RUN useradd --create-home --shell /bin/bash --uid 1000 qc101
63+
64+
WORKDIR /home/qc101/quantum-computing-101
65+
66+
# =============================================================================
67+
# Stage 4: Dependencies Installation (CPU Variant)
68+
# =============================================================================
69+
FROM python-setup AS deps-cpu
70+
71+
# Copy requirements
72+
COPY docker/requirements/base.txt /tmp/requirements/base.txt
73+
COPY docker/requirements/cpu.txt /tmp/requirements/cpu.txt
74+
75+
# Install base dependencies
76+
RUN pip install -r /tmp/requirements/base.txt
77+
78+
# Install CPU-specific dependencies
79+
RUN pip install -r /tmp/requirements/cpu.txt
80+
81+
# =============================================================================
82+
# Stage 5: Dependencies Installation (NVIDIA GPU Variant)
83+
# =============================================================================
84+
FROM python-setup AS deps-nvidia
85+
86+
# NVIDIA-specific environment variables
87+
ENV NVIDIA_VISIBLE_DEVICES=all \
88+
NVIDIA_DRIVER_CAPABILITIES=compute,utility \
89+
CUDA_VISIBLE_DEVICES=all \
90+
QISKIT_IN_PARALLEL=TRUE
91+
92+
# Copy requirements
93+
COPY docker/requirements/base.txt /tmp/requirements/base.txt
94+
COPY docker/requirements/gpu-nvidia.txt /tmp/requirements/gpu-nvidia.txt
95+
96+
# Install base dependencies (excluding qiskit-aer to avoid conflicts)
97+
RUN sed '/^qiskit-aer/d' /tmp/requirements/base.txt > /tmp/requirements/base-no-aer.txt && \
98+
pip install -r /tmp/requirements/base-no-aer.txt
99+
100+
# Install NVIDIA-specific dependencies (includes qiskit-aer-gpu)
101+
RUN pip install -r /tmp/requirements/gpu-nvidia.txt
102+
103+
# =============================================================================
104+
# Stage 6: Dependencies Installation (AMD GPU Variant)
105+
# =============================================================================
106+
FROM python-setup AS deps-amd
107+
108+
# ROCm-specific environment variables
109+
ENV ROCM_VISIBLE_DEVICES=all \
110+
HIP_VISIBLE_DEVICES=all
111+
112+
# Copy requirements
113+
COPY docker/requirements/base.txt /tmp/requirements/base.txt
114+
COPY docker/requirements/gpu-amd.txt /tmp/requirements/gpu-amd.txt
115+
116+
# Install base dependencies
117+
RUN pip install -r /tmp/requirements/base.txt
118+
119+
# Install AMD-specific dependencies
120+
RUN pip install -r /tmp/requirements/gpu-amd.txt
121+
122+
# =============================================================================
123+
# Stage 7: Application Setup (Unified)
124+
# =============================================================================
125+
FROM deps-${VARIANT} AS app-setup
126+
127+
# Copy application code
128+
COPY --chown=qc101:qc101 . /home/qc101/quantum-computing-101/
129+
130+
# Install the package in development mode
131+
RUN pip install -e .
132+
133+
# Create output directory
134+
RUN mkdir -p /home/qc101/quantum-computing-101/outputs && \
135+
chown -R qc101:qc101 /home/qc101/quantum-computing-101/outputs
136+
137+
# =============================================================================
138+
# Stage 8: Runtime Image (Final)
139+
# =============================================================================
140+
FROM app-setup AS runtime
141+
142+
# Switch to non-root user
143+
USER qc101
144+
145+
# Set working directory
146+
WORKDIR /home/qc101/quantum-computing-101/examples
147+
148+
# Health check
149+
HEALTHCHECK --interval=30s --timeout=15s --start-period=10s --retries=3 \
150+
CMD python -c "import qiskit; print('✅ Container healthy')" || exit 1
151+
152+
# Resource optimizations
153+
ENV OMP_NUM_THREADS=8 \
154+
MKL_NUM_THREADS=8
155+
156+
# Entrypoint script
157+
COPY --chown=qc101:qc101 docker/entrypoint.sh /home/qc101/entrypoint.sh
158+
RUN chmod +x /home/qc101/entrypoint.sh
159+
160+
ENTRYPOINT ["/home/qc101/entrypoint.sh"]
161+
CMD ["bash"]

docker/Dockerfile.base

Lines changed: 0 additions & 69 deletions
This file was deleted.

docker/Dockerfile.cpu

Lines changed: 0 additions & 71 deletions
This file was deleted.

0 commit comments

Comments
 (0)