Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
MeanFi
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
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
Quantum Tinkerer
MeanFi
Commits
cf866adf
Commit
cf866adf
authored
1 year ago
by
Antonio Manesco
Browse files
Options
Downloads
Patches
Plain Diff
implement multidimensional hermitian Hamiltonians
parent
927f0c20
No related branches found
No related tags found
1 merge request
!3
create solvers and interface modules
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
codes/utils.py
+24
-4
24 additions, 4 deletions
codes/utils.py
with
24 additions
and
4 deletions
codes/utils.py
+
24
−
4
View file @
cf866adf
...
...
@@ -188,7 +188,7 @@ def model2hk(tb_model):
return
bloch_ham
def
kgrid_hamiltonian
(
nk
,
hk
,
dim
,
return_ks
=
False
):
def
kgrid_hamiltonian
(
nk
,
hk
,
dim
,
return_ks
=
False
,
hermitian
=
True
):
"""
Evaluates Hamiltonian on a k-point grid.
...
...
@@ -220,9 +220,10 @@ def kgrid_hamiltonian(nk, hk, dim, return_ks=False):
for
k
in
product
(
*
k_pts
):
ham
.
append
(
hk
(
k
))
ham
=
np
.
array
(
ham
)
assert
np
.
allclose
(
ham
,
np
.
transpose
(
ham
,
(
0
,
2
,
1
)).
conj
()
),
"
Tight-binding provided is non-Hermitian. Not supported yet
"
if
hermitian
:
assert
np
.
allclose
(
ham
,
np
.
transpose
(
ham
,
(
0
,
2
,
1
)).
conj
()
),
"
Tight-binding provided is non-Hermitian. Not supported yet
"
shape
=
(
*
[
nk
]
*
dim
,
ham
.
shape
[
-
1
],
ham
.
shape
[
-
1
])
if
return_ks
:
return
ham
.
reshape
(
*
shape
),
ks
...
...
@@ -358,3 +359,22 @@ def calc_gap(vals, E_F):
emax
=
np
.
max
(
vals
[
vals
<=
E_F
])
emin
=
np
.
min
(
vals
[
vals
>
E_F
])
return
np
.
abs
(
emin
-
emax
)
def
flat_to_matrix
(
flat
,
shape
):
matrix
=
np
.
zeros
(
shape
,
dtype
=
complex
)
matrix
[...,
*
np
.
triu_indices
(
shape
[
-
1
])]
=
flat
.
reshape
(
*
shape
[:
-
2
],
-
1
)
indices
=
np
.
arange
(
shape
[
-
1
])
diagonal
=
matrix
[...,
indices
,
indices
]
matrix
+=
np
.
moveaxis
(
matrix
,
-
1
,
-
2
).
conj
()
matrix
[...,
indices
,
indices
]
-=
diagonal
return
matrix
def
matrix_to_flat
(
matrix
):
return
matrix
[...,
*
np
.
triu_indices
(
matrix
.
shape
[
-
1
])].
flatten
()
def
real_to_complex
(
z
):
# real vector of length 2n -> complex of length n
return
z
[:
len
(
z
)
//
2
]
+
1j
*
z
[
len
(
z
)
//
2
:]
def
complex_to_real
(
z
):
# complex vector of length n -> real of length 2n
return
np
.
concatenate
((
np
.
real
(
z
),
np
.
imag
(
z
)))
\ No newline at end of file
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