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 PI gates implementation #925

Merged
merged 9 commits into from
Oct 2, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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.
[(#923)](https://github.com/PennyLaneAI/pennylane-lightning/pull/923)

* 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 make sure that default ``KernelType::LM`` kernels are only instantiated once with specific compiler flags during the compile process.
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
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`)
maliasadi marked this conversation as resolved.
Show resolved Hide resolved
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-dev32"
__version__ = "0.39.0-dev33"
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
Loading
Loading