Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
  • kwant/kwant
  • jbweston/kwant
  • anton-akhmerov/kwant
  • cwg/kwant
  • Mathieu/kwant
  • slavoutich/kwant
  • pacome/kwant
  • behrmann/kwant
  • michaelwimmer/kwant
  • albeercik/kwant
  • eunjongkim/kwant
  • basnijholt/kwant
  • r-j-skolasinski/kwant
  • sahmed95/kwant
  • pablopiskunow/kwant
  • mare/kwant
  • dvarjas/kwant
  • Paul/kwant
  • bbuijtendorp/kwant
  • tkloss/kwant
  • torosdahl/kwant
  • kel85uk/kwant
  • kpoyhonen/kwant
  • Fromeworld/kwant
  • quaeritis/kwant
  • marwahaha/kwant
  • fernandodfufrpe/kwant
  • oly/kwant
  • jiamingh/kwant
  • mehdi2369/kwant
  • ValFadeev/kwant
  • Kostas/kwant
  • chelseabaptiste03/kwant
33 results
Show changes
......@@ -20,36 +20,12 @@ from . import builder, system, plotter
from .linalg import lll
from .builder import herm_conj, HermConjOfFunc
from .lattice import TranslationalSymmetry
from ._common import get_parameters
from ._common import get_parameters, memoize
__all__ = ['wraparound', 'plot_2d_bands']
def _hashable(obj):
return isinstance(obj, collections.abc.Hashable)
def _memoize(f):
"""Decorator to memoize a function that works even with unhashable args.
This decorator will even work with functions whose args are not hashable.
The cache key is made up by the hashable arguments and the ids of the
non-hashable args. It is up to the user to make sure that non-hashable
args do not change during the lifetime of the decorator.
This decorator will keep reevaluating functions that return None.
"""
def lookup(*args):
key = tuple(arg if _hashable(arg) else id(arg) for arg in args)
result = cache.get(key)
if result is None:
cache[key] = result = f(*args)
return result
cache = {}
return lookup
def _set_signature(func, params):
"""Set the signature of 'func'.
......@@ -103,7 +79,7 @@ def wraparound(builder, keep=None, *, coordinate_names='xyz'):
format. It will be deprecated in the 2.0 release of Kwant.
"""
@_memoize
@memoize
def bind_site(val):
def f(*args):
a, *args = args
......@@ -113,7 +89,7 @@ def wraparound(builder, keep=None, *, coordinate_names='xyz'):
_set_signature(f, get_parameters(val) + momenta)
return f
@_memoize
@memoize
def bind_hopping_as_site(elem, val):
def f(*args):
a, *args = args
......@@ -128,7 +104,7 @@ def wraparound(builder, keep=None, *, coordinate_names='xyz'):
_set_signature(f, params + momenta)
return f
@_memoize
@memoize
def bind_hopping(elem, val):
def f(*args):
a, b, *args = args
......@@ -142,7 +118,7 @@ def wraparound(builder, keep=None, *, coordinate_names='xyz'):
_set_signature(f, params + momenta)
return f
@_memoize
@memoize
def bind_sum(num_sites, *vals):
"""Construct joint signature for all 'vals'."""
......@@ -386,10 +362,14 @@ def plot_2d_bands(syst, k_x=31, k_y=31, params=None,
if not hasattr(syst, '_wrapped_symmetry'):
raise TypeError("Expecting a system that was produced by "
"'kwant.wraparound.wraparound'.")
if not isinstance(syst, system.FiniteSystem):
if isinstance(syst, system.InfiniteSystem):
msg = ("All symmetry directions must be wrapped around: specify "
"'keep=None' when calling 'kwant.wraparound.wraparound'.")
raise TypeError(msg)
if isinstance(syst, builder.Builder):
msg = ("Expecting a finalized system: remember to finalize your "
"system with 'syst.finalized()'.")
raise TypeError(msg)
params = params or {}
lat_ndim, space_ndim = syst._wrapped_symmetry.periods.shape
......
[pytest]
testpaths = kwant
flakes-ignore =
__init__.py UnusedImport
__init__.py UnusedImport ImportStarUsed ImportStarUsage
kwant/_plotter.py UnusedImport
graph/tests/test_scotch.py UndefinedName
graph/tests/test_dissection.py UndefinedName
......@@ -517,7 +517,7 @@ def maybe_add_numpy_include(exts):
def main():
check_python_version((3, 5))
check_python_version((3, 6))
check_versions()
exts = collections.OrderedDict([
......@@ -581,12 +581,12 @@ def main():
'build_ext': build_ext,
'test': test},
ext_modules=exts,
install_requires=['numpy >= 1.11.0', 'scipy >= 0.17.0',
install_requires=['numpy >= 1.13.3', 'scipy >= 0.19.1',
'tinyarray >= 1.2'],
extras_require={
# The oldest versions between: Debian stable, Ubuntu LTS
'plotting': 'matplotlib >= 1.5.1',
'continuum': 'sympy >= 0.7.6',
'plotting': 'matplotlib >= 2.1.1',
'continuum': 'sympy >= 1.1.1',
# qsymm is only packaged on PyPI
'qsymm': 'qsymm >= 1.2.6',
},
......