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
Showing
with 312 additions and 186 deletions
......@@ -9,8 +9,7 @@
"""Functionality for graphs"""
# Merge the public interface of all submodules.
__all__ = []
for module in ['core', 'defs']:
exec('from . import {0}'.format(module))
exec('from .{0} import *'.format(module))
exec('__all__.extend({0}.__all__)'.format(module))
from .core import *
from .defs import *
__all__ = [core.__all__ + defs.__all__]
......@@ -731,23 +731,25 @@ class Correlator:
g_kernel[0] /= 2
mu_kernel = np.outer(g_kernel, g_kernel) * self.moments_matrix
e = (self.energies - self._b) / self._a
e_scaled = (self.energies - self._b) / self._a
# arrays for faster calculation
sqrt_e = np.sqrt(1 - e ** 2)
arccos_e = np.arccos(e)
m_array = np.arange(n_moments)
def _integral_factor(e):
# arrays for faster calculation
sqrt_e = np.sqrt(1 - e ** 2)
arccos_e = np.arccos(e)
exp_n = np.exp(1j * np.outer(arccos_e, np.arange(n_moments)))
t_n = np.real(exp_n)
exp_n = np.exp(1j * arccos_e * m_array)
t_n = np.real(exp_n)
e_plus = (np.outer(e, np.ones(n_moments)) -
1j * np.outer(sqrt_e, np.arange(n_moments)))
e_plus = e_plus * exp_n
e_plus = (e - 1j * sqrt_e * m_array)
e_plus = e_plus * exp_n
big_gamma = e_plus[:, None, :] * t_n[:, :, None]
big_gamma += big_gamma.conj().swapaxes(1, 2)
self._integral_factor = np.tensordot(mu_kernel, big_gamma.T)
big_gamma = e_plus[None, :] * t_n[:, None]
big_gamma += big_gamma.conj().T
return np.tensordot(mu_kernel, big_gamma.T)
self._integral_factor = np.array([_integral_factor(e)
for e in e_scaled]).T
def conductivity(hamiltonian, alpha='x', beta='x', positions=None, **kwargs):
......
......@@ -10,7 +10,10 @@ __all__ = ['lapack']
from . import lapack
# Merge the public interface of the other submodules.
for module in ['decomp_lu', 'decomp_ev', 'decomp_schur']:
exec('from . import {0}'.format(module))
exec('from .{0} import *'.format(module))
exec('__all__.extend({0}.__all__)'.format(module))
from .decomp_lu import *
from .decomp_schur import *
from .decomp_ev import *
__all__.extend([decomp_lu.__all__,
decomp_ev.__all__,
decomp_schur.__all__])
......@@ -65,7 +65,7 @@ def test_schur_complement_with_dense():
def test_error_minus_9(r=10):
"""Test if MUMPSError -9 is properly caught by increasing memory"""
graphene = honeycomb()
graphene = honeycomb(norbs=1)
a, b = graphene.sublattices
def circle(pos):
......
......@@ -13,6 +13,7 @@ import cython
from operator import itemgetter
import functools as ft
import collections
import numbers
import numpy as np
import tinyarray as ta
......@@ -21,6 +22,7 @@ from scipy.sparse import coo_matrix
from libc cimport math
from .graph.core cimport EdgeIterator
from .graph.core import DisabledFeatureError, NodeDoesNotExistError
from .graph.defs cimport gint
from .graph.defs import gint_dtype
from .system import InfiniteSystem
......@@ -159,34 +161,42 @@ def _normalize_site_where(syst, where):
"""Normalize the format of `where` when `where` contains sites.
If `where` is None, then all sites in the system are returned.
If it is a general iterator then it is expanded into an array. If `syst`
is a finalized Builder then `where` should contain `Site` objects,
If it is a general sequence then it is expanded into an array. If `syst`
is a finalized Builder then `where` may contain `Site` objects,
otherwise it should contain integers.
"""
if where is None:
size = (syst.cell_size
if isinstance(syst, InfiniteSystem) else syst.graph.num_nodes)
_where = list(range(size))
if isinstance(syst, InfiniteSystem):
where = list(range(syst.cell_size))
else:
where = list(range(syst.graph.num_nodes))
elif callable(where):
try:
_where = [syst.id_by_site[a] for a in filter(where, syst.sites)]
where = [syst.id_by_site[s] for s in filter(where, syst.sites)]
except AttributeError:
_where = list(filter(where, range(syst.graph.num_nodes)))
if isinstance(syst, InfiniteSystem):
where = [s for s in range(syst.cell_size) if where(s)]
else:
where = [s for s in range(syst.graph.num_nodes) if where(s)]
else:
try:
_where = list(syst.id_by_site[s] for s in where)
except AttributeError:
_where = list(where)
if any(w < 0 or w >= syst.graph.num_nodes for w in _where):
raise ValueError('`where` contains sites that are not in the '
'system.')
# Cannot check for builder.Site due to circular imports
if not isinstance(where[0], numbers.Integral):
try:
where = [syst.id_by_site[s] for s in where]
except AttributeError:
raise TypeError("'where' contains Sites, but the system is not "
"a finalized Builder.")
where = np.asarray(where, dtype=gint_dtype).reshape(-1, 1)
if isinstance(syst, InfiniteSystem):
if any(w >= syst.cell_size for w in _where):
raise ValueError('Only sites in the fundamental domain may be '
'specified using `where`.')
if isinstance(syst, InfiniteSystem) and np.any(where >= syst.cell_size):
raise ValueError('Only sites in the fundamental domain may be '
'specified using `where`.')
if np.any(np.logical_or(where < 0, where >= syst.graph.num_nodes)):
raise ValueError('`where` contains sites that are not in the '
'system.')
return np.asarray(_where, dtype=gint_dtype).reshape(len(_where), 1)
return where
def _normalize_hopping_where(syst, where):
......@@ -194,7 +204,7 @@ def _normalize_hopping_where(syst, where):
If `where` is None, then all hoppings in the system are returned.
If it is a general iterator then it is expanded into an array. If `syst` is
a finalized Builder then `where` should contain pairs of `Site` objects,
a finalized Builder then `where` may contain pairs of `Site` objects,
otherwise it should contain pairs of integers.
"""
if where is None:
......@@ -203,33 +213,42 @@ def _normalize_hopping_where(syst, where):
if isinstance(syst, InfiniteSystem):
raise ValueError('`where` must be provided when calculating '
'current in an InfiniteSystem.')
_where = list(syst.graph)
where = list(syst.graph)
elif callable(where):
if hasattr(syst, "sites"):
def idx_where(hop):
def idxwhere(hop):
a, b = hop
return where(syst.sites[a], syst.sites[b])
_where = list(filter(idx_where, syst.graph))
where = list(filter(idxwhere, syst.graph))
else:
_where = list(filter(lambda h: where(*h), syst.graph))
where = list(filter(lambda h: where(*h), syst.graph))
else:
# Cannot check for builder.Site due to circular imports
if not isinstance(where[0][0], numbers.Integral):
try:
where = list((syst.id_by_site[a], syst.id_by_site[b])
for a, b in where)
except AttributeError:
raise TypeError("'where' contains Sites, but the system is not "
"a finalized Builder.")
# NOTE: if we ever have operators that contain elements that are
# not in the system graph, then we should modify this check
try:
_where = list((syst.id_by_site[a], syst.id_by_site[b])
for a, b in where)
except AttributeError:
_where = list(where)
# NOTE: if we ever have operators that contain elements that are
# not in the system graph, then we should modify this check
error = ValueError('`where` contains hoppings that are not '
'in the system.')
if any(not syst.graph.has_edge(*w) for w in where):
raise ValueError('`where` contains hoppings that are not in the '
'system.')
raise error
# If where contains: negative integers, or integers > # of sites
except (NodeDoesNotExistError, DisabledFeatureError):
raise error
where = np.asarray(where, dtype=gint_dtype)
if isinstance(syst, InfiniteSystem):
if any(a > syst.cell_size or b > syst.cell_size for a, b in _where):
raise ValueError('Only intra-cell hoppings may be specified '
'using `where`.')
if isinstance(syst, InfiniteSystem) and np.any(where > syst.cell_size):
raise ValueError('Only intra-cell hoppings may be specified '
'using `where`.')
return np.asarray(_where, dtype=gint_dtype)
return where
## These two classes are here to avoid using closures, as these will
......
......@@ -8,8 +8,14 @@
"""Physics-related algorithms"""
# Merge the public interface of all submodules.
__all__ = []
for module in ['leads', 'dispersion', 'noise', 'symmetry', 'gauge']:
exec('from . import {0}'.format(module))
exec('from .{0} import *'.format(module))
exec('__all__.extend({0}.__all__)'.format(module))
from .leads import *
from .dispersion import *
from .noise import *
from .symmetry import *
from .gauge import *
__all__ = [leads.__all__
+ dispersion.__all__
+ noise.__all__
+ symmetry.__all__
+ gauge.__all__]
......@@ -173,11 +173,11 @@ class StabilizedModes:
Translation eigenvectors divided by the corresponding eigenvalues.
nmodes : int
Number of left-moving (or right-moving) modes.
sqrt_hop : numpy array or None
Part of the SVD of `h_hop`, or None if the latter is invertible.
sqrt_hop : numpy array
Part of the SVD of `h_hop`.
"""
def __init__(self, vecs, vecslmbdainv, nmodes, sqrt_hop=None):
def __init__(self, vecs, vecslmbdainv, nmodes, sqrt_hop):
kwargs = locals()
kwargs.pop('self')
self.__dict__.update(kwargs)
......
......@@ -17,7 +17,7 @@ from math import pi, cos, sin
def make_lead():
syst = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst[[lat(0, 0), lat(0, 1)]] = 3
syst[lat(0, 1), lat(0, 0)] = -1
syst[((lat(1, y), lat(0, y)) for y in range(2))] = -1
......@@ -35,7 +35,7 @@ def test_band_energies(N=5):
def test_same_as_lead():
syst = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst[lat(0)] = 0
syst[lat(0), lat(1)] = complex(cos(0.2), sin(0.2))
......@@ -49,7 +49,7 @@ def test_same_as_lead():
def test_raise_nonhermitian():
syst = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst[lat(0)] = 1j
syst[lat(0), lat(1)] = complex(cos(0.2), sin(0.2))
syst = syst.finalized()
......@@ -58,7 +58,7 @@ def test_raise_nonhermitian():
def test_band_velocities():
syst = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst[lat(0, 0)] = 1
syst[lat(0, 1)] = 3
syst[lat(1, 0), lat(0, 0)] = -1
......@@ -75,7 +75,7 @@ def test_band_velocities():
def test_band_velocity_derivative():
syst = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst[lat(0, 0)] = 1
syst[lat(0, 1)] = 3
syst[lat(1, 0), lat(0, 0)] = -1
......
......@@ -267,7 +267,7 @@ def test_modes():
def test_modes_bearded_ribbon():
# Check if bearded graphene ribbons work.
lat = kwant.lattice.honeycomb()
lat = kwant.lattice.honeycomb(norbs=1)
syst = kwant.Builder(kwant.TranslationalSymmetry((1, 0)))
syst[lat.shape((lambda pos: -20 < pos[1] < 20),
(0, 0))] = 0.3
......@@ -417,7 +417,7 @@ def test_zero_hopping():
def make_clean_lead(W, E, t):
syst = kwant.Builder(kwant.TranslationalSymmetry((1, 0)))
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst[(lat(0, j) for j in range(W))] = E
syst[lat.neighbors()] = -t
return syst.finalized()
......
......@@ -14,7 +14,7 @@ from kwant.physics import two_terminal_shotnoise
from kwant._common import ensure_rng
n = 5
chain = kwant.lattice.chain()
chain = kwant.lattice.chain(norbs=n)
def twoterminal_system():
rng = ensure_rng(11)
......
......@@ -735,17 +735,21 @@ def plot(sys, num_lead_cells=2, unit='nn',
symbols specifications (only for kwant.system.FiniteSystem).
site_size : number, function, array, or `None`
Relative (linear) size of the site symbol.
An array may not be used when 'syst' is a kwant.Builder.
site_color : ``matplotlib`` color description, function, array, or `None`
A color used for plotting a site in the system. If a colormap is used,
it should be a function returning single floats or a one-dimensional
array of floats. By default sites are colored by their site family,
using the current matplotlib color cycle.
An array of colors may not be used when 'syst' is a kwant.Builder.
site_edgecolor : ``matplotlib`` color description, function, array, or `None`
Color used for plotting the edges of the site symbols. Only
valid matplotlib color descriptions are allowed (and no
combination of floats and colormap as for site_color).
An array of colors may not be used when 'syst' is a kwant.Builder.
site_lw : number, function, array, or `None`
Linewidth of the site symbol edges.
An array may not be used when 'syst' is a kwant.Builder.
hop_color : ``matplotlib`` color description or a function
Same as `site_color`, but for hoppings. A function is passed two sites
in this case. (arrays are not allowed in this case).
......@@ -911,7 +915,11 @@ def plot(sys, num_lead_cells=2, unit='nn',
raise ValueError('Invalid value of unit argument.')
# make all specs proper: either constant or lists/np.arrays:
def make_proper_site_spec(spec, fancy_indexing=False):
def make_proper_site_spec(spec_name, spec, fancy_indexing=False):
if _p.isarray(spec) and isinstance(syst, builder.Builder):
raise TypeError('{} cannot be an array when plotting'
' a Builder; use a function instead.'
.format(spec_name))
if callable(spec):
spec = [spec(i[0]) for i in sites if i[1] is None]
if (fancy_indexing and _p.isarray(spec)
......@@ -933,7 +941,8 @@ def plot(sys, num_lead_cells=2, unit='nn',
spec = np.asarray(spec, dtype='object')
return spec
site_symbol = make_proper_site_spec(site_symbol)
site_symbol = make_proper_site_spec('site_symbol', site_symbol)
if site_symbol is None: site_symbol = defaults['site_symbol'][dim]
# separate different symbols (not done in 3D, the separation
# would mess up sorting)
......@@ -967,10 +976,10 @@ def plot(sys, num_lead_cells=2, unit='nn',
# Unknown finalized system, no sites access.
site_color = defaults['site_color'][dim]
site_size = make_proper_site_spec(site_size, fancy_indexing)
site_color = make_proper_site_spec(site_color, fancy_indexing)
site_edgecolor = make_proper_site_spec(site_edgecolor, fancy_indexing)
site_lw = make_proper_site_spec(site_lw, fancy_indexing)
site_size = make_proper_site_spec('site_size', site_size, fancy_indexing)
site_color = make_proper_site_spec('site_color', site_color, fancy_indexing)
site_edgecolor = make_proper_site_spec('site_edgecolor', site_edgecolor, fancy_indexing)
site_lw = make_proper_site_spec('site_lw', site_lw, fancy_indexing)
hop_color = make_proper_hop_spec(hop_color)
hop_lw = make_proper_hop_spec(hop_lw)
......
......@@ -210,8 +210,7 @@ class SparseSolver(metaclass=abc.ABCMeta):
iface_orbs = np.r_[tuple(slice(offsets[i], offsets[i + 1])
for i in interface)]
n_lead_orbs = (svd_v.shape[0] if svd_v is not None
else u_out.shape[0])
n_lead_orbs = svd_v.shape[0]
if n_lead_orbs != len(iface_orbs):
msg = ('Lead {0} has hopping with dimensions '
'incompatible with its interface dimension.')
......@@ -221,25 +220,17 @@ class SparseSolver(metaclass=abc.ABCMeta):
transf = sp.csc_matrix((np.ones(len(iface_orbs)), coords),
shape=(iface_orbs.size, lhs.shape[0]))
if svd_v is not None:
v_sp = sp.csc_matrix(svd_v.T.conj()) * transf
vdaguout_sp = (transf.T *
sp.csc_matrix(np.dot(svd_v, u_out)))
lead_mat = - ulinv_out
else:
v_sp = transf
vdaguout_sp = transf.T * sp.csc_matrix(u_out)
lead_mat = - ulinv_out
v_sp = sp.csc_matrix(svd_v.T.conj()) * transf
vdaguout_sp = (transf.T *
sp.csc_matrix(np.dot(svd_v, u_out)))
lead_mat = - ulinv_out
lhs = sp.bmat([[lhs, vdaguout_sp], [v_sp, lead_mat]],
format=self.lhsformat)
if leadnum in in_leads and nprop > 0:
if svd_v is not None:
vdaguin_sp = transf.T * sp.csc_matrix(
-np.dot(svd_v, u_in))
else:
vdaguin_sp = transf.T * sp.csc_matrix(-u_in)
vdaguin_sp = transf.T * sp.csc_matrix(
-np.dot(svd_v, u_in))
# defer formation of the real matrix until the proper
# system size is known
......
......@@ -15,8 +15,8 @@ import kwant
from kwant._common import ensure_rng
n = 5
chain = kwant.lattice.chain()
sq = square = kwant.lattice.square()
chain = kwant.lattice.chain(norbs=n)
sq = square = kwant.lattice.square(norbs=n)
class LeadWithOnlySelfEnergy:
......@@ -111,6 +111,8 @@ def test_one_lead(smatrix):
# Test that a system with one lead with no propagating modes has a
# 0x0 S-matrix.
def test_smatrix_shape(smatrix):
chain = kwant.lattice.chain(norbs=1)
system = kwant.Builder()
lead0 = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
lead1 = kwant.Builder(kwant.TranslationalSymmetry((1,)))
......@@ -264,6 +266,8 @@ def test_singular_graph_system(smatrix):
# zero eigenvalues than the lead hopping matrix. Older version of the
# sparse solver failed here.
def test_tricky_singular_hopping(smatrix):
sq = kwant.lattice.square(norbs=1)
system = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry((4, 0)))
......@@ -294,6 +298,7 @@ def test_tricky_singular_hopping(smatrix):
# Test the consistency of transmission and conductance_matrix for a four-lead
# system without time-reversal symmetry.
def test_many_leads(*factories):
sq = kwant.lattice.square(norbs=1)
E=2.1
B=0.01
......@@ -428,7 +433,7 @@ def test_selfenergy_reflection(greens_function, smatrix):
def test_very_singular_leads(smatrix):
syst = kwant.Builder()
chain = kwant.lattice.chain()
chain = kwant.lattice.chain(norbs=2)
left_lead = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
right_lead = kwant.Builder(kwant.TranslationalSymmetry((1,)))
syst[chain(0)] = left_lead[chain(0)] = right_lead[chain(0)] = np.identity(2)
......@@ -443,7 +448,7 @@ def test_very_singular_leads(smatrix):
def test_ldos(ldos):
syst = kwant.Builder()
chain = kwant.lattice.chain()
chain = kwant.lattice.chain(norbs=1)
lead = kwant.Builder(kwant.TranslationalSymmetry(chain.vec((1,))))
syst[chain(0)] = syst[chain(1)] = lead[chain(0)] = 0
syst[chain(0), chain(1)] = lead[chain(0), chain(1)] = 1
......@@ -512,6 +517,7 @@ def test_arg_passing(wave_function, ldos, smatrix):
def hopping(site1, site2, a, b):
return b - a
square = kwant.lattice.square(norbs=1)
W = 3
L = 4
......
......@@ -28,7 +28,7 @@ def test_bad_keys():
def setitem(key):
syst[key] = None
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
syst = builder.Builder()
failures = [
......@@ -97,9 +97,9 @@ def test_bad_keys():
def test_site_families():
syst = builder.Builder()
fam = builder.SimpleSiteFamily()
ofam = builder.SimpleSiteFamily()
yafam = builder.SimpleSiteFamily('another_name')
fam = builder.SimpleSiteFamily(norbs=1)
ofam = builder.SimpleSiteFamily(norbs=1)
yafam = builder.SimpleSiteFamily('another_name', norbs=1)
syst[fam(0)] = 7
assert syst[fam(0)] == 7
......@@ -162,7 +162,7 @@ class VerySimpleSymmetry(builder.Symmetry):
# made.
def check_construction_and_indexing(sites, sites_fd, hoppings, hoppings_fd,
unknown_hoppings, sym=None):
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
syst = builder.Builder(sym)
t, V = 1.0j, 0.0
syst[sites] = V
......@@ -212,7 +212,7 @@ def check_construction_and_indexing(sites, sites_fd, hoppings, hoppings_fd,
def test_construction_and_indexing():
# Without symmetry
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
sites = [fam(0, 0), fam(0, 1), fam(1, 0)]
hoppings = [(fam(0, 0), fam(0, 1)),
(fam(0, 1), fam(1, 0)),
......@@ -250,7 +250,7 @@ def test_hermitian_conjugation():
raise ValueError
syst = builder.Builder()
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
syst[fam(0)] = syst[fam(1)] = ta.identity(2)
syst[fam(0), fam(1)] = f
......@@ -266,7 +266,7 @@ def test_hermitian_conjugation():
def test_value_equality_and_identity():
m = ta.array([[1, 2], [3j, 4j]])
syst = builder.Builder()
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
syst[fam(0)] = m
syst[fam(1)] = m
......@@ -378,7 +378,7 @@ def test_finalization():
# Build scattering region from blueprint and test it.
syst = builder.Builder()
fam = kwant.lattice.general(ta.identity(2))
fam = kwant.lattice.general(ta.identity(2), norbs=1)
for site, value in sr_sites.items():
syst[fam(*site)] = value
for hop, value in sr_hops.items():
......@@ -488,8 +488,11 @@ def test_site_ranges():
ranges = syst.finalized().site_ranges
expected = [(0, lat.norbs, 0), (10, 0, 10 * lat.norbs)]
assert ranges == expected
# poison system with a single site with no norbs defined
syst[kwant.lattice.chain()(0)] = 1
# poison system with a single site with no norbs defined.
# Also catch the deprecation warning.
with warnings.catch_warnings():
warnings.simplefilter("ignore")
syst[kwant.lattice.chain(norbs=None)(0)] = 1
ranges = syst.finalized().site_ranges
assert ranges == None
......@@ -506,7 +509,7 @@ def test_hamiltonian_evaluation():
edges = [(0, 1), (0, 2), (0, 3), (1, 2)]
syst = builder.Builder()
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
sites = [fam(*tag) for tag in tags]
syst[(fam(*tag) for tag in tags)] = f_onsite
syst[((fam(*tags[i]), fam(*tags[j])) for (i, j) in edges)] = f_hopping
......@@ -570,7 +573,7 @@ def test_dangling():
# / \
# 3-0---2-4-5 6-7 8
syst = builder.Builder()
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
syst[(fam(i) for i in range(9))] = None
syst[[(fam(0), fam(1)), (fam(1), fam(2)), (fam(2), fam(0))]] = None
syst[[(fam(0), fam(3)), (fam(2), fam(4)), (fam(4), fam(5))]] = None
......@@ -596,7 +599,7 @@ def test_dangling():
def test_builder_with_symmetry():
g = kwant.lattice.general(ta.identity(3))
g = kwant.lattice.general(ta.identity(3), norbs=1)
sym = kwant.TranslationalSymmetry((0, 0, 3), (0, 2, 0))
syst = builder.Builder(sym)
......@@ -642,7 +645,7 @@ def test_builder_with_symmetry():
def test_fill():
g = kwant.lattice.square()
g = kwant.lattice.square(norbs=1)
sym_x = kwant.TranslationalSymmetry((-1, 0))
sym_xy = kwant.TranslationalSymmetry((-1, 0), (0, 1))
......@@ -658,7 +661,7 @@ def test_fill():
lambda pos: True),
(builder.NoSymmetry(),
lambda pos: ta.dot(pos, pos) < 17)]:
cubic = kwant.lattice.general(ta.identity(3))
cubic = kwant.lattice.general(ta.identity(3), norbs=1)
# Make a weird system.
orig = kwant.Builder(sym)
......@@ -769,7 +772,7 @@ def test_fill():
assert sorted(target.hoppings()) == sorted(should_be_syst.hoppings())
## test that 'fill' respects the symmetry of the target builder
lat = kwant.lattice.chain(a=1)
lat = kwant.lattice.chain(a=1, norbs=1)
template = builder.Builder(kwant.TranslationalSymmetry((-1,)))
template[lat(0)] = 2
template[lat.neighbors()] = -1
......@@ -796,7 +799,7 @@ def test_fill():
target.fill(template, lambda x: True, lat(0))
# Test for warning when one of the starting sites is outside the template
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
template = builder.Builder(kwant.TranslationalSymmetry((-1, 0)))
template[lat(0, 0)] = None
template[lat.neighbors()] = None
......@@ -811,7 +814,7 @@ def test_fill_sticky():
separately.
"""
# Generate model template.
lat = kwant.lattice.kagome()
lat = kwant.lattice.kagome(norbs=1)
template = kwant.Builder(kwant.TranslationalSymmetry(
lat.vec((1, 0)), lat.vec((0, 1))))
for i, sl in enumerate(lat.sublattices):
......@@ -844,7 +847,7 @@ def test_fill_sticky():
def test_attach_lead():
fam = builder.SimpleSiteFamily(norbs=1)
fam_noncommensurate = builder.SimpleSiteFamily(name='other')
fam_noncommensurate = builder.SimpleSiteFamily(name='other', norbs=1)
syst = builder.Builder()
syst[fam(1)] = 0
......@@ -901,7 +904,7 @@ def test_attach_lead():
def test_attach_lead_incomplete_unit_cell():
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst = kwant.Builder()
lead = kwant.Builder(kwant.TranslationalSymmetry((2,)))
syst[lat(1)] = lead[lat(0)] = lead[lat(1)] = 0
......@@ -912,7 +915,7 @@ def test_attach_lead_incomplete_unit_cell():
def test_neighbors_not_in_single_domain():
sr = builder.Builder()
lead = builder.Builder(VerySimpleSymmetry(-1))
fam = builder.SimpleSiteFamily()
fam = builder.SimpleSiteFamily(norbs=1)
sr[(fam(x, y) for x in range(3) for y in range(3) if x >= y)] = 0
sr[builder.HoppingKind((1, 0), fam)] = 1
sr[builder.HoppingKind((0, 1), fam)] = 1
......@@ -935,7 +938,7 @@ def test_closest():
rng = ensure_rng(10)
for sym_dim in range(1, 4):
for space_dim in range(sym_dim, 4):
lat = kwant.lattice.general(ta.identity(space_dim))
lat = kwant.lattice.general(ta.identity(space_dim), norbs=1)
# Choose random periods.
while True:
......@@ -967,7 +970,7 @@ def test_closest():
def test_update():
lat = builder.SimpleSiteFamily()
lat = builder.SimpleSiteFamily(norbs=1)
syst = builder.Builder()
syst[[lat(0,), lat(1,)]] = 1
......@@ -1006,8 +1009,8 @@ def test_update():
# ghgh hhgh
#
def test_HoppingKind():
g = kwant.lattice.general(ta.identity(3), name='some_lattice')
h = kwant.lattice.general(ta.identity(3), name='another_lattice')
g = kwant.lattice.general(ta.identity(3), name='some_lattice', norbs=1)
h = kwant.lattice.general(ta.identity(3), name='another_lattice', norbs=1)
sym = kwant.TranslationalSymmetry((0, 2, 0))
syst = builder.Builder(sym)
syst[((h if max(x, y, z) % 2 else g)(x, y, z)
......@@ -1047,8 +1050,8 @@ def test_HoppingKind():
def test_invalid_HoppingKind():
g = kwant.lattice.general(ta.identity(3))
h = kwant.lattice.general(np.identity(3)[:-1]) # 2D lattice in 3D
g = kwant.lattice.general(ta.identity(3), norbs=1)
h = kwant.lattice.general(np.identity(3)[:-1], norbs=1) # 2D lattice in 3D
delta = (1, 0, 0)
......@@ -1062,7 +1065,7 @@ def test_invalid_HoppingKind():
def test_ModesLead_and_SelfEnergyLead():
lat = builder.SimpleSiteFamily()
lat = builder.SimpleSiteFamily(norbs=1)
hoppings = [builder.HoppingKind((1, 0), lat),
builder.HoppingKind((0, 1), lat)]
rng = Random(123)
......@@ -1139,7 +1142,7 @@ def test_ModesLead_and_SelfEnergyLead():
def test_site_pickle():
site = kwant.lattice.square()(0, 0)
site = kwant.lattice.square(norbs=1)(0, 0)
assert pickle.loads(pickle.dumps(site)) == site
......@@ -1202,7 +1205,7 @@ def test_discrete_symmetries():
# all the deprecation warnings in the test logs
@pytest.mark.filterwarnings("ignore:.*'args' parameter")
def test_argument_passing():
chain = kwant.lattice.chain()
chain = kwant.lattice.chain(norbs=1)
# Test for passing parameters to hamiltonian matrix elements
def onsite(site, p1, p2):
......@@ -1336,7 +1339,7 @@ def test_subs():
salt = str(b) + str(c)
return kwant.digest.uniform(ta.array((sitea.tag, siteb.tag)), salt=salt)
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
def make_system(sym=kwant.builder.NoSymmetry(), n=3):
syst = kwant.Builder(sym)
......@@ -1389,7 +1392,7 @@ def test_subs():
assert lead.parameters == {'lead_a', 'lead_b', 'lead_c'}
def test_attach_stores_padding():
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst = kwant.Builder()
syst[lat(0)] = 0
lead = kwant.Builder(kwant.TranslationalSymmetry(lat.prim_vecs[0]))
......@@ -1400,7 +1403,7 @@ def test_attach_stores_padding():
def test_finalization_preserves_padding():
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst = kwant.Builder()
for i in range(10):
syst[lat(i)] = 0
......@@ -1416,3 +1419,28 @@ def test_finalization_preserves_padding():
syst = syst.finalized()
# The order is guaranteed because the paddings are sorted.
assert [syst.sites[i] for i in syst.lead_paddings[0]] == padding[:-1]
def test_add_peierls_phase():
lat = kwant.lattice.square(norbs=1)
syst = kwant.Builder()
syst[(lat(i, j) for i in range(5) for j in range(5))] = 4
syst[lat.neighbors()] = lambda a, b, t: -t
lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
lead[(lat(0, j) for j in range(5))] = 4
lead[lat.neighbors()] = -1
syst.attach_lead(lead)
syst.attach_lead(lead.reversed())
syst, phase = builder.add_peierls_phase(syst)
assert isinstance(syst, builder.FiniteSystem)
params = phase(1, 0, 0)
assert all(p in params for p in ('phi', 'phi_lead0', 'phi_lead1'))
kwant.smatrix(syst, energy=0.1, params=dict(t=-1, **params))
......@@ -18,7 +18,7 @@ def test_qhe(W=16, L=8):
x, y = pos
return -L < x < L and abs(y) < W - 5.5 * math.exp(-x**2 / 5**2)
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst = kwant.Builder()
syst[lat.shape(central_region, (0, 0))] = onsite
......
......@@ -6,6 +6,7 @@
# the file AUTHORS.rst at the top-level directory of this distribution and at
# http://kwant-project.org/authors.
import warnings
from math import sqrt
import numpy as np
import tinyarray as ta
......@@ -17,40 +18,42 @@ import pytest
def test_closest():
rng = ensure_rng(4)
lat = lattice.general(((1, 0), (0.5, sqrt(3)/2)))
lat = lattice.general(((1, 0), (0.5, sqrt(3)/2)), norbs=1)
for i in range(50):
point = 20 * rng.random_sample(2)
closest = lat(*lat.closest(point)).pos
assert np.linalg.norm(point - closest) <= 1 / sqrt(3)
lat = lattice.general(rng.randn(3, 3))
lat = lattice.general(rng.randn(3, 3), norbs=1)
for i in range(50):
tag = rng.randint(10, size=(3,))
assert lat.closest(lat(*tag).pos) == tag
def test_general():
for lat in (lattice.general(((1, 0), (0.5, 0.5))),
for lat in (lattice.general(((1, 0), (0.5, 0.5)), norbs=1),
lattice.general(((1, 0), (0.5, sqrt(3)/2)),
((0, 0), (0, 1/sqrt(3))))):
((0, 0), (0, 1/sqrt(3))),
norbs=1,
)):
for sl in lat.sublattices:
tag = (-5, 33)
site = sl(*tag)
assert tag == sl.closest(site.pos)
# Test 2D lattice with 1 vector.
lat = lattice.general([[1, 0]])
lat = lattice.general([[1, 0]], norbs=1)
site = lat(0)
raises(ValueError, lat, 0, 1)
def test_neighbors():
lat = lattice.honeycomb(1e-10)
lat = lattice.honeycomb(1e-10, norbs=1)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == [2, 3, 6, 3, 6]
lat = lattice.general([(0, 1e8, 0, 0), (0, 0, 1e8, 0)])
lat = lattice.general([(0, 1e8, 0, 0), (0, 0, 1e8, 0)], norbs=1)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == [1, 2, 2, 2, 4]
lat = lattice.chain(1e-10)
lat = lattice.chain(1e-10, norbs=1)
num_nth_nearest = [len(lat.neighbors(n)) for n in range(5)]
assert num_nth_nearest == 5 * [1]
......@@ -59,7 +62,7 @@ def test_shape():
def in_circle(pos):
return pos[0] ** 2 + pos[1] ** 2 < 3
lat = lattice.honeycomb()
lat = lattice.honeycomb(norbs=1)
sites = list(lat.shape(in_circle, (0, 0))())
sites_alt = list()
sl0, sl1 = lat.sublattices
......@@ -88,7 +91,7 @@ def test_wire():
vecs = rng.randn(3, 3)
vecs[0] = [1, 0, 0]
center = rng.randn(3)
lat = lattice.general(vecs, rng.randn(4, 3))
lat = lattice.general(vecs, rng.randn(4, 3), norbs=1)
syst = builder.Builder(lattice.TranslationalSymmetry((2, 0, 0)))
def wire_shape(pos):
pos = np.array(pos)
......@@ -103,8 +106,8 @@ def test_wire():
def test_translational_symmetry():
ts = lattice.TranslationalSymmetry
f2 = lattice.general(np.identity(2))
f3 = lattice.general(np.identity(3))
f2 = lattice.general(np.identity(2), norbs=1)
f3 = lattice.general(np.identity(3), norbs=1)
shifted = lambda site, delta: site.family(*ta.add(site.tag, delta))
raises(ValueError, ts, (0, 0, 4), (0, 5, 0), (0, 0, 2))
......@@ -112,7 +115,7 @@ def test_translational_symmetry():
raises(ValueError, sym.add_site_family, f2)
# Test lattices with dimension smaller than dimension of space.
f2in3 = lattice.general([[4, 4, 0], [4, -4, 0]])
f2in3 = lattice.general([[4, 4, 0], [4, -4, 0]], norbs=1)
sym = ts((8, 0, 0))
sym.add_site_family(f2in3)
sym = ts((8, 0, 1))
......@@ -150,7 +153,7 @@ def test_translational_symmetry():
(site, shifted(site, hop)))
# Test act for hoppings belonging to different lattices.
f2p = lattice.general(2 * np.identity(2))
f2p = lattice.general(2 * np.identity(2), norbs=1)
sym = ts(*(2 * np.identity(2)))
assert sym.act((1, 1), f2(0, 0), f2p(0, 0)) == (f2(2, 2), f2p(1, 1))
assert sym.act((1, 1), f2p(0, 0), f2(0, 0)) == (f2p(1, 1), f2(2, 2))
......@@ -160,7 +163,7 @@ def test_translational_symmetry():
# generated symmetry with proper vectors.
rng = ensure_rng(30)
vec = rng.randn(3, 5)
lat = lattice.general(vec)
lat = lattice.general(vec, norbs=1)
total = 0
for k in range(1, 4):
for i in range(10):
......@@ -176,7 +179,7 @@ def test_translational_symmetry():
def test_translational_symmetry_reversed():
rng = ensure_rng(30)
lat = lattice.general(np.identity(3))
lat = lattice.general(np.identity(3), norbs=1)
sites = [lat(i, j, k) for i in range(-2, 6) for j in range(-2, 6)
for k in range(-2, 6)]
for i in range(4):
......@@ -194,9 +197,9 @@ def test_translational_symmetry_reversed():
def test_monatomic_lattice():
lat = lattice.square()
lat2 = lattice.general(np.identity(2))
lat3 = lattice.square(name='no')
lat = lattice.square(norbs=1)
lat2 = lattice.general(np.identity(2), norbs=1)
lat3 = lattice.square(name='no', norbs=1)
assert len(set([lat, lat2, lat3, lat(0, 0), lat2(0, 0), lat3(0, 0)])) == 4
@pytest.mark.parametrize('prim_vecs, basis', [
......@@ -210,16 +213,22 @@ def test_monatomic_lattice():
])
def test_lattice_constraints(prim_vecs, basis):
with pytest.raises(ValueError):
lattice.general(prim_vecs, basis)
lattice.general(prim_vecs, basis, norbs=1)
def test_norbs():
id_mat = np.identity(2)
# Monatomic lattices
assert lattice.general(id_mat).norbs == None
# Catch deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore")
assert lattice.general(id_mat).norbs == None
assert lattice.general(id_mat, norbs=2).norbs == 2
# Polyatomic lattices
lat = lattice.general(id_mat, basis=id_mat, norbs=None)
# Catch deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore")
lat = lattice.general(id_mat, basis=id_mat, norbs=None)
for l in lat.sublattices:
assert l.norbs == None
lat = lattice.general(id_mat, basis=id_mat, norbs=2)
......@@ -237,8 +246,14 @@ def test_norbs():
raises(ValueError, lattice.general, id_mat, norbs=1.5)
raises(ValueError, lattice.general, id_mat, id_mat, norbs=1.5)
raises(ValueError, lattice.general, id_mat, id_mat, norbs=[1.5, 1.5])
# should raise ValueError if norbs is <= 0
raises(ValueError, lattice.general, id_mat, norbs=0)
raises(ValueError, lattice.general, id_mat, norbs=-1)
# test that lattices with different norbs are compared `not equal`
lat = lattice.general(id_mat, basis=id_mat, norbs=None)
# Catch deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore")
lat = lattice.general(id_mat, basis=id_mat, norbs=None)
lat1 = lattice.general(id_mat, basis=id_mat, norbs=1)
lat2 = lattice.general(id_mat, basis=id_mat, norbs=2)
assert lat != lat1
......@@ -247,7 +262,7 @@ def test_norbs():
def test_symmetry_act():
lat = lattice.square()
lat = lattice.square(norbs=1)
sym = lattice.TranslationalSymmetry((1, 0), (0, 1))
site = lat(0, 0)
hopping = (lat(0, 0), lat(1, 0))
......
......@@ -6,6 +6,7 @@
# the file AUTHORS.rst at the top-level directory of this distribution and at
# http://kwant-project.org/authors.
import warnings
import functools as ft
from collections import deque
import pickle
......@@ -59,7 +60,10 @@ def test_operator_construction():
N = len(fsyst.sites)
# test construction failure if norbs not given
latnone = kwant.lattice.chain()
# Catch deprecation warning
with warnings.catch_warnings():
warnings.simplefilter("ignore")
latnone = kwant.lattice.chain()
syst[latnone(0)] = 1
for A in opservables:
raises(ValueError, A, syst.finalized())
......@@ -128,12 +132,35 @@ def test_operator_construction():
fwhere = tuple(fsyst.id_by_site[s] for s in where)
A = ops.Density(fsyst, where=where)
assert np.all(np.asarray(A.where).reshape(-1) == fwhere)
# Test for passing integers as 'where'
A = ops.Density(fsyst, where=fwhere)
assert np.all(np.asarray(A.where).reshape(-1) == fwhere)
# Test passing invalid sites
with raises(ValueError):
ops.Density(fsyst, where=[lat(100)])
with raises(ValueError):
ops.Density(fsyst, where=[-1])
with raises(ValueError):
ops.Density(fsyst, where=[10000])
where = [(lat(2, 2), lat(1, 2)), (lat(0, 0), lat(0, 1))]
fwhere = np.asarray([(fsyst.id_by_site[a], fsyst.id_by_site[b])
for a, b in where])
A = ops.Current(fsyst, where=where)
assert np.all(np.asarray(A.where) == fwhere)
# Test for passing integers as 'where'
A = ops.Current(fsyst, where=fwhere)
assert np.all(np.asarray(A.where) == fwhere)
# Test passing invalid hoppings
with raises(ValueError):
ops.Current(fsyst, where=[(lat(2, 2), lat(0, 0))])
with raises(ValueError):
ops.Current(fsyst, where=[(-1, 1)])
with raises(ValueError):
ops.Current(fsyst, where=[(len(fsyst.sites), 1)])
with raises(ValueError):
ops.Current(fsyst, where=[(fsyst.id_by_site[lat(2, 2)],
fsyst.id_by_site[lat(0, 0)])])
# test construction with `where` given by a function
tag_list = [(1, 0), (1, 1), (1, 2)]
......@@ -304,7 +331,7 @@ def test_opservables_spin():
down, up = kwant.wave_function(fsyst, energy=1., params=params)(0)
x_hoppings = kwant.builder.HoppingKind((1,), lat)
spin_current_z = ops.Current(fsyst, sigmaz, where=x_hoppings(syst))
spin_current_z = ops.Current(fsyst, sigmaz, where=list(x_hoppings(syst)))
_test(spin_current_z, up, params=params, per_el_val=1)
_test(spin_current_z, down, params=params, per_el_val=-1)
......@@ -366,12 +393,14 @@ def test_opservables_gauged():
(Us[i], sigmaz, Us[i].conjugate().transpose()))
x_hoppings = kwant.builder.HoppingKind((1,), lat)
spin_current_gauge = ops.Current(fsyst, M_a, where=x_hoppings(syst))
spin_current_gauge = ops.Current(fsyst, M_a,
where=list(x_hoppings(syst)))
_test(spin_current_gauge, up, per_el_val=1)
_test(spin_current_gauge, down, per_el_val=-1)
# check the reverse is also true
minus_x_hoppings = kwant.builder.HoppingKind((-1,), lat)
spin_current_gauge = ops.Current(fsyst, M_a, where=minus_x_hoppings(syst))
spin_current_gauge = ops.Current(fsyst, M_a,
where=list(minus_x_hoppings(syst)))
_test(spin_current_gauge, up, per_el_val=-1)
_test(spin_current_gauge, down, per_el_val=1)
......
......@@ -91,7 +91,7 @@ def syst_2d(W=3, r1=3, r2=8):
def syst_3d(W=3, r1=2, r2=4, a=1, t=1.0):
lat = kwant.lattice.general(((a, 0, 0), (0, a, 0), (0, 0, a)))
lat = kwant.lattice.general(((a, 0, 0), (0, a, 0), (0, 0, a)), norbs=1)
syst = kwant.Builder()
def ring(pos):
......@@ -162,13 +162,29 @@ def test_plot_more_site_families_than_colors():
# https://gitlab.kwant-project.org/kwant/kwant/issues/257
ncolors = len(pyplot.rcParams['axes.prop_cycle'])
syst = kwant.Builder()
lattices = [kwant.lattice.square(name=i) for i in range(ncolors + 1)]
lattices = [kwant.lattice.square(name=i, norbs=1)
for i in range(ncolors + 1)]
for i, lat in enumerate(lattices):
syst[lat(i, 0)] = None
with tempfile.TemporaryFile('w+b') as out:
plotter.plot(syst, file=out)
@pytest.mark.skipif(not _plotter.mpl_available, reason="Matplotlib unavailable.")
def test_plot_raises_on_bad_site_spec():
syst = kwant.Builder()
lat = kwant.lattice.square(norbs=1)
syst[(lat(i, j) for i in range(5) for j in range(5))] = None
# Cannot provide site_size as an array when syst is a Builder
with pytest.raises(TypeError):
plotter.plot(syst, site_size=[1] * 25)
# Cannot provide site_size as an array when syst is a Builder
with pytest.raises(TypeError):
plotter.plot(syst, site_symbol=['o'] * 25)
def good_transform(pos):
x, y = pos
return y, x
......@@ -237,7 +253,7 @@ def test_spectrum():
def ham_2d(a, b, c):
return np.eye(2) * (a**2 + b**2 + c**2)
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst = kwant.Builder()
syst[(lat(i) for i in range(3))] = lambda site, a, b: a + b
syst[lat.neighbors()] = lambda site1, site2, c: c
......@@ -361,7 +377,7 @@ def _border_is_0(field):
def _test_border_0(interpolator):
## Test that current is always identically zero at box boundaries
syst = kwant.Builder()
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst[[lat(0, 0), lat(1, 0)]] = None
syst[(lat(0, 0), lat(1, 0))] = None
syst = syst.finalized()
......@@ -488,7 +504,7 @@ def test_current_interpolation():
### Tests on a divergence-free current (closed system)
lat = kwant.lattice.general([(1, 0), (0.5, np.sqrt(3) / 2)])
lat = kwant.lattice.general([(1, 0), (0.5, np.sqrt(3) / 2)], norbs=1)
syst = kwant.Builder()
sites = [lat(0, 0), lat(1, 0), lat(0, 1), lat(2, 2)]
syst[sites] = None
......
......@@ -17,7 +17,7 @@ from kwant._common import ensure_rng
def test_hamiltonian_submatrix():
syst = kwant.Builder()
chain = kwant.lattice.chain()
chain = kwant.lattice.chain(norbs=1)
for i in range(3):
syst[chain(i)] = 0.5 * i
for i in range(2):
......@@ -87,7 +87,7 @@ def test_hamiltonian_submatrix():
def test_pickling():
syst = kwant.Builder()
lead = kwant.Builder(symmetry=kwant.TranslationalSymmetry([1.]))
lat = kwant.lattice.chain()
lat = kwant.lattice.chain(norbs=1)
syst[lat(0)] = syst[lat(1)] = 0
syst[lat(0), lat(1)] = 1
lead[lat(0)] = syst[lat(1)] = 0
......
......@@ -37,7 +37,8 @@ def _simple_syst(lat, E=0, t=1+1j, sym=None):
def test_consistence_with_bands(kx=1.9, nkys=31):
kys = np.linspace(-np.pi, np.pi, nkys)
for lat in [kwant.lattice.honeycomb(), kwant.lattice.square()]:
for lat in [kwant.lattice.honeycomb(norbs=1),
kwant.lattice.square(norbs=1)]:
syst = _simple_syst(lat)
wa_keep_1 = wraparound(syst, keep=1).finalized()
wa_keep_none = wraparound(syst).finalized()
......@@ -56,7 +57,7 @@ def test_consistence_with_bands(kx=1.9, nkys=31):
def test_opposite_hoppings():
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
for val in [1j, lambda a, b: 1j]:
syst = kwant.Builder(kwant.TranslationalSymmetry((1, 1)))
......@@ -74,7 +75,8 @@ def test_opposite_hoppings():
def test_value_types(k=(-1.1, 0.5), E=2, t=1):
k = dict(zip(('k_x', 'k_y', 'k_z'), k))
sym_extents = [1, 2, 3]
lattices = [kwant.lattice.honeycomb(), kwant.lattice.square()]
lattices = [kwant.lattice.honeycomb(norbs=1),
kwant.lattice.square(norbs=1)]
lat_syms = [
(lat, kwant.TranslationalSymmetry(lat.vec((n, 0)), lat.vec((0, n))))
for n, lat in itertools.product(sym_extents, lattices)
......@@ -112,7 +114,7 @@ def test_value_types(k=(-1.1, 0.5), E=2, t=1):
def test_signatures():
lat = kwant.lattice.square()
lat = kwant.lattice.square(norbs=1)
syst = kwant.Builder(kwant.TranslationalSymmetry((-3, 0), (0, 1)))
# onsites and hoppings that will be bound as sites
syst[lat(-2, 0)] = 4
......@@ -162,7 +164,7 @@ def test_signatures():
def test_symmetry():
syst = _simple_syst(kwant.lattice.square())
syst = _simple_syst(kwant.lattice.square(norbs=1))
matrices = [np.random.rand(2, 2) for i in range(4)]
laws = (matrices, [(lambda a: m) for m in matrices])
......@@ -190,10 +192,10 @@ def test_symmetry():
@pytest.mark.skipif(not _plotter.mpl_available, reason="Matplotlib unavailable.")
def test_plot_2d_bands():
chain = kwant.lattice.chain()
square = kwant.lattice.square()
cube = kwant.lattice.general([(1, 0, 0), (0, 1, 0), (0, 0, 1)])
hc = kwant.lattice.honeycomb()
chain = kwant.lattice.chain(norbs=1)
square = kwant.lattice.square(norbs=1)
cube = kwant.lattice.general([(1, 0, 0), (0, 1, 0), (0, 0, 1)], norbs=1)
hc = kwant.lattice.honeycomb(norbs=1)
syst_1d = kwant.Builder(kwant.TranslationalSymmetry(*chain._prim_vecs))
syst_1d[chain(0)] = 2
......@@ -245,7 +247,7 @@ def test_fd_mismatch():
# around in all directions, but could not be wrapped around when 'keep' is
# provided.
sqrt3 = np.sqrt(3)
lat = kwant.lattice.general([(sqrt3, 0), (-sqrt3/2, 1.5)])
lat = kwant.lattice.general([(sqrt3, 0), (-sqrt3/2, 1.5)], norbs=1)
T = kwant.TranslationalSymmetry((sqrt3, 0), (0, 3))
syst1 = kwant.Builder(T)
......@@ -269,7 +271,8 @@ def test_fd_mismatch():
## Test that spectrum of non-trivial system (including above cases)
## is the same, regardless of the way in which it is wrapped around
lat = kwant.lattice.general([(sqrt3, 0), (-sqrt3/2, 1.5)],
[(sqrt3 / 2, 0.5), (0, 1)])
[(sqrt3 / 2, 0.5), (0, 1)],
norbs=1)
a, b = lat.sublattices
T = kwant.TranslationalSymmetry((3 * sqrt3, 0), (0, 3))
syst = kwant.Builder(T)
......@@ -302,7 +305,7 @@ def test_fd_mismatch():
assert all(np.allclose(E, E[0]) for E in E_k)
# Test square lattice with oblique unit cell
lat = kwant.lattice.general(np.eye(2))
lat = kwant.lattice.general(np.eye(2), norbs=1)
translations = kwant.lattice.TranslationalSymmetry([2, 2], [0, 2])
syst = kwant.Builder(symmetry=translations)
syst[lat.shape(lambda site: True, [0, 0])] = 1
......@@ -314,7 +317,7 @@ def test_fd_mismatch():
# Test Rocksalt structure
# cubic lattice that contains both sublattices
lat = kwant.lattice.general(np.eye(3))
lat = kwant.lattice.general(np.eye(3), norbs=1)
# Builder with FCC translational symmetries.
translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, 0, 1], [0, 1, 1])
syst = kwant.Builder(symmetry=translations)
......@@ -341,7 +344,7 @@ def test_fd_mismatch():
def shape(site):
return abs(site.tag[2]) < 4
lat = kwant.lattice.general(np.eye(3))
lat = kwant.lattice.general(np.eye(3), norbs=1)
# First choice: primitive UC
translations = kwant.lattice.TranslationalSymmetry([1, 1, 0], [1, -1, 0], [1, 0, 1])
syst = kwant.Builder(symmetry=translations)
......