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
ed382724
Commit
ed382724
authored
11 months ago
by
Johanna Zijderveld
Browse files
Options
Downloads
Patches
Plain Diff
fix tests by fixing imports of generate_guess
parent
a7520f38
No related branches found
Branches containing commit
No related tags found
Tags containing commit
1 merge request
!4
Interface refactoring
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
codes/mf.py
+31
-31
31 additions, 31 deletions
codes/mf.py
codes/params/test_params.py
+1
-1
1 addition, 1 deletion
codes/params/test_params.py
codes/tb/test_tb.py
+2
-2
2 additions, 2 deletions
codes/tb/test_tb.py
codes/test_graphene.py
+2
-2
2 additions, 2 deletions
codes/test_graphene.py
with
36 additions
and
36 deletions
codes/mf.py
+
31
−
31
View file @
ed382724
...
...
@@ -26,37 +26,6 @@ def density_matrix(kham, fermi_energy):
return
density_matrix_kgrid
def
fermi_on_grid
(
kham
,
filling
):
"""
Compute the Fermi energy on a grid of k-points.
Parameters
----------
hkfunc : function
Function that returns the Hamiltonian at a given k-point.
nk : int
Number of k-points in the grid.
Returns
-------
fermi_energy : float
Fermi energy
"""
vals
=
np
.
linalg
.
eigvalsh
(
kham
)
norbs
=
vals
.
shape
[
-
1
]
vals_flat
=
np
.
sort
(
vals
.
flatten
())
ne
=
len
(
vals_flat
)
ifermi
=
int
(
round
(
ne
*
filling
/
norbs
))
if
ifermi
>=
ne
:
return
vals_flat
[
-
1
]
elif
ifermi
==
0
:
return
vals_flat
[
0
]
else
:
fermi
=
(
vals_flat
[
ifermi
-
1
]
+
vals_flat
[
ifermi
])
/
2
return
fermi
def
meanfield
(
density_matrix_tb
,
h_int
,
n
=
2
):
"""
Compute the mean-field in k-space.
...
...
@@ -95,3 +64,34 @@ def meanfield(density_matrix_tb, h_int, n=2):
for
vec
in
frozenset
(
h_int
)
}
return
add_tb
(
direct
,
exchange
)
def
fermi_on_grid
(
kham
,
filling
):
"""
Compute the Fermi energy on a grid of k-points.
Parameters
----------
hkfunc : function
Function that returns the Hamiltonian at a given k-point.
nk : int
Number of k-points in the grid.
Returns
-------
fermi_energy : float
Fermi energy
"""
vals
=
np
.
linalg
.
eigvalsh
(
kham
)
norbs
=
vals
.
shape
[
-
1
]
vals_flat
=
np
.
sort
(
vals
.
flatten
())
ne
=
len
(
vals_flat
)
ifermi
=
int
(
round
(
ne
*
filling
/
norbs
))
if
ifermi
>=
ne
:
return
vals_flat
[
-
1
]
elif
ifermi
==
0
:
return
vals_flat
[
0
]
else
:
fermi
=
(
vals_flat
[
ifermi
-
1
]
+
vals_flat
[
ifermi
])
/
2
return
fermi
This diff is collapsed.
Click to expand it.
codes/params/test_params.py
+
1
−
1
View file @
ed382724
# %%
from
codes.params.rparams
import
mf_to_rparams
,
rparams_to_mf
from
codes.
kwant_helper
.utils
import
generate_guess
from
codes.
tb
.utils
import
generate_guess
from
codes.tb.tb
import
compare_dicts
import
pytest
...
...
This diff is collapsed.
Click to expand it.
codes/tb/test_tb.py
+
2
−
2
View file @
ed382724
# %%
import
numpy
as
np
from
codes.tb.tb
import
compare_dicts
from
codes.kwant_helper
import
utils
import
itertools
as
it
from
codes.tb.utils
import
generate_guess
from
codes.tb.transforms
import
kfunc_to_tb
,
tb_to_kfunc
,
tb_to_kham
,
tb_to_khamvector
import
pytest
...
...
@@ -39,7 +39,7 @@ def test_tbkham_transform():
(
-
1
,
-
1
),
)
ndof
=
10
h_0
=
utils
.
generate_guess
(
vectors
,
ndof
)
h_0
=
generate_guess
(
vectors
,
ndof
)
assert
np
.
allclose
(
tb_to_kham
(
h_0
,
nk
=
nk
,
ndim
=
2
),
tb_to_khamvector
(
h_0
,
nk
=
nk
,
ndim
=
2
)
...
...
This diff is collapsed.
Click to expand it.
codes/test_graphene.py
+
2
−
2
View file @
ed382724
...
...
@@ -4,7 +4,7 @@ from codes.model import Model
from
codes.solvers
import
solver
from
codes
import
kwant_examples
from
codes.kwant_helper
import
utils
from
codes.tb.utils
import
compute_gap
from
codes.tb.utils
import
compute_gap
,
generate_guess
from
codes.tb.tb
import
add_tb
import
pytest
...
...
@@ -46,7 +46,7 @@ def gap_prediction(U, V):
nk
=
20
h_int
=
utils
.
builder_to_tb
(
int_builder
,
params
)
guess
=
utils
.
generate_guess
(
frozenset
(
h_int
),
len
(
list
(
h_0
.
values
())[
0
]))
guess
=
generate_guess
(
frozenset
(
h_int
),
len
(
list
(
h_0
.
values
())[
0
]))
model
=
Model
(
h_0
,
h_int
,
filling
)
mf_sol
=
solver
(
model
,
guess
,
nk
=
nk
,
optimizer_kwargs
=
{
"
verbose
"
:
True
,
"
M
"
:
0
})
...
...
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