From 31643ba187adac38fb75be0654c5752e5c311135 Mon Sep 17 00:00:00 2001 From: Vincent Michaud-Rioux Date: Tue, 12 Sep 2023 14:08:53 -0400 Subject: [PATCH] Add make docker & dockerhub readme. --- Makefile | 11 +++++++++ docker/Dockerfile | 12 +++++----- docker/README.md | 61 +++++++++++++++++++++++++++++++++++++---------- 3 files changed, 65 insertions(+), 19 deletions(-) diff --git a/Makefile b/Makefile index 6461b935e3..a7d2a3c901 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/docker/Dockerfile b/docker/Dockerfile index 16d1ec4398..fbaa1b9fd9 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -75,7 +75,7 @@ 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 +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} @@ -94,9 +94,9 @@ RUN cmake -S /opt/kokkos-${KOKKOS_VERSION} -B /opt/kokkos-${KOKKOS_VERSION}/buil 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 +FROM base-build-python AS build-wheel-lightning-kokkos-openmp WORKDIR /opt/pennylane-lightning -COPY --from=build-kokkos /opt/kokkos /opt/kokkos +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 @@ -104,9 +104,9 @@ 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 base-runtime AS wheel-lightning-kokkos -COPY --from=build-kokkos /opt/kokkos /opt/kokkos -COPY --from=build-wheel-lightning-kokkos /opt/pennylane-lightning/dist/ / +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 FROM base-build-python as base-build-cuda diff --git a/docker/README.md b/docker/README.md index c5971da698..c8fe49d9f4 100644 --- a/docker/README.md +++ b/docker/README.md @@ -1,33 +1,68 @@ -# How-to +# PennyLane and the Lightning plugins -## Download +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. -```shell -docker run -v pwd:/io -it vincentmichaudrioux/pennylane bash -``` +## Documentation -## Build +For more information on PennyLane, including the demos, APIs and development guide, visit the [PennyLane documentation site](https://pennylane.ai/). + +## Download & install -### Lightning-Qubit +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 -TARGET=wheel-lightning-qubit -docker build -f docker/Dockerfile --tag=${TARGET} --target ${TARGET} . +docker run -v pwd:/io -it vincentmichaudrioux/pennylane:lightning-qubit bash ``` -## Run +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 -TARGET=wheel-lightning-qubit -docker run -v `pwd`:/io -it ${TARGET} bash +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 -``` \ No newline at end of file +``` + +## 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 +```