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

Add Docker support #234

Merged
merged 12 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
12 changes: 9 additions & 3 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,28 @@

### New features since last release

* Add Docker support.
[(#234)](https://github.com/PennyLaneAI/pennylane-lightning/pull/234)

### Breaking changes

### Improvements

* Update adjointJacobian and VJP methods.
[(#222)](https://github.com/PennyLaneAI/pennylane-lightning/pull/222)

* 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)

* Finalize the new kernel implementation [(#212)](https://github.com/PennyLaneAI/pennylane-lightning/pull/212).
* Finalize the new kernel implementation.
[(#212)](https://github.com/PennyLaneAI/pennylane-lightning/pull/212)

### 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

Expand Down
14 changes: 13 additions & 1 deletion README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ and install the compilied library with

$ python3 setup.py develop


Testing
-------

Expand Down Expand Up @@ -134,7 +135,6 @@ Other supported options are ``-DENABLE_WARNINGS=ON``,
``-DENABLE_CLANG_TIDY=ON``.



Compile on Windows with MSVC
----------------------------

Expand Down Expand Up @@ -166,6 +166,18 @@ Please refer to the `plugin documentation <https://pennylane-lightning.readthedo
well as to the `PennyLane documentation <https://pennylane.readthedocs.io/>`_ 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 -f docker/Dockerfile .

Please refer to the `PennyLane installation <https://pennylane.readthedocs.io/en/stable/development/guide/installation.html#installation>`_ for detailed description about PennyLane Docker support.


Contributing
============
Expand Down
11 changes: 9 additions & 2 deletions cmake/process_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ if(ENABLE_WARNINGS)
else()
target_compile_options(lightning_compile_options INTERFACE $<$<COMPILE_LANGUAGE:CXX>:-Wall;-Wextra;-Werror>)
endif()
else()
message(STATUS "ENABLE_WARNINGS is OFF")
endif()

if(ENABLE_NATIVE)
Expand All @@ -56,10 +58,12 @@ 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)
message(STATUS "ENABLE_OPENMP is ON. Using OpenMP.")
message(STATUS "ENABLE_OPENMP is ON.")
find_package(OpenMP)

if(NOT OpenMP_CXX_FOUND)
Expand All @@ -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)
Expand All @@ -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()
56 changes: 56 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# 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.
# 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:focal AS base

# Setup and install basic packages
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 \
ca-certificates \
ccache \
cmake \
curl \
git \
python3 \
python3-pip \
python3-venv \
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 \
&& python3 -m venv /opt/venv

ENV PATH="/opt/venv/bin:$PATH"

# Setup and build pennylane-lightning
WORKDIR /opt/pennylane-lightning

COPY . .

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 \
&& make test-python \
&& make test-cpp
2 changes: 1 addition & 1 deletion pennylane_lightning/_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.22.0-dev5"
__version__ = "0.22.0-dev6"
6 changes: 2 additions & 4 deletions pennylane_lightning/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))

Expand Down Expand Up @@ -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))

Expand Down
4 changes: 0 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,13 @@
# limitations under the License.
import os
import platform
import setuptools
import sys
import subprocess
import shutil
from pathlib import Path
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=[])
Expand Down