Commit 141688ec authored by Christoph Groth's avatar Christoph Groth

Merge branch 'stable'

parents 1f830ce0 84d1e87f
Pipeline #12296 passed with stages
in 15 minutes and 29 seconds
......@@ -1463,6 +1463,14 @@ class Builder:
if start and not isinstance(start[0], Site):
start = [template.closest(start)]
if any(s not in template for s in start):
warnings.warn("fill(): Some of the starting sites are "
"not in the template builder.",
RuntimeWarning, stacklevel=2)
start = [s for s in start if s in template]
if not start:
return []
try:
# "Active" are sites (mapped to the target's FD) that have been
# verified to lie inside the shape, have been added to the target
......@@ -1553,9 +1561,9 @@ class Builder:
self.H = {}
# Re-raise the exception with an additional message.
msg = ("All sites of this builder have been deleted because an "
"exception\noccurred during the execution of fill():")
e.args = ('\n'.join((msg,) + e.args),)
raise
"exception\noccurred during the execution of fill(): "
"see above.")
raise RuntimeError(msg) from e
return done
......
......@@ -206,7 +206,7 @@ def discretize_symbolic(hamiltonian, coords=None, *, locals=None):
if len(coords) == 0:
raise ValueError("Failed to read any discrete coordinates. This is "
"probably due to a lack of momentum operators in "
"your input. You can use the 'coords'"
"your input. You can use the 'coords' "
"parameter to provide them.")
onsite_zeros = (0,) * len(coords)
......
......@@ -684,7 +684,7 @@ def test_fill():
assert (set(clone.hopping_value_pairs())
== set(orig.hopping_value_pairs()))
## Test for warning when "start" is out.
## Test for warning when "start" is outside the filling shape.
target = builder.Builder()
for start in [(-101, 0), (101, 0)]:
with warns(RuntimeWarning):
......@@ -732,7 +732,6 @@ def test_fill():
assert sorted(target.sites()) == sorted(should_be_syst.sites())
assert sorted(target.hoppings()) == sorted(should_be_syst.hoppings())
## test multiplying unit cell size in 2D
template_2d = builder.Builder(sym_xy)
template_2d[g(0, 0)] = None
......@@ -752,7 +751,6 @@ def test_fill():
assert sorted(target.sites()) == sorted(should_be_syst.sites())
assert sorted(target.hoppings()) == sorted(should_be_syst.hoppings())
## test filling 0D builder with 2D builder
def square_shape(site):
x, y = site.tag
......@@ -790,6 +788,22 @@ def test_fill():
assert len(new_sites) == 1
assert to_target_fd(new_sites[0]) == to_target_fd(lat(-1))
# Test for warning with an empty template
template = builder.Builder(kwant.TranslationalSymmetry((-1,)))
target = builder.Builder()
with warns(RuntimeWarning):
target.fill(template, lambda x: True, lat(0))
# Test for warning when one of the starting sites is outside the template
lat = kwant.lattice.square()
template = builder.Builder(kwant.TranslationalSymmetry((-1, 0)))
template[lat(0, 0)] = None
template[lat.neighbors()] = None
target = builder.Builder()
with warns(RuntimeWarning):
target.fill(template, lambda x: -1 < x.pos[0] < 1,
[lat(0, 0), lat(0, 1)])
def test_fill_sticky():
"""Test that adjacent regions are properly interconnected when filled
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment