Skip to content
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

Feature/docker #496

Merged
merged 40 commits into from
Sep 22, 2023
Merged
Show file tree
Hide file tree
Changes from 16 commits
Commits
Show all changes
40 commits
Select commit Hold shift + click to select a range
03a8781
Refactor Dockerfile.
vincentmr Sep 7, 2023
2b16937
setup.py install
vincentmr Sep 8, 2023
5ef6271
Multi-stage docker build.
vincentmr Sep 8, 2023
2049311
Update docker readme.
vincentmr Sep 8, 2023
2376a23
Add omp deps.
vincentmr Sep 8, 2023
72a641f
Fix pip install warning.
vincentmr Sep 8, 2023
4f2cfab
Merge branch 'master' into feature/docker
vincentmr Sep 8, 2023
6d7da3e
Auto update version
github-actions[bot] Sep 8, 2023
a1f9c24
Add lightning-kokkos stage.
vincentmr Sep 11, 2023
ce91ca4
Add LGPU stage.
vincentmr Sep 11, 2023
2b87bed
Fix codefactor warnings.
vincentmr Sep 11, 2023
d657a41
Add LKokkos+CUDA stage.
vincentmr Sep 11, 2023
5c2272f
Fix wheel-lightning-kokkos-cuda runtime env.
vincentmr Sep 12, 2023
31643ba
Add make docker & dockerhub readme.
vincentmr Sep 12, 2023
21e287b
Build kokkos-cuda from --branch fix-rtld-deepbind https://github.com/…
vincentmr Sep 12, 2023
5dce308
Try fixing codefactor
vincentmr Sep 12, 2023
85989af
Add plugin doc links. Add HIP image. Refactor makefile.
vincentmr Sep 13, 2023
2b14765
Auto update version
github-actions[bot] Sep 13, 2023
c9aed90
Update readme.
vincentmr Sep 13, 2023
81f96ac
Update readme.
vincentmr Sep 13, 2023
12865c1
Update changelog.
vincentmr Sep 13, 2023
1caa0d8
Merge branch 'master' into feature/docker
vincentmr Sep 13, 2023
736fc16
wget --progress.
vincentmr Sep 13, 2023
84098a2
Update docker/README.md
vincentmr Sep 15, 2023
44ef199
Merge branch 'master' into feature/docker
vincentmr Sep 15, 2023
3b97c75
Auto update version
github-actions[bot] Sep 15, 2023
b9f15b3
trigger CI
vincentmr Sep 15, 2023
34a0efb
Add GCC_VERSION build arg.
vincentmr Sep 19, 2023
1708c99
Auto update version
github-actions[bot] Sep 19, 2023
853bf81
Download lightning in base-build-python. Build LQubit without Kokkos.
vincentmr Sep 19, 2023
e477c69
Add PL versions docker.
vincentmr Sep 20, 2023
d292fe7
Auto update version
github-actions[bot] Sep 20, 2023
57bd92e
Merge branch 'master' into feature/docker
vincentmr Sep 20, 2023
c35f6a2
Change CUDA/ROCM ARGs for installer urls. Clear *.deb after install.
vincentmr Sep 20, 2023
08bc65d
Merge branch 'master' into feature/docker
vincentmr Sep 22, 2023
7dc9718
Auto update version
github-actions[bot] Sep 22, 2023
6d0c660
Ship wheel-lightning-kokkos-rocm on top of rocm/dev-ubuntu-22.04.
vincentmr Sep 22, 2023
0f585ba
Merge remote-tracking branch 'origin/master' into feature/docker
vincentmr Sep 22, 2023
0a8e389
Auto update version
github-actions[bot] Sep 22, 2023
fcc5a32
Add rocm/dev-ubuntu-22.04 tag.
vincentmr Sep 22, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@

### New features since last release

