Skip to content

Commit

Permalink
Deprecate PI gates implementation (#925)
Browse files Browse the repository at this point in the history
### Before submitting

Please complete the following checklist when submitting a PR:

- [ ] All new features must include a unit test.
If you've fixed a bug or added code that should be tested, add a test to
the
      [`tests`](../tests) directory!

- [ ] All new functions and code must be clearly commented and
documented.
If you do make documentation changes, make sure that the docs build and
      render correctly by running `make docs`.

- [ ] Ensure that the test suite passes, by running `make test`.

- [ ] Add a new entry to the `.github/CHANGELOG.md` file, summarizing
the
      change, and including a link back to the PR.

- [ ] Ensure that code is properly formatted by running `make format`. 

When all the above are checked, delete everything above the dashed
line and fill in the pull request template.


------------------------------------------------------------------------------------------------------------

**Context:**

**Description of the Change:**

**Benefits:**

**Possible Drawbacks:**

**Related GitHub Issues:**
[sc-73507]

---------

Co-authored-by: ringo-but-quantum <github-ringo-but-quantum@xanadu.ai>
Co-authored-by: Luis Alfredo Nuñez Meneses <alfredo.nunez@xanadu.ai>
  • Loading branch information
3 people authored Oct 2, 2024
1 parent 8796bab commit 3e9b4be
Show file tree
Hide file tree
Showing 19 changed files with 18 additions and 2,066 deletions.
3 changes: 3 additions & 0 deletions .github/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@

### Breaking changes

* Deprecate PI gates implementation.
[(#925)](https://github.com/PennyLaneAI/pennylane-lightning/pull/925)

* Update MacOS wheel builds to require Monterey (12.0) or greater for x86_64 and ARM.
[(#901)](https://github.com/PennyLaneAI/pennylane-lightning/pull/901)

Expand Down
3 changes: 0 additions & 3 deletions doc/benchmark.rst
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@ One can also choose a specific datatype by providing an option:
$ ./benchmarks/plot_gate_benchmark.py --precision float ./bench_result.json # Results for std::complex<float>
$ ./benchmarks/plot_gate_benchmark.py --precision double ./bench_result.json # Results for std::complex<double>
Currently, we have two different kernels in ``Lightning Qubit`` named ``PI`` and ``LM``. For difference between two kernels, see the documents :cpp:class:`Pennylane::Gates::GateImplementationsPI` and :cpp:class:`Pennylane::Gates::GateImplementationsLM`.

Here are some example plots:

.. image:: ./_static/benchmark/PauliX.png
Expand Down
4 changes: 1 addition & 3 deletions doc/lightning_qubit/development/add_gate_kernel.rst
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ This can be done by modifying two files:
// file: gates/KernelType.hpp
namespace Pennylane {
enum class KernelType { PI, LM, MyKernel /* This is added */, None };
enum class KernelType { LM, MyKernel /* This is added */, None };
/* Rest of the file */
Expand All @@ -53,7 +53,6 @@ and
// file: gates/AvailableKernels.hpp
namespace Pennylane {
using AvailableKernels = Util::TypeList<GateImplementationsLM,
GateImplementationsPI,
MyGateImplementation /* This is added*/,
void>;
} // namespace Pennylane
Expand Down Expand Up @@ -111,7 +110,6 @@ To test your own kernel implementations, you can go to ``tests/TestKernels.hpp``
.. code-block:: cpp
using TestKernels = Pennylane::Util::TypeList<Pennylane::Gates::GateImplementationsLM,
Pennylane::Gates::GateImplementationsPI,
MyGateImplementation /*This is added */, void>;
It will automatically test your gate implementation.
Expand Down
5 changes: 2 additions & 3 deletions doc/lightning_qubit/development/avx_kernels/build_system.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@ when the library is loaded, and it is used at runtime when it is the most suitab
To support AVX2 and AVX512 kernels, we always compile those kernels if the target system is UNIX on x86-64.
Specifically, we made separate C++ files for AVX2 and AVX512 kernels and build them as a static library with the corresponding compile options. This is handled by CMake. One can check ``gates/CMakeLists.txt`` file for details.

One caveat is that we want to make sure that default kernels (``KernelType::PI`` and ``KernelType::LM``) are only instantiated once with specific compiler flags during the compile process.
One caveat is that we want to ensure that default ``KernelType::LM`` kernels are only instantiated once with specific compiler flags during the compile process.
This is important as the linker sometimes cannot choose the right instantiation when there are multiple instantiations of the same template class.
This problem does not arise when all instantiations are compiled with the same options, but with the AVX2/512 kernels, we use different compile options for each translation unit. We solve this problem by adding explicit instantiation declarations in the header files for these kernels
(:ref:`file_pennylane_lightning_core_src_simulators_lightning_qubit_gates_cpu_kernels_GateImplementationsLM.hpp` and
:ref:`file_pennylane_lightning_core_src_simulators_lightning_qubit_gates_cpu_kernels_GateImplementationsPI.hpp`)
(:ref:`file_pennylane_lightning_core_src_simulators_lightning_qubit_gates_cpu_kernels_GateImplementationsLM.hpp`)
and compile them as a separate static library.

With this, the AVX2/512 kernels are always included in the binary when compiled for UNIX-compatible OSs on x86-64 architecture.
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.39.0-dev34"
__version__ = "0.39.0-dev35"
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ if (ENABLE_GATE_DISPATCHER AND UNIX AND (${CMAKE_SYSTEM_PROCESSOR} MATCHES "(AMD
target_include_directories(lq_gates_register_kernels_avx512 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(lq_gates_register_kernels_avx512 PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(lq_gates_register_kernels_x64 STATIC RegisterKernels_x64.cpp cpu_kernels/GateImplementationsLM.cpp cpu_kernels/GateImplementationsPI.cpp GateIndices.cpp)
add_library(lq_gates_register_kernels_x64 STATIC RegisterKernels_x64.cpp cpu_kernels/GateImplementationsLM.cpp GateIndices.cpp)
target_link_libraries(lq_gates_register_kernels_x64 PRIVATE lightning_external_libs lightning_compile_options lightning_gates lightning_utils lightning_qubit_utils)
target_include_directories(lq_gates_register_kernels_x64 PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
set_target_properties(lq_gates_register_kernels_x64 PROPERTIES POSITION_INDEPENDENT_CODE ON)
Expand All @@ -53,7 +53,7 @@ else()
lightning_gates)
set_target_properties(lq_gates_kernel_map PROPERTIES POSITION_INDEPENDENT_CODE ON)

add_library(lq_gates_register_kernels_default STATIC RegisterKernels_Default.cpp cpu_kernels/GateImplementationsLM.cpp cpu_kernels/GateImplementationsPI.cpp GateIndices.cpp)
add_library(lq_gates_register_kernels_default STATIC RegisterKernels_Default.cpp cpu_kernels/GateImplementationsLM.cpp GateIndices.cpp)
target_include_directories(lq_gates_register_kernels_default PRIVATE ${CMAKE_CURRENT_SOURCE_DIR})
target_link_libraries(lq_gates_register_kernels_default PRIVATE lightning_gates
lightning_external_libs
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,10 @@ class OperationKernelMap {
OperationKernelMap()
: allowed_kernels_{
// LCOV_EXCL_START
{CPUMemoryModel::Unaligned, {KernelType::LM, KernelType::PI}},
{CPUMemoryModel::Aligned256,
{KernelType::LM, KernelType::PI, KernelType::AVX2}},
{CPUMemoryModel::Unaligned, {KernelType::LM}},
{CPUMemoryModel::Aligned256, {KernelType::LM, KernelType::AVX2}},
{CPUMemoryModel::Aligned512,
{KernelType::LM, KernelType::PI, KernelType::AVX2,
KernelType::AVX512}},
{KernelType::LM, KernelType::AVX2, KernelType::AVX512}},
// LCOV_EXCL_STOP
} {}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ namespace Pennylane::Gates {
/**
* @brief Define kernel id for each implementation.
*/
enum class KernelType { PI, LM, AVX2, AVX512, None };
enum class KernelType { LM, AVX2, AVX512, None };
} // namespace Pennylane::Gates
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,15 @@
#include "DynamicDispatcher.hpp"
#include "RegisterKernel.hpp"
#include "cpu_kernels/GateImplementationsLM.hpp"
#include "cpu_kernels/GateImplementationsPI.hpp"

namespace Pennylane::LightningQubit::Internal {
int registerAllAvailableKernels_Float() {
registerKernel<float, float, Gates::GateImplementationsLM>();
registerKernel<float, float, Gates::GateImplementationsPI>();
return 1;
}

int registerAllAvailableKernels_Double() {
registerKernel<double, double, Gates::GateImplementationsLM>();
registerKernel<double, double, Gates::GateImplementationsPI>();
return 1;
}
} // namespace Pennylane::LightningQubit::Internal
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,11 @@
#include "RegisterKernel.hpp"
#include "RuntimeInfo.hpp"
#include "cpu_kernels/GateImplementationsLM.hpp"
#include "cpu_kernels/GateImplementationsPI.hpp"

namespace Pennylane::LightningQubit::Internal {
int registerAllAvailableKernels_Float() {
using Pennylane::Util::RuntimeInfo;
registerKernel<float, float, Gates::GateImplementationsLM>();
registerKernel<float, float, Gates::GateImplementationsPI>();

if (RuntimeInfo::AVX2() && RuntimeInfo::FMA()) {
registerKernelsAVX2_Float();
Expand All @@ -40,7 +38,6 @@ int registerAllAvailableKernels_Float() {
int registerAllAvailableKernels_Double() {
using Pennylane::Util::RuntimeInfo;
registerKernel<double, double, Gates::GateImplementationsLM>();
registerKernel<double, double, Gates::GateImplementationsPI>();

if (RuntimeInfo::AVX2() && RuntimeInfo::FMA()) {
registerKernelsAVX2_Double();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
#include <tuple>
#include <vector>

#include <iostream>

#include "BitUtil.hpp" // revWireParity
#include "Error.hpp"
#include "GateIndices.hpp"
Expand Down
Loading

0 comments on commit 3e9b4be

Please sign in to comment.