Skip to content

Commit

Permalink
Hubbard model periodic fix (#30)
Browse files Browse the repository at this point in the history
* added hubbard model test that fails

* fixed bottom_neighbor for periodic boundary conditions

* added line break to conform with line width limit

* fixed bug with right/left periodic conditions
  • Loading branch information
kevinsung authored and babbush committed Oct 12, 2017
1 parent 48f027e commit feacc38
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
2 changes: 1 addition & 1 deletion src/openfermion/utils/_hubbard.py
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ def fermi_hubbard(x_dimension, y_dimension, tunneling, coulomb,
# Account for periodic boundaries.
if periodic:
if (x_dimension > 2) and ((site + 1) % x_dimension == 0):
right_neighbor -= (x_dimension - 1)
right_neighbor -= x_dimension
if (y_dimension > 2) and (site + x_dimension + 1 > n_sites):
bottom_neighbor -= x_dimension * y_dimension

Expand Down
10 changes: 9 additions & 1 deletion src/openfermion/utils/_hubbard_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ def test_two_by_two_spinless_periodic_rudimentary(self):
self.chemical_potential, self.magnetic_field,
periodic=True, spinless=True)


def test_two_by_three_spinless_periodic_rudimentary(self):
hubbard_model = fermi_hubbard(
2, 3, self.tunneling, self.coulomb,
Expand All @@ -111,3 +110,12 @@ def test_two_by_three_spinless_periodic_rudimentary(self):
# Check up top/bottom hopping terms.
self.assertAlmostEqual(hubbard_model.terms[((4, 1), (0, 0))],
-self.tunneling)

def test_three_by_two_spinless_periodic_rudimentary(self):
hubbard_model = fermi_hubbard(
3, 2, self.tunneling, self.coulomb,
self.chemical_potential, self.magnetic_field,
periodic=True, spinless=True)
# Check up top/bottom hopping terms.
self.assertAlmostEqual(hubbard_model.terms[((2, 1), (0, 0))],
-self.tunneling)

0 comments on commit feacc38

Please sign in to comment.