* Add `Dockerfile` in `docker` and `make docker` workflow in `Makefile`. The Docker images and documentation are available on [DockerHub](https://hub.docker.com/r/vincentmichaudrioux/pennylane).
[(#496)](https://github.com/PennyLaneAI/pennylane-lightning/pull/496)
vincentmr marked this conversation as resolved.
Show resolved Hide resolved

* Add mid-circuit state preparation operation tests.
[(#495)](https://github.com/PennyLaneAI/pennylane-lightning/pull/495)

Expand Down
11 changes: 11 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,3 +123,14 @@ docs:
.PHONY : clean-docs
clean-docs:
$(MAKE) -C doc clean

.PHONY : docker
docker:
docker build -f docker/Dockerfile --tag=vincentmichaudrioux/pennylane:lightning-gpu --target wheel-lightning-gpu .
docker build -f docker/Dockerfile --tag=vincentmichaudrioux/pennylane:lightning-kokkos-cuda --target wheel-lightning-kokkos-cuda .
docker build -f docker/Dockerfile --tag=vincentmichaudrioux/pennylane:lightning-kokkos-openmp --target wheel-lightning-kokkos-openmp .
docker build -f docker/Dockerfile --tag=vincentmichaudrioux/pennylane:lightning-qubit --target wheel-lightning-qubit .
docker push vincentmichaudrioux/pennylane:lightning-gpu
docker push vincentmichaudrioux/pennylane:lightning-kokkos-cuda
docker push vincentmichaudrioux/pennylane:lightning-kokkos-openmp
docker push vincentmichaudrioux/pennylane:lightning-qubit
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
194 changes: 168 additions & 26 deletions docker/Dockerfile
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2018-2021 Xanadu Quantum Technologies Inc.
# Copyright 2018-2023 Xanadu Quantum Technologies Inc.

# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
Expand All @@ -12,43 +12,185 @@
# See the License for the specific language governing permissions and
# limitations under the License.

FROM ubuntu:focal AS base
# Setup and build pennylane-lightning


# Setup and install basic packages
FROM ubuntu:jammy AS base-runtime
ARG KOKKOS_VERSION=4.1.00
ARG LIGHTNING_VERSION=0.32.0
ARG CUDA_VERSION=12.2
RUN apt-get update \
&& apt-get install --no-install-recommends -y apt-utils \
&& DEBIAN_FRONTEND="noninteractive" \
apt-get install --no-install-recommends -y tzdata \
build-essential \
&& apt-get install --no-install-recommends -y \
apt-utils \
ca-certificates \
libgomp1 \
python3 \
python3-pip \
python3-venv \
tzdata \
wget \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/opt/venv-build
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"

FROM base-runtime AS base-build
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
build-essential \
ccache \
cmake \
curl \
git \
python3 \
python3-pip \
python3-venv \
ninja-build \
python3-dev \
gcc-11 g++-11 cpp-11 \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/* \
&& update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-11 100 --slave /usr/bin/g++ g++ /usr/bin/g++-11 --slave /usr/bin/gcov gcov /usr/bin/gcov-10 \
&& /usr/sbin/update-ccache-symlinks \
&& mkdir /opt/ccache \
&& ccache --set-config=cache_dir=/opt/ccache \
&& python3 -m venv /opt/venv
&& rm -rf /var/lib/apt/lists/*
RUN update-alternatives \
--install /usr/bin/gcc gcc /usr/bin/gcc-11 100 \
--slave /usr/bin/g++ g++ /usr/bin/g++-11 \
--slave /usr/bin/gcov gcov /usr/bin/gcov-10
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
RUN /usr/sbin/update-ccache-symlinks
RUN mkdir /opt/ccache
RUN ccache --set-config=cache_dir=/opt/ccache
vincentmr marked this conversation as resolved.
Show resolved Hide resolved

ENV PATH="/opt/venv/bin:$PATH"
FROM base-build AS base-build-python
RUN pip install --no-cache-dir wheel
RUN --mount=type=bind,source=requirements-dev.txt,target=requirements-dev.txt \
pip install --no-cache-dir -r requirements-dev.txt
RUN --mount=type=bind,source=doc/requirements.txt,target=requirements-doc.txt \
pip install --no-cache-dir -r requirements-doc.txt

# Setup and build pennylane-lightning
FROM base-build-python AS build-wheel-lightning-qubit
WORKDIR /opt/pennylane-lightning
RUN wget --progress=dot:giga https://github.com/PennyLaneAI/pennylane-lightning/archive/refs/tags/v${LIGHTNING_VERSION}.tar.gz
RUN tar -zxf v${LIGHTNING_VERSION}.tar.gz && mv pennylane-lightning-${LIGHTNING_VERSION}/* /opt/pennylane-lightning
RUN pip uninstall -y pennylane-lightning
RUN python setup.py build_ext
RUN python setup.py bdist_wheel

FROM base-runtime AS wheel-lightning-qubit
COPY --from=build-wheel-lightning-qubit /opt/pennylane-lightning/dist/ /
RUN pip install --force-reinstall --no-cache-dir PennyLane_Lightning*.whl

FROM base-build as build-kokkos-openmp
WORKDIR /opt/kokkos-${KOKKOS_VERSION}
RUN wget --progress=dot:giga https://github.com/kokkos/kokkos/archive/refs/tags/${KOKKOS_VERSION}.tar.gz
RUN tar -zxf ${KOKKOS_VERSION}.tar.gz && mv /opt/kokkos-${KOKKOS_VERSION}/kokkos-${KOKKOS_VERSION}/* /opt/kokkos-${KOKKOS_VERSION}
RUN cmake -S /opt/kokkos-${KOKKOS_VERSION} -B /opt/kokkos-${KOKKOS_VERSION}/build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/kokkos \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DBUILD_TESTING:BOOL=OFF \
-DKokkos_ENABLE_SERIAL:BOOL=ON \
-DKokkos_ENABLE_OPENMP:BOOL=ON \
-DCMAKE_CXX_STANDARD=20 \
-DKokkos_ENABLE_EXAMPLES:BOOL=OFF \
-DKokkos_ENABLE_TESTS:BOOL=OFF \
-DKokkos_ENABLE_LIBDL:BOOL=OFF
RUN cmake --build /opt/kokkos-${KOKKOS_VERSION}/build
RUN cmake --install /opt/kokkos-${KOKKOS_VERSION}/build

FROM base-build-python AS build-wheel-lightning-kokkos-openmp
WORKDIR /opt/pennylane-lightning
COPY --from=build-kokkos-openmp /opt/kokkos /opt/kokkos
ENV CMAKE_PREFIX_PATH=/opt/kokkos:$CMAKE_PREFIX_PATH
RUN wget --progress=dot:giga https://github.com/PennyLaneAI/pennylane-lightning/archive/refs/tags/v${LIGHTNING_VERSION}.tar.gz
RUN tar -zxf v${LIGHTNING_VERSION}.tar.gz && mv pennylane-lightning-${LIGHTNING_VERSION}/* /opt/pennylane-lightning
RUN pip uninstall -y pennylane-lightning
RUN PL_BACKEND=lightning_kokkos python setup.py build_ext
RUN PL_BACKEND=lightning_kokkos python setup.py bdist_wheel

COPY . .
FROM base-runtime AS wheel-lightning-kokkos-openmp
COPY --from=build-kokkos-openmp /opt/kokkos /opt/kokkos
COPY --from=build-wheel-lightning-kokkos-openmp /opt/pennylane-lightning/dist/ /
RUN pip install --force-reinstall --no-cache-dir PennyLane_Lightning*.whl

RUN pip install --no-cache-dir wheel \
sphinx \
&& pip install --no-cache-dir -r requirements-dev.txt \
&& pip uninstall -y PennyLane_Lightning \
&& make install \
&& make test-python \
&& make test-cpp
FROM base-build-python as base-build-cuda
WORKDIR /opt/cuda-build
RUN curl -o cuda-12_2.run https://developer.download.nvidia.com/compute/cuda/12.2.2/local_installers/cuda_12.2.2_535.104.05_linux.run
RUN chmod a+x cuda-12_2.run
RUN ./cuda-12_2.run --silent --toolkit --toolkitpath=/usr/local/cuda-12.2
ENV PATH=/usr/local/cuda/bin:${PATH}
ENV LD_LIBRARY_PATH=/usr/local/cuda/lib64:${LD_LIBRARY_PATH}
vincentmr marked this conversation as resolved.
Show resolved Hide resolved

FROM base-build-cuda as build-kokkos-cuda
WORKDIR /opt/kokkos-${KOKKOS_VERSION}
# RUN wget --progress=dot:giga https://github.com/kokkos/kokkos/archive/refs/tags/${KOKKOS_VERSION}.tar.gz
# RUN tar -zxf ${KOKKOS_VERSION}.tar.gz && mv /opt/kokkos-${KOKKOS_VERSION}/kokkos-${KOKKOS_VERSION}/* /opt/kokkos-${KOKKOS_VERSION}
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
RUN git clone --branch fix-rtld-deepbind https://github.com/cz4rs/kokkos.git /opt/kokkos-${KOKKOS_VERSION}
vincentmr marked this conversation as resolved.
Show resolved Hide resolved
RUN cmake -S /opt/kokkos-${KOKKOS_VERSION} -B /opt/kokkos-${KOKKOS_VERSION}/build \
-G Ninja \
-DCMAKE_BUILD_TYPE=Release \
-DCMAKE_INSTALL_PREFIX=/opt/kokkos \
-DBUILD_SHARED_LIBS:BOOL=ON \
-DBUILD_TESTING:BOOL=OFF \
-DKokkos_ENABLE_SERIAL:BOOL=ON \
-DKokkos_ENABLE_OPENMP:BOOL=ON \
-DCMAKE_CXX_STANDARD=20 \
-DKokkos_ENABLE_EXAMPLES:BOOL=OFF \
-DKokkos_ENABLE_TESTS:BOOL=OFF \
-DKokkos_ENABLE_LIBDL:BOOL=OFF \
-DKokkos_ENABLE_CUDA:BOOL=ON \
-DKokkos_ARCH_AMPERE80=ON
RUN cmake --build /opt/kokkos-${KOKKOS_VERSION}/build
RUN cmake --install /opt/kokkos-${KOKKOS_VERSION}/build

FROM base-build-cuda AS build-wheel-lightning-kokkos-cuda
WORKDIR /opt/pennylane-lightning
COPY --from=build-kokkos-cuda /opt/kokkos /opt/kokkos
ENV CMAKE_PREFIX_PATH=/opt/kokkos:$CMAKE_PREFIX_PATH
RUN wget --progress=dot:giga https://github.com/PennyLaneAI/pennylane-lightning/archive/refs/tags/v${LIGHTNING_VERSION}.tar.gz
RUN tar -zxf v${LIGHTNING_VERSION}.tar.gz && mv pennylane-lightning-${LIGHTNING_VERSION}/* /opt/pennylane-lightning
RUN pip uninstall -y pennylane-lightning
RUN PL_BACKEND=lightning_kokkos python setup.py build_ext
RUN PL_BACKEND=lightning_kokkos python setup.py bdist_wheel

FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS wheel-lightning-kokkos-cuda
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libgomp1 \
python3 \
python3-pip \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
COPY --from=build-kokkos-cuda /opt/kokkos /opt/kokkos
COPY --from=build-wheel-lightning-kokkos-cuda /opt/pennylane-lightning/dist/ /
RUN pip install --force-reinstall --no-cache-dir PennyLane_Lightning*.whl

FROM base-build-cuda AS build-wheel-lightning-gpu
WORKDIR /opt/pennylane-lightning
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN wget --progress=dot:giga https://github.com/PennyLaneAI/pennylane-lightning-gpu/archive/refs/tags/v${LIGHTNING_VERSION}.tar.gz
RUN tar -zxf v${LIGHTNING_VERSION}.tar.gz && mv pennylane-lightning-gpu-${LIGHTNING_VERSION}/* /opt/pennylane-lightning
RUN pip uninstall -y pennylane-lightning-gpu
RUN pip install --no-cache-dir wheel custatevec-cu12
RUN --mount=type=bind,source=requirements.txt,target=requirements.txt \
pip install --no-cache-dir -r requirements.txt
RUN python setup.py build_ext --cuquantum=$(python -c "import site; print( f'{site.getsitepackages()[0]}/cuquantum/lib')")
RUN python setup.py bdist_wheel

FROM nvidia/cuda:12.2.0-runtime-ubuntu22.04 AS wheel-lightning-gpu
RUN apt-get update \
&& apt-get install --no-install-recommends -y \
libgomp1 \
python3 \
python3-pip \
python3-venv \
&& apt-get clean \
&& rm -rf /var/lib/apt/lists/*
ENV VIRTUAL_ENV=/opt/venv
RUN python3 -m venv $VIRTUAL_ENV
ENV PATH="$VIRTUAL_ENV/bin:$PATH"
RUN pip install --no-cache-dir custatevec-cu12
COPY --from=build-wheel-lightning-gpu /opt/pennylane-lightning/dist/ /
RUN pip install --no-cache-dir --force-reinstall PennyLane_Lightning*.whl
68 changes: 68 additions & 0 deletions docker/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
# PennyLane and the Lightning plugins

PennyLane is an open-source software framework for quantum machine learning, quantum chemistry, and quantum computing, with the ability to run on all hardware. Maintained with ❤️ by Xanadu.

## Documentation

For more information on PennyLane, including the demos, APIs and development guide, visit the [PennyLane documentation site](https://pennylane.ai/).
vincentmr marked this conversation as resolved.
Show resolved Hide resolved

## Download & install

Each image contains PennyLane and one of several high-performance plugins.
Choose a device (plugin) among:

- `lightning-gpu`: [pennylane-lightning-gpu](https://github.com/PennyLaneAI/pennylane-lightning-gpu) is a plugin based on the NVIDIA [cuQuantum SDK](https://developer.nvidia.com/cuquantum-sdk).
- `lightning-kokkos-cuda`: [pennylane-lightning-kokkos](https://github.com/PennyLaneAI/pennylane-lightning#lightning-kokkos-installation) parallelizes state-vector simulations using Kokkos' CUDA backend.
- `lightning-kokkos-openmp`: [pennylane-lightning-kokkos](https://github.com/PennyLaneAI/pennylane-lightning#lightning-kokkos-installation) parallelizes state-vector simulations using Kokkos' OpenMP backend.
- `lightning-qubit`: [pennylane-lightning](https://github.com/PennyLaneAI/pennylane-lightning) provides a fast state-vector simulator written in C++.

If you have Docker installed, download and spawn a container with `pennylane-lightning` as follows

```shell
docker run -v pwd:/io -it vincentmichaudrioux/pennylane:lightning-qubit bash
```

On certain systems, there may be other solutions supporting Docker containers.
For instance, NERSC computers (e.g. Perlmutter) have [Shifter](https://docs.nersc.gov/development/shifter/) bringing containers to HPC.
In this case, spawning a container is simple as

```shell
shifterimg pull vincentmichaudrioux/pennylane:lightning-qubit
shifter --image=vincentmichaudrioux/pennylane:lightning-qubit /bin/bash
```

where the first command downloads the image and the second spawns a container.

## Test

You can test PennyLane and the `lightning-qubit` plugin, for example, with

```shell
pip install pytest pytest-mock flaky
pl-device-test --device default.qubit
pl-device-test --device default.qubit --shots 10000
pl-device-test --device lightning.qubit
pl-device-test --device lightning.qubit --shots 10000
```

## Build

Decide on a target among:

- `wheel-lightning-gpu`: pennylane-lightning-gpu
- `wheel-lightning-kokkos`: pennylane-lightning-kokkos with Kokkos' OpenMP backend.
- `wheel-lightning-kokkos-cuda`: pennylane-lightning-kokkos with Kokkos' CUDA backend.
- `wheel-lightning-qubit`: pennylane-lightning

For instance `TARGET=wheel-lightning-qubit`.
Then the following command will build the target

```shell
docker build -f docker/Dockerfile --tag=${TARGET} --target ${TARGET} .
```

To start a container with a `bash` shell use

```shell
docker run -v `pwd`:/io -it ${TARGET} bash
```
2 changes: 1 addition & 1 deletion pennylane_lightning/core/_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@
Version number (major.minor.patch[-label])
"""

__version__ = "0.33.0-dev7"
__version__ = "0.33.0-dev8"