Skip to content

Commit

Permalink
Merge branch 'master' into testing/gpu
Browse files Browse the repository at this point in the history
  • Loading branch information
vincentmr authored Sep 21, 2023
2 parents 1d76edd + 460aa5e commit 20dea67
Show file tree
Hide file tree
Showing 18 changed files with 116 additions and 71 deletions.
15 changes: 12 additions & 3 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,26 @@
* Add `tests_gpu.yml` workflow to test the Lightning-Kokkos backend with CUDA-12.
[(#494)](https://github.com/PennyLaneAI/pennylane-lightning/pull/494)

* Introduce `timeout-minutes` in various workflows, mainly to avoid Windows builds hanging for several hours.
[(#503)](https://github.com/PennyLaneAI/pennylane-lightning/pull/503)

* Cast integral-valued arrays to the device's complex type on entry in `_preprocess_state_vector` to ensure the state is correctly represented with floating-point numbers.
[(#501)](https://github.com/PennyLaneAI/pennylane-lightning/pull/501)

* Update DefaultQubit to DefaultQubitLegacy on Lightning fallback.
[(#500)](https://github.com/PennyLaneAI/pennylane-lightning/pull/500)

* Enums defined in `GateOperation.hpp` start at `1` (previously `0`). `::BEGIN` is introduced in a few places where it was assumed `0` accordingly.
[(#485)](https://github.com/PennyLaneAI/pennylane-lightning/pull/485)

* Enable pre-commit hooks to format all Python files and linting of all Python source files.
[(#485)](https://github.com/PennyLaneAI/pennylane-lightning/pull/485)

* Update DefaultQubit to DefaultQubitLegacy on Lightning fallback.
[(#500)](https://github.com/PennyLaneAI/pennylane-lightning/pull/500)

### Improvements

* Update setup.py to allow for multi-package co-existence. The PennyLane_Lightning package now is the responsible for the core functionality, and will be depended upon by all other extensions.
[(#504)] (https://github.com/PennyLaneAI/pennylane-lightning/pull/504)

* Refactor LKokkos `StateVectorKokkos` class to use Kokkos `RangePolicy` together with special functors in `applyMultiQubitOp` to apply 1- to 4-wire generic unitary gates. For more than 4 wires, the general implementation using Kokkos `TeamPolicy` is employed to yield the best all-around performance.
[(#490)] (https://github.com/PennyLaneAI/pennylane-lightning/pull/490)

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/build_and_cache_Kokkos_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
matrix:
exec_model: ${{ fromJson(needs.linux-set-builder-matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.linux-set-builder-matrix.outputs.kokkos_version) }}

timeout-minutes: 30
name: Kokkos core (${{ matrix.exec_model }})
runs-on: ${{ inputs.os }}

Expand Down
16 changes: 8 additions & 8 deletions .github/workflows/tests_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_qubit"]

timeout-minutes: 30
name: C++ tests
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -77,7 +77,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_qubit"]

timeout-minutes: 30
name: Python tests
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -133,7 +133,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_qubit"]

timeout-minutes: 30
name: C++ tests (OpenBLAS)
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -189,7 +189,7 @@ jobs:
matrix:
os: [ubuntu-22.04]
pl_backend: ["lightning_qubit"]

timeout-minutes: 30
name: Python tests with OpenBLAS
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -240,7 +240,7 @@ jobs:
name: ubuntu-codecov-results-python
path: ./main/coverage-${{ github.job }}-${{ matrix.pl_backend }}.xml

build_and_cache_Kokkos:
build_and_cache_Kokkos:
name: "Build and cache Kokkos"
uses: ./.github/workflows/build_and_cache_Kokkos_linux.yml
with:
Expand All @@ -254,7 +254,7 @@ jobs:
pl_backend: ["lightning_kokkos"]
exec_model: ${{ fromJson(needs.build_and_cache_Kokkos.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.build_and_cache_Kokkos.outputs.kokkos_version) }}

timeout-minutes: 30
name: C++ tests (Kokkos)
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -329,7 +329,7 @@ jobs:
exclude:
- pl_backend: ["all"]
exec_model: OPENMP

timeout-minutes: 30
name: Python tests with Kokkos
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -465,7 +465,7 @@ jobs:
os: [ubuntu-22.04]
exec_model: ${{ fromJson(needs.build_and_cache_Kokkos.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.build_and_cache_Kokkos.outputs.kokkos_version) }}

timeout-minutes: 30
name: C++ tests (multiple backends)
runs-on: ${{ matrix.os }}

Expand Down
6 changes: 4 additions & 2 deletions .github/workflows/tests_windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ concurrency:

jobs:
cpptests:
timeout-minutes: 30
name: C++ tests (Windows)
runs-on: ${{ matrix.os }}
strategy:
Expand Down Expand Up @@ -98,7 +99,7 @@ jobs:
os: [windows-latest]
exec_model: ${{ fromJson(needs.win-set-matrix-x86.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.win-set-matrix-x86.outputs.kokkos_version) }}

timeout-minutes: 30
name: Kokkos core (${{ matrix.exec_model }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -152,6 +153,7 @@ jobs:
exec_model: ${{ fromJson(needs.win-set-matrix-x86.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.win-set-matrix-x86.outputs.kokkos_version) }}

timeout-minutes: 30
name: C++ tests (Windows, Kokkos)
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -226,7 +228,7 @@ jobs:
path: .\coverage-${{ github.job }}-${{ matrix.pl_backend }}.xml

upload-to-codecov-windows:
needs: [cpptests, cpptestswithKokkos]
needs: [cpptests, cpptestswithkokkos]
name: Upload coverage data to codecov
runs-on: ubuntu-latest
steps:
Expand Down
15 changes: 8 additions & 7 deletions .github/workflows/tests_without_binary.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ concurrency:

jobs:
pythontests:
timeout-minutes: 30
name: Python tests
runs-on: ${{ matrix.os }}
strategy:
Expand All @@ -37,20 +38,20 @@ jobs:
cd main
python -m pip install -r requirements-dev.txt
- name: Install lightning.qubit device
- name: Install the pennylane_lightning package
if: ${{ matrix.pl_backend == 'lightning_kokkos'}}
run: |
cd main
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv
- name: Install backend device
env:
SKIP_COMPILATION: True
PL_BACKEND: ${{ matrix.pl_backend }}
run: |
cd main
python -m pip install -e . -vv
- name: Install the new pennylane_lightning package
if: ${{ matrix.pl_backend == 'lightning_kokkos'}}
run: |
cd main
SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv
- name: Run PennyLane-Lightning unit tests
run: |
cd main/
Expand Down
8 changes: 5 additions & 3 deletions .github/workflows/wheel_linux_aarch64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_aarch64"]

timeout-minutes: 45
name: Kokkos core (${{ matrix.exec_model }}::${{ matrix.arch }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_aarch64"]

timeout-minutes: 45
name: ${{ matrix.os }}::${{ matrix.arch }} - ${{ matrix.pl_backend }} (Python ${{ fromJson('{ "cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -141,7 +141,9 @@ jobs:

CIBW_TEST_REQUIRES: pytest pytest-cov pytest-mock flaky

CIBW_BEFORE_TEST: if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
CIBW_BEFORE_TEST: |
python -m pip install git+https://github.com/PennyLaneAI/pennylane.git@master
if ${{ matrix.pl_backend == 'lightning_kokkos'}}; then SKIP_COMPILATION=True PL_BACKEND="lightning_qubit" pip install -e . -vv; fi
CIBW_TEST_COMMAND: |
DEVICENAME=`echo ${{ matrix.pl_backend }} | sed "s/_/./g"`
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel_linux_ppc64le.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_ppc64le"]

timeout-minutes: 45
name: Kokkos core (${{ matrix.exec_model }}::${{ matrix.arch }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -91,7 +91,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_ppc64le"]

timeout-minutes: 45
name: ${{ matrix.os }}::${{ matrix.arch }} - ${{ matrix.pl_backend }} (Python ${{ fromJson('{"cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel_linux_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_x86_64"]

timeout-minutes: 30
name: Kokkos core (${{ matrix.exec_model }})
runs-on: ${{ matrix.os }}
container: ${{ matrix.container_img }}
Expand Down Expand Up @@ -96,7 +96,7 @@ jobs:
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}
container_img: ["quay.io/pypa/manylinux2014_x86_64"]

timeout-minutes: 30
name: ${{ matrix.os }}::${{ matrix.arch }} - ${{ matrix.pl_backend }} (Python ${{ fromJson('{ "cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}
container: ${{ matrix.container_img }}
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ concurrency:

jobs:
mac-set-matrix-arm:
timeout-minutes: 30
name: Set builder matrix
runs-on: ubuntu-latest

Expand Down Expand Up @@ -56,7 +57,7 @@ jobs:
arch: [arm64]
pl_backend: ["lightning_kokkos", "lightning_qubit"]
cibw_build: ${{fromJson(needs.mac-set-matrix-arm.outputs.python_version)}}

timeout-minutes: 30
name: macos-latest::arm64 - ${{ matrix.pl_backend }} (Python ${{ fromJson('{ "cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}

Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/wheel_macos_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ concurrency:
cancel-in-progress: true

jobs:
set_wheel_build_matrix:
set_wheel_build_matrix:
name: "Set wheel build matrix"
uses: ./.github/workflows/set_wheel_build_matrix.yml
with:
Expand All @@ -35,7 +35,7 @@ jobs:
arch: [x86_64]
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}

timeout-minutes: 30
name: Kokkos (${{ matrix.exec_model }}::${{ matrix.arch }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -94,7 +94,7 @@ jobs:
cibw_build: ${{fromJson(needs.set_wheel_build_matrix.outputs.python_version)}}
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}

timeout-minutes: 30
name: ${{ matrix.os }} - ${{ matrix.pl_backend }} (Python ${{ fromJson('{ "cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/wheel_noarch.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
matrix:
os: [ubuntu-latest]
pl_backend: ["lightning_kokkos", "lightning_qubit"]

timeout-minutes: 30
name: ${{ matrix.os }} - Pure Python wheels - ${{ matrix.pl_backend }} (Python 3.9)
runs-on: ${{ matrix.os }}

Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/wheel_win_x86_64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ jobs:
os: [windows-2022]
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}

timeout-minutes: 30
name: Kokkos core (${{ matrix.exec_model }})
runs-on: ${{ matrix.os }}

Expand Down Expand Up @@ -92,7 +92,7 @@ jobs:
cibw_build: ${{ fromJson(needs.set_wheel_build_matrix.outputs.python_version) }}
exec_model: ${{ fromJson(needs.set_wheel_build_matrix.outputs.exec_model) }}
kokkos_version: ${{ fromJson(needs.set_wheel_build_matrix.outputs.kokkos_version) }}

timeout-minutes: 30
name: ${{ matrix.os }} - ${{ matrix.pl_backend }} (Python ${{ fromJson('{ "cp39-*":"3.9","cp310-*":"3.10","cp311-*":"3.11" }')[matrix.cibw_build] }})
runs-on: ${{ matrix.os }}

Expand Down
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-dev9"
__version__ = "0.33.0-dev13"
4 changes: 4 additions & 0 deletions pennylane_lightning/core/lightning_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,7 @@ def accepts_obj(obj):

return qml.BooleanFn(accepts_obj)

# pylint: disable=missing-function-docstring
@classmethod
def capabilities(cls):
capabilities = super().capabilities().copy()
Expand Down Expand Up @@ -206,6 +207,9 @@ def _preprocess_state_vector(self, state, device_wires):
# translate to wire labels used by device
device_wires = self.map_wires(device_wires)

# special case for integral types
if state.dtype.kind == "i":
state = qml.numpy.array(state, dtype=self.C_DTYPE)
state = self._asarray(state, dtype=self.C_DTYPE)

if len(device_wires) == self.num_wires and Wires(sorted(device_wires)) == device_wires:
Expand Down
8 changes: 6 additions & 2 deletions pennylane_lightning/lightning_qubit/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,7 @@ def __init__(
self._state = self._create_basis_state(0)
self._pre_rotated_state = self._state

self._batch_obs = batch_obs
self._mcmc = mcmc
if self._mcmc:
if kernel_name not in [
Expand Down Expand Up @@ -281,7 +282,7 @@ def measurements(self):

@property
def state(self):
# Flattening the state.
"""Returns the flattened state vector."""
shape = (1 << self.num_wires,)
return self._reshape(self._pre_rotated_state, shape)

Expand Down Expand Up @@ -368,7 +369,9 @@ def apply_lightning(self, state, operations):

return np.reshape(state_vector, state.shape)

# pylint: disable=unused-argument
def apply(self, operations, rotations=None, **kwargs):
"""Applies operations to the state vector."""
# State preparation is currently done in Python
if operations: # make sure operations[0] exists
if isinstance(operations[0], StatePrep):
Expand Down Expand Up @@ -629,6 +632,7 @@ def _init_process_jacobian_tape(self, tape, starting_state, use_device_state):
return StateVectorC64(ket) if self.use_csingle else StateVectorC128(ket)

def adjoint_jacobian(self, tape, starting_state=None, use_device_state=False):
"""Computes and returns the Jacobian with the adjoint method."""
if self.shots is not None:
warn(
"Requested adjoint differentiation to be computed with finite shots. "
Expand Down Expand Up @@ -812,7 +816,7 @@ def processing_fn_state(tape):
else:

class LightningQubit(LightningBaseFallBack): # pragma: no cover
# pylint: disable=missing-class-docstring
# pylint: disable=missing-class-docstring, too-few-public-methods
name = "Lightning qubit PennyLane plugin [No binaries found - Fallback: default.qubit]"
short_name = "lightning.qubit"

Expand Down
Loading

0 comments on commit 20dea67

Please sign in to comment.