wraparound: cryptic error message when k_x, k_y, ... not provided
Evaluating the Hamiltonian of a wrapped-around system without providing the required momenta parameters leads to an error message that is inscrutable even for advanced users of Kwant. For example, executing the following piece of code (only the last line differs from https://kwant-project.org/doc/1/pre/whatsnew/1.3#finalizing-builders-with-multiple-translational-symmetries)
from matplotlib import pyplot
import kwant
lat = kwant.lattice.honeycomb()
sym = kwant.TranslationalSymmetry(lat.vec((1, 0)), lat.vec((0, 1)))
bulk = kwant.Builder(sym)
bulk[ [lat.a(0, 0), lat.b(0, 0)] ] = 0
bulk[lat.neighbors()] = 1
wrapped = kwant.wraparound.wraparound(bulk).finalized()
ham = wrapped.hamiltonian_submatrix()
The above code can be fixed by changing the last line to
ham = wrapped.hamiltonian_submatrix(params=dict(k_x=0, k_y=0))
but the problem is the unhelpful error message produced by the original snippet:
/home/cwg/wo/11/kwant-src/kwant/lattice.py:120: KwantDeprecationWarning: Not specfying norbs is deprecated. Always specify norbs when creating site families.
self.sublattices = [Monatomic(prim_vecs, offset, sname, norb)
Traceback (most recent call last):
File "/home/cwg/wo/11/kwant-src/kwant/builder.py", line 1815, in hamiltonian
value = value(site_i, site_j, *args)
File "/home/cwg/wo/11/kwant-src/kwant/wraparound.py", line 135, in f
acc = acc + val(*out_args)
File "/home/cwg/wo/11/kwant-src/kwant/wraparound.py", line 115, in f
phase = cmath.exp(1j * ta.dot(elem, args[mnp:]))
TypeError: Expecting a number.
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/home/cwg/wo/11/kwant-src/test2.py", line 11, in <module>
ham = wrapped.hamiltonian_submatrix()
File "/home/cwg/wo/11/kwant-src/kwant/_common.py", line 73, in inner
return f(*args, **kwargs)
File "kwant/_system.pyx", line 324, in kwant._system.hamiltonian_submatrix
mat = func(ham, args, params, self.graph, diag, to_norb, to_off,
File "kwant/_system.pyx", line 223, in kwant._system.make_dense_full
h = mat = matrix(ham(ts, fs, *args, params=params), complex)
File "/home/cwg/wo/11/kwant-src/kwant/builder.py", line 1823, in hamiltonian
_raise_user_error(exc, value)
File "/home/cwg/wo/11/kwant-src/kwant/builder.py", line 1719, in _raise_user_error
raise UserCodeError(msg.format(func.__name__)) from exc
kwant._common.UserCodeError: Error occurred in user-supplied value function "f".
See the upper part of the above backtrace for more information.