Skip to content

Commit 3279c45

Browse files
patched reporters and optimised applyTrotter
See PR #589 for info on each patch
1 parent 53f8f3a commit 3279c45

File tree

9 files changed

+54
-17
lines changed

9 files changed

+54
-17
lines changed

.github/workflows/audit.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ on:
1414
push:
1515
branches:
1616
- main
17+
- devel
1718
pull_request:
1819
branches:
1920
- main
21+
- devel
2022

2123

2224
jobs:

.github/workflows/compile.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@ on:
2020
push:
2121
branches:
2222
- main
23+
- devel
2324
pull_request:
2425
branches:
2526
- main
27+
- devel
2628

2729

2830
jobs:

.github/workflows/doc.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ permissions:
1515
on:
1616
push:
1717
branches:
18-
- master
18+
- main
1919
workflow_dispatch:
2020

2121

.github/workflows/test_free.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,11 @@ on:
1414
push:
1515
branches:
1616
- main
17+
- devel
1718
pull_request:
1819
branches:
1920
- main
21+
- devel
2022

2123

2224
jobs:

.github/workflows/test_paid.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ name: test (paid, accelerated)
1919

2020
# @todo
2121
# this workflow can only be run on the 'default'
22-
# branch (i.e. master) when manually triggered by
22+
# branch (i.e. main) when manually triggered by
2323
# github actions, so as not to incur unexpected
2424
# costs. I want for this to be automatically
2525
# enqueued but not run in a PR, requiring manual

quest/src/api/operations.cpp

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1135,8 +1135,8 @@ void applyFirstOrderTrotter(Qureg qureg, PauliStrSum sum, qreal angle, bool reve
11351135

11361136
for (qindex i=0; i<sum.numTerms; i++) {
11371137
int j = reverse? sum.numTerms - i - 1 : i;
1138-
qreal arg = 2 * angle * std::real(sum.coeffs[j]); // 2 undoes Gadget convention
1139-
applyPauliGadget(qureg, sum.strings[j], arg); // re-validates, grr
1138+
qreal arg = 2 * angle * std::real(sum.coeffs[j]); // 2 undoes Gadget convention
1139+
applyPauliGadget(qureg, sum.strings[j], arg); // caller disabled valiation therein
11401140
}
11411141
}
11421142

@@ -1172,16 +1172,27 @@ void applyTrotterizedPauliStrSumGadget(Qureg qureg, PauliStrSum sum, qreal angle
11721172
validate_pauliStrSumIsHermitian(sum, __func__);
11731173
validate_trotterParams(qureg, order, reps, __func__);
11741174

1175-
/// @todo
1176-
/// the accuracy of Trotterisation is greatly improved by randomisation
1177-
/// or (even sub-optimal) grouping into commuting terms. Should we
1178-
/// implement these here or into another function?
1179-
1175+
// exp(i angle sum) = identity when angle=0
11801176
if (angle == 0)
11811177
return;
11821178

1179+
// record validation state then disable to avoid repeated
1180+
// re-validations in each invoked applyPauliGadget() below
1181+
bool wasValidationEnabled = validateconfig_isEnabled();
1182+
validateconfig_disable();
1183+
1184+
// perform sequence of applyPauliGadget()
11831185
for (int r=0; r<reps; r++)
11841186
applyHigherOrderTrotter(qureg, sum, angle/reps, order);
1187+
1188+
// potentially restore validation
1189+
if (wasValidationEnabled)
1190+
validateconfig_enable();
1191+
1192+
/// @todo
1193+
/// the accuracy of Trotterisation is greatly improved by randomisation
1194+
/// or (even sub-optimal) grouping into commuting terms. Should we
1195+
/// implement these above or into another function?
11851196
}
11861197

11871198
} // end de-mangler

quest/src/core/printer.cpp

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -339,6 +339,14 @@ template string printer_toStr<double>(complex<double> num);
339339
template string printer_toStr<long double>(complex<long double> num);
340340

341341

342+
// explicit qreal overload so that real sig-figs can be changed
343+
string printer_toStr(qreal num) {
344+
345+
// uses user-set significant figures
346+
return floatToStr(num);
347+
}
348+
349+
342350
// alias as toStr() just for internal brevity
343351
// (this seems backward; ordinarily we would define toStr() as
344352
// the templated inner-function and define concretely-typed public
@@ -776,11 +784,12 @@ MatrixQuadrantInds getTruncatedMatrixQuadrantInds(qindex numRows, qindex numCols
776784

777785
MatrixQuadrantInds inds;
778786

779-
// according to the user-set truncations
780-
qindex maxNumLeftCols = global_maxNumPrintedCols / 2; // floors
781-
qindex maxNumRightCols = global_maxNumPrintedCols - maxNumLeftCols;
782-
qindex maxNumUpperRows = global_maxNumPrintedRows / 2; // floors
783-
qindex maxNumLowerRows = global_maxNumPrintedRows - maxNumUpperRows;
787+
// find maximum size of matrix quadrants according to user-truncatins.
788+
// Choose right & lower first so that When num=odd, extra left & upper elem is shown
789+
qindex maxNumRightCols = global_maxNumPrintedCols / 2; // floors
790+
qindex maxNumLeftCols = global_maxNumPrintedCols - maxNumRightCols;
791+
qindex maxNumLowerRows = global_maxNumPrintedRows / 2; // floors
792+
qindex maxNumUpperRows = global_maxNumPrintedRows - maxNumLowerRows;
784793

785794
// may be ignored (and will unimportantly underflow when not truncating)
786795
inds.rightStartCol = numCols - maxNumRightCols;

quest/src/core/printer.hpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <sstream>
2222
#include <type_traits>
2323

24+
// beware that files including this header receive all these
25+
// namespace items; a worthwhile evil to keep this readable
2426
using std::tuple;
2527
using std::string;
2628
using std::vector;
@@ -70,12 +72,18 @@ template<typename T>
7072
string printer_toStr(T expr) {
7173

7274
// write to buffer (rather than use to_string()) so that floating-point numbers
73-
// are automatically converted to scientific notation when necessary
75+
// are automatically converted to scientific notation when necessary. Beware
76+
// that the user configured significant figures are not reflected here.
77+
7478
std::ostringstream buffer;
7579
buffer << expr;
7680
return buffer.str();
7781
}
7882

83+
// explicit qreal version of above, affected by user-set significant figures
84+
string printer_toStr(qreal num);
85+
86+
7987

8088
/*
8189
* SUBSTRING PREPARATION

quest/src/core/validation.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1066,8 +1066,11 @@ namespace report {
10661066

10671067
void default_inputErrorHandler(const char* func, const char* msg) {
10681068

1069-
// safe to call even before MPI has been setup, and ignores user-set trailing newlines
1070-
print(string("")
1069+
// safe to call even before MPI has been setup, and ignores user-set trailing newlines.
1070+
// It begins with \n to interrupt half-printed lines (when trailing newlines are set to
1071+
// 0 via setNumReportedNewlines(0)), for visual clarity. Note that user's overriding
1072+
// functions might not think to print an initial newline but oh well!
1073+
print(string("\n")
10711074
+ "QuEST encountered a validation error during function "
10721075
+ "'" + func + "':\n" + msg + "\n"
10731076
+ "Exiting...\n");

0 commit comments

Comments
 (0)