Repository: quantumlib/OpenFermion
Pull request #27 (2017-10-12 03:16:52)

Hubbard model periodic fix
Hi, I am a graduate student at the University of Michigan working with Zhang Jiang from NASA Ames. We indeed find this project useful to us and have been working on some contributions. I submitted a corporate CLA yesterday through the UM Office of Tech Transfer; it was signed by Bryce Pilz (bpilz@umich.edu). My UMich email is kevjsung@umich.edu. The Authorized Contributors Group email address is "um-contributors-to-openfermion@googlegroups.com".

This is just a minor fix to a bug that I found. I added a test that the original code fails, and I fixed the bug.

googlebot: Thanks for your pull request.  It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

:memo: **Please visit <https://cla.developers.google.com/> to sign.**

Once you've signed, please reply here (e.g. `I signed it!`) and we'll verify.  Thanks.

---

- If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address.  Check [your existing CLA data](https://cla.developers.google.com/clas) and verify that your [email is set on your git commits](https://help.github.com/articles/setting-your-email-in-git/).
- If your company signed a CLA, they designated a Point of Contact who decides which employees are authorized to participate. You may need to contact the Point of Contact for your company and ask to be added to the group of authorized contributors. If you don't know who your Point of Contact is, direct the project maintainer to go/cla#troubleshoot.
- In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again.

<!-- need_sender_cla -->
kevinsung: I signed it!
babbush: Thanks for the contribution Kevin! Yes, if you added the email that is associated with your github account that should be enough. Normally that is enough for the CLA bot to be happy. I can look at the CLAs we have on file in a few hours to try to figure out what is going on in your case. We'll figure it out!
babbush: Kevin, I think the issue might be with the group CLA. Usually people (even those working for other companies and in academia) sign the individual CLA (which can still cover contributions made on behalf of your employer). Are you able to sign the individual CLA? If so, I think that might fix the problem.
kevinsung: Ok I just signed an individual agreement.
googlebot: So there's good news and bad news.

:thumbsup: The good news is that everyone that needs to sign a CLA (the pull request submitter and all commit authors) have done so.  Everything is all good there.

:confused: The bad news is that it appears that one or more commits were authored by someone other than the pull request submitter.  We need to confirm that they're okay with their commits being contributed to this project.  Please have them confirm that here in the pull request.

*Note to project maintainer: This is a terminal state, meaning the `cla/google` commit status will not change from this State. It's up to you to confirm consent of the commit author(s) and merge this pull request when appropriate.*

<!-- need_author_consent -->
babbush: Hmm, from the looks of this Kevin's CLA is good to go but perhaps Ian needs to comment here for things to get approved. Sorry this is so complicated!
idk3: @googlebot I'm OK with this

Patch:
diff --git a/src/openfermion/utils/_hubbard.py b/src/openfermion/utils/_hubbard.py
index 84a5893..ec3167a 100644
--- a/src/openfermion/utils/_hubbard.py
+++ b/src/openfermion/utils/_hubbard.py
@@ -126,12 +126,12 @@ def fermi_hubbard(x_dimension, y_dimension, tunneling, coulomb,
         right_neighbor = site + 1
         bottom_neighbor = site + x_dimension
 
-        # Account  periodic boundaries.
+        # Account for periodic boundaries.
         if periodic:
             if (x_dimension > 2) and ((site + 1) % x_dimension == 0):
                 right_neighbor -= (x_dimension - 1)
             if (y_dimension > 2) and (site + x_dimension + 1 > n_sites):
-                bottom_neighbor -= (x_dimension - 1) * y_dimension
+                bottom_neighbor -= x_dimension * y_dimension
 
         # Add transition to neighbor on right.
         if (site + 1) % x_dimension or (periodic and x_dimension > 2):


Test patch:
diff --git a/src/openfermion/utils/_hubbard_test.py b/src/openfermion/utils/_hubbard_test.py
index d6ee321..8eabe1b 100644
--- a/src/openfermion/utils/_hubbard_test.py
+++ b/src/openfermion/utils/_hubbard_test.py
@@ -101,3 +101,13 @@ class FermiHubbardTest(unittest.TestCase):
             self.x_dimension, self.y_dimension, self.tunneling, self.coulomb,
             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,
+            self.chemical_potential, self.magnetic_field,
+            periodic=True, spinless=True)
+        # Check up top/bottom hopping terms.
+        self.assertAlmostEqual(hubbard_model.terms[((4, 1), (0, 0))],
+                               -self.tunneling)