From 829672c3525c53b7859457988eb408f3c86099e7 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Fri, 11 Feb 2022 16:49:36 -0500 Subject: [PATCH 1/9] Add Dockerfile --- Dockerfile | 50 +++++++++++++++++++++++++++++++++++++ cmake/process_options.cmake | 9 ++++++- setup.py | 4 --- 3 files changed, 58 insertions(+), 5 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000000..f1181119a6 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,50 @@ +# Copyright 2018-2022 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. +# You may obtain a copy of the License at + +# http://www.apache.org/licenses/LICENSE-2.0 + +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +FROM ubuntu:latest AS base + +#Setup and install basic packages +RUN apt-get update \ + && apt-get install -y apt-utils --no-install-recommends + +RUN DEBIAN_FRONTEND="noninteractive" \ + apt-get install -y tzdata \ + build-essential \ + ca-certificates \ + ccache \ + cmake \ + curl \ + git \ + python3 \ + python3-pip \ + python3-venv \ + libjpeg-dev \ + libpng-dev && \ + rm -rf /var/lib/apt/lists/* \ + && /usr/sbin/update-ccache-symlinks \ + && mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache \ + && python3 -m venv /opt/venv + +ENV PATH="/opt/venv/bin:$PATH" + +#Setup and build pennylane-lightning +WORKDIR /opt/pennylane-lightning +COPY . . +RUN pip install wheel \ + && pip install -r requirements.txt \ + && pip install pytest pytest-cov pytest-mock flaky \ + && pip uninstall -y PennyLane_Lightning \ + && make install \ + && make test-python \ + && make test-cpp diff --git a/cmake/process_options.cmake b/cmake/process_options.cmake index 7b8372118b..015267c819 100644 --- a/cmake/process_options.cmake +++ b/cmake/process_options.cmake @@ -46,6 +46,8 @@ if(ENABLE_WARNINGS) else() target_compile_options(lightning_compile_options INTERFACE $<$:-Wall;-Wextra;-Werror>) endif() +else() + message(STATUS "ENABLE_WARNINGS is OFF") endif() if(ENABLE_NATIVE) @@ -56,6 +58,8 @@ endif() if(ENABLE_AVX) message(STATUS "ENABLE_AVX is ON.") target_compile_options(lightning_compile_options INTERFACE -mavx) +else() + message(STATUS "ENABLE_AVX is OFF") endif() if(ENABLE_OPENMP) @@ -68,9 +72,10 @@ if(ENABLE_OPENMP) endif() target_link_libraries(lightning_external_libs INTERFACE OpenMP::OpenMP_CXX) +else() + message(STATUS "ENABLE_OPENMP is OFF") endif() - if(ENABLE_BLAS) message(STATUS "ENABLE_BLAS is ON. Find BLAS.") find_package(BLAS) @@ -88,4 +93,6 @@ if(ENABLE_BLAS) target_link_libraries(lightning_external_libs INTERFACE "${BLAS_LIBRARIES}") target_link_options(lightning_external_libs INTERFACE "${BLAS_LINKER_FLAGS}") target_compile_options(lightning_compile_options INTERFACE "-D_ENABLE_BLAS=1") +else() + message(STATUS "ENABLE_BLAS is OFF") endif() diff --git a/setup.py b/setup.py index 1318f56a7a..2193d2bfac 100644 --- a/setup.py +++ b/setup.py @@ -13,7 +13,6 @@ # limitations under the License. import os import platform -import setuptools import sys import subprocess import shutil @@ -21,9 +20,6 @@ from setuptools import setup, Extension, find_packages from setuptools.command.build_ext import build_ext -from distutils.util import get_platform - - class CMakeExtension(Extension): def __init__(self, name, sourcedir=""): Extension.__init__(self, name, sources=[]) From 56b54336aad60e4ef3d66acabb448d0fc3995aec Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Fri, 11 Feb 2022 17:30:34 -0500 Subject: [PATCH 2/9] Update Readme --- README.rst | 14 +++++++++++++- cmake/process_options.cmake | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 0a2239134a..7b28939553 100644 --- a/README.rst +++ b/README.rst @@ -93,6 +93,7 @@ and install the compilied library with $ python3 setup.py develop + Testing ------- @@ -134,7 +135,6 @@ Other supported options are ``-DENABLE_WARNINGS=ON``, ``-DENABLE_CLANG_TIDY=ON``. - Compile on Windows with MSVC ---------------------------- @@ -166,6 +166,18 @@ Please refer to the `plugin documentation `_ for further reference. +Docker Support +------------ +One can also build the Pennylane-Lightning image using Docker: + +.. code-block:: console + + $ git clone https://github.com/XanaduAI/pennylane-lightning.git + $ cd pennylane-lightning + $ docker build -t lightning/base . + +Please refer to the `PennyLane installation `_ for detailed description about PennyLane Docker support. + Contributing ============ diff --git a/cmake/process_options.cmake b/cmake/process_options.cmake index 015267c819..d3ecccd3f9 100644 --- a/cmake/process_options.cmake +++ b/cmake/process_options.cmake @@ -63,7 +63,7 @@ else() endif() if(ENABLE_OPENMP) - message(STATUS "ENABLE_OPENMP is ON. Using OpenMP.") + message(STATUS "ENABLE_OPENMP is ON.") find_package(OpenMP) if(NOT OpenMP_CXX_FOUND) From a2018fd1927e446b1d4ec47f63b30b11e60b3dd7 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Sat, 12 Feb 2022 02:07:41 +0000 Subject: [PATCH 3/9] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index b7247672af..6492811e4b 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.22.0-dev4" +__version__ = "0.22.0-dev5" From eb9e0644d2dcffb28f196cafad243f619ff32f30 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Fri, 11 Feb 2022 21:54:23 -0500 Subject: [PATCH 4/9] Update Dockerfile --- .github/CHANGELOG.md | 9 +++++++-- Dockerfile | 27 ++++++++++++++++----------- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 761dde00e7..44b1ec6fe2 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -2,17 +2,22 @@ ### New features since last release +* Add Docker support +[(#234)](https://github.com/PennyLaneAI/pennylane-lightning/pull/234). + ### Breaking changes ### Improvements -* Set GitHub workflow to upload wheels to Test PyPI [(#220)](https://github.com/PennyLaneAI/pennylane-lightning/pull/220). +* Set GitHub workflow to upload wheels to Test PyPI +[(#220)](https://github.com/PennyLaneAI/pennylane-lightning/pull/220). ### Documentation ### Bug fixes -* Refactor utility header and fix a bug in linear algebra function with CBLAS [(#228)](https://github.com/PennyLaneAI/pennylane-lightning/pull/228). +* Refactor utility header and fix a bug in linear algebra function with CBLAS +[(#228)](https://github.com/PennyLaneAI/pennylane-lightning/pull/228). ### Contributors diff --git a/Dockerfile b/Dockerfile index f1181119a6..c567fa2a3e 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,11 +14,10 @@ FROM ubuntu:latest AS base -#Setup and install basic packages -RUN apt-get update \ - && apt-get install -y apt-utils --no-install-recommends - -RUN DEBIAN_FRONTEND="noninteractive" \ +# Setup and install basic packages +RUN apt-get update \ + && apt-get install -y apt-utils --no-install-recommends \ + && DEBIAN_FRONTEND="noninteractive" \ apt-get install -y tzdata \ build-essential \ ca-certificates \ @@ -30,20 +29,26 @@ RUN DEBIAN_FRONTEND="noninteractive" \ python3-pip \ python3-venv \ libjpeg-dev \ - libpng-dev && \ - rm -rf /var/lib/apt/lists/* \ + libpng-dev \ + && apt-get clean \ + && rm -rf /var/lib/apt/lists/* \ && /usr/sbin/update-ccache-symlinks \ && mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache \ && python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" -#Setup and build pennylane-lightning +# Setup and build pennylane-lightning WORKDIR /opt/pennylane-lightning + COPY . . -RUN pip install wheel \ - && pip install -r requirements.txt \ - && pip install pytest pytest-cov pytest-mock flaky \ + +RUN pip install --no-cache-dir wheel \ + pytest \ + pytest-cov \ + pytest-mock \ + flaky \ + && pip install --no-cache-dir -r requirements.txt \ && pip uninstall -y PennyLane_Lightning \ && make install \ && make test-python \ From e2fe4f0cc47b8c8c69fe5ae54af5cee5b5018ac9 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Fri, 11 Feb 2022 22:33:28 -0500 Subject: [PATCH 5/9] Update --- .github/CHANGELOG.md | 12 ++++++------ Dockerfile | 16 ++++++++-------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/.github/CHANGELOG.md b/.github/CHANGELOG.md index 44b1ec6fe2..1d9fbe58e4 100644 --- a/.github/CHANGELOG.md +++ b/.github/CHANGELOG.md @@ -2,22 +2,22 @@ ### New features since last release -* Add Docker support -[(#234)](https://github.com/PennyLaneAI/pennylane-lightning/pull/234). +* Add Docker support. +[(#234)](https://github.com/PennyLaneAI/pennylane-lightning/pull/234) ### Breaking changes ### Improvements -* Set GitHub workflow to upload wheels to Test PyPI -[(#220)](https://github.com/PennyLaneAI/pennylane-lightning/pull/220). +* Set GitHub workflow to upload wheels to Test PyPI. +[(#220)](https://github.com/PennyLaneAI/pennylane-lightning/pull/220) ### Documentation ### Bug fixes -* Refactor utility header and fix a bug in linear algebra function with CBLAS -[(#228)](https://github.com/PennyLaneAI/pennylane-lightning/pull/228). +* Refactor utility header and fix a bug in linear algebra function with CBLAS. +[(#228)](https://github.com/PennyLaneAI/pennylane-lightning/pull/228) ### Contributors diff --git a/Dockerfile b/Dockerfile index c567fa2a3e..ed36e014b1 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,4 +1,4 @@ -# Copyright 2018-2022 Xanadu Quantum Technologies Inc. +# Copyright 2018-2021 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. @@ -12,13 +12,13 @@ # See the License for the specific language governing permissions and # limitations under the License. -FROM ubuntu:latest AS base +FROM ubuntu:focal AS base # Setup and install basic packages -RUN apt-get update \ - && apt-get install -y apt-utils --no-install-recommends \ +RUN apt-get update \ + && apt-get install --no-install-recommends -y apt-utils \ && DEBIAN_FRONTEND="noninteractive" \ - apt-get install -y tzdata \ + apt-get install --no-install-recommends -y tzdata \ build-essential \ ca-certificates \ ccache \ @@ -28,12 +28,12 @@ RUN apt-get update \ python3 \ python3-pip \ python3-venv \ - libjpeg-dev \ - libpng-dev \ + python3-dev \ && apt-get clean \ && rm -rf /var/lib/apt/lists/* \ && /usr/sbin/update-ccache-symlinks \ - && mkdir /opt/ccache && ccache --set-config=cache_dir=/opt/ccache \ + && mkdir /opt/ccache \ + && ccache --set-config=cache_dir=/opt/ccache \ && python3 -m venv /opt/venv ENV PATH="/opt/venv/bin:$PATH" From 89fd3246ff9ed9e98c1874546ece0b902cb295c0 Mon Sep 17 00:00:00 2001 From: Dev version update bot Date: Sun, 13 Feb 2022 20:00:27 +0000 Subject: [PATCH 6/9] Auto update version --- pennylane_lightning/_version.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pennylane_lightning/_version.py b/pennylane_lightning/_version.py index 6492811e4b..a4efa46ed4 100644 --- a/pennylane_lightning/_version.py +++ b/pennylane_lightning/_version.py @@ -16,4 +16,4 @@ Version number (major.minor.patch[-label]) """ -__version__ = "0.22.0-dev5" +__version__ = "0.22.0-dev6" From 485acc13cfe2406246b8549a250faf2b31827f0b Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Sun, 13 Feb 2022 15:04:59 -0500 Subject: [PATCH 7/9] Update --- pennylane_lightning/lightning_qubit.py | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/pennylane_lightning/lightning_qubit.py b/pennylane_lightning/lightning_qubit.py index 344870fd61..c056af4db4 100644 --- a/pennylane_lightning/lightning_qubit.py +++ b/pennylane_lightning/lightning_qubit.py @@ -550,12 +550,11 @@ def expval(self, observable, shot_range=None, bin_size=None): "Hamiltonian", "SparseHamiltonian", ]: - # TODO: requires backend support return super().expval(observable, shot_range=shot_range, bin_size=bin_size) if self.shots is not None: # estimate the expectation value - # TODO: Lightning support for sampling + # LightningQubit doesn't support sampling yet samples = self.sample(observable, shot_range=shot_range, bin_size=bin_size) return np.squeeze(np.mean(samples, axis=0)) @@ -601,12 +600,11 @@ def var(self, observable, shot_range=None, bin_size=None): "Projector", "Hermitian", ]: - # TODO: requires backend support return super().var(observable, shot_range=shot_range, bin_size=bin_size) if self.shots is not None: # estimate the var - # TODO: Lightning support for sampling + # LightningQubit doesn't support sampling yet samples = self.sample(observable, shot_range=shot_range, bin_size=bin_size) return np.squeeze(np.var(samples, axis=0)) From b3b7e61127e91054be368359fa34a5a23433dff9 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Tue, 15 Feb 2022 12:32:23 -0500 Subject: [PATCH 8/9] Update Dockerfile --- README.rst | 2 +- Dockerfile => docker/Dockerfile | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) rename Dockerfile => docker/Dockerfile (96%) diff --git a/README.rst b/README.rst index 7b28939553..e4a54cd04d 100644 --- a/README.rst +++ b/README.rst @@ -174,7 +174,7 @@ One can also build the Pennylane-Lightning image using Docker: $ git clone https://github.com/XanaduAI/pennylane-lightning.git $ cd pennylane-lightning - $ docker build -t lightning/base . + $ docker build -t lightning/base -f docker/Dockerfile . Please refer to the `PennyLane installation `_ for detailed description about PennyLane Docker support. diff --git a/Dockerfile b/docker/Dockerfile similarity index 96% rename from Dockerfile rename to docker/Dockerfile index ed36e014b1..dfb3136795 100644 --- a/Dockerfile +++ b/docker/Dockerfile @@ -43,11 +43,12 @@ WORKDIR /opt/pennylane-lightning COPY . . -RUN pip install --no-cache-dir wheel \ +RUN pip install --no-cache-dir wheel\ pytest \ pytest-cov \ pytest-mock \ flaky \ + sphinx \ && pip install --no-cache-dir -r requirements.txt \ && pip uninstall -y PennyLane_Lightning \ && make install \ From db35c2e1c39e1fa30b46e9bb8bc96f170e5fb292 Mon Sep 17 00:00:00 2001 From: Ali Asadi Date: Tue, 15 Feb 2022 12:33:47 -0500 Subject: [PATCH 9/9] Update --- docker/Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docker/Dockerfile b/docker/Dockerfile index dfb3136795..2e67eed946 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -43,7 +43,7 @@ WORKDIR /opt/pennylane-lightning COPY . . -RUN pip install --no-cache-dir wheel\ +RUN pip install --no-cache-dir wheel \ pytest \ pytest-cov \ pytest-mock \