From 7ee5221f2e6829ad814a02bbffb26a9bef377c77 Mon Sep 17 00:00:00 2001 From: Joseph Weston <joseph@weston.cloud> Date: Tue, 26 Nov 2019 14:19:36 +0100 Subject: [PATCH] replace 'builder' with 'system' when referring to 'Symmetry' Even though we currently import 'Symmetry' and 'NoSymmetry' in 'builder' (to maintain backwards compatibility), we should use the canonical location within Kwant itself. --- kwant/builder.py | 8 ++++---- kwant/continuum/landau_levels.py | 3 ++- kwant/continuum/tests/test_landau_levels.py | 4 ++-- kwant/lattice.py | 10 +++++----- kwant/physics/tests/test_gauge.py | 3 ++- kwant/tests/test_builder.py | 10 +++++----- kwant/tests/test_lattice.py | 4 ++-- 7 files changed, 22 insertions(+), 20 deletions(-) diff --git a/kwant/builder.py b/kwant/builder.py index 05ee58f7..156c97f6 100644 --- a/kwant/builder.py +++ b/kwant/builder.py @@ -482,7 +482,7 @@ class Builder: Parameters ---------- - symmetry : `Symmetry` or `None` + symmetry : `~kwant.system.Symmetry` or `None` The spatial symmetry of the system. conservation_law : 2D array, dictionary, function, or `None` An onsite operator with integer eigenvalues that commutes with the @@ -531,8 +531,8 @@ class Builder: that if ``builder[a, b]`` has been set, there is no need to set ``builder[b, a]``. - Builder instances can be made to automatically respect a `Symmetry` that is - passed to them during creation. The behavior of builders with a symmetry + Builder instances can be made to automatically respect a `~kwant.system.Symmetry` + that is passed to them during creation. The behavior of builders with a symmetry is slightly more sophisticated: all keys are mapped to the fundamental domain of the symmetry before storing them. This may produce confusing results when neighbors of a site are queried. @@ -1481,7 +1481,7 @@ class Builder: system to be returned. Currently, only Builder instances without or with a 1D translational - `Symmetry` can be finalized. + `~kwant.system.Symmetry` can be finalized. """ if self.symmetry.num_directions == 0: if self.vectorize: diff --git a/kwant/continuum/landau_levels.py b/kwant/continuum/landau_levels.py index c653c55e..b2b8fc80 100644 --- a/kwant/continuum/landau_levels.py +++ b/kwant/continuum/landau_levels.py @@ -18,6 +18,7 @@ import sympy import kwant.lattice import kwant.builder +import kwant.system import kwant.continuum import kwant.continuum._common @@ -144,7 +145,7 @@ def discretize_landau(hamiltonian, N, momenta=None, grid_spacing=1): if _has_coordinate(normal_coordinate, hamiltonian): sym = kwant.lattice.TranslationalSymmetry([grid_spacing, 0]) else: - sym = kwant.builder.NoSymmetry() + sym = kwant.system.NoSymmetry() lat = LandauLattice(grid_spacing, norbs=norbs) syst = kwant.Builder(sym) diff --git a/kwant/continuum/tests/test_landau_levels.py b/kwant/continuum/tests/test_landau_levels.py index 8a568e6f..5878724f 100644 --- a/kwant/continuum/tests/test_landau_levels.py +++ b/kwant/continuum/tests/test_landau_levels.py @@ -13,8 +13,8 @@ import sympy import pytest import itertools -import kwant.builder import kwant.lattice +import kwant.system from .._common import position_operators, momentum_operators, sympify from ..landau_levels import ( @@ -118,7 +118,7 @@ def test_discretize_landau(): # test a basic Hamiltonian with no normal coordinate dependence syst = discretize_landau("k_x**2 + k_y**2", N=n_levels) lat = LandauLattice(1, norbs=1) - assert isinstance(syst.symmetry, kwant.builder.NoSymmetry) + assert isinstance(syst.symmetry, kwant.system.NoSymmetry) syst = syst.finalized() assert set(syst.sites) == {lat(0, j) for j in range(n_levels)} assert np.allclose( diff --git a/kwant/lattice.py b/kwant/lattice.py index 7e0d5590..976213d3 100644 --- a/kwant/lattice.py +++ b/kwant/lattice.py @@ -153,7 +153,7 @@ class Polyatomic: algorithm finds and yields all the lattice sites inside the specified shape starting from the specified position. - A `~kwant.builder.Symmetry` or `~kwant.builder.Builder` may be passed as + A `~kwant.system.Symmetry` or `~kwant.builder.Builder` may be passed as sole argument when calling the function returned by this method. This will restrict the flood-fill to the fundamental domain of the symmetry (or the builder's symmetry). Note that unless the shape function has @@ -174,8 +174,8 @@ class Polyatomic: Site = system.Site if symmetry is None: - symmetry = builder.NoSymmetry() - elif not isinstance(symmetry, builder.Symmetry): + symmetry = system.NoSymmetry() + elif not isinstance(symmetry, system.Symmetry): symmetry = symmetry.symmetry def fd_site(lat, tag): @@ -259,7 +259,7 @@ class Polyatomic: center = ta.array(center, float) def wire_sites(sym): - if not isinstance(sym, builder.Symmetry): + if not isinstance(sym, system.Symmetry): sym = sym.symmetry if not isinstance(sym, TranslationalSymmetry): raise ValueError('wire shape only works with ' @@ -568,7 +568,7 @@ class TranslationalSymmetry(system.Symmetry): return TranslationalSymmetry(*ta.dot(generators, self.periods)) def has_subgroup(self, other): - if isinstance(other, builder.NoSymmetry): + if isinstance(other, system.NoSymmetry): return True elif not isinstance(other, TranslationalSymmetry): raise ValueError("Unknown symmetry type.") diff --git a/kwant/physics/tests/test_gauge.py b/kwant/physics/tests/test_gauge.py index 067c3244..40e5f66d 100644 --- a/kwant/physics/tests/test_gauge.py +++ b/kwant/physics/tests/test_gauge.py @@ -6,7 +6,8 @@ import pytest import kwant from ... import lattice -from ...builder import HoppingKind, Builder, NoSymmetry, Site +from ...builder import HoppingKind, Builder, Site +from ...system import NoSymmetry from .. import gauge diff --git a/kwant/tests/test_builder.py b/kwant/tests/test_builder.py index 3355a4ff..f4a70985 100644 --- a/kwant/tests/test_builder.py +++ b/kwant/tests/test_builder.py @@ -153,7 +153,7 @@ def test_site_families(): assert fam1 < fam2 # string '1' is lexicographically less than '2' -class VerySimpleSymmetry(builder.Symmetry): +class VerySimpleSymmetry(system.Symmetry): def __init__(self, period): self.period = period @@ -162,7 +162,7 @@ class VerySimpleSymmetry(builder.Symmetry): return 1 def has_subgroup(self, other): - if isinstance(other, builder.NoSymmetry): + if isinstance(other, system.NoSymmetry): return True elif isinstance(other, VerySimpleSymmetry): return not other.period % self.period @@ -809,7 +809,7 @@ def test_vectorized_value_normalization(): @pytest.mark.parametrize("sym", [ - builder.NoSymmetry(), + system.NoSymmetry(), kwant.TranslationalSymmetry([-1]), ]) def test_vectorized_requires_norbs(sym): @@ -918,7 +918,7 @@ def test_fill(): ## Test that copying a builder by "fill" preserves everything. for sym, func in [(kwant.TranslationalSymmetry(*np.diag([3, 4, 5])), lambda pos: True), - (builder.NoSymmetry(), + (system.NoSymmetry(), lambda pos: ta.dot(pos, pos) < 17)]: cubic = kwant.lattice.general(ta.identity(3), norbs=1) @@ -1639,7 +1639,7 @@ def test_subs(): lat = kwant.lattice.chain(norbs=1) - def make_system(sym=kwant.builder.NoSymmetry(), n=3): + def make_system(sym=system.NoSymmetry(), n=3): syst = kwant.Builder(sym) syst[(lat(i) for i in range(n))] = onsite syst[lat.neighbors()] = hopping diff --git a/kwant/tests/test_lattice.py b/kwant/tests/test_lattice.py index 5e7a9976..4850e451 100644 --- a/kwant/tests/test_lattice.py +++ b/kwant/tests/test_lattice.py @@ -11,7 +11,7 @@ from math import sqrt import numpy as np import tinyarray as ta from pytest import raises -from kwant import lattice, builder +from kwant import lattice, builder, system from kwant._common import ensure_rng import pytest @@ -285,7 +285,7 @@ def test_symmetry_has_subgroup(): ## test whether actual subgroups are detected as such vecs = rng.randn(3, 3) sym1 = lattice.TranslationalSymmetry(*vecs) - ns = builder.NoSymmetry() + ns = system.NoSymmetry() assert ns.has_subgroup(ns) assert sym1.has_subgroup(sym1) assert sym1.has_subgroup(ns) -- GitLab