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

Create release candidate v0.24.0 #304

Merged
merged 22 commits into from
Jun 20, 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
28 changes: 18 additions & 10 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Release 0.24.0-dev
# Release 0.24.0

### New features since last release

Expand All @@ -8,7 +8,10 @@
* Add a new dispatch mechanism for future kernels.
[(#291)](https://github.com/PennyLaneAI/pennylane-lightning/pull/291)

* Support qml.state() in vjp and Hamiltonian in adjoint jacobian.
* Add `IsingXY` gate operation.
[(#303)](https://github.com/PennyLaneAI/pennylane-lightning/pull/303)

* Support `qml.state()` in vjp and Hamiltonian in adjoint jacobian.
[(#294)](https://github.com/PennyLaneAI/pennylane-lightning/pull/294)

### Breaking changes
Expand All @@ -21,6 +24,14 @@

### Improvements

* Split matrix operations, refactor dispatch mechanisms, and add a benchmark suits.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

benchmark suite

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah! It's fixed in the release notes and will update CHANGELOG consequently. Thanks!

[(#274)](https://github.com/PennyLaneAI/pennylane-lightning/pull/274)

* Add native support for the calculation of sparse Hamiltonians' expectation values.
Sparse operations are offloaded to [Kokkos](https://github.com/kokkos/kokkos) and
[Kokkos-Kernels](https://github.com/kokkos/kokkos-kernels).
[(#283)](https://github.com/PennyLaneAI/pennylane-lightning/pull/283)

* Device `lightning.qubit` now accepts a datatype for a statevector.
[(#290)](https://github.com/PennyLaneAI/pennylane-lightning/pull/290)

Expand All @@ -29,12 +40,6 @@ dev1 = qml.device('lightning.qubit', wires=4, c_dtype=np.complex64) # for single
dev2 = qml.device('lightning.qubit', wires=4, c_dtype=np.complex128) # for double precision
```

* Split matrix operations, refactor dispatch mechanisms, and add a benchmark suits.
[(#274)](https://github.com/PennyLaneAI/pennylane-lightning/pull/274)

* Add native support for the calculation of sparse Hamiltonians' expectation values. Sparse operations are offloaded to [Kokkos](https://github.com/kokkos/kokkos) and [Kokkos-Kernels](https://github.com/kokkos/kokkos-kernels).
[(#283)](https://github.com/PennyLaneAI/pennylane-lightning/pull/283)

### Documentation

* Use the centralized [Xanadu Sphinx Theme](https://github.com/XanaduAI/xanadu-sphinx-theme)
Expand All @@ -44,13 +49,16 @@ dev2 = qml.device('lightning.qubit', wires=4, c_dtype=np.complex128) # for doubl
### Bug fixes

* Fix the issue with using available `clang-format` version in format.
[#(288)](https://github.com/PennyLaneAI/pennylane-lightning/pull/288)
[(#288)](https://github.com/PennyLaneAI/pennylane-lightning/pull/288)

* Fix a bug in the generator of `DoubleExcitationPlus`.
[(#298)](https://github.com/PennyLaneAI/pennylane-lightning/pull/298)

### Contributors
maliasadi marked this conversation as resolved.
Show resolved Hide resolved

This release contains contributions from (in alphabetical order):
maliasadi marked this conversation as resolved.
Show resolved Hide resolved

Ali Asadi, Amintor Dusko, Chae-Yeun Park, Lee James O'Riordan, Mikhail Andrenkov
Mikhail Andrenkov, Ali Asadi, Amintor Dusko, Lee James O'Riordan, Chae-Yeun Park, and Shuli Shu

---

Expand Down
16 changes: 1 addition & 15 deletions .github/workflows/tests_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,13 +51,6 @@ jobs:
name: ubuntu-test-report
path: Build/tests/results/report.xml

- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
check_name: Test Report (C++) on Ubuntu
files: Build/tests/results/report.xml

- name: Build and run unit tests for code Coverage
run: |
cmake pennylane_lightning/src -BBuildCov -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON -DCMAKE_CXX_COMPILER="$(which g++-$GCC_VERSION)"
Expand Down Expand Up @@ -111,13 +104,6 @@ jobs:
name: ubuntu-test-report
path: Build/tests/results/report.xml

- name: Publish test results
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
check_name: Test Report (C++) on Ubuntu
files: Build/tests/results/report.xml

- name: Build and run unit tests for code coverage
run: |
cmake pennylane_lightning/src -BBuildCov -DCMAKE_BUILD_TYPE=Debug -DBUILD_TESTS=ON -DENABLE_COVERAGE=ON -DENABLE_BLAS=ON -DCMAKE_CXX_COMPILER="$(which g++-$GCC_VERSION)"
Expand Down Expand Up @@ -184,7 +170,7 @@ jobs:
uses: EnricoMi/publish-unit-test-result-action@v1
if: always()
with:
check_name: Test Report (C++) on Ubuntu
check_name: Test Report (Linux, Kokkos, and Kokkos Kernels) on Ubuntu
files: BuildCov/tests/results/report.xml

cppbenchmarksuite:
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/wheel_macos_arm64.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ on:
env:
CIBW_BUILD: 'cp37-* cp38-* cp39-* cp310-*'

ARCHS: 'arm64'

# MacOS specific build settings
CIBW_BEFORE_ALL_MACOS: |
brew uninstall --force oclint
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ doc/code/
*.so
cpptests
*.o

.DS_Store
.cache/*
.vscode/*
.ycm_extra_conf.py
Expand Down
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ option(ENABLE_WARNINGS "Enable warnings" ON)
option(ENABLE_NATIVE "Enable native CPU build tuning" OFF)
option(ENABLE_AVX "Enable AVX support" OFF)
option(ENABLE_OPENMP "Enable OpenMP" ON)
option(ENABLE_KOKKOS "Enable Kokkos" OFF)
option(ENABLE_KOKKOS "Enable Kokkos" ON)
option(ENABLE_BLAS "Enable BLAS" OFF)

# Other build options
Expand Down
2 changes: 1 addition & 1 deletion doc/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
breathe
docutils==0.16
exhale
exhale==0.3.1
graphviz
pybind11
sphinx
Expand Down
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.24.0-dev16"
__version__ = "0.24.0"
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
9 changes: 5 additions & 4 deletions pennylane_lightning/lightning_qubit.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ def apply_lightning(self, state, operations):

@staticmethod
def _check_adjdiff_supported_measurements(measurements: List[MeasurementProcess]):
"""Check whether given list of measurement is supported by adjoint_diff
"""Check whether given list of measurement is supported by adjoint_diff.

Args:
measurements (List[MeasurementProcess]): a list of measurement processes to check.
Expand Down Expand Up @@ -266,8 +266,7 @@ def _check_adjdiff_supported_operations(operations):
observables, or operations by the Lightning adjoint differentiation method.

Args:
tape (.QuantumTape): quantum tape to differentiate

tape (.QuantumTape): quantum tape to differentiate.
"""
for op in operations:
if op.num_params > 1 and not isinstance(op, Rot):
Expand Down Expand Up @@ -423,6 +422,7 @@ def vjp(self, measurements, dy, starting_state=None, use_device_state=False):
use_device_state (bool): use current device state to initialize. A forward pass of the same
circuit should be the last thing the device has executed. If a ``starting_state`` is
provided, that takes precedence.

Returns:
The processing function required to compute the vector-Jacobian products of a tape.
"""
Expand Down Expand Up @@ -494,12 +494,12 @@ def batch_vjp(
):
"""Generate the processing function required to compute the vector-Jacobian products
of a batch of tapes.

Args:
tapes (Sequence[.QuantumTape]): sequence of quantum tapes to differentiate
dys (Sequence[tensor_like]): Sequence of gradient-output vectors ``dy``. Must be the
same length as ``tapes``. Each ``dy`` tensor should have shape
matching the output shape of the corresponding tape.
Keyword Args:
reduction (str): Determines how the vector-Jacobian products are returned.
If ``append``, then the output of the function will be of the form
``List[tensor_like]``, with each element corresponding to the VJP of each
Expand All @@ -509,6 +509,7 @@ def batch_vjp(
use_device_state (bool): use current device state to initialize. A forward pass of the same
circuit should be the last thing the device has executed. If a ``starting_state`` is
provided, that takes precedence.

Returns:
The processing function required to compute the vector-Jacobian products of a batch of tapes.
"""
Expand Down
3 changes: 3 additions & 0 deletions pennylane_lightning/src/gates/Constant.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,8 @@ namespace Pennylane::Gates::Constant {
"GeneratorCRZ"},
std::pair<GeneratorOperation, std::string_view>{GeneratorOperation::IsingXX,
"GeneratorIsingXX"},
std::pair<GeneratorOperation, std::string_view>{GeneratorOperation::IsingXY,
"GeneratorIsingXY"},
std::pair<GeneratorOperation, std::string_view>{GeneratorOperation::IsingYY,
"GeneratorIsingYY"},
std::pair<GeneratorOperation, std::string_view>{GeneratorOperation::IsingZZ,
Expand Down Expand Up @@ -203,6 +205,7 @@ namespace Pennylane::Gates::Constant {
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::RY, 1},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::RZ, 1},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::IsingXX, 2},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::IsingXY, 2},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::IsingYY, 2},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::IsingZZ, 2},
std::pair<GeneratorOperation, std::size_t>{GeneratorOperation::CRX, 2},
Expand Down
1 change: 1 addition & 0 deletions pennylane_lightning/src/gates/GateOperation.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ enum class GeneratorOperation : uint32_t {
RY,
RZ,
IsingXX,
IsingXY,
IsingYY,
IsingZZ,
CRX,
Expand Down
6 changes: 6 additions & 0 deletions pennylane_lightning/src/gates/OpToMemberFuncPtr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,12 @@ struct GeneratorOpToMemberFuncPtr<PrecisionT, GateImplementation,
&GateImplementation::template applyGeneratorIsingXX<PrecisionT>;
};
template <class PrecisionT, class GateImplementation>
struct GeneratorOpToMemberFuncPtr<PrecisionT, GateImplementation,
GeneratorOperation::IsingXY> {
constexpr static auto value =
&GateImplementation::template applyGeneratorIsingXY<PrecisionT>;
};
template <class PrecisionT, class GateImplementation>
struct GeneratorOpToMemberFuncPtr<PrecisionT, GateImplementation,
GeneratorOperation::IsingYY> {
constexpr static auto value =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {
GeneratorOperation::CRY,
GeneratorOperation::CRZ,
GeneratorOperation::IsingXX,
GeneratorOperation::IsingXY,
GeneratorOperation::IsingYY,
GeneratorOperation::IsingZZ,
GeneratorOperation::ControlledPhaseShift,
Expand Down Expand Up @@ -1111,6 +1112,34 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {
return -static_cast<PrecisionT>(0.5);
}

template <class PrecisionT>
[[nodiscard]] static auto
applyGeneratorIsingXY(std::complex<PrecisionT> *arr, size_t num_qubits,
const std::vector<size_t> &wires,
[[maybe_unused]] bool adj) -> PrecisionT {
PL_ASSERT(wires.size() == 2);
const size_t rev_wire0 = num_qubits - wires[1] - 1;
const size_t rev_wire1 = num_qubits - wires[0] - 1; // Control qubit
const size_t rev_wire0_shift = static_cast<size_t>(1U) << rev_wire0;
const size_t rev_wire1_shift = static_cast<size_t>(1U) << rev_wire1;
const auto [parity_high, parity_middle, parity_low] =
revWireParity(rev_wire0, rev_wire1);

for (size_t k = 0; k < Util::exp2(num_qubits - 2); k++) {
const size_t i00 = ((k << 2U) & parity_high) |
((k << 1U) & parity_middle) | (k & parity_low);
const size_t i01 = i00 | rev_wire0_shift;
const size_t i10 = i00 | rev_wire1_shift;
const size_t i11 = i00 | rev_wire0_shift | rev_wire1_shift;

std::swap(arr[i10], arr[i01]);
arr[i00] = std::complex<PrecisionT>{0.0, 0.0};
arr[i11] = std::complex<PrecisionT>{0.0, 0.0};
}
// NOLINTNEXTLINE(readability-magic-numbers)
return static_cast<PrecisionT>(0.5);
}

template <class PrecisionT>
[[nodiscard]] static auto
applyGeneratorIsingYY(std::complex<PrecisionT> *arr, size_t num_qubits,
Expand Down Expand Up @@ -1320,10 +1349,10 @@ class GateImplementationsLM : public PauliGenerator<GateImplementationsLM> {

for (size_t k = 0; k < Util::exp2(num_qubits); k++) {
arr[k] *= static_cast<PrecisionT>(
2 * int(std::popcount(k & wires_parity) % 2) - 1);
1 - 2 * int(std::popcount(k & wires_parity) % 2));
}
// NOLINTNEXTLINE(readability-magic-numbers)
return static_cast<PrecisionT>(0.5);
return -static_cast<PrecisionT>(0.5);
}
};
} // namespace Pennylane::Gates
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ class GateImplementationsPI : public PauliGenerator<GateImplementationsPI> {
GeneratorOperation::RZ,
GeneratorOperation::PhaseShift,
GeneratorOperation::IsingXX,
GeneratorOperation::IsingXY,
GeneratorOperation::IsingYY,
GeneratorOperation::IsingZZ,
GeneratorOperation::CRX,
Expand Down Expand Up @@ -922,6 +923,26 @@ class GateImplementationsPI : public PauliGenerator<GateImplementationsPI> {
return -static_cast<PrecisionT>(0.5);
}

template <class PrecisionT>
[[nodiscard]] static auto
applyGeneratorIsingXY(std::complex<PrecisionT> *arr, size_t num_qubits,
const std::vector<size_t> &wires,
[[maybe_unused]] bool adj) -> PrecisionT {
PL_ASSERT(wires.size() == 2);
const auto [indices, externalIndices] = GateIndices(wires, num_qubits);

for (const size_t &externalIndex : externalIndices) {
std::complex<PrecisionT> *shiftedState = arr + externalIndex;

std::swap(shiftedState[indices[2]], shiftedState[indices[1]]);
shiftedState[indices[0]] = std::complex<PrecisionT>{0.0, 0.0};
shiftedState[indices[3]] = std::complex<PrecisionT>{0.0, 0.0};
}

// NOLINTNEXTLINE(readability-magic-numbers)
return static_cast<PrecisionT>(0.5);
}

template <class PrecisionT>
[[nodiscard]] static auto
applyGeneratorIsingYY(std::complex<PrecisionT> *arr, size_t num_qubits,
Expand Down
3 changes: 3 additions & 0 deletions pennylane_lightning/src/simulator/KernelMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,9 @@ int assignDefaultKernelsForGeneratorOp() {
instance.assignKernelForOp(GeneratorOperation::IsingXX, all_threading,
all_memory_model, all_qubit_numbers,
KernelType::LM);
instance.assignKernelForOp(GeneratorOperation::IsingXY, all_threading,
all_memory_model, all_qubit_numbers,
KernelType::LM);
instance.assignKernelForOp(GeneratorOperation::IsingYY, all_threading,
all_memory_model, all_qubit_numbers,
KernelType::LM);
Expand Down
1 change: 1 addition & 0 deletions pennylane_lightning/src/tests/Test_OpToMemberFuncPtr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,7 @@ class DummyImplementation {
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(RY)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(RZ)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(IsingXX)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(IsingXY)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(IsingYY)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(IsingZZ)
PENNYLANE_TESTS_DEFINE_GENERATOR_OP(CRX)
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,11 @@ def build_extension(self, ext: CMakeExtension):

# Add more platform dependent options
if platform.system() == "Darwin":
#To support ARM64
if os.getenv('ARCHS') == "arm64":
configure_args += ["-DCMAKE_CXX_FLAGS='-target arm64-apple-macos11'"]
else:
configure_args += []
# Disable OpenMP in M1 Macs
if os.environ.get("USE_OMP"):
configure_args += []
Expand Down
1 change: 1 addition & 0 deletions tests/test_adjoint_jacobian.py
Original file line number Diff line number Diff line change
Expand Up @@ -875,6 +875,7 @@ def circuit_ansatz(params, wires):
# # qml.PauliRot(params[12], "XXYZ", wires=[wires[0], wires[1], wires[2], wires[3]])
qml.CPhase(params[12], wires=[wires[3], wires[2]])
qml.IsingXX(params[13], wires=[wires[1], wires[0]])
qml.IsingXY(params[14], wires=[wires[3], wires[2]])
qml.IsingYY(params[14], wires=[wires[3], wires[2]])
qml.IsingZZ(params[14], wires=[wires[2], wires[1]])
qml.U1(params[15], wires=wires[0])
Expand Down
2 changes: 0 additions & 2 deletions tests/test_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@
Unit tests for the :mod:`pennylane_lightning.LightningQubit` device.
"""
import numpy as np
import pennylane as qml
import pytest
from pennylane import DeviceError

from pennylane_lightning.lightning_qubit import CPP_BINARY_AVAILABLE

Expand Down
2 changes: 0 additions & 2 deletions tests/test_serialize.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,7 @@
"""
Unit tests for the serialization helper functions
"""
from asyncio import set_child_watcher
import pennylane as qml
from pennylane import numpy as qnp
import numpy as np
import pennylane_lightning

Expand Down