Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
K
kwant
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Joseph Weston
kwant
Commits
08cbaaad
Commit
08cbaaad
authored
8 years ago
by
Jörg Behrmann
Committed by
Joseph Weston
8 years ago
Browse files
Options
Downloads
Patches
Plain Diff
define ordering for `SiteFamily` and add a test for this
parent
91b58d4a
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kwant/builder.py
+8
-0
8 additions, 0 deletions
kwant/builder.py
kwant/tests/test_builder.py
+17
-0
17 additions, 0 deletions
kwant/tests/test_builder.py
with
25 additions
and
0 deletions
kwant/builder.py
+
8
−
0
View file @
08cbaaad
...
...
@@ -12,6 +12,7 @@ __all__ = ['Builder', 'Site', 'SiteFamily', 'SimpleSiteFamily', 'Symmetry',
import
abc
import
warnings
import
operator
from
functools
import
total_ordering
from
itertools
import
islice
,
chain
import
tinyarray
as
ta
import
numpy
as
np
...
...
@@ -82,6 +83,7 @@ class Site(tuple):
return
self
.
family
.
pos
(
self
.
tag
)
@total_ordering
class
SiteFamily
(
metaclass
=
abc
.
ABCMeta
):
"""
Abstract base class for site families.
...
...
@@ -154,6 +156,12 @@ class SiteFamily(metaclass=abc.ABCMeta):
except
AttributeError
:
return
True
def
__lt__
(
self
,
other
):
try
:
return
self
.
canonical_repr
<
other
.
canonical_repr
except
AttributeError
:
return
False
@abc.abstractmethod
def
normalize_tag
(
self
,
tag
):
"""
Return a normalized version of the tag.
...
...
This diff is collapsed.
Click to expand it.
kwant/tests/test_builder.py
+
17
−
0
View file @
08cbaaad
...
...
@@ -111,6 +111,23 @@ def test_site_families():
assert_not_equal
(
fam
,
'
a
'
)
def
test_site_families_sorting
():
fam1
=
builder
.
SimpleSiteFamily
(
'
fam1
'
)
fam2
=
builder
.
SimpleSiteFamily
(
'
fam2
'
)
rng
=
Random
(
123
)
tags
=
[(
rng
.
randint
(
0
,
10
),
rng
.
randint
(
0
,
10
))
for
i
in
range
(
10
)]
tags_sorted
=
[
t
for
t
in
sorted
(
tags
)]
sites
=
[
fam1
(
*
t
)
for
t
in
tags
]
+
[
fam2
(
*
t
)
for
t
in
tags
]
rng
.
shuffle
(
sites
)
sites_sorted
=
([
fam1
(
*
t
)
for
t
in
tags_sorted
]
+
[
fam2
(
*
t
)
for
t
in
tags_sorted
])
assert_equal
(
list
(
sorted
(
sites
)),
sites_sorted
)
class
VerySimpleSymmetry
(
builder
.
Symmetry
):
def
__init__
(
self
,
period
):
self
.
period
=
period
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment