Commit 0d5600c9 authored by Christoph Groth's avatar Christoph Groth
Browse files

restore compatibility with future Kwant 1.4.1

Kwant 1.4.1 is required because 1.4.0 does not accept value functions
that take *args.

tkwant.leads exposes functions/classes that take a 'params' argument.
Setting this to anything else than the default 'None' currently does not
work with Kwant 1.4 (it should continue to work with Kwant 1.3).  This
problem will be resolved once tkwant is rewritten to no longer use
Kwant's args mechanism internally.
parent 3ae5dce5
......@@ -49,16 +49,32 @@ def extract_matrix_elements(syst):
(int, int)
The site indices of the matrix elements that depend on time.
"""
# TODO: remove Kwant <=1.3 compatibility once it's no longer deemed
# necessary.
kwant_14_or_newer = hasattr(syst, 'onsites')
# Get onsites first
for i, (onsite, _) in enumerate(syst.onsites):
if callable(onsite) and getattr(onsite, _time_dependent, False):
yield (i, i)
if kwant_14_or_newer:
for i, (onsite, _) in enumerate(syst.onsites):
if callable(onsite) and getattr(onsite, _time_dependent, False):
yield (i, i)
else:
for i, onsite in enumerate(syst.onsite_hamiltonians):
if callable(onsite) and getattr(onsite, _time_dependent, False):
yield (i, i)
# Now the hoppings -- half of the edges store "kwant.builder.Other", which
# means that we will only store the actual hoppings we need to evaluate.
for edge_id, hopping in enumerate(syst.graph):
hop_val, _ = syst.hoppings[edge_id]
if callable(hop_val) and getattr(hop_val, _time_dependent, False):
yield hopping
if kwant_14_or_newer:
for edge_id, hopping in enumerate(syst.graph):
hop_val, _ = syst.hoppings[edge_id]
if callable(hop_val) and getattr(hop_val, _time_dependent, False):
yield hopping
else:
for edge_id, hopping in enumerate(syst.graph):
hop_val = syst.hoppings[edge_id]
if callable(hop_val) and getattr(hop_val, _time_dependent, False):
yield hopping
# TODO: this only works for finalized builders so far -- how to extend
......
......@@ -302,8 +302,8 @@ def test_absorbing_reflection_solver():
x = site.pos[0]
return - 1j / L * (degree + 1) * strength * (x / L)**degree
def onsite(*args, **kwargs):
return 2 * gamma + aborbing_potential(*args, **kwargs)
def onsite(*args):
return 2 * gamma + aborbing_potential(*args)
lat = kwant.lattice.square(a=a, norbs=1)
syst = kwant.Builder()
......@@ -335,7 +335,7 @@ def test_absorbing_reflection_solver():
# note that the lead is not involved in this calculation but only syst
def reflection(syst, E, A, n):
return np.sqrt(kwant.smatrix(syst, E, check_hermiticity=False,
params={'strength': A, 'degree': n}).transmission(0, 0))
args=(A, n)).transmission(0, 0))
refl_ref = [reflection(syst, energy, strength, degree) for energy in energies]
assert_array_almost_equal(refl, refl_ref)
......
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