Commit 195e4249 authored by Christoph Groth's avatar Christoph Groth
Browse files

Merge branch 'python3'

parents 2de760a3 0f3068d1
......@@ -136,5 +136,5 @@ $(foreach name,$(SCRIPTS),$(eval $(call makedep,$(name))))
# Generation of images
.%_flag: %.py
cd $(dir $<) && python $(notdir $<)
cd $(dir $<) && python3 $(notdir $<)
@touch $@
......@@ -42,8 +42,8 @@ source_suffix = '.rst'
master_doc = 'index'
# General information about the project.
project = u'Kwant'
copyright = u'2011-2015, C. W. Groth (CEA), M. Wimmer, A. R. Akhmerov, X. Waintal (CEA), and others'
project = 'Kwant'
copyright = '2011-2015, C. W. Groth (CEA), M. Wimmer, A. R. Akhmerov, X. Waintal (CEA), and others'
# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
......@@ -208,7 +208,7 @@ r"""\makeatletter
# We use "et al." as it is shorter and there's not much space left horizontally.
latex_documents = [
('index', 'kwant.tex', 'Kwant {0} documentation'.format(release),
u'C. W. Groth, M. Wimmer, A. R. Akhmerov, X. Waintal, et al.',
'C. W. Groth, M. Wimmer, A. R. Akhmerov, X. Waintal, et al.',
'manual'),
]
......@@ -249,9 +249,9 @@ class BoundMethodDocumenter(autodoc.FunctionDocumenter):
# Return True iff `member` is a bound method. Taken from
# <http://stackoverflow.com/a/1260881>.
return (isinstance(member, types.MethodType) and
member.im_self is not None and
not issubclass(member.im_class, type) and
member.im_class is not types.ClassType)
member.__self__ is not None and
not issubclass(member.__self__.__class__, type) and
member.__self__.__class__ is not type)
def format_args(self):
args = super(BoundMethodDocumenter, self).format_args()
......
--- original
+++ modified
@@ -11,6 +11,7 @@
@@ -11,5 +11,6 @@
# lattice, namely graphene
from __future__ import division # so that 1/2 == 0.5, and not 0
+import _defs
from math import pi, sqrt, tanh
import kwant
@@ -97,22 +98,40 @@
@@ -96,22 +97,40 @@
smatrix = kwant.smatrix(sys, energy)
data.append(smatrix.transmission(0, 1))
......@@ -57,7 +56,7 @@
def main():
@@ -124,8 +143,11 @@
@@ -123,8 +142,11 @@
def family_colors(site):
return 0 if site.family == a else 1
......@@ -71,7 +70,7 @@
# Compute some eigenvalues.
compute_evs(sys.finalized())
@@ -134,9 +156,11 @@
@@ -133,9 +155,11 @@
for lead in leads:
sys.attach_lead(lead)
......
......@@ -118,7 +118,7 @@ def main():
# We should see a conductance that is periodic with the flux quantum
plot_conductance(sys, energy=0.15, fluxes=[0.01 * i * 3 * 2 * pi
for i in xrange(100)])
for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported).
......
......@@ -24,7 +24,7 @@ def make_lead(a=1, t=1.0, W=10):
# build up one unit cell of the lead, and add the hoppings
# to the next unit cell
for j in xrange(W):
for j in range(W):
lead[lat(0, j)] = 4 * t
if j > 0:
......
......@@ -106,7 +106,7 @@ def main():
try:
# We should observe energy levels that flow towards Landau
# level energies with increasing magnetic field.
plot_spectrum(sys, [iB * 0.002 for iB in xrange(100)])
plot_spectrum(sys, [iB * 0.002 for iB in range(100)])
# Plot an eigenmode of a circular dot. Here we create a larger system for
# better spatial resolution.
......@@ -114,8 +114,8 @@ def main():
plot_wave_function(sys)
except ValueError as e:
if e.message == "Input matrix is not real-valued.":
print "The calculation of eigenvalues failed because of a bug in SciPy 0.9."
print "Please upgrade to a newer version of SciPy."
print("The calculation of eigenvalues failed because of a bug in SciPy 0.9.")
print("Please upgrade to a newer version of SciPy.")
else:
raise
......
......@@ -10,7 +10,6 @@
# - Application of all the aspects of tutorials 1-3 to a more complicated
# lattice, namely graphene
from __future__ import division # so that 1/2 == 0.5, and not 0
from math import pi, sqrt, tanh
import kwant
......@@ -102,7 +101,7 @@ def compute_evs(sys):
sparse_mat = sys.hamiltonian_submatrix(sparse=True)
evs = sla.eigs(sparse_mat, 2)[0]
print evs.real
print(evs.real)
#HIDDEN_END_zydk
......@@ -166,11 +165,11 @@ def main():
sys = sys.finalized()
# Compute the band structure of lead 0.
momenta = [-pi + 0.02 * pi * i for i in xrange(101)]
momenta = [-pi + 0.02 * pi * i for i in range(101)]
plot_bandstructure(sys.leads[0], momenta)
# Plot conductance.
energies = [-2 * pot + 4. / 50. * pot * i for i in xrange(51)]
energies = [-2 * pot + 4. / 50. * pot * i for i in range(51)]
plot_conductance(sys, energies)
......
......@@ -43,7 +43,7 @@ def make_system(a=1, t=1.0, W=10, L=30, L_well=10):
#### Define and attach the leads. ####
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in xrange(W))] = 4 * t
lead[(lat(0, j) for j in range(W))] = 4 * t
lead[lat.neighbors()] = -t
sys.attach_lead(lead)
sys.attach_lead(lead.reversed())
......@@ -79,7 +79,7 @@ def main():
# We should see conductance steps.
plot_conductance(sys, energy=0.2,
welldepths=[0.01 * i for i in xrange(100)])
welldepths=[0.01 * i for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported).
......
......@@ -35,8 +35,8 @@ L = 30
# Define the scattering region
for i in xrange(L):
for j in xrange(W):
for i in range(L):
for j in range(W):
# On-site Hamiltonian
sys[lat(i, j)] = 4 * t
......@@ -59,7 +59,7 @@ left_lead = kwant.Builder(sym_left_lead)
#HIDDEN_END_xcmc
#HIDDEN_BEGIN_ndez
for j in xrange(W):
for j in range(W):
left_lead[lat(0, j)] = 4 * t
if j > 0:
left_lead[lat(0, j), lat(0, j - 1)] = -t
......@@ -75,7 +75,7 @@ sys.attach_lead(left_lead)
sym_right_lead = kwant.TranslationalSymmetry((a, 0))
right_lead = kwant.Builder(sym_right_lead)
for j in xrange(W):
for j in range(W):
right_lead[lat(0, j)] = 4 * t
if j > 0:
right_lead[lat(0, j), lat(0, j - 1)] = -t
......@@ -98,7 +98,7 @@ sys = sys.finalized()
#HIDDEN_BEGIN_buzn
energies = []
data = []
for ie in xrange(100):
for ie in range(100):
energy = ie * 0.01
# compute the scattering matrix at a given energy
......
......@@ -39,7 +39,7 @@ def make_system(a=1, t=1.0, W=10, L=30):
# Construct the left lead.
#HIDDEN_BEGIN_iepx
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
lead[(lat(0, j) for j in xrange(W))] = 4 * t
lead[(lat(0, j) for j in range(W))] = 4 * t
lead[lat.neighbors()] = -t
#HIDDEN_END_iepx
......@@ -79,7 +79,7 @@ def main():
sys = sys.finalized()
# We should see conductance steps.
plot_conductance(sys, energies=[0.01 * i for i in xrange(100)])
plot_conductance(sys, energies=[0.01 * i for i in range(100)])
#HIDDEN_END_cjel
......
......@@ -55,7 +55,7 @@ def make_system(a=1, t=1.0, alpha=0.5, e_z=0.08, W=10, L=30):
lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0)))
#HIDDEN_BEGIN_yliu
lead[(lat(0, j) for j in xrange(W))] = 4 * t * sigma_0 + e_z * sigma_z
lead[(lat(0, j) for j in range(W))] = 4 * t * sigma_0 + e_z * sigma_z
# hoppings in x-direction
lead[kwant.builder.HoppingKind((1, 0), lat, lat)] = \
-t * sigma_0 - 1j * alpha * sigma_y
......@@ -95,7 +95,7 @@ def main():
sys = sys.finalized()
# We should see non-monotonic conductance steps.
plot_conductance(sys, energies=[0.01 * i - 0.3 for i in xrange(100)])
plot_conductance(sys, energies=[0.01 * i - 0.3 for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported).
......
......@@ -35,7 +35,7 @@ def make_lead(a=1, t=1.0, mu=0.7, Delta=0.1, W=10):
# build up one unit cell of the lead, and add the hoppings
# to the next unit cell
for j in xrange(W):
for j in range(W):
lead[lat(0, j)] = (4 * t - mu) * tau_z + Delta * tau_x
if j > 0:
......
......@@ -55,12 +55,12 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
# left electron lead
lead0 = kwant.Builder(sym_left)
lead0[(lat_e(0, j) for j in xrange(W))] = 4 * t - mu
lead0[(lat_e(0, j) for j in range(W))] = 4 * t - mu
lead0[lat_e.neighbors()] = -t
# left hole lead
lead1 = kwant.Builder(sym_left)
lead1[(lat_h(0, j) for j in xrange(W))] = mu - 4 * t
lead1[(lat_h(0, j) for j in range(W))] = mu - 4 * t
lead1[lat_h.neighbors()] = t
#HIDDEN_END_ttth
......@@ -72,7 +72,7 @@ def make_system(a=1, W=10, L=10, barrier=1.5, barrierpos=(3, 4),
lead2 = kwant.Builder(sym_right)
lead2 += lead0
lead2 += lead1
lead2[((lat_e(0, j), lat_h(0, j)) for j in xrange(W))] = Delta
lead2[((lat_e(0, j), lat_h(0, j)) for j in range(W))] = Delta
#HIDDEN_END_mhiw
#### Attach the leads and return the system. ####
......@@ -113,7 +113,7 @@ def main():
# Finalize the system.
sys = sys.finalized()
plot_conductance(sys, energies=[0.002 * i for i in xrange(100)])
plot_conductance(sys, energies=[0.002 * i for i in range(100)])
# Call the main function if the script gets executed (as opposed to imported).
......
from math import sqrt
import scipy.sparse.linalg as sla
import matplotlib.pyplot
from matplotlib import pyplot
import kwant
sys = kwant.Builder()
......@@ -9,11 +9,11 @@ lat = kwant.lattice.general([(1,0,0), (0,1,0), (0,0,1)])
t = 1.0
R = 10
sys[(lat(x,y,z) for x in xrange(-R-1, R+1)
for y in xrange(-R-1, R+1) for z in xrange(R+1)
sys[(lat(x,y,z) for x in range(-R-1, R+1)
for y in range(-R-1, R+1) for z in range(R+1)
if sqrt(x**2 + y**2 + z**2) < R + 0.01)] = 4 * t
sys[(lat(x,y,z) for x in xrange(-2*R, 2*R + 1)
for y in xrange(-R, R+1) for z in xrange(-R, 0))] = 4 * t
sys[(lat(x,y,z) for x in range(-2*R, 2*R + 1)
for y in range(-R, R+1) for z in range(-R, 0))] = 4 * t
sys[lat.neighbors()] = -t
sys = sys.finalized()
kwant.plot(sys)
......
"""An example of advanced system creation."""
from __future__ import division
from math import tanh
from cmath import exp
import tinyarray as ta
......@@ -48,7 +47,7 @@ def make_system(R):
def main():
sys = make_system(100)
print kwant.smatrix(sys, 1.1, [0.1]).transmission(0, 1)
print(kwant.smatrix(sys, 1.1, [0.1]).transmission(0, 1))
if __name__ == '__main__':
......
"""The script generating Kwant logo. In addition to Kwant it also needs Python
image library (PIL)."""
image library Pillow."""
import Image
import ImageFont
import ImageDraw
from PIL import Image, ImageFont, ImageDraw
import matplotlib
import numpy as np
import scipy
import scipy.misc
import kwant
def main():
......@@ -86,7 +84,7 @@ def main():
# result is not too empty or not too dark.
out = np.zeros(textpos.shape)
for i, rho in enumerate(ldos**.2):
x1, y1 = sys.site(i).tag
x1, y1 = sys.sites[i].tag
out[x1, y1] = rho
out = normalize_data(out)
......
......@@ -2,7 +2,6 @@
kwant.Builder.
"""
from __future__ import division
import numpy as np
from matplotlib import pyplot
import kwant
......@@ -10,6 +9,7 @@ from kwant.physics.leads import square_selfenergy
__all__ = ['System']
class Lead(object):
def __init__(self, width, t, potential):
self.width = width
......@@ -20,6 +20,7 @@ class Lead(object):
return square_selfenergy(self.width, self.t,
self.potential + fermi_energy)
class System(kwant.system.FiniteSystem):
def __init__(self, shape, hopping,
potential=0, lead_potentials=(0, 0),
......@@ -56,7 +57,7 @@ class System(kwant.system.FiniteSystem):
edges[:shape[across], 1] += increment[along]
edges[shape[across]:, (0, 1)] = edges[:shape[across], (1, 0)]
g.add_edges(edges)
for i in xrange(shape[along] - 2):
for i in range(shape[along] - 2):
edges += increment[along]
g.add_edges(edges)
self.graph = g.compressed()
......@@ -66,7 +67,7 @@ class System(kwant.system.FiniteSystem):
# We have to use list here, as numpy.array does not understand
# generators.
interface = list(self.nodeid_from_pos((x, y))
for y in xrange(shape[1]))
for y in range(shape[1]))
self.lead_interfaces.append(np.array(interface))
self.leads = [Lead(shape[1], hopping, lead_potentials[i])
......@@ -85,7 +86,7 @@ class System(kwant.system.FiniteSystem):
return result
def nodeid_from_pos(self, pos):
for i in xrange(2):
for i in range(2):
assert int(pos[i]) == pos[i]
assert pos[i] >= 0 and pos[i] < self.shape[i]
return pos[0] + pos[1] * self.shape[0]
......@@ -98,8 +99,8 @@ class System(kwant.system.FiniteSystem):
def main():
sys = System((10, 5), 1)
energies = [0.04 * i for i in xrange(100)]
data = [kwant.smatrix(sys, energy).transmission(1, 0)
energies = [0.04 * i for i in range(100)]
data = [kwant.greens_function(sys, energy).transmission(1, 0)
for energy in energies]
pyplot.plot(energies, data)
......
......@@ -4,18 +4,18 @@ from numpy.testing import assert_almost_equal
def test_nodeid_to_from_pos():
s = square.System((3, 4), 1)
assert_raises(StandardError, s.nodeid_from_pos, (0, -2))
assert_raises(StandardError, s.nodeid_from_pos, (-1, 3))
assert_raises(StandardError, s.nodeid_from_pos, (3, 1))
assert_raises(StandardError, s.pos_from_nodeid, -1)
assert_raises(StandardError, s.pos_from_nodeid, 12)
assert_raises(Exception, s.nodeid_from_pos, (0, -2))
assert_raises(Exception, s.nodeid_from_pos, (-1, 3))
assert_raises(Exception, s.nodeid_from_pos, (3, 1))
assert_raises(Exception, s.pos_from_nodeid, -1)
assert_raises(Exception, s.pos_from_nodeid, 12)
assert_equal(s.nodeid_from_pos((0, 0)), 0)
assert_equal(s.nodeid_from_pos(s.pos_from_nodeid(7)), 7)
assert_equal(s.pos_from_nodeid(s.nodeid_from_pos((2, 3))), (2, 3))
def test_hamiltonian():
sys = square.System((4, 5), 1)
for i in xrange(sys.graph.num_nodes):
for i in range(sys.graph.num_nodes):
shape = sys.hamiltonian(i, i).shape
assert_equal(len(shape), 2)
assert_equal(shape[0], 1)
......@@ -28,7 +28,7 @@ def test_hamiltonian():
def test_selfenergy():
sys = square.System((2, 4), 1)
for lead in xrange(len(sys.lead_interfaces)):
for lead in range(len(sys.lead_interfaces)):
se = sys.leads[lead].selfenergy(0)
assert_equal(len(se.shape), 2)
assert_equal(se.shape[0], se.shape[1])
......
......@@ -29,7 +29,7 @@ __all__.append('KwantDeprecationWarning')
from ._common import version as __version__
for module in ['system', 'builder', 'lattice', 'solvers', 'digest', 'rmt']:
exec 'from . import {0}'.format(module)
exec('from . import {0}'.format(module))
__all__.append(module)
# Make selected functionality available directly in the root namespace.
......@@ -38,7 +38,7 @@ available = [('builder', ['Builder', 'HoppingKind']),
('solvers.default',
['smatrix', 'greens_function', 'ldos', 'wave_function'])]
for module, names in available:
exec 'from .{0} import {1}'.format(module, ', '.join(names))
exec('from .{0} import {1}'.format(module, ', '.join(names)))
__all__.extend(names)
# Importing plotter might not work, but this does not have to be a problem --
......
......@@ -11,7 +11,9 @@ import os
__all__ = ['version', 'KwantDeprecationWarning']
distr_root = os.path.dirname(os.path.dirname(os.path.realpath(__file__)))
package_root = os.path.dirname(os.path.realpath(__file__))
distr_root = os.path.dirname(package_root)
version_file = '_kwant_version.py'
def get_version_from_git():
try:
......@@ -22,8 +24,7 @@ def get_version_from_git():
return
if p.wait() != 0:
return
# TODO: use os.path.samefile once we depend on Python >= 3.3.
if os.path.normpath(p.communicate()[0].rstrip('\n')) != distr_root:
if not os.path.samefile(p.communicate()[0].decode().rstrip('\n'), distr_root):
# The top-level directory of the current Git repository is not the same
# as the root directory of the Kwant distribution: do not extract the
# version from Git.
......@@ -42,7 +43,7 @@ def get_version_from_git():
break
else:
return
description = p.communicate()[0].strip('v').rstrip('\n')
description = p.communicate()[0].decode().strip('v').rstrip('\n')
release, dev, git = description.rsplit('-', 2)
version = [release]
......@@ -67,7 +68,11 @@ def get_version_from_git():
from _kwant_version import version
# populate the version_info dictionary with values stored in the version file
version_info = {}
with open(os.path.join(package_root, version_file), 'r') as f:
exec(f.read(), {}, version_info)
version = version_info['version']
version_is_from_git = (version == "__use_git__")
if version_is_from_git:
version = get_version_from_git()
......
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