Skip to content

Commit

Permalink
fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
austingmhuang committed Sep 20, 2024
1 parent 0d49388 commit 3cfbe56
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 3 deletions.
2 changes: 1 addition & 1 deletion pennylane/spin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@
fermi_hubbard,
heisenberg,
kitaev,
spin_hamiltonian,
transverse_ising,
custom_hamiltonian_from_lattice,
)
26 changes: 24 additions & 2 deletions tests/spin/test_spin_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
from pennylane import I, X, Y, Z
from pennylane.spin import (
Lattice,
custom_hamiltonian_from_lattice,
fermi_hubbard,
heisenberg,
kitaev,
transverse_ising,
spin_hamiltonian
)

pytestmark = pytest.mark.usefixtures("new_opmath_only")
Expand Down Expand Up @@ -907,10 +907,32 @@ def test_kitaev_hamiltonian(n_cells, j, boundary_condition, expected_ham):
),
),
],
("lattice", "expected_ham"),
[
(
Lattice(
n_cells=[2, 2],
vectors=[[1, 0], [0, 1]],
positions=[[0, 0], [1, 5]],
boundary_condition=False,
custom_edges=[[(0, 1), ("XX", 0.5)], [(1, 2), ("YY", 0.6)], [(1, 4), ("ZZ", 0.7)]],
),
(
0.5 * (X(0) @ X(1))
+ 0.5 * (X(2) @ X(3))
+ 0.5 * (X(4) @ X(5))
+ 0.5 * (X(6) @ X(7))
+ 0.6 * (Y(1) @ Y(2))
+ 0.6 * (Y(5) @ Y(6))
+ 0.7 * (Z(1) @ Z(4))
+ 0.7 * (Z(3) @ Z(6))
),
),
],
)
def test_custom_hamiltonian(lattice, expected_ham):
r"""Test that the correct Hamiltonian is generated"""
custom_ham = custom_hamiltonian_from_lattice(lattice=lattice)
custom_ham = spin_hamiltonian(lattice=lattice)

qml.assert_equal(custom_ham, expected_ham)

Expand Down

0 comments on commit 3cfbe56

Please sign in to comment.