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
Merge requests
!6
Documentation
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Documentation
documentation
into
main
Overview
16
Commits
28
Pipelines
19
Changes
1
Merged
Kostas Vilkelis
requested to merge
documentation
into
main
10 months ago
Overview
16
Commits
28
Pipelines
19
Changes
1
Expand
Construct the documentation for the release of the package.
0
0
Merge request reports
Viewing commit
4d0f7031
Prev
Next
Show latest version
1 file
+
1
−
0
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
4d0f7031
add default solver to docstring
· 4d0f7031
Kostas Vilkelis
authored
10 months ago
pymf/solvers.py
+
49
−
38
Options
from
functools
import
partial
import
numpy
as
np
import
scipy
from
typing
import
Optional
,
Callable
from
pymf.params.rparams
import
rparams_to_tb
,
tb_to_rparams
from
pymf.tb.tb
import
add_tb
from
pymf.tb.tb
import
add_tb
,
_tb_type
from
pymf.model
import
Model
from
pymf.tb.utils
import
calculate_fermi_energy
def
cost
(
mf_param
,
Model
,
nk
=
100
)
:
"""
Define the cost function for
fixed point iteration
.
def
cost
(
mf_param
:
np
.
ndarray
,
model
:
Model
,
nk
:
int
=
20
)
->
np
.
ndarray
:
"""
Define
s
the cost function for
root solver
.
The cost function is the difference between the input mean-field real space
parametrisation and a new mean-field.
The cost function is the difference between the computed and inputted mean-field.
Parameters
----------
mf_param : numpy.array
The mean-field real space parametrisation.
Model : Model
The model object.
nk : int, optional
The number of k-points to use in the grid. The default is 100.
mf_param :
1D real array that parametrises the mean-field correction.
Model :
Interacting tight-binding problem definition.
nk :
Number of k-points in a grid to sample the Brillouin zone along each dimension.
If the system is 0-dimensional (finite), this parameter is ignored.
Returns
-------
:
1D real array that is the difference between the computed and inputted mean-field
parametrisations
"""
shape
=
M
odel
.
_
size
mf
_tb
=
rparams_to_tb
(
mf_param
,
list
(
M
odel
.
h_int
),
shape
)
mf_
tb_
new
=
M
odel
.
mfield
(
mf
_tb
,
nk
=
nk
)
mf_params_new
=
tb_to_rparams
(
mf_
tb_
new
)
shape
=
m
odel
.
_
ndof
mf
=
rparams_to_tb
(
mf_param
,
list
(
m
odel
.
h_int
),
shape
)
mf_new
=
m
odel
.
mfield
(
mf
,
nk
=
nk
)
mf_params_new
=
tb_to_rparams
(
mf_new
)
return
mf_params_new
-
mf_param
def
solver
(
Model
,
mf_guess
,
nk
=
100
,
optimizer
=
scipy
.
optimize
.
anderson
,
optimizer_kwargs
=
{}
):
"""
Solve the mean-field self-consistent equation.
model
:
Model
,
mf_guess
:
np
.
ndarray
,
nk
:
int
=
20
,
optimizer
:
Optional
[
Callable
]
=
scipy
.
optimize
.
anderson
,
optimizer_kwargs
:
Optional
[
dict
[
str
,
str
]]
=
{
"
M
"
:
0
},
)
->
_tb_type
:
"""
Solve for the mean-field correction through self-consistent root finding.
Parameters
----------
M
odel :
Model
The model object
.
mf_guess :
numpy.array
The initial guess for the mean-field
tight-binding model
.
nk :
int, optional
The n
umber of k-points
to use in the grid. The default is 100. In the
0-dimensional
case
, this parameter is ignored.
optimizer :
scipy.optimize, optional
The
optimizer to
use to solve
for
fixed
-
point
s. The default is
scipy.optimize.anderson.
optimizer_kwargs :
dict, optional
The keyword arguments to pass to the optimizer.
The default is {}.
m
odel :
Interacting tight-binding problem definition
.
mf_guess :
The initial guess for the mean-field
correction in the tight-binding dictionary format
.
nk :
N
umber of k-points
in a grid to sample the Brillouin zone along each dimension.
If the system is
0-dimensional
(finite)
, this parameter is ignored.
optimizer :
The
solver
use
d
to solve
the
fixed
point
iteration.
Default uses `
scipy.optimize.anderson
`
.
optimizer_kwargs :
The keyword arguments to pass to the optimizer.
Returns
-------
result : numpy.array
The m
ean-field
tight-binding model
.
:
M
ean-field
correction solution in the tight-binding dictionary format
.
"""
shape
=
M
odel
.
_
size
shape
=
m
odel
.
_
ndof
mf_params
=
tb_to_rparams
(
mf_guess
)
f
=
partial
(
cost
,
M
odel
=
M
odel
,
nk
=
nk
)
f
=
partial
(
cost
,
m
odel
=
m
odel
,
nk
=
nk
)
result
=
rparams_to_tb
(
optimizer
(
f
,
mf_params
,
**
optimizer_kwargs
),
list
(
M
odel
.
h_int
),
shape
optimizer
(
f
,
mf_params
,
**
optimizer_kwargs
),
list
(
m
odel
.
h_int
),
shape
)
fermi
=
calculate_fermi_energy
(
add_tb
(
M
odel
.
h_0
,
result
),
M
odel
.
filling
,
nk
=
nk
)
return
add_tb
(
result
,
{
M
odel
.
_local_key
:
-
fermi
*
np
.
eye
(
M
odel
.
_
size
)})
fermi
=
calculate_fermi_energy
(
add_tb
(
m
odel
.
h_0
,
result
),
m
odel
.
filling
,
nk
=
nk
)
return
add_tb
(
result
,
{
m
odel
.
_local_key
:
-
fermi
*
np
.
eye
(
m
odel
.
_
ndof
)})
Loading