The Quantum Exact Simulation Toolkit v4.0.0
Loading...
Searching...
No Matches

Testing utilities which define 'qmatrix', used to perform reference complex matrix algebra, and as a reference proxy to a quantum density matrix. More...

Typedefs

typedef vector< vector< qcomp > > qmatrix
 

Functions

qmatrix getConstantMatrix (size_t dim, qcomp elem)
 
qmatrix getDiagonalMatrix (qvector v)
 
qvector getDiagonals (qmatrix m)
 
qmatrix getIdentityMatrix (size_t dim)
 
qmatrix getPauliMatrix (int id)
 
qmatrix getZeroMatrix (size_t dim)
 
qmatrix operator* (const qcomp &, const qmatrix &)
 
qmatrix operator* (const qmatrix &, const qcomp &)
 
qmatrix operator* (const qmatrix &, const qmatrix &)
 
qmatrix operator* (const qmatrix &, const qreal &)
 
qmatrix operator* (const qreal &, const qmatrix &)
 
qmatrix operator*= (qmatrix &, const qcomp &)
 
qmatrix operator*= (qmatrix &, const qmatrix &)
 
qmatrix operator*= (qmatrix &, const qreal &)
 
qmatrix operator+ (const qmatrix &, const qmatrix &)
 
qmatrix operator+= (qmatrix &, const qmatrix &)
 
qmatrix operator- (const qmatrix &, const qmatrix &)
 
qmatrix operator-= (qmatrix &, const qmatrix &)
 
qmatrix operator/ (const qmatrix &, const qcomp &)
 
qmatrix operator/ (const qmatrix &, const qreal &)
 
qmatrix operator/= (qmatrix &, const qcomp &)
 
qmatrix operator/= (qmatrix &, const qreal &)
 
void setSubMatrix (qmatrix &dest, qmatrix sub, size_t r, size_t c)
 
void setSubMatrix (qmatrix &dest, qvector sub, size_t flatInd)
 
void setToDebugState (qmatrix &m)
 

Detailed Description

Testing utilities which define 'qmatrix', used to perform reference complex matrix algebra, and as a reference proxy to a quantum density matrix.

Typedef Documentation

◆ qmatrix

typedef vector<vector<qcomp> > qmatrix

Definition at line 23 of file qmatrix.hpp.

Function Documentation

◆ getConstantMatrix()

qmatrix getConstantMatrix ( size_t dim,
qcomp elem )

Definition at line 24 of file qmatrix.cpp.

24 {
25 DEMAND( dim >= 1 );
26
27 return qmatrix(dim, qvector(dim, elem));
28}

◆ getDiagonalMatrix()

qmatrix getDiagonalMatrix ( qvector v)

Definition at line 41 of file qmatrix.cpp.

41 {
42 DEMAND( v.size() >= 1 );
43
44 qmatrix out = getZeroMatrix(v.size());
45
46 for (size_t i=0; i<v.size(); i++)
47 out[i][i] = v[i];
48
49 return out;
50}
qmatrix getZeroMatrix(size_t dim)
Definition qmatrix.cpp:18

◆ getDiagonals()

qvector getDiagonals ( qmatrix m)

Definition at line 246 of file qmatrix.cpp.

246 {
247 DEMAND( m.size() > 1 );
248
249 qvector out = getZeroVector(m.size());
250
251 for (size_t i=0; i<out.size(); i++)
252 out[i] = m[i][i];
253
254 return out;
255}

◆ getIdentityMatrix()

qmatrix getIdentityMatrix ( size_t dim)

Definition at line 30 of file qmatrix.cpp.

30 {
31 DEMAND( dim >= 1 );
32
33 qmatrix out = getZeroMatrix(dim);
34
35 for (size_t i=0; i<dim; i++)
36 out[i][i] = 1;
37
38 return out;
39}

◆ getPauliMatrix()

qmatrix getPauliMatrix ( int id)

Definition at line 52 of file qmatrix.cpp.

52 {
53 DEMAND( id >= 0 );
54 DEMAND( id <= 3 );
55
56 if (id == 0)
57 return {{1 ,0}, {0, 1}};
58
59 if (id == 1)
60 return {{0, 1}, {1, 0}};
61
62 if (id == 2)
63 return {{0, -1_i}, {1_i, 0}};
64
65 if (id == 3)
66 return {{1, 0}, {0, -1}};
67
68 // unreachable
69 return {{-1}};
70}

◆ getZeroMatrix()

qmatrix getZeroMatrix ( size_t dim)

Definition at line 18 of file qmatrix.cpp.

18 {
19 DEMAND( dim >= 1 );
20
21 return qmatrix(dim, qvector(dim, 0));
22}

◆ operator*() [1/5]

qmatrix operator* ( const qcomp & a,
const qmatrix & m )

Definition at line 77 of file qmatrix.cpp.

77 {
78 qmatrix out = m;
79
80 for (auto& row : out)
81 for (auto& elem : row)
82 elem *= a;
83
84 return out;
85}

◆ operator*() [2/5]

qmatrix operator* ( const qmatrix & m,
const qcomp & a )

Definition at line 87 of file qmatrix.cpp.

87 {
88 return a * m;
89}

◆ operator*() [3/5]

qmatrix operator* ( const qmatrix & m1,
const qmatrix & m2 )

Definition at line 175 of file qmatrix.cpp.

