-
Notifications
You must be signed in to change notification settings - Fork 172
Expand file tree
/
Copy pathprinter.hpp
More file actions
200 lines (139 loc) · 4.87 KB
/
printer.hpp
File metadata and controls
200 lines (139 loc) · 4.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
/** @file
* Functions for formatting and outputting strings, used
* primarily by reporters (e.g. reportQureg).
*
* @author Tyson Jones
*/
#ifndef PRINTER_HPP
#define PRINTER_HPP
#include "quest/include/types.h"
#include "quest/include/qureg.h"
#include "quest/include/matrices.h"
#include "quest/include/channels.h"
#include "quest/include/paulis.h"
#include <tuple>
#include <vector>
#include <complex>
#include <string>
#include <sstream>
#include <type_traits>
using std::tuple;
using std::string;
using std::vector;
using std::complex;
/*
* USER-CONFIGURABLE GLOBALS
*/
void printer_setMaxNumPrintedScalars(qindex numRows, qindex numCols);
void printer_setMaxNumPrintedSigFig(int numSigFigs);
void printer_setNumTrailingNewlines(int numNewlines);
int printer_getNumTrailingNewlines();
/*
* TYPE NAME STRINGS
*/
string printer_getQrealType();
string printer_getQcompType();
string printer_getQindexType();
string printer_getFloatPrecisionFlag();
/*
* STRING CASTS
*/
// type T can be int, qindex, float, double, long double.
// this more specific printer_toStr() definition is called when passing complex
template <typename T>
string printer_toStr(complex<T> num);
// type T can be any non-complex type recognised by ostringstream!
template<typename T>
string printer_toStr(T expr) {
// write to buffer (rather than use to_string()) so that floating-point numbers
// are automatically converted to scientific notation when necessary
std::ostringstream buffer;
buffer << expr;
return buffer.str();
}
/*
* SUBSTRING PREPARATION
*/
string printer_getMemoryWithUnitStr(size_t numBytes);
/*
* SUBSTRINGS USED BY REPORTERS
*
* which are padded with 1 whitespace either side
*/
namespace printer_substrings {
extern string eq; // =
extern string pn; // per node
extern string pg; // per gpu
extern string ig; // in gpu
extern string pm; // per machine
extern string bt; // 2^
extern string na; // N/A
extern string un; // unknown
}
/*
* DEFAULT INDENTS OF PRINTERS
*
* which doesn't need to be publicly accessible but we want them as
* default arguments to the public signatures, so whatever. Declared
* static to avoid symbol duplication by repeated header inclusion.
*/
static string defaultMatrIndent = " ";
static string defaultQuregIndent = " ";
static string defaultKrausIndent = " ";
static string defaultTableIndent = " ";
/*
* TRAILING NEWLINE PRINTING
*/
void print_newlines();
void print_oneFewerNewlines();
/*
* PRIMITIVE PRINTING
*/
// never prints any newlines (except within supplied str)
void print(const char* str);
void print(string str);
void print(qcomp num);
/*
* STRUCT HEADER PRINTING
*/
// always prints "label:\n"
void print_label(string label);
// always prints a single trailing newline
void print_header(CompMatr1 m, size_t numBytes);
void print_header(CompMatr2 m, size_t numBytes);
void print_header(CompMatr m, size_t numBytes);
void print_header(DiagMatr1 m, size_t numBytes);
void print_header(DiagMatr2 m, size_t numBytes);
void print_header(DiagMatr m, size_t numBytes);
void print_header(SuperOp op, size_t numBytes);
void print_header(KrausMap map, size_t numBytes);
void print_header(PauliStrSum sum, size_t numBytes);
void print_header(FullStateDiagMatr m, size_t numBytesPerNode);
void print_header(Qureg qureg, size_t numBytesPerNode);
/*
* STRUCT ELEMENT PRINTING
*/
// always prints a SINGLE trailing newline, so never supports run-on
// of multiple matrices/multi-line prints; caller must ergo validate
// that user's num-newlines > 0 (else we violatd it) and add lines
// if necessary. Note the default indentation is almost never overriden
void print_elems(CompMatr1, string indent=defaultMatrIndent);
void print_elems(CompMatr2, string indent=defaultMatrIndent);
void print_elems(CompMatr , string indent=defaultMatrIndent);
void print_elems(DiagMatr1, string indent=defaultMatrIndent);
void print_elems(DiagMatr2, string indent=defaultMatrIndent);
void print_elems(DiagMatr, string indent=defaultMatrIndent);
void print_elems(KrausMap, string indent=defaultMatrIndent);
void print_elems(SuperOp, string indent=defaultMatrIndent);
void print_elems(Qureg, string indent=defaultMatrIndent);
void print_elems(PauliStrSum, string indent=defaultMatrIndent);
void print_elems(FullStateDiagMatr, string indent=defaultMatrIndent);
// always prints NO trailing newlines
void print_elemsWithoutNewline(PauliStr, string indent="");
/*
* TABLE PRINTING
*/
void print_table(string title, vector<tuple<string, string>> rows, string indent=defaultTableIndent);
void print_table(string title, vector<tuple<string, long long int>> rows, string indent=defaultTableIndent);
void print_table(string title, string emptyPlaceholder, string indent=defaultTableIndent);
#endif // PRINTER_HPP