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
92b1c068
There was a problem fetching the pipeline summary.
Commit
92b1c068
authored
7 years ago
by
Christoph Groth
Browse files
Options
Downloads
Plain Diff
Merge !202 (do not overwrite variable in loop) into stable
parents
c1bcca9b
6cfceda4
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Pipeline
#
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
kwant/continuum/discretizer.py
+3
-3
3 additions, 3 deletions
kwant/continuum/discretizer.py
kwant/continuum/tests/test_discretizer.py
+17
-14
17 additions, 14 deletions
kwant/continuum/tests/test_discretizer.py
with
20 additions
and
17 deletions
kwant/continuum/discretizer.py
+
3
−
3
View file @
92b1c068
...
...
@@ -601,12 +601,12 @@ def _builder_value(expr, coords, grid_spacing, onsite,
{
str
(
k
.
func
)
for
k
in
map_func_calls
})
# check if all argument names are valid python identifiers
for
name
in
arg_names
:
if
not
(
name
.
isidentifier
()
and
not
iskeyword
(
name
)):
for
arg_
name
in
arg_names
:
if
not
(
arg_
name
.
isidentifier
()
and
not
iskeyword
(
arg_
name
)):
raise
ValueError
(
"
Invalid name in used symbols: {}
\n
"
"
Names of symbols used in Hamiltonian
"
"
must be valid Python identifiers and
"
"
may not be keywords
"
.
format
(
name
))
"
may not be keywords
"
.
format
(
arg_
name
))
arg_names
=
'
,
'
.
join
(
sorted
(
arg_names
))
...
...
This diff is collapsed.
Click to expand it.
kwant/continuum/tests/test_discretizer.py
+
17
−
14
View file @
92b1c068
...
...
@@ -45,7 +45,7 @@ x, y, z = sympy.symbols('x y z', commutative=False)
ax
,
ay
,
az
=
sympy
.
symbols
(
'
a_x a_y a_z
'
)
a
=
sympy
.
symbols
(
'
a
'
)
wf
=
_wf
wf
=
_wf
Psi
=
wf
(
x
,
y
,
z
)
A
,
B
=
sympy
.
symbols
(
'
A B
'
,
commutative
=
False
)
...
...
@@ -62,7 +62,7 @@ def test_reading_coordinates(commutative):
kx
**
2
+
ky
**
2
+
kz
**
2
:
[
'
x
'
,
'
y
'
,
'
z
'
],
ky
**
2
+
kz
**
2
:
[
'
y
'
,
'
z
'
],
kz
**
2
:
[
'
z
'
],
kx
*
A
(
x
,
y
)
*
kx
:
[
'
x
'
],
kx
*
A
(
x
,
y
)
*
kx
:
[
'
x
'
],
kx
**
2
+
kz
*
B
(
y
)
:
[
'
x
'
,
'
z
'
],
}
for
inp
,
out
in
test
.
items
():
...
...
@@ -78,7 +78,7 @@ def test_reading_coordinates_matrix():
(
sympy
.
Matrix
([
kx
**
2
+
ky
**
2
+
kz
**
2
])
,
[
'
x
'
,
'
y
'
,
'
z
'
]),
(
sympy
.
Matrix
([
ky
**
2
+
kz
**
2
])
,
[
'
y
'
,
'
z
'
]),
(
sympy
.
Matrix
([
kz
**
2
])
,
[
'
z
'
]),
(
sympy
.
Matrix
([
kx
*
A
(
x
,
y
)
*
kx
])
,
[
'
x
'
]),
(
sympy
.
Matrix
([
kx
*
A
(
x
,
y
)
*
kx
])
,
[
'
x
'
]),
(
sympy
.
Matrix
([
kx
**
2
+
kz
*
B
(
y
)])
,
[
'
x
'
,
'
z
'
]),
]
for
inp
,
out
in
test
:
...
...
@@ -113,7 +113,7 @@ def test_simple_derivations(commutative):
kz
**
2
:
{(
0
,):
2
/
a
**
2
,
(
1
,):
-
1
/
a
**
2
},
}
non_commutative_test
=
{
kx
*
A
(
x
,
y
)
*
kx
:
{(
1
,
):
-
A
(
a
/
2
+
x
,
y
)
/
a
**
2
,
kx
*
A
(
x
,
y
)
*
kx
:
{(
1
,
):
-
A
(
a
/
2
+
x
,
y
)
/
a
**
2
,
(
0
,
):
A
(
-
a
/
2
+
x
,
y
)
/
a
**
2
+
A
(
a
/
2
+
x
,
y
)
/
a
**
2
},
kx
**
2
+
kz
*
B
(
y
)
:
{(
1
,
0
):
-
1
/
a
**
2
,
(
0
,
1
):
-
I
*
B
(
y
)
/
(
2
*
a
),
(
0
,
0
):
2
/
a
**
2
},
...
...
@@ -160,7 +160,7 @@ def test_simple_derivations_matrix():
ky
**
2
+
kz
**
2
:
{(
0
,
1
):
-
1
/
a
**
2
,
(
0
,
0
):
4
/
a
**
2
,
(
1
,
0
):
-
1
/
a
**
2
},
kz
**
2
:
{(
0
,):
2
/
a
**
2
,
(
1
,):
-
1
/
a
**
2
},
kx
*
A
(
x
,
y
)
*
kx
:
{(
1
,
):
-
A
(
a
/
2
+
x
,
y
)
/
a
**
2
,
kx
*
A
(
x
,
y
)
*
kx
:
{(
1
,
):
-
A
(
a
/
2
+
x
,
y
)
/
a
**
2
,
(
0
,
):
A
(
-
a
/
2
+
x
,
y
)
/
a
**
2
+
A
(
a
/
2
+
x
,
y
)
/
a
**
2
},
kx
**
2
+
kz
*
B
(
y
)
:
{(
1
,
0
):
-
1
/
a
**
2
,
(
0
,
1
):
-
I
*
B
(
y
)
/
(
2
*
a
),
(
0
,
0
):
2
/
a
**
2
},
...
...
@@ -195,9 +195,9 @@ def test_simple_derivations_matrix():
def
test_integer_float_input
():
test
=
{
0
:
{(
0
,
0
,
0
):
0
},
1
:
{(
0
,
0
,
0
):
1
},
5
:
{(
0
,
0
,
0
):
5
},
0
:
{(
0
,
0
,
0
):
0
},
1
:
{(
0
,
0
,
0
):
1
},
5
:
{(
0
,
0
,
0
):
5
},
}
for
inp
,
out
in
test
.
items
():
...
...
@@ -266,7 +266,7 @@ def test_different_discrete_coordinates():
'
z
'
,
{
(
0
,):
ky
**
2
+
kx
**
2
+
2
/
a
**
2
,
(
1
,):
-
1
/
a
**
2
}
)
,
),
]
for
inp
,
out
in
test
:
got
,
_
=
discretize_symbolic
(
kx
**
2
+
ky
**
2
+
kz
**
2
,
inp
)
...
...
@@ -298,8 +298,8 @@ def test_matrix_with_zeros():
Matrix
=
sympy
.
Matrix
symbolic
,
_
=
discretize_symbolic
(
"
[[k_x*A(x)*k_x, 0], [0, k_x*A(x)*k_x]]
"
)
output
=
{
(
0
,)
:
Matrix
([[
A
(
-
a
/
2
+
x
)
/
a
**
2
+
A
(
a
/
2
+
x
)
/
a
**
2
,
0
],
[
0
,
A
(
-
a
/
2
+
x
)
/
a
**
2
+
A
(
a
/
2
+
x
)
/
a
**
2
]]),
(
1
,)
:
Matrix
([[
-
A
(
a
/
2
+
x
)
/
a
**
2
,
0
],
[
0
,
-
A
(
a
/
2
+
x
)
/
a
**
2
]]),
(
0
,):
Matrix
([[
A
(
-
a
/
2
+
x
)
/
a
**
2
+
A
(
a
/
2
+
x
)
/
a
**
2
,
0
],
[
0
,
A
(
-
a
/
2
+
x
)
/
a
**
2
+
A
(
a
/
2
+
x
)
/
a
**
2
]]),
(
1
,):
Matrix
([[
-
A
(
a
/
2
+
x
)
/
a
**
2
,
0
],
[
0
,
-
A
(
a
/
2
+
x
)
/
a
**
2
]]),
}
assert
symbolic
==
output
...
...
@@ -326,7 +326,7 @@ def test_numeric_functions_basic_symbolic():
assert
+
1j
*
p
[
'
t
'
]
==
builder
[
lat
(
1
),
lat
(
0
)](
None
,
None
,
**
p
)
@pytest.mark.parametrize
(
'
commutative
'
,
[
True
,
False
])
@pytest.mark.parametrize
(
'
commutative
'
,
[
True
,
False
])
def
test_numeric_function_coords_from_site
(
commutative
):
tb
=
{(
0
,):
sympy
.
symbols
(
'
x
'
,
commutative
=
commutative
)}
builder
=
build_discretized
(
tb
,
'
x
'
)
...
...
@@ -336,7 +336,6 @@ def test_numeric_function_coords_from_site(commutative):
assert
(
onsite
(
lat
(
0
))
==
0
and
onsite
(
lat
(
1
))
==
1
)
def
test_numeric_functions_not_discrete_coords
():
builder
=
discretize
(
'
k_y + y
'
,
'
x
'
)
lat
=
next
(
iter
(
builder
.
sites
()))[
0
]
...
...
@@ -401,8 +400,12 @@ def test_numeric_functions_with_subs(e_to_subs, e, subs):
hop_direct
=
builder_direct
[
lat
(
0
),
lat
(
1
)](
None
,
None
,
**
p
)
hop_subs
=
builder_subs
[
lat
(
0
),
lat
(
1
)](
None
,
None
,
**
p
)
assert
hop_direct
==
hop_subs
assert
hop_direct
==
hop_subs
def
test_onsite_hopping_function_name
():
template
=
str
(
discretize
(
'
A * k_x
'
))
assert
'
def hopping
'
in
template
def
test_numeric_functions_advance
():
...
...
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