175 {
176 DEMAND( m1.size() > 0 );
177 DEMAND( m2.size() > 0 );
178 DEMAND( m1[0].size() == m2.size() );
179
180 // unlike most functions which assume qmatrix is square,
181 // we cheekily permit m1 and m2 to be non-square (and
182 // ergo differing), necessary to calculate partial traces
183 qmatrix out = qmatrix(m1.size(), qvector(m2[0].size(),0));
184
185 for (size_t r=0; r<out.size(); r++)
186 for (size_t c=0; c<out[0].size(); c++)
187 for (size_t k=0; k<m2.size(); k++)
188 out[r][c] += m1[r][k] * m2[k][c];
189
190 return out;
191}

◆ operator*() [4/5]

qmatrix operator* ( const qmatrix & m,
const qreal & a )

Definition at line 100 of file qmatrix.cpp.

100 {
101 return a * m;
102}

◆ operator*() [5/5]

qmatrix operator* ( const qreal & a,
const qmatrix & m )

Definition at line 96 of file qmatrix.cpp.

96 {
97 return qcomp(a,0) * m;
98}

◆ operator*=() [1/3]

qmatrix operator*= ( qmatrix & m,
const qcomp & a )

Definition at line 91 of file qmatrix.cpp.

91 {
92 m = a * m;
93 return m;
94}

◆ operator*=() [2/3]

qmatrix operator*= ( qmatrix & m1,
const qmatrix & m2 )

Definition at line 193 of file qmatrix.cpp.

193 {
194 m1 = m1 * m2;
195 return m1;
196}

◆ operator*=() [3/3]

qmatrix operator*= ( qmatrix & m,
const qreal & a )

Definition at line 104 of file qmatrix.cpp.

104 {
105 m = a * m;
106 return m;
107}

◆ operator+()

qmatrix operator+ ( const qmatrix & m1,
const qmatrix & m2 )

Definition at line 139 of file qmatrix.cpp.

139 {
140 DEMAND( m1.size() == m2.size() );
141
142 qmatrix out = m1;
143
144 for (size_t r=0; r<m1.size(); r++)
145 for (size_t c=0; c<m1.size(); c++)
146 out[r][c] += m2[r][c];
147
148 return out;
149}

◆ operator+=()

qmatrix operator+= ( qmatrix & m1,
const qmatrix & m2 )

Definition at line 151 of file qmatrix.cpp.

151 {
152 m1 = m1 + m2;
153 return m1;
154}

◆ operator-()

qmatrix operator- ( const qmatrix & m1,
const qmatrix & m2 )

Definition at line 161 of file qmatrix.cpp.

161 {
162 return m1 + (-1 * m2);
163}

◆ operator-=()

qmatrix operator-= ( qmatrix & m1,
const qmatrix & m2 )

Definition at line 165 of file qmatrix.cpp.

165 {
166 m1 = m1 - m2;
167 return m1;
168}

◆ operator/() [1/2]

qmatrix operator/ ( const qmatrix & m,
const qcomp & a )

Definition at line 114 of file qmatrix.cpp.

114 {
115 DEMAND( std::abs(a) != 0 );
116
117 return (1/a) * m;
118}

◆ operator/() [2/2]

qmatrix operator/ ( const qmatrix & m,
const qreal & a )

Definition at line 125 of file qmatrix.cpp.

125 {
126 return m / qcomp(a,0);
127}

◆ operator/=() [1/2]

qmatrix operator/= ( qmatrix & m,
const qcomp & a )

Definition at line 120 of file qmatrix.cpp.

120 {
121 m = m / a;
122 return m;
123}

◆ operator/=() [2/2]

qmatrix operator/= ( qmatrix & m,
const qreal & a )

Definition at line 129 of file qmatrix.cpp.

129 {
130 m = m / a;
131 return m;
132}

◆ setSubMatrix() [1/2]

void setSubMatrix ( qmatrix & dest,
qmatrix sub,
size_t r,
size_t c )

Definition at line 203 of file qmatrix.cpp.

203 {
204 DEMAND( sub.size() > 0 );
205 DEMAND( sub .size() + r <= dest.size() );
206 DEMAND( sub[0].size() + c <= dest.size() );
207
208 // this function cheekily supports when 'sub' is non-square,
209 // which is inconsistent with the preconditions of most of
210 // the qmatrix functions, but is needed by setDensityQuregAmps()
211
212 for (size_t i=0; i<sub.size(); i++)
213 for (size_t j=0; j<sub[i].size(); j++)
214 dest[r+i][c+j] = sub[i][j];
215}

◆ setSubMatrix() [2/2]

void setSubMatrix ( qmatrix & dest,
qvector sub,
size_t flatInd )

Definition at line 217 of file qmatrix.cpp.

217 {
218 DEMAND( sub.size() + flatInd <= dest.size()*dest.size() );
219
220 for (size_t i=0; i<sub.size(); i++) {
221 size_t r = (i + flatInd) / dest.size(); // floors
222 size_t c = (i + flatInd) % dest.size();
223 dest[r][c] = sub[i];
224 }
225}

◆ setToDebugState()

void setToDebugState ( qmatrix & m)

Definition at line 227 of file qmatrix.cpp.

227 {
228 DEMAND( !m.empty() );
229
230 size_t i = 0;
231
232 // iterate column-wise
233 for (size_t c=0; c<m.size(); c++) {
234 for (size_t r=0; r<m.size(); r++) {
235 m[r][c] = qcomp(2*i/10., (2*i+1)/10.);
236 i++;
237 }
238 }
239}