|
| 1 | +######################################################## |
| 2 | +# PennyLane Docker Image for Grace Hopper supercomputer |
| 3 | + |
| 4 | +#docker buildx build --platform linux/arm64 -f pennylane-gh.dockerfile --target wheel-out --build-arg CUDA_VER=12.8.1 --build-arg LIGHTNING_VERSION=v0.43.0 --build-arg PY_VER=3.11 --build-arg PENNYLANE_VERSION=0.43.0 --output type=local,dest=./wheelhouse . |
| 5 | +# or download from quay.io/pawsey/pennylane-gracehopper:0.0.1 |
| 6 | + |
| 7 | +######################################################## |
| 8 | + |
| 9 | +# Define global build defaults |
| 10 | +ARG PENNYLANE_VERSION=master |
| 11 | +ARG PYTHON_VERSION=3.11 |
| 12 | +ARG CUDA_VER=12.8.1 |
| 13 | +ARG LIGHTNING_VERSION=master |
| 14 | + |
| 15 | +# Create basic runtime environment base on Ubuntu 22.04 (jammy) |
| 16 | +# Create and activate runtime virtual environment |
| 17 | +FROM ubuntu:jammy AS base-runtime |
| 18 | +ARG PYTHON_VERSION |
| 19 | +ARG CUDA_ARCH=HOPPER90 |
| 20 | +ARG CUDA_VER |
| 21 | +ARG DEBIAN_FRONTEND=noninteractive |
| 22 | +ARG GCC_VERSION=11 |
| 23 | +ARG LIGHTNING_VERSION |
| 24 | +ARG PENNYLANE_VERSION |
| 25 | +RUN apt-get update \ |
| 26 | + && apt-get install --no-install-recommends -y \ |
| 27 | + apt-utils \ |
| 28 | + software-properties-common \ |
| 29 | + gnupg \ |
| 30 | + && add-apt-repository ppa:deadsnakes/ppa \ |
| 31 | + && apt-get update \ |
| 32 | + && apt-get install --no-install-recommends -y \ |
| 33 | + ca-certificates \ |
| 34 | + git \ |
| 35 | + libgomp1 \ |
| 36 | + python${PYTHON_VERSION} \ |
| 37 | + python3-pip \ |
| 38 | + python${PYTHON_VERSION}-venv \ |
| 39 | + tzdata \ |
| 40 | + wget \ |
| 41 | + && apt-get clean \ |
| 42 | + && rm -rf /var/lib/apt/lists/* |
| 43 | +ENV VIRTUAL_ENV=/opt/venv |
| 44 | +RUN python${PYTHON_VERSION} -m venv $VIRTUAL_ENV |
| 45 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 46 | + |
| 47 | +# Create basic build environment with build tools and compilers |
| 48 | +FROM base-runtime AS base-build |
| 49 | +ARG PYTHON_VERSION |
| 50 | +ARG GCC_VERSION=11 |
| 51 | +RUN apt-get update \ |
| 52 | + && apt-get install --no-install-recommends -y \ |
| 53 | + build-essential \ |
| 54 | + ccache \ |
| 55 | + cmake \ |
| 56 | + curl \ |
| 57 | + ninja-build \ |
| 58 | + python${PYTHON_VERSION}-dev \ |
| 59 | + gcc-${GCC_VERSION} g++-${GCC_VERSION} cpp-${GCC_VERSION} \ |
| 60 | + && apt-get clean \ |
| 61 | + && rm -rf /var/lib/apt/lists/* |
| 62 | +RUN update-alternatives \ |
| 63 | + --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \ |
| 64 | + --slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \ |
| 65 | + --slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} |
| 66 | +RUN /usr/sbin/update-ccache-symlinks |
| 67 | +RUN mkdir /opt/ccache |
| 68 | +RUN ccache --set-config=cache_dir=/opt/ccache |
| 69 | + |
| 70 | +# Create and activate build virtual environment |
| 71 | +# Install Lightning dev requirements |
| 72 | +FROM base-build AS base-build-python |
| 73 | +ARG LIGHTNING_VERSION |
| 74 | +ARG PYTHON_VERSION |
| 75 | +WORKDIR /opt/pennylane-lightning |
| 76 | +ENV VIRTUAL_ENV=/opt/venv-build |
| 77 | +RUN python${PYTHON_VERSION} -m venv $VIRTUAL_ENV |
| 78 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 79 | +RUN rm -rf tmp && git clone --depth 1 --branch ${LIGHTNING_VERSION} https://github.com/PennyLaneAI/pennylane-lightning.git tmp\ |
| 80 | + && mv tmp/* /opt/pennylane-lightning && rm -rf tmp |
| 81 | +RUN pip install --no-cache-dir build cmake ninja toml wheel setuptools>=75.8.1 |
| 82 | + |
| 83 | +# Download Lightning release and build lightning-qubit backend |
| 84 | +FROM base-build-python AS build-wheel-lightning-qubit |
| 85 | +WORKDIR /opt/pennylane-lightning |
| 86 | +RUN pip uninstall -y pennylane-lightning |
| 87 | +RUN python scripts/configure_pyproject_toml.py || true |
| 88 | +RUN python -m build --wheel |
| 89 | + |
| 90 | +# Install lightning-qubit backend |
| 91 | +FROM base-runtime AS wheel-lightning-qubit |
| 92 | +COPY --from=build-wheel-lightning-qubit /opt/pennylane-lightning/dist/ / |
| 93 | +RUN pip install --force-reinstall --no-cache-dir pennylane_lightning*.whl && rm pennylane_lightning*.whl |
| 94 | +RUN pip install --no-cache-dir git+https://github.com/PennyLaneAI/pennylane.git@${PENNYLANE_VERSION} |
| 95 | + |
| 96 | +# Use NVIDIA CUDA devel image with CUDA toolkit pre-installed |
| 97 | +FROM nvidia/cuda:${CUDA_VER}-devel-ubuntu22.04 AS base-build-cuda |
| 98 | +ARG CUDA_VER |
| 99 | +ARG PYTHON_VERSION |
| 100 | +ARG GCC_VERSION=11 |
| 101 | +ARG LIGHTNING_VERSION=master |
| 102 | +ENV DEBIAN_FRONTEND=noninteractive |
| 103 | +RUN apt-get update \ |
| 104 | + && apt-get install --no-install-recommends -y \ |
| 105 | + software-properties-common \ |
| 106 | + gnupg \ |
| 107 | + && add-apt-repository ppa:deadsnakes/ppa \ |
| 108 | + && apt-get update \ |
| 109 | + && apt-get install --no-install-recommends -y \ |
| 110 | + build-essential \ |
| 111 | + ccache \ |
| 112 | + cmake \ |
| 113 | + curl \ |
| 114 | + git \ |
| 115 | + ninja-build \ |
| 116 | + python${PYTHON_VERSION} \ |
| 117 | + python${PYTHON_VERSION}-dev \ |
| 118 | + python${PYTHON_VERSION}-venv \ |
| 119 | + python3-pip \ |
| 120 | + wget \ |
| 121 | + gcc-${GCC_VERSION} g++-${GCC_VERSION} cpp-${GCC_VERSION} \ |
| 122 | + && apt-get clean \ |
| 123 | + && rm -rf /var/lib/apt/lists/* |
| 124 | +RUN update-alternatives \ |
| 125 | + --install /usr/bin/gcc gcc /usr/bin/gcc-${GCC_VERSION} 100 \ |
| 126 | + --slave /usr/bin/g++ g++ /usr/bin/g++-${GCC_VERSION} \ |
| 127 | + --slave /usr/bin/gcov gcov /usr/bin/gcov-${GCC_VERSION} |
| 128 | +ENV VIRTUAL_ENV=/opt/venv-build |
| 129 | +RUN python${PYTHON_VERSION} -m venv $VIRTUAL_ENV |
| 130 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 131 | +WORKDIR /opt/pennylane-lightning |
| 132 | +RUN rm -rf tmp && git clone --depth 1 --branch ${LIGHTNING_VERSION} https://github.com/PennyLaneAI/pennylane-lightning.git tmp\ |
| 133 | + && mv tmp/* /opt/pennylane-lightning && rm -rf tmp |
| 134 | +RUN pip install --no-cache-dir build cmake ninja toml wheel setuptools>=75.8.1 |
| 135 | +ENV PATH=/usr/local/cuda/bin:${PATH} |
| 136 | +ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH} |
| 137 | + |
| 138 | +# Download and build Lightning-GPU release |
| 139 | +FROM base-build-cuda AS build-wheel-lightning-gpu |
| 140 | +WORKDIR /opt/pennylane-lightning |
| 141 | +ENV PL_BACKEND=lightning_gpu |
| 142 | +RUN pip install --no-cache-dir wheel custatevec-cu12 |
| 143 | +RUN pip uninstall -y pennylane-lightning |
| 144 | +RUN python scripts/configure_pyproject_toml.py || true |
| 145 | +RUN CUQUANTUM_SDK=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum/lib')") python -m build --wheel |
| 146 | + |
| 147 | + |
| 148 | +# Install python3 and setup runtime virtual env in CUDA-12-runtime image (includes CUDA runtime and math libraries) |
| 149 | +# Install lightning-gpu CUDA backend |
| 150 | +FROM nvidia/cuda:${CUDA_VER}-runtime-ubuntu22.04 AS wheel-lightning-gpu |
| 151 | +ARG CUDA_VER |
| 152 | +ARG PENNYLANE_VERSION |
| 153 | +ARG PYTHON_VERSION |
| 154 | +ENV DEBIAN_FRONTEND=noninteractive |
| 155 | +RUN apt-get update \ |
| 156 | + && apt-get install --no-install-recommends -y \ |
| 157 | + software-properties-common \ |
| 158 | + gnupg \ |
| 159 | + && add-apt-repository ppa:deadsnakes/ppa -y \ |
| 160 | + && apt-get update \ |
| 161 | + && apt-get install --no-install-recommends -y \ |
| 162 | + git \ |
| 163 | + libgomp1 \ |
| 164 | + python${PYTHON_VERSION} \ |
| 165 | + python3-pip \ |
| 166 | + python${PYTHON_VERSION}-venv \ |
| 167 | + && apt-get clean \ |
| 168 | + && rm -rf /var/lib/apt/lists/* |
| 169 | +ENV VIRTUAL_ENV=/opt/venv |
| 170 | +RUN python${PYTHON_VERSION} -m venv $VIRTUAL_ENV |
| 171 | +ENV PATH="$VIRTUAL_ENV/bin:$PATH" |
| 172 | +RUN pip install --no-cache-dir custatevec-cu12 |
| 173 | +ENV LD_LIBRARY_PATH="$VIRTUAL_ENV/lib/python${PYTHON_VERSION}/site-packages/cuquantum/lib:$LD_LIBRARY_PATH" |
| 174 | +COPY --from=build-wheel-lightning-gpu /opt/pennylane-lightning/dist/ / |
| 175 | +COPY --from=build-wheel-lightning-qubit /opt/pennylane-lightning/dist/ / |
| 176 | +RUN pip install --no-cache-dir --force-reinstall pennylane_lightning*.whl |
| 177 | +RUN pip install --no-cache-dir git+https://github.com/PennyLaneAI/pennylane.git@${PENNYLANE_VERSION} |
| 178 | +RUN pip install --no-cache-dir matplotlib jupyterlab |
| 179 | +LABEL org.opencontainers.image.authors="Shusen Liu" |
| 180 | +LABEL org.opencontainers.image.name="pennylane-python${PYTHON_VERSION}-cuda${CUDA_VER}-lightening${LIGHTNING_VERSION}-gcc${GCC_VERSION}" |
| 181 | +LABEL org.opencontainers.image.noscan="false" |
| 182 | +LABEL org.opencontainers.image.version="0.0.3" |
| 183 | +LABEL org.opencontainers.image.devmode="true" |
| 184 | +LABEL org.opencontainers.image.scan="false" |
| 185 | +LABEL org.opencontainers.image.platform="arm" |
0 commit comments