| 164 | for (auto& [label, qureg]: getCachedDensmatrs()) { |
| 165 | |
| 166 | DYNAMIC_SECTION( label ) { |
| 167 | |
| 168 | SECTION( "same seed consistency" ) { |
| 169 | |
| 170 | unsigned seeds[] = {123, 543, 755}; |
| 171 | const int numSeeds = 3; |
| 172 | const int numMixedStates = 10; |
| 173 | const int numReps = 5; |
| 174 | |
| 175 | // set an arbitrary fixed seed... |
| 176 | setSeeds(seeds, numSeeds); |
| 177 | |
| 178 | // generate and remember a random state |
| 179 | initRandomMixedState(qureg, numMixedStates); |
| 180 | qmatrix ref = getMatrix(qureg); |
| 181 | |
| 182 | // get a set of random measurement outcomes |
| 183 | vector<int> outcomes(qureg.numQubits); |
| 184 | for (int i=0; i<qureg.numQubits; i++) |
| 185 | outcomes[i] = applyQubitMeasurement(qureg, i); |
| 186 | |
| 187 | // repeatedly... |
| 188 | for (int r=0; r<numReps; r++) { |
| 189 | |
| 190 | // reset the seed |
| 191 | setSeeds(seeds, numSeeds); |
| 192 | |
| 193 | // and confirm all random states are re-produced |
| 194 | initRandomMixedState(qureg, numMixedStates); |
| 195 | REQUIRE_AGREE( qureg, ref); |
| 196 | |
| 197 | // as are all measurement outcomes |
| 198 | for (int i=0; i<qureg.numQubits; i++) |
| 199 | REQUIRE( outcomes[i] == applyQubitMeasurement(qureg,i) ); |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | SECTION( "different key inconsistency" ) { |
| 204 | |
| 205 | unsigned seeds[] = {123, 543, 755}; |
| 206 | const int numSeeds = 3; |
| 207 | const int ampInd = 0; |
| 208 | |
| 209 | // set arbitrary seed and collect random-state amp |
| 210 | setSeeds(seeds, numSeeds); |
| 211 | initRandomPureState(qureg); |
| 212 | qcomp amp1 = getDensityQuregAmp(qureg, ampInd, ampInd); |
| 213 | |
| 214 | // change one passed seed and re-collect random-state amp |
| 215 | int i = GENERATE_COPY( range(0,numSeeds) ); |
| 216 | seeds[i] = 987654321; |
| 217 | setSeeds(seeds, numSeeds); |
| 218 | initRandomPureState(qureg); |
| 219 | qcomp amp2 = getDensityQuregAmp(qureg, ampInd, ampInd); |
| 220 | |
| 221 | // amps differ if seed successfully impacts outcomes |
| 222 | REQUIRE( amp1 != amp2 ); |
| 223 | } |
nothing calls this directly
no test coverage detected