diff --git a/TODO b/TODO index e815e850861bc07d264a9f2228c06812dd5005d6..b9a4746610b707bf6e29788c11d74cd78923a64f 100644 --- a/TODO +++ b/TODO @@ -99,7 +99,7 @@ Roughly in order of importance. -*-org-*- * Adopt mincut/maxflow algorithm from networkx or python-graph to find the best representation of a lead unit cell. -* Speed up kwant.contrib.digest +* Speed up kwant.digest by using SipHash and Ziggurat algorithm in C/Cython * Improve finding of modes with zero velocity or infinite decay length diff --git a/doc/source/contrib/digest.rst b/doc/source/contrib/digest.rst deleted file mode 100644 index ee3460b9533a419f6d495a450b2e8ecd7fb3e5d1..0000000000000000000000000000000000000000 --- a/doc/source/contrib/digest.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`kwant.contrib.digest` -- Random-access random numbers -=========================================================== - -.. automodule:: kwant.contrib.digest - :members: diff --git a/doc/source/contrib/index.rst b/doc/source/contrib/index.rst deleted file mode 100644 index 67c11ab22e74568cbbdef340627fe5a1510764a3..0000000000000000000000000000000000000000 --- a/doc/source/contrib/index.rst +++ /dev/null @@ -1,20 +0,0 @@ -Contributed modules -=================== - -.. module:: kwant.contrib - -:mod:`kwant.contrib` is a collection of independent modules that is part of the -official Kwant distribution, but is not considered to be an integral part of -Kwant. The intention is to keep interesting modules that are useful with Kwant -here (maybe even experimental ones) to give users an easier access to them, and -them wider exposure. Users of Kwant are welcome to submit their own modules for -inclusion. - -For simplicity, all contributions share the same license as Kwant. (This -requirement may be relaxed to allow other free licenses if requested.) - -.. toctree:: - :maxdepth: 1 - - digest - rmt diff --git a/doc/source/contrib/rmt.rst b/doc/source/contrib/rmt.rst deleted file mode 100644 index 929b791650b1e9a0fdfea5f096ff8fb67c28f974..0000000000000000000000000000000000000000 --- a/doc/source/contrib/rmt.rst +++ /dev/null @@ -1,5 +0,0 @@ -:mod:`kwant.contrib.rmt` -- RMT (random matrix theory) Hamiltonians -=================================================================== - -.. automodule:: kwant.contrib.rmt - :members: diff --git a/doc/source/index.rst b/doc/source/index.rst index 270cbde2b2110938d201cfd4e24f943975627e46..d0bf73f31a1ac5f76885dd56b51ae01e134d1747 100644 --- a/doc/source/index.rst +++ b/doc/source/index.rst @@ -17,26 +17,9 @@ that have developed it <authors>`. license authors acknowledgements - -.. toctree:: - :maxdepth: 1 - whatsnew/index install - -.. toctree:: - :maxdepth: 2 - tutorial/index - -.. toctree:: - :maxdepth: 2 - reference/index -.. toctree:: - :maxdepth: 2 - - contrib/index - * :ref:`genindex` diff --git a/doc/source/reference/index.rst b/doc/source/reference/index.rst index 1c54208857b03f7d7805266d32672b60f0e656b3..95fdcf47b0cc3685b6652325bcffebd9073a23e7 100644 --- a/doc/source/reference/index.rst +++ b/doc/source/reference/index.rst @@ -1,8 +1,8 @@ Reference guide =============== -In the following, all Kwant modules appear in the order of decreasing end-user -relevance. +Core modules of Kwant, appearing in the order of decreasing +end-user relevance. .. toctree:: :maxdepth: 1 @@ -14,5 +14,19 @@ relevance. kwant.solvers kwant.physics kwant.system + +Miscellaneous modules for special applications. + +.. toctree:: + :maxdepth: 1 + + kwant.digest + kwant.rmt + +Modules mainly for internal use. + +.. toctree:: + :maxdepth: 1 + kwant.graph kwant.linalg diff --git a/doc/source/reference/kwant.digest.rst b/doc/source/reference/kwant.digest.rst new file mode 100644 index 0000000000000000000000000000000000000000..ae9a724c5c8b591fe3aaea6a1c56aa2e9645ec84 --- /dev/null +++ b/doc/source/reference/kwant.digest.rst @@ -0,0 +1,5 @@ +:mod:`kwant.digest` -- Random-access random numbers +=================================================== + +.. automodule:: kwant.digest + :members: diff --git a/doc/source/reference/kwant.rmt.rst b/doc/source/reference/kwant.rmt.rst new file mode 100644 index 0000000000000000000000000000000000000000..eb94c209b02923dff913c6fd2492f49fa4c2126c --- /dev/null +++ b/doc/source/reference/kwant.rmt.rst @@ -0,0 +1,5 @@ +:mod:`kwant.rmt` -- Random matrix theory Hamiltonians +===================================================== + +.. automodule:: kwant.rmt + :members: diff --git a/doc/source/whatsnew/1.0.rst b/doc/source/whatsnew/1.0.rst index c9a3bc69e6e6aabdfea195efa13937c9865d0014..15bbde16bbbc01c60ce95a4bf711bc7722a635bd 100644 --- a/doc/source/whatsnew/1.0.rst +++ b/doc/source/whatsnew/1.0.rst @@ -179,10 +179,19 @@ the `lead_info` attribute of `~kwant.solvers.common.SMatrix` contains the real space information about the modes in the leads (a list of `~kwant.physics.PropagatingModes` objects). -Inclusion of contributed modules --------------------------------- -Kwant now contains a sub-package :mod:`kwant.contrib` that contains various -modules that are useful with Kwant but are not considered to be part of it. +New module for random-access random numbers +------------------------------------------- +The module `kwant.digest` provides functions that given some input compute a +"random" output that depends on the input in a (cryptographically) intractable +way. This functionality is useful for introducing disorder, e.g.:: + + def onsite(site): + return 0.3 * kwant.digest.gauss(repr(site)) + 4 + +New module for random matrix theory Hamiltonians +------------------------------------------------ +The module `kwant.rmt` supports the creation of random matrix theory +Hamiltonians. Improved plotting functionality ------------------------------- diff --git a/kwant/__init__.py b/kwant/__init__.py index ad89ef0b1e5498078a978fc4a1c83f3cff57a133..fbd14a0572cf41d756b22bf0d8a01df494790725 100644 --- a/kwant/__init__.py +++ b/kwant/__init__.py @@ -6,7 +6,8 @@ # the AUTHORS file at the top-level directory of this distribution and at # http://kwant-project.org/authors. -__all__ = ['system', 'version', 'builder', 'lattice', 'solvers'] +__all__ = ['system', 'version', 'builder', 'lattice', 'solvers', + 'digest', 'rmt'] for module in __all__: exec 'from . import {0}'.format(module) diff --git a/kwant/contrib/__init__.py b/kwant/contrib/__init__.py deleted file mode 100644 index ac63bbcdd045fe61b03990d369ff86adff438561..0000000000000000000000000000000000000000 --- a/kwant/contrib/__init__.py +++ /dev/null @@ -1,13 +0,0 @@ -# Copyright 2011-2013 Kwant authors. -# -# This file is part of Kwant. It is subject to the license terms in the -# LICENSE file found in the top-level directory of this distribution and at -# http://kwant-project.org/license. A list of Kwant authors can be found in -# the AUTHORS file at the top-level directory of this distribution and at -# http://kwant-project.org/authors. - -"""This package contains various sub-packages that are useful with Kwant, but -are not considered to be a part of it. - -The sub-packages have to be imported explicitly. -""" diff --git a/kwant/contrib/tests/__init__.py b/kwant/contrib/tests/__init__.py deleted file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..0000000000000000000000000000000000000000 diff --git a/kwant/contrib/digest.py b/kwant/digest.py similarity index 89% rename from kwant/contrib/digest.py rename to kwant/digest.py index ef338a475dca5f7d8df5599f94032664d58f8e3f..014ec63d563e0d76b36afd04c5a51c6bab6c77ff 100644 --- a/kwant/contrib/digest.py +++ b/kwant/digest.py @@ -25,7 +25,7 @@ from math import pi, log, sqrt, sin, cos from hashlib import md5 from struct import unpack -__all__ = ['digest', 'gauss', 'test'] +__all__ = ['uniform', 'gauss', 'test'] TWOPI = 2 * pi @@ -34,7 +34,7 @@ BPF_MASK = 2**53 - 1 RECIP_BPF = 2**-BPF -def digest2(input, salt=''): +def uniform2(input, salt=''): """Return two independent [0,1)-distributed numbers.""" input = memoryview(input).tobytes() + salt a, b = unpack('qq', md5(input).digest()) @@ -43,13 +43,13 @@ def digest2(input, salt=''): return a * RECIP_BPF, b * RECIP_BPF -def digest(input, salt=''): +def uniform(input, salt=''): """md5-hash `input` and `salt` and map the result to the [0,1) interval. `input` must be some object that supports the buffer protocol (i.e. a string or a numpy/tinyarray array). `salt` must be a string or a bytes object. """ - return digest2(input, salt)[0] + return uniform2(input, salt)[0] def gauss(input, salt=''): @@ -61,12 +61,12 @@ def gauss(input, salt=''): """ # This uses the Box-Muller transform. Only one of the two results is # computed. - a, b = digest2(input, salt) + a, b = uniform2(input, salt) return cos(a * TWOPI) * sqrt(-2.0 * log(1.0 - b)) def test(n=20000): - """Test func with the dieharder suite generating n**2 samples. + """Test the generator with the dieharder suite generating n**2 samples. Executing this function may take a very long time. """ @@ -81,7 +81,7 @@ def test(n=20000): for x in xrange(n): for y in xrange(n): a = array((x, y)) - i = int(2**32 * digest(a)) + i = int(2**32 * uniform(a)) f.write(pack('I', i)) f.close() subprocess.call(['dieharder', '-a', '-g', '201', '-f', f.name]) diff --git a/kwant/contrib/rmt.py b/kwant/rmt.py similarity index 100% rename from kwant/contrib/rmt.py rename to kwant/rmt.py diff --git a/kwant/tests/test_comprehensive.py b/kwant/tests/test_comprehensive.py index 55494f29256f4b57dd050bd2d28d293ac0eaddd1..8a6f39b9ff6723032d3712a715deef0fe87b1326 100644 --- a/kwant/tests/test_comprehensive.py +++ b/kwant/tests/test_comprehensive.py @@ -1,7 +1,6 @@ import math from cmath import exp import kwant -from kwant.contrib.digest import gauss def hopping(sitei, sitej, phi, salt): @@ -11,7 +10,7 @@ def hopping(sitei, sitej, phi, salt): def onsite(site, phi, salt): - return 0.3 * gauss(repr(site), salt) + 4 + return 0.3 * kwant.digest.gauss(repr(site), salt) + 4 def test_qhe(W=16, L=8): diff --git a/kwant/contrib/tests/test_rmt.py b/kwant/tests/test_rmt.py similarity index 99% rename from kwant/contrib/tests/test_rmt.py rename to kwant/tests/test_rmt.py index 8cc0bcca936d80d8c7f8e91e634cddaeb5f0a211..87ef04fb8e68bf58a6181e3e849f35444b97b30a 100644 --- a/kwant/contrib/tests/test_rmt.py +++ b/kwant/tests/test_rmt.py @@ -9,7 +9,7 @@ import numpy as np from scipy import stats from nose.tools import assert_raises -from kwant.contrib import rmt +from kwant import rmt assert_allclose = np.testing.assert_allclose