Skip to content

Commit a6ac16b

Browse files
committed
added calcRealAmpSum frontend
1 parent 1c051cf commit a6ac16b

File tree

4 files changed

+98
-0
lines changed

4 files changed

+98
-0
lines changed

quest/include/calculations.h

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,57 @@ extern "C" {
4242

4343

4444

45+
/**
46+
* @defgroup example_prs Example PR functions
47+
* @brief Nonsensical functions to demonstrate good PRs.
48+
* @{
49+
*/
50+
51+
52+
/** Calculates the real component of the sum of every amplitude in the state,
53+
* but only for states which contain an even number of qubits (for no reason :3 ).
54+
*
55+
* @formulae
56+
* Let @f$ n @f$ qubits be the number of qubits in @p qureg, assumed even.
57+
*
58+
* - When @p qureg is a statevector @f$ \svpsi @f$, this function returns
59+
* @f[
60+
\text{Re}\left( \sum\limits_i^{2^n} \langle i \svpsi \right) \in \mathbb{R}.
61+
* @f]
62+
* - When @p qureg is a density matrix @f$ \dmrho @f$, this function returns
63+
* @f[
64+
\text{Re}\left( \sum\limits_i^{2^n} \sum\limits_j^{2^n} \bra{i} \dmrho \ket{j} \right) \in \mathbb{R}.
65+
* @f]
66+
*
67+
* @constraints
68+
* - The number of qubits in the register must be even.
69+
*
70+
* @myexample
71+
* ```
72+
Qureg qureg = createQureg(4);
73+
initRandomPureState(qureg);
74+
75+
qreal reAmpSum = calcRealAmpSum(qureg);
76+
reportScalar("reAmpSum", reAmpSum);
77+
* ```
78+
*
79+
* @see
80+
* - calcTotalProb()
81+
82+
* @param[in] qureg the state with the processed amplitudes.
83+
* @returns The real component of the sum of all contained amplitudes.
84+
* @throws @validationerror
85+
* - if @p qureg is uninitialised.
86+
* - if @p qureg contains an odd number of qubits.
87+
* @author Tyson Jones
88+
*/
89+
qreal calcRealAmpSum(Qureg qureg);
90+
91+
92+
/** @} */
93+
94+
95+
4596
/**
4697
* @defgroup calc_expec Expectation values
4798
* @brief Functions for calculating expected values of Hermitian observables.

quest/src/api/calculations.cpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,22 @@ extern "C" {
125125

126126

127127

128+
/*
129+
* PR DEMOS
130+
*/
131+
132+
133+
qreal calcRealAmpSum(Qureg qureg) {
134+
validate_quregFields(qureg, __func__);
135+
validate_quregHasEvenNumQubits(qureg, __func__);
136+
137+
/// @todo
138+
/// implement and call new backend function
139+
return -1;
140+
}
141+
142+
143+
128144
/*
129145
* EXPECTED VALUES
130146
*/

quest/src/core/validation.cpp

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,14 @@ using std::vector;
5757
namespace report {
5858

5959

60+
/*
61+
* NONSENSE VALIDATION FOR DEMO PR
62+
*/
63+
64+
string QUREG_HAS_ODD_NUM_QUBITS =
65+
"The given Qureg contained ${NUM_QUBITS} qubits, but must contain an even number.";
66+
67+
6068
/*
6169
* ENVIRONMENT CREATION
6270
*/
@@ -1306,6 +1314,21 @@ bool isIndexListUnique(int* list, int len) {
13061314

13071315

13081316

1317+
/*
1318+
* NONSENSE VALIDATION FOR DEMO PR
1319+
*/
1320+
1321+
void validate_quregHasEvenNumQubits(Qureg qureg, const char* caller) {
1322+
1323+
tokenSubs vars = {
1324+
{"${NUM_QUBITS}", qureg.numQubits}
1325+
};
1326+
1327+
assertThat(qureg.numQubits % 2 == 0, report::QUREG_HAS_ODD_NUM_QUBITS, vars, caller);
1328+
}
1329+
1330+
1331+
13091332
/*
13101333
* ENVIRONMENT CREATION
13111334
*/

quest/src/core/validation.hpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,14 @@ qreal validateconfig_getEpsilon();
6363

6464

6565

66+
/*
67+
* NONSENSE VALIDATION FOR DEMO PR
68+
*/
69+
70+
void validate_quregHasEvenNumQubits(Qureg qureg, const char* caller);
71+
72+
73+
6674
/*
6775
* ENVIRONMENT CREATION
6876
*/

0 commit comments

Comments
 (0)