____________________________________________ test_current_interpolation ____________________________________________
def test_current_interpolation():
## Passing a Builder will raise an error
pytest.raises(TypeError, plotter.interpolate_current, syst_2d(), None)
def R(theta):
return ta.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])
def make_lattice(a, theta):
x = ta.dot(R(theta), (a, 0))
y = ta.dot(R(theta), (0, a))
return kwant.lattice.general([x, y], norbs=1)
_test_border_0(plotter.interpolate_current)
## Check current through cross section is same for different lattice
## parameters and orientations of the system wrt. the discretization grid
for a, theta, width in [(1, 0, 1),
(1, 0, 0.5),
(2, 0, 1),
(1, 0.2, 1),
(2, 0.4, 1)]:
lat = make_lattice(a, theta)
syst = syst_rect(lat, salt='0').finalized()
psi = kwant.wave_function(syst, energy=3)(0)
def cut(a, b):
return b.tag[0] < 0 and a.tag[0] >= 0
J = kwant.operator.Current(syst).bind()
J_cut = kwant.operator.Current(syst, where=cut, sum=True).bind()
J_exact = J_cut(psi[0])
data = []
for n in [4, 6, 8, 11, 16]:
j0, box = plotter.interpolate_current(syst, J(psi[0]),
n=n, abswidth=width)
x, y = (np.linspace(mn, mx, shape)
for (mn, mx), shape in zip(box, j0.shape))
# slice field perpendicular to a cut along the y axis
y_axis = (np.argmin(np.abs(x)), slice(None), 0)
J_interp = scipy.integrate.simps(j0[y_axis], y)
data.append((n, abs(J_interp - J_exact)))
# 3rd value returned from 'linregress' is 'rvalue'
assert scipy.stats.linregress(np.log(data))[2] < -0.8
### Tests on a divergence-free current (closed system)
lat = kwant.lattice.general([(1, 0), (0.5, np.sqrt(3) / 2)])
syst = kwant.Builder()
sites = [lat(0, 0), lat(1, 0), lat(0, 1), lat(2, 2)]
syst[sites] = None
syst[((s, t) for s, t in itertools.product(sites, sites) if s != t)] = None
del syst[lat(0, 0), lat(2, 2)]
syst = syst.finalized()
# generate random divergence-free currents
> Js = rotational_currents(syst.graph)
kwant/tests/test_plotter.py:483:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
kwant/tests/test_plotter.py:326: in rotational_currents
perm = scipy.sparse.coo_matrix((perm_data, perm_ij))
/home/jbw/.local/miniconda/envs/kwant-latest/lib/python3.6/site-packages/scipy/sparse/coo.py:150: in __init__
self._shape = check_shape((M, N))
/home/jbw/.local/miniconda/envs/kwant-latest/lib/python3.6/site-packages/scipy/sparse/sputils.py:281: in check_shape
new_shape = tuple(operator.index(arg) for arg in args)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
.0 = <tuple_iterator object at 0x7fc1707c5588>
> new_shape = tuple(operator.index(arg) for arg in args)
E TypeError: 'numpy.float64' object cannot be interpreted as an integer