Skip to content
Snippets Groups Projects
Commit b0211f10 authored by Rafal Skolasinski's avatar Rafal Skolasinski Committed by Joseph Weston
Browse files

take site position from underlying discretizer lattice

Previously we were manually computing the position from
the site tag an an extra 'grid_spacing' parameter. Even
though we now have one additional Python function call,
using the position as determined by the underlying lattice
is less susceptible to bugs.

Closes #199.
parent 19c7e943
No related branches found
No related tags found
No related merge requests found
Pipeline #11197 passed with warnings
......@@ -582,16 +582,13 @@ def _return_string(expr, coords):
return 'return {}'.format(output), map_func_calls, const_symbols, _cache
def _assign_symbols(map_func_calls, grid_spacing,
coords, onsite):
def _assign_symbols(map_func_calls, coords, onsite):
"""Generate a series of assignments.
Parameters
----------
map_func_calls : dict
mapping of function calls to assigned constants.
grid_spacing : int or float
Used to get site.pos from site.tag
coords : sequence of strings
If left as None coordinates will not be read from a site.
onsite : bool
......@@ -606,8 +603,8 @@ def _assign_symbols(map_func_calls, grid_spacing,
if coords:
site = 'site' if onsite else 'site1'
args = ', '.join(coords), str(grid_spacing), site
lines.append('({}, ) = {} * {}.tag'.format(*args))
args = ', '.join(coords), site
lines.append('({}, ) = {}.pos'.format(*args))
for k, v in map_func_calls.items():
lines.append("{} = {}".format(v, _print_sympy(k)))
......@@ -667,10 +664,7 @@ def _builder_value(expr, coords, grid_spacing, onsite,
else:
return complex(expr)
lines = _assign_symbols(map_func_calls, onsite=onsite,
grid_spacing=grid_spacing,
coords=coords)
lines = _assign_symbols(map_func_calls, onsite=onsite, coords=coords)
lines.append(return_string)
separator = '\n '
......
......@@ -563,6 +563,16 @@ def test_grid_input(ham, grid_offset, offset, norbs):
assert tmp.lattice.norbs == norbs
def test_grid_offset_passed_to_functions():
V = lambda x: x
grid = Monatomic([[1, ]], offset=[0.5, ])
tb = discretize('V(x)', 'x', grid=grid)
onsite = tb[tb.lattice(0)]
bools = [np.allclose(onsite(tb.lattice(i), V), V(tb.lattice(i).pos))
for i in [0, 1, 5]]
assert all(bools)
@pytest.mark.parametrize("ham, coords, grid", [
("k_x", None, Monatomic([[1, 0]])),
("k_x", 'xy', Monatomic([[1, 0]])),
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment