Skip to content
Snippets Groups Projects
Commit 3bb749eb authored by Joseph Weston's avatar Joseph Weston
Browse files

change TranslationalSymmetry.act() to reject non-integer input

Previously, if a tuple of floats was passed as the 'domain' argument to
'act' then the tags of the resulting sites would be floats, rather than
integers. This is because the tags of sites created inside 'act' were
not normalized to integers, as they would usually be, and this causes
bugs in other locations where an integer dtype is assumed.
parent 2ae8a8d6
Branches
Tags
No related merge requests found
......@@ -693,6 +693,9 @@ class TranslationalSymmetry(builder.Symmetry):
return -result if self.is_reversed else result
def act(self, element, a, b=None):
element = ta.array(element)
if element.dtype is not int:
raise ValueError("group element must be a tuple of integers")
m_part = self._get_site_family_data(a.family)[0]
try:
delta = ta.dot(m_part, element)
......
......@@ -232,6 +232,25 @@ def test_norbs():
assert lat1 != lat2
def test_symmetry_act():
lat = lattice.square()
sym = lattice.TranslationalSymmetry((1, 0), (0, 1))
site = lat(0, 0)
hopping = (lat(0, 0), lat(1, 0))
el = (1, 0)
# Verify that the dtype of tags of sites returned by 'act' is 'int'
for el in [el, ta.array(el, int)]:
assert sym.act(el, site).tag.dtype is int
assert all(s.tag.dtype is int for s in sym.act(el, *hopping))
for el in [(1.0, 0), (1.5, 0)]:
with raises(ValueError):
sym.act(el, site)
with raises(ValueError):
sym.act(ta.array(el), site)
def test_symmetry_subgroup():
rng = np.random.RandomState(0)
## test whether actual subgroups are detected as such
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment