From 33b79fc7d5894a3e01328a4e59fa4019251b3ae3 Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph@weston.cloud> Date: Wed, 21 Aug 2019 14:01:22 +0200 Subject: [PATCH] specify 'norbs' on lattice creation in all tests --- kwant/continuum/tests/test_discretizer.py | 22 +++---- kwant/linalg/tests/test_mumps.py | 2 +- kwant/physics/tests/test_dispersion.py | 10 ++-- kwant/physics/tests/test_leads.py | 4 +- kwant/physics/tests/test_noise.py | 2 +- kwant/solvers/tests/_test_sparse.py | 8 +-- kwant/tests/test_builder.py | 73 ++++++++++++----------- kwant/tests/test_comprehensive.py | 2 +- kwant/tests/test_lattice.py | 60 +++++++++++-------- kwant/tests/test_operator.py | 6 +- kwant/tests/test_plotter.py | 13 ++-- kwant/tests/test_system.py | 4 +- kwant/tests/test_wraparound.py | 31 +++++----- 13 files changed, 130 insertions(+), 107 deletions(-) diff --git a/kwant/continuum/tests/test_discretizer.py b/kwant/continuum/tests/test_discretizer.py index b8953e6b..6307b1f7 100644 --- a/kwant/continuum/tests/test_discretizer.py +++ b/kwant/continuum/tests/test_discretizer.py @@ -548,14 +548,14 @@ def test_grid(ham, grid_spacing, grid): @pytest.mark.parametrize('ham, grid_offset, offset, norbs', [ - ('k_x', None, 0, None), + ('k_x', None, 0, 1), ('k_x', None, 0, 1), ('k_x * eye(2)', None, 0, 2), - ('k_x', (0,), 0, None), - ('k_x', (1,), 1, None), - ('k_x + k_y', None, (0, 0), None), - ('k_x + k_y', (0, 0), (0, 0), None), - ('k_x + k_y', (1, 2), (1, 2), None), + ('k_x', (0,), 0, 1), + ('k_x', (1,), 1, 1), + ('k_x + k_y', None, (0, 0), 1), + ('k_x + k_y', (0, 0), (0, 0), 1), + ('k_x + k_y', (1, 2), (1, 2), 1), ]) def test_grid_input(ham, grid_offset, offset, norbs): # build appriopriate grid @@ -579,7 +579,7 @@ def test_grid_input(ham, grid_offset, offset, norbs): def test_grid_offset_passed_to_functions(): V = lambda x: x - grid = Monatomic([[1, ]], offset=[0.5, ]) + grid = Monatomic([[1, ]], offset=[0.5, ], norbs=1) tb = discretize('V(x)', 'x', grid=grid) onsite = tb[tb.lattice(0)] bools = [np.allclose(onsite(tb.lattice(i), V), V(tb.lattice(i).pos)) @@ -588,11 +588,11 @@ def test_grid_offset_passed_to_functions(): @pytest.mark.parametrize("ham, coords, grid", [ - ("k_x", None, Monatomic([[1, 0]])), - ("k_x", 'xy', Monatomic([[1, 0]])), + ("k_x", None, Monatomic([[1, 0]], norbs=1)), + ("k_x", 'xy', Monatomic([[1, 0]], norbs=1)), ("k_x", None, Monatomic([[1, ]], norbs=2)), ("k_x * eye(2)", None, Monatomic([[1, ]], norbs=1)), - ("k_x+k_y", None, Monatomic([[1, 0], [1, 1]])), + ("k_x+k_y", None, Monatomic([[1, 0], [1, 1]], norbs=1)), ]) def test_grid_constraints(ham, coords, grid): with pytest.raises(ValueError): @@ -606,7 +606,7 @@ def test_check_symbol_names(name): def test_rectangular_grid(): - lat = Monatomic([[1, 0], [0, 2]]) + lat = Monatomic([[1, 0], [0, 2]], norbs=1) tb = discretize("V(x, y)", 'xy', grid=lat) assert np.allclose(tb[lat(0, 0)](lat(1, 0), lambda x, y: x), 1) diff --git a/kwant/linalg/tests/test_mumps.py b/kwant/linalg/tests/test_mumps.py index b28e6f1e..c2d3b56f 100644 --- a/kwant/linalg/tests/test_mumps.py +++ b/kwant/linalg/tests/test_mumps.py @@ -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): diff --git a/kwant/physics/tests/test_dispersion.py b/kwant/physics/tests/test_dispersion.py index a42d6dea..745e58b8 100644 --- a/kwant/physics/tests/test_dispersion.py +++ b/kwant/physics/tests/test_dispersion.py @@ -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 diff --git a/kwant/physics/tests/test_leads.py b/kwant/physics/tests/test_leads.py index e7994941..a3b795a2 100644 --- a/kwant/physics/tests/test_leads.py +++ b/kwant/physics/tests/test_leads.py @@ -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() diff --git a/kwant/physics/tests/test_noise.py b/kwant/physics/tests/test_noise.py index 144a298f..6235c2ab 100644 --- a/kwant/physics/tests/test_noise.py +++ b/kwant/physics/tests/test_noise.py @@ -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=2) def twoterminal_system(): rng = ensure_rng(11) diff --git a/kwant/solvers/tests/_test_sparse.py b/kwant/solvers/tests/_test_sparse.py index 8b2efa92..84748086 100644 --- a/kwant/solvers/tests/_test_sparse.py +++ b/kwant/solvers/tests/_test_sparse.py @@ -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=1) +sq = square = kwant.lattice.square(norbs=1) class LeadWithOnlySelfEnergy: @@ -428,7 +428,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 +443,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 diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 3885940a..7ba00b40 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -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 @@ -1420,7 +1423,7 @@ def test_finalization_preserves_padding(): def test_add_peierls_phase(): - lat = kwant.lattice.square() + 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 diff --git a/kwant/tests/test_comprehensive.py b/kwant/tests/test_comprehensive.py index 9989bf59..11f82ae3 100644 --- a/kwant/tests/test_comprehensive.py +++ b/kwant/tests/test_comprehensive.py @@ -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 diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py index 3f9088aa..5e7a9976 100644 --- a/kwant/tests/test_lattice.py +++ b/kwant/tests/test_lattice.py @@ -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) @@ -241,7 +250,10 @@ def test_norbs(): 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 @@ -250,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)) diff --git a/kwant/tests/test_operator.py b/kwant/tests/test_operator.py index 6bb05593..bb8a185e 100644 --- a/kwant/tests/test_operator.py +++ b/kwant/tests/test_operator.py @@ -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()) diff --git a/kwant/tests/test_plotter.py b/kwant/tests/test_plotter.py index a8358284..9edc9027 100644 --- a/kwant/tests/test_plotter.py +++ b/kwant/tests/test_plotter.py @@ -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,7 +162,8 @@ 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: @@ -172,7 +173,7 @@ def test_plot_more_site_families_than_colors(): @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() + 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 @@ -252,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 @@ -376,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() @@ -503,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 diff --git a/kwant/tests/test_system.py b/kwant/tests/test_system.py index 7b324193..9bba152b 100644 --- a/kwant/tests/test_system.py +++ b/kwant/tests/test_system.py @@ -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 diff --git a/kwant/tests/test_wraparound.py b/kwant/tests/test_wraparound.py index aa53e1c3..90014b60 100644 --- a/kwant/tests/test_wraparound.py +++ b/kwant/tests/test_wraparound.py @@ -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) -- GitLab