Skip to content

Commit

Permalink
Fix: Revert changes to numpy.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam-XiaoyueLi committed Jun 5, 2024
1 parent a29b2af commit df62deb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions double_bracket_flow_as_a_diagonalization_quantum_algorithm
Submodule double_bracket_flow_as_a_diagonalization_quantum_algorithm added at 808dd6
8 changes: 4 additions & 4 deletions src/qibo/backends/numpy.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,15 +758,15 @@ def calculate_matrix_exp(self, a, matrix, eigenvectors=None, eigenvalues=None):
return self.np.matmul(eigenvectors, self.np.matmul(expd, ud))

def calculate_expectation_state(self, hamiltonian, state, normalize):
ev = self.np.real(self.np.sum(self.np.conj(state) * hamiltonian.matrix @ state))
statec = self.np.conj(state)
hstate = hamiltonian @ state
ev = self.np.real(self.np.sum(statec * hstate))
if normalize:
ev /= self.np.sum(self.np.square(self.np.abs(state)))
return ev

def calculate_expectation_density_matrix(self, hamiltonian, state, normalize):
statec = self.np.conj(state)
hstate = hamiltonian @ state
ev = self.np.real(self.np.sum(statec * hstate))
ev = self.np.real(self.np.trace(self.cast(hamiltonian @ state)))
if normalize:
norm = self.np.real(self.np.trace(state))
ev /= norm
Expand Down

0 comments on commit df62deb

Please sign in to comment.