Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
k-yoshimi committed Nov 11, 2024
1 parent 1c35122 commit faf5296
Showing 1 changed file with 71 additions and 0 deletions.
71 changes: 71 additions & 0 deletions src/hwave/solver/uhfr.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,77 @@ def _transform_interall(self, ham_info):
"""
return ham_info

def _calc_hartree(self):
"""Calculate Hartree terms in the Hamiltonian.
Calculates the diagonal Hartree terms in the Hamiltonian by iterating through
interaction parameters and adding contributions to Ham_tmp and Ham_trans_tmp.
Parameters
----------
None
Returns
-------
None
Updates self.Ham_tmp and self.Ham_trans_tmp arrays
"""
site = np.zeros(4, dtype=np.int32)
for site_info, value in self.param_ham.items():
for i in range(4):
site[i] = site_info[2 * i] + site_info[2 * i + 1] * self.Nsize
# Diagonal Fock term
self.Ham_tmp[site[0]][site[1]][site[2]][site[3]] += value
self.Ham_tmp[site[2]][site[3]][site[0]][site[1]] += value
if site[1] == site[2]:
self.Ham_trans_tmp[site[1]][site[2]] += value
pass

def _calc_fock(self):
"""Calculate Fock exchange terms in the Hamiltonian.
Calculates the off-diagonal Fock exchange terms in the Hamiltonian by iterating
through interaction parameters and adding contributions to Ham_tmp.
Parameters
----------
None
Returns
-------
None
Updates self.Ham_tmp array
"""
site = np.zeros(4,dtype=np.int32)
for site_info, value in self.param_ham.items():
for i in range(4):
site[i] = site_info[2 * i] + site_info[2 * i + 1] * self.Nsize
# OffDiagonal Fock term
self.Ham_tmp[site[0]][site[3]][site[2]][site[1]] -= value
self.Ham_tmp[site[2]][site[1]][site[0]][site[3]] -= value
pass

def get_ham(self, type):
"""Get the Hamiltonian matrices.
Calculates and returns the Hartree and Fock terms of the Hamiltonian.
Parameters
----------
type : str
Type of calculation - either "hartree" or "hartreefock"
Returns
-------
tuple of ndarray
(Ham_tmp, Ham_trans_tmp) containing the Hamiltonian matrices
"""
self._calc_hartree()
if type == "hartreefock":
self._calc_fock()
return self.Ham_tmp, self.Ham_trans_tmp


def _check_range(self):
"""Check that site indices are within valid range."""
err = 0
Expand Down

0 comments on commit faf5296

Please sign in to comment.