Skip to content

Commit

Permalink
Merge pull request #88 from RichRick1/website
Browse files Browse the repository at this point in the history
add tests
  • Loading branch information
RichRick1 authored Apr 15, 2024
2 parents 786d639 + da32f0a commit d0a1f63
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 0 deletions.
10 changes: 10 additions & 0 deletions docs/spin.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,13 @@ Spin-based Hamiltonians
:members:

.. automethod:: __init__

.. autoclass:: moha.HamIsing
:members:

.. automethod:: __init__

.. autoclass:: moha.HamRG
:members:

.. automethod:: __init__
66 changes: 66 additions & 0 deletions moha/test/test_Heisenberg.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,69 @@ def test_heisenberg_2_spin():
for i, j, k, l in zip(*inds):
print(i, j, k, l, v[i, j, k, l], v_exact[i, j, k, l])
assert_allclose(v, v_exact)


def test_Ising():
n_sites = 8
J_xy = 0
J_z = np.random.rand()
connectivity = np.zeros((n_sites, n_sites))
for i in range(n_sites):
j = i+1
if j == n_sites:
j = 0
connectivity[i, j] = 1
connectivity[j, i] = 1

v_exact = np.zeros((n_sites, n_sites, n_sites, n_sites))
for i in range(n_sites):
j = i+1
if j == n_sites:
j = 0

v_exact[j, j, i, i] = J_z/4
v_exact[i, i, j, j] = J_z/4

v_exact[j, i, j, i] = J_xy/2
v_exact[i, j, i, j] = J_xy/2

ham = HamIsing(J_ax=J_z, mu=0, connectivity=connectivity)
v = ham.generate_two_body_integral(basis='spatial basis',
dense=True,
sym=4)
# convert to chemists notation
v = np.transpose(v, (0, 2, 1, 3))
assert_allclose(v, v_exact)


def test_RG():
n_sites = 8
J_xy = np.random.rand()
J_z = 0
connectivity = np.zeros((n_sites, n_sites))
for i in range(n_sites):
j = i+1
if j == n_sites:
j = 0
connectivity[i, j] = 1
connectivity[j, i] = 1

v_exact = np.zeros((n_sites, n_sites, n_sites, n_sites))
for i in range(n_sites):
j = i+1
if j == n_sites:
j = 0

v_exact[j, j, i, i] = J_z/4
v_exact[i, i, j, j] = J_z/4

v_exact[j, i, j, i] = J_xy/2
v_exact[i, j, i, j] = J_xy/2

ham = HamRG(J_eq=J_xy, mu=0, connectivity=connectivity)
v = ham.generate_two_body_integral(basis='spatial basis',
dense=True,
sym=4)
# convert to chemists notation
v = np.transpose(v, (0, 2, 1, 3))
assert_allclose(v, v_exact)

0 comments on commit d0a1f63

Please sign in to comment.