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

Remove CPhase + Tidy up src #717

Merged
merged 20 commits into from
May 10, 2024
Merged
Show file tree
Hide file tree
Changes from 6 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
8 changes: 7 additions & 1 deletion .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,24 @@

### Improvements

* Remove `CPhase` in favour of `CPhaseShift` in Lightning devices.
[(#717)](https://github.com/PennyLaneAI/pennylane-lightning/pull/717)

* Update Linux wheels to use manylinux_2_28 images.
[(#667)](https://github.com/PennyLaneAI/pennylane-lightning/pull/667)

### Documentation

* Add the release notes to docs.
[(#717)](https://github.com/PennyLaneAI/pennylane-lightning/pull/717)

### Bug fixes

### Contributors

This release contains contributions from (in alphabetical order):

Amintor Dusko
Ali Asadi, Amintor Dusko

---

Expand Down
34 changes: 23 additions & 11 deletions .github/workflows/dev_version_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,16 @@
# See the License for the specific language governing permissions and
# limitations under the License.

import re
import argparse
import re
from pathlib import Path

try:
from semver import Version
except ImportError as exc:
raise ImportError("Unable to import semver. Install semver by running `pip install semver`") from exc
raise ImportError(
"Unable to import semver. Install semver by running `pip install semver`"
) from exc

DEV_PRERELEASE_TAG_PREFIX = "dev"
DEV_PRERELEASE_TAG_START = "dev0"
Expand All @@ -45,10 +47,14 @@ def extract_version(repo_root_path: Path) -> Version:
if line.startswith("__version__"):
if (m := rgx_ver.match(line.strip())) is not None:
if not m.groups():
raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'")
raise ValueError(
f"Unable to find valid semver for __version__. Got: '{line}'"
)
parsed_semver = m.group(1)
if not Version.is_valid(parsed_semver):
raise ValueError(f"Invalid semver for __version__. Got: '{parsed_semver}' from line '{line}'")
raise ValueError(
f"Invalid semver for __version__. Got: '{parsed_semver}' from line '{line}'"
)
return Version.parse(parsed_semver)
raise ValueError(f"Unable to find valid semver for __version__. Got: '{line}'")
raise ValueError("Cannot parse version")
Expand All @@ -67,10 +73,7 @@ def update_prerelease_version(repo_root_path: Path, version: Version):
raise FileNotFoundError(f"Unable to find version file at location {version_file_path}")

with version_file_path.open() as f:
lines = [
rgx_ver.sub(f"__version__ = \"{str(version)}\"", line)
for line in f
]
lines = [rgx_ver.sub(f'__version__ = "{str(version)}"', line) for line in f]

with version_file_path.open("w") as f:
f.write("".join(lines))
Expand Down Expand Up @@ -98,8 +101,14 @@ def update_prerelease_version(repo_root_path: Path, version: Version):
# If a PR is of a higher version AND the prerelease tag is reset, then do nothing
# This captures the case during release where we might bump the release version
# within a PR and reset tag back to dev0
if pr_version > master_version and pr_version.prerelease and pr_version.prerelease == DEV_PRERELEASE_TAG_START:
print("This Pull Request is upgrading the package version to next release ... skipping bumping!")
if (
pr_version > master_version
and pr_version.prerelease
and pr_version.prerelease == DEV_PRERELEASE_TAG_START
):
print(
"This Pull Request is upgrading the package version to next release ... skipping bumping!"
)
print("If this is happening in error, please report it to the PennyLane team!")
elif pr_version.prerelease and pr_version.prerelease.startswith(DEV_PRERELEASE_TAG_PREFIX):
# If master branch does not have a prerelease (for any reason) OR does not have an ending number
Expand All @@ -109,7 +118,10 @@ def update_prerelease_version(repo_root_path: Path, version: Version):
else:
# If master branch does not have a prerelease (for any reason) OR does not have an ending number
# Then default to the starting tag
if not master_version.prerelease or master_version.prerelease == DEV_PRERELEASE_TAG_PREFIX:
if (
not master_version.prerelease
or master_version.prerelease == DEV_PRERELEASE_TAG_PREFIX
):
next_prerelease_version = DEV_PRERELEASE_TAG_START
else:
# Generate the next prerelease version (eg: dev1 -> dev2). Sourcing from master version.
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/vb_script.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
# See the License for the specific language governing permissions and
# limitations under the License.
import argparse

import pennylane as qml

pl_version = '"' + qml.version() + '"'
Expand Down
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,8 @@ test-builtin:
PL_DEVICE=$(if $(device:-=),$(device),lightning.qubit) $(PYTHON) -I $(TESTRUNNER)

test-suite:
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --skip-ops --shots=20000
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --shots=None --skip-ops
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --skip-ops --shots=20000 -n auto
pl-device-test --device $(if $(device:-=),$(device),lightning.qubit) --shots=None --skip-ops -n auto
maliasadi marked this conversation as resolved.
Show resolved Hide resolved

test-cpp:
rm -rf ./BuildTests
Expand Down
2 changes: 1 addition & 1 deletion doc/docker.rst → doc/dev/docker.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. include:: ../README.rst
.. include:: ../../README.rst
:start-after: docker-start-inclusion-marker-do-not-remove
:end-before: docker-end-inclusion-marker-do-not-remove
12 changes: 6 additions & 6 deletions doc/installation.rst → doc/dev/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,17 @@ Each device in the Lightning ecosystem is a separate Python package. Select the
.. title-card::
:name: Lightning Qubit
:description: Guidelines to installing and testing the Lightning Qubit device.
:link: ./lightning_qubit/installation.html
:link: ../lightning_qubit/installation.html

.. title-card::
:name: Lightning GPU
:description: Guidelines to installing and testing the Lightning GPU device
:link: ./lightning_gpu/installation.html
:link: ../lightning_gpu/installation.html

.. title-card::
:name: Lightning Kokkos
:description: Guidelines to installing and testing the Lightning Kokkos device
:link: ./lightning_kokkos/installation.html
:link: ../lightning_kokkos/installation.html

.. raw:: html

Expand All @@ -26,6 +26,6 @@ Each device in the Lightning ecosystem is a separate Python package. Select the
.. toctree::
:hidden:

lightning_qubit/installation
lightning_gpu/installation
lightning_kokkos/installation
../lightning_qubit/installation
../lightning_gpu/installation
../lightning_kokkos/installation
6 changes: 6 additions & 0 deletions doc/dev/release_notes.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Release notes
-------------

This page contains the release notes for PennyLane Lightning.

.. mdinclude:: ../../.github/CHANGELOG.md
2 changes: 1 addition & 1 deletion doc/support.rst → doc/dev/support.rst
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
.. include:: ../README.rst
.. include:: ../../README.rst
:start-after: support-start-inclusion-marker-do-not-remove
:end-before: support-end-inclusion-marker-do-not-remove
7 changes: 4 additions & 3 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,10 @@ The Lightning ecosystem provides the following devices:
:titlesonly:
:hidden:

installation
docker
support
dev/installation
dev/release_notes
dev/docker
dev/support

.. toctree::
:maxdepth: 2
Expand Down
1 change: 0 additions & 1 deletion doc/lightning_gpu/device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@ Supported operations and observables
~pennylane.CNOT
~pennylane.ControlledPhaseShift
~pennylane.ControlledQubitUnitary
~pennylane.CPhase
~pennylane.CRot
~pennylane.CRX
~pennylane.CRY
Expand Down
1 change: 0 additions & 1 deletion doc/lightning_kokkos/device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ Supported operations and observables
~pennylane.CNOT
~pennylane.ControlledPhaseShift
~pennylane.ControlledQubitUnitary
~pennylane.CPhase
~pennylane.CRot
~pennylane.CRX
~pennylane.CRY
Expand Down
1 change: 0 additions & 1 deletion doc/lightning_qubit/device.rst
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ Supported operations and observables
~pennylane.CNOT
~pennylane.ControlledPhaseShift
~pennylane.ControlledQubitUnitary
~pennylane.CPhase
~pennylane.CRot
~pennylane.CRX
~pennylane.CRY
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.37.0-dev1"
__version__ = "0.37.0-dev2"
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
/**
* @file
* Defines a class for the measurement of observables in quantum states
* represented by a Lightning Qubit StateVector class.
* represented by a Lightning GPU StateVector class.
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
*/

#pragma once
Expand Down
58 changes: 30 additions & 28 deletions pennylane_lightning/core/src/utils/NDPermuter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,14 @@ namespace Pennylane::Util {
* reference directly.
*
* Example 1:
* const std::vector<size_t> data_in {0,1,2,3,4,5};
* std::vector<size_t> data_out(data_in.size(), 0);
* Permuter<DefaultPermuter<size_t>> p;
* const std::vector<std::size_t> data_in {0,1,2,3,4,5};
* std::vector<std::size_t> data_out(data_in.size(), 0);
* Permuter<DefaultPermuter<std::size_t>> p;
* p.Transpose(data_in, {2,3}, data_out, {"a","b"}, {"b","a"});
*
* Example 2:
* const std::vector<size_t> data_in {0,1,2,3,4,5};
* Permuter<DefaultPermuter<size_t>> p;
* const std::vector<std::size_t> data_in {0,1,2,3,4,5};
* Permuter<DefaultPermuter<std::size_t>> p;
* auto data_out = p.Transpose(data_in, {2,3}, {"a","b"}, {"b","a"});
*
* @tparam PermuteBackend
Expand All @@ -68,7 +68,8 @@ template <class PermuterBackend> class Permuter {
*/
template <class T>
void Transpose(const std::vector<T> &data_in,
const std::vector<size_t> &shape, std::vector<T> &data_out,
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
const std::vector<std::size_t> &shape,
std::vector<T> &data_out,
const std::vector<std::string> &current_order,
const std::vector<std::string> &new_order) {
const std::set<std::string> idx_old(current_order.begin(),
Expand Down Expand Up @@ -110,7 +111,7 @@ template <class PermuterBackend> class Permuter {
*/
template <class T>
std::vector<T> Transpose(const std::vector<T> &data_in,
const std::vector<size_t> &shape,
const std::vector<std::size_t> &shape,
const std::vector<std::string> &current_order,
const std::vector<std::string> &new_order) {
const std::set<std::string> idx_old(current_order.begin(),
Expand Down Expand Up @@ -157,18 +158,19 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
* details.
*/
template <class T>
void Transpose(const std::vector<T> &data_,
const std::vector<size_t> &shape, std::vector<T> &data_out,
void Transpose(const std::vector<T> &data_in,
const std::vector<std::size_t> &shape,
std::vector<T> &data_out,
const std::vector<std::string> &old_indices,
const std::vector<std::string> &new_indices) {
data_out = data_;
data_out = data_in;

if (new_indices == old_indices) {
return;
}

const std::size_t num_indices = old_indices.size();
const std::size_t total_dim = data_.size();
const std::size_t total_dim = data_in.size();
std::size_t remaining_data = total_dim;

if (num_indices == 0) {
Expand All @@ -177,10 +179,10 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {

// Create map_old_to_new_idxpos from old to new indices, and
// new_dimensions.
std::vector<size_t> map_old_to_new_idxpos(num_indices);
std::vector<size_t> new_dimensions(num_indices);
for (size_t i = 0; i < num_indices; ++i) {
for (size_t j = 0; j < num_indices; ++j) {
std::vector<std::size_t> map_old_to_new_idxpos(num_indices);
std::vector<std::size_t> new_dimensions(num_indices);
for (std::size_t i = 0; i < num_indices; ++i) {
for (std::size_t j = 0; j < num_indices; ++j) {
if (old_indices[i] == new_indices[j]) {
map_old_to_new_idxpos[i] = j;
new_dimensions[j] = shape[i];
Expand All @@ -189,11 +191,11 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
}
}

std::vector<size_t> old_super_dimensions(num_indices, 1);
std::vector<size_t> new_super_dimensions(num_indices, 1);
std::vector<std::size_t> old_super_dimensions(num_indices, 1);
std::vector<std::size_t> new_super_dimensions(num_indices, 1);

const std::size_t old_dimensions_size = shape.size();
for (size_t i = old_dimensions_size; --i;) {
for (std::size_t i = old_dimensions_size; --i;) {
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
old_super_dimensions[i - 1] = old_super_dimensions[i] * shape[i];
new_super_dimensions[i - 1] =
new_super_dimensions[i] * new_dimensions[i];
Expand All @@ -206,7 +208,7 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
std::size_t pn = 0;
// Counter of the values of each indices in the iteration (old
// ordering).
std::vector<size_t> old_counter(num_indices, 0);
std::vector<std::size_t> old_counter(num_indices, 0);
// offset is important when doing this in blocks, as it's indeed
// implemented.
std::size_t offset = 0;
Expand All @@ -216,8 +218,8 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {

T *data = data_out.data();
const T *scratch =
data_.data(); // internal pointer offers better performance than
// pointer from argument
data_in.data(); // internal pointer offers better performance than
// pointer from argument

std::size_t effective_max;

Expand All @@ -233,7 +235,7 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
while (true) {
po = 0;
pn = 0;
for (size_t i = 0; i < num_indices; i++) {
for (std::size_t i = 0; i < num_indices; i++) {
po += old_super_dimensions[i] * old_counter[i];
pn += new_super_dimensions[map_old_to_new_idxpos[i]] *
old_counter[i];
Expand All @@ -242,7 +244,7 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {

bool complete{true};
// NOLINTBEGIN
for (size_t j = num_indices; j--;) {
for (std::size_t j = num_indices; j--;) {
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
if (++old_counter[j] < shape[j]) {
complete = false;
break;
Expand All @@ -264,7 +266,7 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
// Copy data for this block, taking into account offset of
// small_map...
effective_max = std::min(blocksize_, remaining_data);
for (size_t p = 0; p < effective_max; p++) {
for (std::size_t p = 0; p < effective_max; p++) {
data[small_map_old_to_new_position[p]] = scratch[offset + p];
}

Expand All @@ -278,12 +280,12 @@ template <size_t BLOCKSIZE = 1024> class DefaultPermuter {
* details.
*/
template <class T>
std::vector<T> Transpose(std::vector<T> data_,
const std::vector<size_t> &shape,
std::vector<T> Transpose(std::vector<T> data_in,
const std::vector<std::size_t> &shape,
const std::vector<std::string> &old_indices,
const std::vector<std::string> &new_indices) {
std::vector<T> data_out(std::move(data_));
Transpose(data_, shape, data_out, old_indices, new_indices);
std::vector<T> data_out(std::move(data_in));
Transpose(data_in, shape, data_out, old_indices, new_indices);
return data_out;
}

Expand Down
3 changes: 2 additions & 1 deletion pennylane_lightning/core/src/utils/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,5 +19,6 @@

#ifndef CONFIG_H
#define CONFIG_H
#define SCIPY_LIBS_PATH ""
#define SCIPY_LIBS_PATH \
"/home/ali/miniforge3/envs/cat/lib/python3.11/site-packages/scipy.libs"
#endif
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

// Copyright 2018-2023 Xanadu Quantum Technologies Inc.
// Copyright 2024 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 Down
Loading
Loading