Skip to content

Commit 1f03368

Browse files
Revert SQRT2 definition to v0.31.0 (#479)
* Do not import numbers header in main code. * Auto update version * Update changelog. * Fix INVSQRT2 * Cannot use sqrt on Windows/Mac. * Build doc with PL@master. * Revert SQTR2 to old def. * Update requirements.txt --------- Co-authored-by: Dev version update bot <github-actions[bot]@users.noreply.github.com>
1 parent d853d80 commit 1f03368

File tree

4 files changed

+23
-3
lines changed

4 files changed

+23
-3
lines changed

.github/CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@
2121

2222
### Bug fixes
2323

24+
* Do no import `sqrt2_v` from `<numbers>` in `Util.hpp` to resolve issue with Lightning-GPU builds.
25+
[(#479)](https://github.com/PennyLaneAI/pennylane-lightning/pull/479)
26+
2427
* Update the CMake internal references to enable sub-project compilation with affecting the parent package.
2528
[(#478)](https://github.com/PennyLaneAI/pennylane-lightning/pull/478)
2629

pennylane_lightning/core/_version.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,4 @@
1616
Version number (major.minor.patch[-label])
1717
"""
1818

19-
__version__ = "0.32.0-dev9"
19+
__version__ = "0.32.0-dev10"

pennylane_lightning/core/src/simulators/lightning_qubit/algorithms/tests/Test_VectorJacobianProduct.cpp

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414
#include <algorithm>
15+
#include <numbers>
1516
#include <random>
1617
#include <span>
1718
#include <vector>

pennylane_lightning/core/src/utils/Util.hpp

+18-2
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020

2121
#include <cmath>
2222
#include <complex>
23-
#include <numbers> // sqrt2_v
23+
#include <numbers>
2424
#include <numeric> // transform_reduce
2525
#include <set>
2626
#include <type_traits> // is_same_v
@@ -175,7 +175,15 @@ inline static constexpr auto IMAG() -> ComplexT<T> {
175175
* @return constexpr T sqrt(2)
176176
*/
177177
template <class T> inline static constexpr auto SQRT2() -> T {
178+
#if __cpp_lib_math_constants >= 201907L
178179
return std::numbers::sqrt2_v<T>;
180+
#else
181+
if constexpr (std::is_same_v<T, float>) {
182+
return 0x1.6a09e6p+0F; // NOLINT: To be replaced in C++20
183+
} else {
184+
return 0x1.6a09e667f3bcdp+0; // NOLINT: To be replaced in C++20
185+
}
186+
#endif
179187
}
180188

181189
/**
@@ -187,7 +195,15 @@ template <class T> inline static constexpr auto SQRT2() -> T {
187195
*/
188196
template <template <class> class ComplexT, class T>
189197
inline static constexpr auto SQRT2() -> ComplexT<T> {
198+
#if __cpp_lib_math_constants >= 201907L
190199
return std::numbers::sqrt2_v<T>;
200+
#else
201+
if constexpr (std::is_same_v<T, float>) {
202+
return 0x1.6a09e6p+0F; // NOLINT: To be replaced in C++20
203+
} else {
204+
return 0x1.6a09e667f3bcdp+0; // NOLINT: To be replaced in C++20
205+
}
206+
#endif
191207
}
192208

193209
/**
@@ -209,7 +225,7 @@ template <class T> inline static constexpr auto INVSQRT2() -> T {
209225
*/
210226
template <template <class> class ComplexT, class T>
211227
inline static constexpr auto INVSQRT2() -> ComplexT<T> {
212-
return {1 / SQRT2<T>()};
228+
return static_cast<ComplexT<T>>(INVSQRT2<T>());
213229
}
214230

215231
/**

0 commit comments

Comments
 (0)