| 24 | */ |
| 25 | |
| 26 | PauliStrSum createMyHamiltonian(int numQubits) { |
| 27 | |
| 28 | // we prepare a Heisenberg XYZ spin-ring Hamiltonian, |
| 29 | // i.e. H = -1/2 sum( Jx XX + Jy YY + Jz ZZ + h Z ) |
| 30 | // upon all nearest neighbour qubits, with periodicity. |
| 31 | // The coefficients must be real for H to be Hermitian |
| 32 | // and ergo its time-evolution operator to be unitary, |
| 33 | // although they must be represented with a qcomp type. |
| 34 | vector<string> operators = {"XX", "YY", "ZZ", "Z"}; |
| 35 | vector<qcomp> coefficients = {.1, .2, .3, .4}; // Jx,Jy,Jz,h |
| 36 | |
| 37 | // we will populate the below vectors with 4*numQubits |
| 38 | // elements which we could pre-allocate with .reserve, |
| 39 | // but we might incur Donald Knuth's justified wrath. |
| 40 | vector<PauliStr> allStrings; |
| 41 | vector<qcomp> allCoeffs; |
| 42 | |
| 43 | // prepare all XX + YY + ZZ |
| 44 | for (int p=0; p<3; p++) { |
| 45 | for (int i=0; i<numQubits; i++) { |
| 46 | |
| 47 | // A_i, A_i+1 |
| 48 | vector<int> targs = {i, (i+1)%numQubits}; |
| 49 | PauliStr str = getPauliStr(operators[p], targs); |
| 50 | |
| 51 | allStrings.push_back(str); |
| 52 | allCoeffs.push_back(coefficients[p]); |
| 53 | } |
| 54 | } |
| 55 | |
| 56 | // prepare Z |
| 57 | for (int i=0; i<numQubits; i++) { |
| 58 | allStrings.push_back(getPauliStr(operators[3], {i})); |
| 59 | allCoeffs.push_back(coefficients[3]); |
| 60 | } |
| 61 | |
| 62 | // must be freed by caller |
| 63 | return createPauliStrSum(allStrings, allCoeffs); |
| 64 | } |
| 65 | |
| 66 | |
| 67 |
no test coverage detected