The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches
wrappers.h
1/** @file
2 * C-compatible functions which are alternatives to C++-only API
3 * functions, ultimately providing an identical interface. This is
4 * necessary because these functions otherwise return qcomps by-value
5 * which is prohibited between C and C++ compiled binaries (because
6 * complex numbers are not agreed upon in their ABI, despite having
7 * identical memory layouts in the C and C++ standard libraries).
8 * Ergo this file defines no new API functions as far as the user/
9 * documentation is aware, but secretly ensures the backend C++
10 * binaries return qcomps to the user's C code only by pointer.
11 *
12 * (( _passing_ qcomps by value to a function seems to be okay,
13 * although I am not entirely sure why ))
14 *
15 * Note that matrix getters and setters (like getCompMatr1()) are
16 * excluded, and instead defined directly in matrices.h/.cpp .
17 *
18 * An unimportant by-product of this method of achieving interoperability
19 * is that the internal wrapped functions are exposed to the C user; so
20 * we prefix them with "_wrap_" to imply privacy. Note the "extern"
21 * declarations are superfluous (the behaviour is default), but used
22 * to explicitly distinguish the intendedly-private internal functions
23 * from the C API functions herein defined.
24 *
25 * @author Tyson Jones
26 *
27 * (no doxygen doc)
28 */
29
30#ifndef WRAPPERS_H
31#define WRAPPERS_H
32
33#include "quest/include/types.h"
34#include "quest/include/qureg.h"
35#include "quest/include/paulis.h"
36#include "quest/include/matrices.h"
37
38/// @cond EXCLUDE_FROM_DOXYGEN
39
40// these definitions are only exposed to C,
41// since they duplicate existing C++ functions
42#ifndef __cplusplus
43
44
45
46extern void _wrap_calcInnerProduct(Qureg bra, Qureg ket, qcomp* out);
47
48qcomp calcInnerProduct(Qureg bra, Qureg ket) {
49
50 qcomp out;
51 _wrap_calcInnerProduct(bra, ket, &out);
52 return out;
53}
54
55
56extern void _wrap_calcExpecNonHermitianPauliStrSum(qcomp*, Qureg, PauliStrSum);
57
59
60 qcomp out;
61 _wrap_calcExpecNonHermitianPauliStrSum(&out, qureg, sum);
62 return out;
63}
64
65
66extern void _wrap_calcExpecNonHermitianFullStateDiagMatr(qcomp*, Qureg, FullStateDiagMatr);
67
69
70 qcomp out;
71 _wrap_calcExpecNonHermitianFullStateDiagMatr(&out, qureg, matr);
72 return out;
73}
74
75
76extern void _wrap_calcExpecNonHermitianFullStateDiagMatrPower(qcomp*, Qureg, FullStateDiagMatr, qcomp);
77
79
80 qcomp out;
81 _wrap_calcExpecNonHermitianFullStateDiagMatrPower(&out, qureg, matr, expo);
82 return out;
83}
84
85
86extern void _wrap_getQuregAmp(qcomp* out, Qureg qureg, qindex index);
87
88qcomp getQuregAmp(Qureg qureg, qindex index) {
89
90 qcomp out;
91 _wrap_getQuregAmp(&out, qureg, index);
92 return out;
93}
94
95
96extern void _wrap_getDensityQuregAmp(qcomp* out, Qureg qureg, qindex row, qindex column);
97
98qcomp getDensityQuregAmp(Qureg qureg, qindex row, qindex column) {
99
100 qcomp out;
101 _wrap_getDensityQuregAmp(&out, qureg, row, column);
102 return out;
103}
104
105
106
107#endif // !__cplusplus
108
109/// @endcond // EXCLUDE_FROM_DOXYGEN
110
111#endif // WRAPPERS_H
qcomp calcInnerProduct(Qureg qureg1, Qureg qureg2)
qcomp calcExpecNonHermitianFullStateDiagMatr(Qureg qureg, FullStateDiagMatr matr)
qcomp calcExpecNonHermitianPauliStrSum(Qureg qureg, PauliStrSum sum)
qcomp calcExpecNonHermitianFullStateDiagMatrPower(Qureg qureg, FullStateDiagMatr matrix, qcomp exponent)
qcomp getQuregAmp(Qureg qureg, qindex index)
Definition qureg.cpp:484
qcomp getDensityQuregAmp(Qureg qureg, qindex row, qindex column)
Definition qureg.cpp:497
Definition qureg.h:49