pennylane-qrack 0.13.4__tar.gz → 0.24.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/CMakeLists.txt +15 -3
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/Makefile +11 -6
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/PKG-INFO +6 -3
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/README.rst +3 -1
- pennylane_qrack-0.24.0/catalyst/runtime/include/DataView.hpp +150 -0
- pennylane_qrack-0.24.0/catalyst/runtime/include/Exception.hpp +87 -0
- pennylane_qrack-0.24.0/catalyst/runtime/include/OQDRuntimeCAPI.h +56 -0
- pennylane_qrack-0.24.0/catalyst/runtime/include/QuantumDevice.hpp +580 -0
- pennylane_qrack-0.24.0/catalyst/runtime/include/RuntimeCAPI.h +122 -0
- pennylane_qrack-0.24.0/catalyst/runtime/include/Types.h +165 -0
- pennylane_qrack-0.24.0/pennylane_qrack/QrackAceDeviceConfig.toml +108 -0
- pennylane_qrack-0.24.0/pennylane_qrack/QrackStabilizerDeviceConfig.toml +99 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack/_version.py +2 -2
- pennylane_qrack-0.24.0/pennylane_qrack/qrack_ace_device.py +447 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack/qrack_device.cpp +40 -33
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack/qrack_device.py +20 -5
- pennylane_qrack-0.24.0/pennylane_qrack/qrack_stabilizer_device.py +313 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack.egg-info/PKG-INFO +6 -3
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack.egg-info/SOURCES.txt +10 -0
- pennylane_qrack-0.24.0/pennylane_qrack.egg-info/entry_points.txt +4 -0
- pennylane_qrack-0.24.0/requirements.txt +3 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/setup.py +1 -1
- pennylane_qrack-0.13.4/pennylane_qrack.egg-info/entry_points.txt +0 -2
- pennylane_qrack-0.13.4/requirements.txt +0 -3
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/CHANGELOG.md +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/LICENSE +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/MANIFEST.in +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack/QrackDeviceConfig.toml +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack/__init__.py +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack.egg-info/dependency_links.txt +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack.egg-info/requires.txt +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/pennylane_qrack.egg-info/top_level.txt +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/setup.cfg +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/tests/test_apply.py +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/tests/test_integration.py +0 -0
- {pennylane_qrack-0.13.4 → pennylane_qrack-0.24.0}/tests/test_units.py +0 -0
|
@@ -5,6 +5,18 @@ project(qrack_device)
|
|
|
5
5
|
if (NOT MSVC)
|
|
6
6
|
set(CMAKE_CXX_STANDARD 20)
|
|
7
7
|
set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|
8
|
+
set(QRACK_BUILD_DIR "${CMAKE_CURRENT_SOURCE_DIR}/qrack/build")
|
|
9
|
+
|
|
10
|
+
find_library(QRACK_LIB
|
|
11
|
+
NAMES qrack libqrack
|
|
12
|
+
PATHS "${QRACK_BUILD_DIR}"
|
|
13
|
+
NO_DEFAULT_PATH)
|
|
14
|
+
|
|
15
|
+
if (NOT QRACK_LIB)
|
|
16
|
+
message(FATAL_ERROR "Could not find libqrack in ${QRACK_BUILD_DIR}")
|
|
17
|
+
endif ()
|
|
18
|
+
|
|
19
|
+
message(STATUS "Found Qrack library: ${QRACK_LIB}")
|
|
8
20
|
|
|
9
21
|
option(ENABLE_OPENCL "Use OpenCL optimizations" ON)
|
|
10
22
|
find_package(OpenCL)
|
|
@@ -17,12 +29,12 @@ if (NOT MSVC)
|
|
|
17
29
|
if (ENABLE_OPENCL)
|
|
18
30
|
if (APPLE)
|
|
19
31
|
target_include_directories(qrack_device PUBLIC ${CMAKE_SOURCE_DIR}/qrack/build/_deps/opencl-headers-src/ ${CMAKE_SOURCE_DIR}/qrack/build/_deps/opencl-clhpp-src/include/)
|
|
20
|
-
target_link_libraries(qrack_device PUBLIC
|
|
32
|
+
target_link_libraries(qrack_device PUBLIC ${QRACK_LIB} "-framework OpenCL")
|
|
21
33
|
else (APPLE)
|
|
22
|
-
target_link_libraries(qrack_device PUBLIC
|
|
34
|
+
target_link_libraries(qrack_device PUBLIC ${QRACK_LIB} OpenCL)
|
|
23
35
|
endif (APPLE)
|
|
24
36
|
else (ENABLE_OPENCL)
|
|
25
|
-
target_link_libraries(qrack_device PUBLIC
|
|
37
|
+
target_link_libraries(qrack_device PUBLIC ${QRACK_LIB})
|
|
26
38
|
endif (ENABLE_OPENCL)
|
|
27
39
|
set_property(TARGET qrack_device PROPERTY POSITION_INDEPENDENT_CODE ON)
|
|
28
40
|
install(TARGETS qrack_device LIBRARY DESTINATION pennylane_qrack)
|
|
@@ -24,26 +24,31 @@ help:
|
|
|
24
24
|
build-deps:
|
|
25
25
|
ifneq ($(OS),Windows_NT)
|
|
26
26
|
ifeq ($(QRACK_PRESENT),)
|
|
27
|
-
git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout
|
|
27
|
+
git clone https://github.com/unitaryfund/qrack.git; cd qrack; git checkout 3ddf43b67c9ab43657823a28a96a590f112ea220; cd ..
|
|
28
28
|
endif
|
|
29
29
|
mkdir -p qrack/build
|
|
30
30
|
ifeq ($(UNAME_S),Linux)
|
|
31
31
|
ifeq ($(UNAME_P),x86_64)
|
|
32
|
-
cd qrack/build; cmake -DENABLE_RDRAND=OFF -DENABLE_DEVRAND=ON ..; make
|
|
32
|
+
cd qrack/build; cmake -DENABLE_RDRAND=OFF -DENABLE_DEVRAND=ON -DQBCAPPOW=11 ..; make qrack; cd ../..
|
|
33
33
|
else
|
|
34
|
-
cd qrack/build; cmake -DENABLE_RDRAND=OFF -DENABLE_DEVRAND=ON -DENABLE_COMPLEX_X2=OFF -DENABLE_SSE3=OFF ..; make
|
|
34
|
+
cd qrack/build; cmake -DENABLE_RDRAND=OFF -DENABLE_DEVRAND=ON -DENABLE_COMPLEX_X2=OFF -DENABLE_SSE3=OFF -DQBCAPPOW=11 ..; make qrack; cd ../..
|
|
35
35
|
endif
|
|
36
36
|
endif
|
|
37
37
|
ifeq ($(UNAME_S),Darwin)
|
|
38
38
|
ifeq ($(UNAME_P),x86_64)
|
|
39
|
-
cd qrack/build; cmake ..; make
|
|
39
|
+
cd qrack/build; cmake -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++ -DENABLE_RDRAND=OFF -DQBCAPPOW=11 -DCPP_STD=14 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack; cd ../..
|
|
40
40
|
else
|
|
41
|
-
cd qrack/build; cmake -
|
|
41
|
+
cd qrack/build; cmake -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++ -DENABLE_OPENCL=OFF -DENABLE_COMPLEX_X2=OFF -DENABLE_SSE3=OFF -DENABLE_RDRAND=OFF -DQBCAPPOW=11 -DCPP_STD=14 -DBoost_INCLUDE_DIR=/opt/homebrew/include -DBoost_LIBRARY_DIRS=/opt/homebrew/lib ..; make qrack; cd ../..
|
|
42
42
|
endif
|
|
43
43
|
endif
|
|
44
44
|
endif
|
|
45
|
-
|
|
45
|
+
ifeq ($(UNAME_S),Darwin)
|
|
46
|
+
rm -rf _qrack_include; mkdir _qrack_include; mkdir _qrack_include/qrack; cp -r qrack/include/* _qrack_include/qrack; cp -r qrack/build/include/* _qrack_include/qrack; \
|
|
47
|
+
cd pennylane_qrack; cmake -DCMAKE_CXX_COMPILER=/opt/homebrew/bin/g++ ..; make all
|
|
48
|
+
else
|
|
49
|
+
rm -rf _qrack_include; mkdir _qrack_include; mkdir _qrack_include/qrack; cp -r qrack/include/* _qrack_include/qrack; cp -r qrack/build/include/* _qrack_include/qrack; \
|
|
46
50
|
cd pennylane_qrack; cmake ..; make all
|
|
51
|
+
endif
|
|
47
52
|
|
|
48
53
|
.PHONY: install
|
|
49
54
|
install:
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
Metadata-Version: 2.
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
2
|
Name: pennylane-qrack
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.24.0
|
|
4
4
|
Summary: PennyLane plugin for Qrack.
|
|
5
5
|
Home-page: http://github.com/vm6502q
|
|
6
6
|
Maintainer: vm6502q
|
|
@@ -34,6 +34,7 @@ Dynamic: description
|
|
|
34
34
|
Dynamic: description-content-type
|
|
35
35
|
Dynamic: home-page
|
|
36
36
|
Dynamic: license
|
|
37
|
+
Dynamic: license-file
|
|
37
38
|
Dynamic: maintainer
|
|
38
39
|
Dynamic: maintainer-email
|
|
39
40
|
Dynamic: provides
|
|
@@ -47,7 +48,7 @@ PennyLane-Qrack Plugin
|
|
|
47
48
|
|
|
48
49
|
The PennyLane-Qrack plugin integrates the Qrack quantum computing framework with PennyLane's quantum machine learning capabilities.
|
|
49
50
|
|
|
50
|
-
|
|
51
|
+
Performance can benefit greatly from following the `Qrack repository "Quick Start" and "Power user considerations." <https://github.com/unitaryfund/qrack/blob/main/README.md#quick-start>`__
|
|
51
52
|
|
|
52
53
|
This plugin is addapted from the `PennyLane-Qulacs plugin, <https://github.com/PennyLaneAI/pennylane-qulacs>`__ under the Apache License 2.0, with many thanks to the original developers!
|
|
53
54
|
|
|
@@ -64,6 +65,8 @@ Features
|
|
|
64
65
|
|
|
65
66
|
* Provides access to a PyQrack simulator backend via the ``qrack.simulator`` device
|
|
66
67
|
* Provides access to a (C++) Qrack simulator backend for Catalyst (also) via the ``qrack.simulator`` device
|
|
68
|
+
* Provides access to a PyQrack Clifford-only simulator backend via the ``qrack.stabilizer`` device
|
|
69
|
+
* Provides access to a PyQrack simulator backend optimized for large-scale approximate simulation via the ``qrack.ace`` device
|
|
67
70
|
|
|
68
71
|
.. installation-start-inclusion-marker-do-not-remove
|
|
69
72
|
|
|
@@ -5,7 +5,7 @@ PennyLane-Qrack Plugin
|
|
|
5
5
|
|
|
6
6
|
The PennyLane-Qrack plugin integrates the Qrack quantum computing framework with PennyLane's quantum machine learning capabilities.
|
|
7
7
|
|
|
8
|
-
|
|
8
|
+
Performance can benefit greatly from following the `Qrack repository "Quick Start" and "Power user considerations." <https://github.com/unitaryfund/qrack/blob/main/README.md#quick-start>`__
|
|
9
9
|
|
|
10
10
|
This plugin is addapted from the `PennyLane-Qulacs plugin, <https://github.com/PennyLaneAI/pennylane-qulacs>`__ under the Apache License 2.0, with many thanks to the original developers!
|
|
11
11
|
|
|
@@ -22,6 +22,8 @@ Features
|
|
|
22
22
|
|
|
23
23
|
* Provides access to a PyQrack simulator backend via the ``qrack.simulator`` device
|
|
24
24
|
* Provides access to a (C++) Qrack simulator backend for Catalyst (also) via the ``qrack.simulator`` device
|
|
25
|
+
* Provides access to a PyQrack Clifford-only simulator backend via the ``qrack.stabilizer`` device
|
|
26
|
+
* Provides access to a PyQrack simulator backend optimized for large-scale approximate simulation via the ``qrack.ace`` device
|
|
25
27
|
|
|
26
28
|
.. installation-start-inclusion-marker-do-not-remove
|
|
27
29
|
|
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
// Copyright 2023 Xanadu Quantum Technologies Inc.
|
|
2
|
+
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#pragma once
|
|
16
|
+
|
|
17
|
+
#include <vector>
|
|
18
|
+
|
|
19
|
+
#include <Exception.hpp>
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* A multi-dimensional view for MemRef-like and std::vector<T> types.
|
|
23
|
+
*
|
|
24
|
+
* @tparam T The underlying data type
|
|
25
|
+
* @tparam R The Rank (R > 0)
|
|
26
|
+
*
|
|
27
|
+
* @note A forward iterator is implemented in this view for traversing over the entire
|
|
28
|
+
* elements of MemRef types rank-by-rank starting from the last dimension (R-1). For example,
|
|
29
|
+
* The DataView iterator for MemRef<T, 2> starts from index (0, 0) and traverses elements
|
|
30
|
+
* in the following order:
|
|
31
|
+
* (0, 0), ..., (0, sizes[1]-1), (1, 0), ..., (1, sizes[1]-1), ... (sizes[0]-1, sizes[1]-1).
|
|
32
|
+
*/
|
|
33
|
+
template <typename T, size_t R> class DataView {
|
|
34
|
+
private:
|
|
35
|
+
T *data_aligned;
|
|
36
|
+
size_t offset;
|
|
37
|
+
size_t sizes[R] = {0};
|
|
38
|
+
size_t strides[R] = {0};
|
|
39
|
+
|
|
40
|
+
public:
|
|
41
|
+
class iterator {
|
|
42
|
+
private:
|
|
43
|
+
const DataView<T, R> &view;
|
|
44
|
+
|
|
45
|
+
int64_t loc; // physical index
|
|
46
|
+
size_t indices[R] = {0};
|
|
47
|
+
|
|
48
|
+
public:
|
|
49
|
+
using iterator_category = std::forward_iterator_tag; // LCOV_EXCL_LINE
|
|
50
|
+
using value_type = T; // LCOV_EXCL_LINE
|
|
51
|
+
using difference_type = std::ptrdiff_t; // LCOV_EXCL_LINE
|
|
52
|
+
using pointer = T *; // LCOV_EXCL_LINE
|
|
53
|
+
using reference = T &; // LCOV_EXCL_LINE
|
|
54
|
+
|
|
55
|
+
iterator(const DataView<T, R> &_view, int64_t begin_idx) : view(_view), loc(begin_idx) {}
|
|
56
|
+
pointer operator->() const { return &view.data_aligned[loc]; }
|
|
57
|
+
reference operator*() const { return view.data_aligned[loc]; }
|
|
58
|
+
iterator &operator++()
|
|
59
|
+
{
|
|
60
|
+
int64_t next_axis = -1;
|
|
61
|
+
for (int64_t axis = R - 1; axis >= 0; axis--) {
|
|
62
|
+
if (++indices[axis] < view.sizes[axis]) {
|
|
63
|
+
next_axis = axis;
|
|
64
|
+
break;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
indices[axis] = 0;
|
|
68
|
+
|
|
69
|
+
loc -= view.sizes[axis] == 0 ? 0 : (view.sizes[axis] - 1) * view.strides[axis];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
loc = next_axis == -1 ? -1 : loc + view.strides[next_axis];
|
|
73
|
+
return *this;
|
|
74
|
+
}
|
|
75
|
+
iterator operator++(int)
|
|
76
|
+
{
|
|
77
|
+
auto cached_iter = *this;
|
|
78
|
+
int64_t next_axis = -1;
|
|
79
|
+
for (int64_t axis = R - 1; axis >= 0; axis--) {
|
|
80
|
+
if (++indices[axis] < view.sizes[axis]) {
|
|
81
|
+
next_axis = axis;
|
|
82
|
+
break;
|
|
83
|
+
}
|
|
84
|
+
indices[axis] = 0;
|
|
85
|
+
loc -= view.sizes[axis] == 0 ? 0 : (view.sizes[axis] - 1) * view.strides[axis];
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
loc = next_axis == -1 ? -1 : loc + view.strides[next_axis];
|
|
89
|
+
return cached_iter;
|
|
90
|
+
}
|
|
91
|
+
bool operator==(const iterator &other) const
|
|
92
|
+
{
|
|
93
|
+
return (loc == other.loc && view.data_aligned == other.view.data_aligned);
|
|
94
|
+
}
|
|
95
|
+
bool operator!=(const iterator &other) const { return !(*this == other); }
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
explicit DataView(std::vector<T> &buffer) : data_aligned(buffer.data()), offset(0)
|
|
99
|
+
{
|
|
100
|
+
static_assert(R == 1, "[Class: DataView] Assertion: R == 1");
|
|
101
|
+
sizes[0] = buffer.size();
|
|
102
|
+
strides[0] = 1;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
explicit DataView(T *_data_aligned, size_t _offset, const size_t *_sizes,
|
|
106
|
+
const size_t *_strides)
|
|
107
|
+
: data_aligned(_data_aligned), offset(_offset)
|
|
108
|
+
{
|
|
109
|
+
static_assert(R > 0, "[Class: DataView] Assertion: R > 0");
|
|
110
|
+
if (_sizes != nullptr && _strides != nullptr) {
|
|
111
|
+
for (size_t i = 0; i < R; i++) {
|
|
112
|
+
sizes[i] = _sizes[i];
|
|
113
|
+
strides[i] = _strides[i];
|
|
114
|
+
}
|
|
115
|
+
} // else sizes = {0}, strides = {0}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
[[nodiscard]] auto size() const -> size_t
|
|
119
|
+
{
|
|
120
|
+
if (!data_aligned) {
|
|
121
|
+
return 0;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
size_t tsize = 1;
|
|
125
|
+
for (size_t i = 0; i < R; i++) {
|
|
126
|
+
tsize *= sizes[i];
|
|
127
|
+
}
|
|
128
|
+
return tsize;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
template <typename... I> T &operator()(I... idxs) const
|
|
132
|
+
{
|
|
133
|
+
static_assert(sizeof...(idxs) == R,
|
|
134
|
+
"[Class: DataView] Error in Catalyst Runtime: Wrong number of indices");
|
|
135
|
+
size_t indices[] = {static_cast<size_t>(idxs)...};
|
|
136
|
+
|
|
137
|
+
size_t loc = offset;
|
|
138
|
+
for (size_t axis = 0; axis < R; axis++) {
|
|
139
|
+
loc += indices[axis] * strides[axis];
|
|
140
|
+
}
|
|
141
|
+
return data_aligned[loc];
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
iterator begin()
|
|
145
|
+
{
|
|
146
|
+
return iterator{*this, (*this).size() == 0 ? -1 : static_cast<int64_t>(offset)};
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
iterator end() { return iterator{*this, -1}; }
|
|
150
|
+
};
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
// Copyright 2023 Xanadu Quantum Technologies Inc.
|
|
2
|
+
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#pragma once
|
|
16
|
+
|
|
17
|
+
#include <exception>
|
|
18
|
+
#include <iostream>
|
|
19
|
+
|
|
20
|
+
#include <sstream>
|
|
21
|
+
#include <string>
|
|
22
|
+
#include <type_traits>
|
|
23
|
+
#include <utility>
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* @brief Macro that throws `RuntimeException` with given message.
|
|
27
|
+
*/
|
|
28
|
+
#define RT_FAIL(message) Catalyst::Runtime::_abort((message), __FILE__, __LINE__, __func__)
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @brief Macro that throws `RuntimeException` if expression evaluates
|
|
32
|
+
* to true.
|
|
33
|
+
*/
|
|
34
|
+
#define RT_FAIL_IF(expression, message) \
|
|
35
|
+
if ((expression)) { \
|
|
36
|
+
RT_FAIL(message); \
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* @brief Macro that throws `RuntimeException` with the given expression
|
|
41
|
+
* and source location if expression evaluates to false.
|
|
42
|
+
*/
|
|
43
|
+
#define RT_ASSERT(expression) RT_FAIL_IF(!(expression), "Assertion: " #expression)
|
|
44
|
+
|
|
45
|
+
namespace Catalyst::Runtime {
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* @brief This is the general exception thrown by Catalyst for runtime errors
|
|
49
|
+
* that is derived from `std::exception`.
|
|
50
|
+
*/
|
|
51
|
+
class RuntimeException : public std::exception {
|
|
52
|
+
private:
|
|
53
|
+
const std::string err_msg;
|
|
54
|
+
|
|
55
|
+
public:
|
|
56
|
+
explicit RuntimeException(std::string msg) noexcept
|
|
57
|
+
: err_msg{std::move(msg)} {} // LCOV_EXCL_LINE
|
|
58
|
+
~RuntimeException() override = default; // LCOV_EXCL_LINE
|
|
59
|
+
|
|
60
|
+
RuntimeException(const RuntimeException &) = default;
|
|
61
|
+
RuntimeException(RuntimeException &&) noexcept = default;
|
|
62
|
+
|
|
63
|
+
RuntimeException &operator=(const RuntimeException &) = delete;
|
|
64
|
+
RuntimeException &operator=(RuntimeException &&) = delete;
|
|
65
|
+
|
|
66
|
+
[[nodiscard]] auto what() const noexcept -> const char * override
|
|
67
|
+
{
|
|
68
|
+
return err_msg.c_str();
|
|
69
|
+
} // LCOV_EXCL_LINE
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* @brief Throws a `RuntimeException` with the given error message.
|
|
74
|
+
*
|
|
75
|
+
* @note This is not supposed to be called directly.
|
|
76
|
+
*/
|
|
77
|
+
[[noreturn]] inline void _abort(const char *message, const char *file_name, size_t line,
|
|
78
|
+
const char *function_name)
|
|
79
|
+
{
|
|
80
|
+
std::stringstream sstream;
|
|
81
|
+
sstream << "[" << file_name << ":" << line << "][Function:" << function_name
|
|
82
|
+
<< "] Error in Catalyst Runtime: " << message;
|
|
83
|
+
|
|
84
|
+
throw RuntimeException(sstream.str());
|
|
85
|
+
} // LCOV_EXCL_LINE
|
|
86
|
+
|
|
87
|
+
} // namespace Catalyst::Runtime
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
// Copyright 2025 Xanadu Quantum Technologies Inc.
|
|
2
|
+
|
|
3
|
+
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
4
|
+
// you may not use this file except in compliance with the License.
|
|
5
|
+
// You may obtain a copy of the License at
|
|
6
|
+
|
|
7
|
+
// http://www.apache.org/licenses/LICENSE-2.0
|
|
8
|
+
|
|
9
|
+
// Unless required by applicable law or agreed to in writing, software
|
|
10
|
+
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
11
|
+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
12
|
+
// See the License for the specific language governing permissions and
|
|
13
|
+
// limitations under the License.
|
|
14
|
+
|
|
15
|
+
#pragma once
|
|
16
|
+
#ifndef OQDRUNTIMECAPI_H
|
|
17
|
+
#define OQDRUNTIMECAPI_H
|
|
18
|
+
|
|
19
|
+
#include <array>
|
|
20
|
+
#include <cstdint>
|
|
21
|
+
|
|
22
|
+
#include "Exception.hpp"
|
|
23
|
+
#include "Types.h"
|
|
24
|
+
|
|
25
|
+
#ifdef __cplusplus
|
|
26
|
+
extern "C" {
|
|
27
|
+
#endif
|
|
28
|
+
|
|
29
|
+
struct Beam {
|
|
30
|
+
int64_t transition_index;
|
|
31
|
+
double rabi;
|
|
32
|
+
double detuning;
|
|
33
|
+
std::array<int64_t, 3> polarization;
|
|
34
|
+
std::array<int64_t, 3> wavevector;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
struct Pulse {
|
|
38
|
+
Beam *beam;
|
|
39
|
+
size_t target;
|
|
40
|
+
double duration;
|
|
41
|
+
double phase;
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
// OQD Runtime Instructions
|
|
45
|
+
void __catalyst__oqd__rt__initialize();
|
|
46
|
+
void __catalyst__oqd__rt__finalize(const std::string &openapl_file_name);
|
|
47
|
+
void __catalyst__oqd__ion(const std::string &ion_specs);
|
|
48
|
+
void __catalyst__oqd__modes(const std::vector<std::string> &phonon_specs);
|
|
49
|
+
Pulse *__catalyst__oqd__pulse(QUBIT *qubit, double duration, double phase, Beam *beam);
|
|
50
|
+
void __catalyst__oqd__ParallelProtocol(Pulse **pulses, size_t n);
|
|
51
|
+
|
|
52
|
+
#ifdef __cplusplus
|
|
53
|
+
} // extern "C"
|
|
54
|
+
#endif
|
|
55
|
+
|
|
56
|
+
#endif
|