| 128 | */ |
| 129 | |
| 130 | int main() { |
| 131 | initQuESTEnv(); |
| 132 | |
| 133 | // prepare qureg=|0>, H and O |
| 134 | int numQubits = 20; |
| 135 | Qureg qureg = createQureg(numQubits); |
| 136 | PauliStrSum hamil = createMyHamiltonian(numQubits); |
| 137 | PauliStrSum observ = createMyObservable(numQubits); |
| 138 | |
| 139 | // init qureg=|+> and report qureg, H, O |
| 140 | initPlusState(qureg); |
| 141 | reportMyStructs(qureg, hamil, observ); |
| 142 | |
| 143 | // tidy reporting of below expectation values |
| 144 | setMaxNumReportedSigFigs(3); |
| 145 | setNumReportedNewlines(1); |
| 146 | |
| 147 | // evolve by repeatedly (each is a "step") Trotterising |
| 148 | // exp(-i dt H) with the specified order and repetitions. |
| 149 | qreal dt = 0.1; |
| 150 | int order = 4; |
| 151 | int reps = 5; |
| 152 | int steps = 20; |
| 153 | |
| 154 | for (int i=0; i<steps; i++) { |
| 155 | |
| 156 | // evolve qureg under (approx) exp(-i dt H) |
| 157 | applyTrotterizedUnitaryTimeEvolution(qureg, hamil, dt, order, reps); |
| 158 | |
| 159 | // calculate and report <O> |
| 160 | qreal time = dt * (i+1); |
| 161 | qreal expec = calcExpecPauliStrSum(qureg, observ); |
| 162 | reportScalar("<O(t=" + std::to_string(time) + ")>", expec); |
| 163 | } |
| 164 | |
| 165 | reportStr(""); |
| 166 | |
| 167 | // preview the final state... |
| 168 | setNumReportedNewlines(2); |
| 169 | setMaxNumReportedItems(25, 25); |
| 170 | reportStr("[Final state]"); |
| 171 | reportQureg(qureg); |
| 172 | |
| 173 | // and some of its properties... |
| 174 | reportScalar("Normalisation", calcTotalProb(qureg)); |
| 175 | reportScalar("Probability of first qubit", calcProbOfQubitOutcome(qureg, 0, 0)); |
| 176 | |
| 177 | // including the overlap with |+> |
| 178 | for (int i=0; i<numQubits; i++) |
| 179 | applyHadamard(qureg, i); |
| 180 | reportScalar("Probability of initial state", calcProbOfBasisState(qureg, 0)); |
| 181 | |
| 182 | // verify results by uninterrupted higher-order simulation to target time |
| 183 | initPlusState(qureg); |
| 184 | applyTrotterizedUnitaryTimeEvolution(qureg, hamil, dt*steps, order+2, reps*steps); |
| 185 | reportScalar("final <O>", calcExpecPauliStrSum(qureg, observ)); |
| 186 | |
| 187 | // clean up |
nothing calls this directly
no test coverage detected