-
-
Notifications
You must be signed in to change notification settings - Fork 1
Add unified docker #9
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. Weβll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
074d551
Refactor the docker build
coketaste a4177cf
Updated script of build
coketaste 7b7dc23
cleanup
coketaste 1b4aa97
Fixed the setup
coketaste aa8ce9c
Updated docker compose
coketaste 0c5927f
cleanup the requirements for docker and native installation
coketaste File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,161 @@ | ||
| # Quantum Computing 101 - Unified Multi-Architecture Dockerfile | ||
| # Supports CPU, NVIDIA GPU (CUDA), and AMD GPU (ROCm) | ||
| # Best practices: Multi-stage build, build args, minimal layers | ||
|
|
||
| # Build arguments for variant selection | ||
| ARG VARIANT=cpu | ||
| ARG PYTORCH_VERSION=2.8.0 | ||
| ARG CUDA_VERSION=12.9 | ||
| ARG CUDNN_VERSION=9 | ||
|
|
||
| # ============================================================================= | ||
| # Stage 1: Base Image Selection | ||
| # ============================================================================= | ||
| FROM pytorch/pytorch:${PYTORCH_VERSION}-cuda${CUDA_VERSION}-cudnn${CUDNN_VERSION}-devel AS base-nvidia | ||
| FROM rocm/pytorch:latest AS base-amd | ||
| FROM python:3.12-slim AS base-cpu | ||
|
|
||
| # Select appropriate base based on variant | ||
| FROM base-${VARIANT} AS base | ||
|
|
||
| # ============================================================================= | ||
| # Stage 2: Common Setup - System Dependencies | ||
| # ============================================================================= | ||
| FROM base AS system-deps | ||
|
|
||
| # Metadata | ||
| LABEL maintainer="Quantum Computing 101" | ||
| LABEL version="3.0" | ||
| LABEL description="Quantum computing educational platform with multi-GPU support" | ||
|
|
||
| # Environment variables | ||
| ENV DEBIAN_FRONTEND=noninteractive \ | ||
| PYTHONUNBUFFERED=1 \ | ||
| PYTHONDONTWRITEBYTECODE=1 \ | ||
| MPLBACKEND=Agg \ | ||
| QC101_CONTAINER=1 \ | ||
| PIP_NO_CACHE_DIR=1 \ | ||
| PIP_DISABLE_PIP_VERSION_CHECK=1 | ||
|
|
||
| # Install common system dependencies | ||
| RUN apt-get update && apt-get install -y --no-install-recommends \ | ||
| gcc \ | ||
| g++ \ | ||
| make \ | ||
| git \ | ||
| curl \ | ||
| wget \ | ||
| vim \ | ||
| htop \ | ||
| ca-certificates \ | ||
| && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # ============================================================================= | ||
| # Stage 3: Python Environment Setup | ||
| # ============================================================================= | ||
| FROM system-deps AS python-setup | ||
|
|
||
| # Upgrade pip and install build tools | ||
| RUN pip install --upgrade pip setuptools wheel | ||
|
|
||
| # Create non-root user for security | ||
| RUN useradd --create-home --shell /bin/bash --uid 1000 qc101 | ||
|
|
||
| WORKDIR /home/qc101/quantum-computing-101 | ||
|
|
||
| # ============================================================================= | ||
| # Stage 4: Dependencies Installation (CPU Variant) | ||
| # ============================================================================= | ||
| FROM python-setup AS deps-cpu | ||
|
|
||
| # Copy requirements | ||
| COPY docker/requirements/base.txt /tmp/requirements/base.txt | ||
| COPY docker/requirements/cpu.txt /tmp/requirements/cpu.txt | ||
|
|
||
| # Install base dependencies | ||
| RUN pip install -r /tmp/requirements/base.txt | ||
|
|
||
| # Install CPU-specific dependencies | ||
| RUN pip install -r /tmp/requirements/cpu.txt | ||
|
|
||
| # ============================================================================= | ||
| # Stage 5: Dependencies Installation (NVIDIA GPU Variant) | ||
| # ============================================================================= | ||
| FROM python-setup AS deps-nvidia | ||
|
|
||
| # NVIDIA-specific environment variables | ||
| ENV NVIDIA_VISIBLE_DEVICES=all \ | ||
| NVIDIA_DRIVER_CAPABILITIES=compute,utility \ | ||
| CUDA_VISIBLE_DEVICES=all \ | ||
| QISKIT_IN_PARALLEL=TRUE | ||
|
|
||
| # Copy requirements | ||
| COPY docker/requirements/base.txt /tmp/requirements/base.txt | ||
| COPY docker/requirements/gpu-nvidia.txt /tmp/requirements/gpu-nvidia.txt | ||
|
|
||
| # Install base dependencies (excluding qiskit-aer to avoid conflicts) | ||
| RUN sed '/^qiskit-aer/d' /tmp/requirements/base.txt > /tmp/requirements/base-no-aer.txt && \ | ||
| pip install -r /tmp/requirements/base-no-aer.txt | ||
|
|
||
| # Install NVIDIA-specific dependencies (includes qiskit-aer-gpu) | ||
| RUN pip install -r /tmp/requirements/gpu-nvidia.txt | ||
|
|
||
| # ============================================================================= | ||
| # Stage 6: Dependencies Installation (AMD GPU Variant) | ||
| # ============================================================================= | ||
| FROM python-setup AS deps-amd | ||
|
|
||
| # ROCm-specific environment variables | ||
| ENV ROCM_VISIBLE_DEVICES=all \ | ||
| HIP_VISIBLE_DEVICES=all | ||
|
|
||
| # Copy requirements | ||
| COPY docker/requirements/base.txt /tmp/requirements/base.txt | ||
| COPY docker/requirements/gpu-amd.txt /tmp/requirements/gpu-amd.txt | ||
|
|
||
| # Install base dependencies | ||
| RUN pip install -r /tmp/requirements/base.txt | ||
|
|
||
| # Install AMD-specific dependencies | ||
| RUN pip install -r /tmp/requirements/gpu-amd.txt | ||
|
|
||
| # ============================================================================= | ||
| # Stage 7: Application Setup (Unified) | ||
| # ============================================================================= | ||
| FROM deps-${VARIANT} AS app-setup | ||
|
|
||
| # Copy application code | ||
| COPY --chown=qc101:qc101 . /home/qc101/quantum-computing-101/ | ||
|
|
||
| # Install the package in development mode | ||
| RUN pip install -e . | ||
|
|
||
| # Create output directory | ||
| RUN mkdir -p /home/qc101/quantum-computing-101/outputs && \ | ||
| chown -R qc101:qc101 /home/qc101/quantum-computing-101/outputs | ||
|
|
||
| # ============================================================================= | ||
| # Stage 8: Runtime Image (Final) | ||
| # ============================================================================= | ||
| FROM app-setup AS runtime | ||
|
|
||
| # Switch to non-root user | ||
| USER qc101 | ||
|
|
||
| # Set working directory | ||
| WORKDIR /home/qc101/quantum-computing-101/examples | ||
|
|
||
| # Health check | ||
| HEALTHCHECK --interval=30s --timeout=15s --start-period=10s --retries=3 \ | ||
| CMD python -c "import qiskit; print('β Container healthy')" || exit 1 | ||
|
|
||
| # Resource optimizations | ||
| ENV OMP_NUM_THREADS=8 \ | ||
| MKL_NUM_THREADS=8 | ||
|
|
||
| # Entrypoint script | ||
| COPY --chown=qc101:qc101 docker/entrypoint.sh /home/qc101/entrypoint.sh | ||
| RUN chmod +x /home/qc101/entrypoint.sh | ||
|
|
||
| ENTRYPOINT ["/home/qc101/entrypoint.sh"] | ||
| CMD ["bash"] | ||
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The sed command to exclude qiskit-aer from base requirements is duplicated between the NVIDIA and AMD stages. Consider extracting this logic to a shared stage or create a separate base-no-aer.txt file to reduce code duplication.