| 66 | |
| 67 | |
| 68 | def expectation(self,waveform): |
| 69 | |
| 70 | expectation = 0 |
| 71 | prob_from_waveform = (np.absolute(waveform.final_state))**2 |
| 72 | #print(prob_from_waveform) |
| 73 | for i in range(len(prob_from_waveform)): |
| 74 | base = bin(i).replace("0b", "") |
| 75 | base = (self.num_elems - len(base))*'0' + base |
| 76 | base_array = [] |
| 77 | for b in base: |
| 78 | if int(b) == 0: |
| 79 | base_array.append(-1) |
| 80 | else: |
| 81 | base_array.append(1) |
| 82 | |
| 83 | base_array = np.array(base_array) |
| 84 | base_interactions = np.outer(base_array, base_array) |
| 85 | #print(i, prob_from_waveform[i], np.sum(np.multiply(base_interactions,self.hamiltonian_interactions))) |
| 86 | expectation =+ prob_from_waveform[i]*np.sum(np.multiply(base_interactions,self.hamiltonian_interactions)) |
| 87 | return expectation |
| 88 | |
| 89 | def optimize_params(self, gammas, betas, verbose=True): |
| 90 | expectation_dict = {} |