Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wfc extrapolation / MD #1003

Open
wants to merge 47 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
47 commits
Select commit Hold shift + click to select a range
1c3b304
nlcglib/md-extrapolation changes
simonpintarelli May 15, 2024
8335a25
format
simonpintarelli May 15, 2024
dd61eb1
sirius_api
simonpintarelli May 15, 2024
ac0ae0e
format
simonpintarelli May 15, 2024
f75d4ca
format
simonpintarelli May 15, 2024
e0e5b07
format
simonpintarelli May 15, 2024
3d9e3af
format
simonpintarelli May 16, 2024
1bfda28
missing ifdef guard
simonpintarelli May 16, 2024
8e508b7
fix python api
simonpintarelli May 16, 2024
2f82b21
add nlcglib spack recipe
simonpintarelli Jun 6, 2024
4600043
ci: use nlcglib@develop
simonpintarelli Jun 7, 2024
2399c72
fix recipe
simonpintarelli Jun 7, 2024
c4339e5
python fixes
simonpintarelli Jun 9, 2024
46213a8
format
simonpintarelli Jun 9, 2024
3183fa5
wfc extrapolation
simonpintarelli May 15, 2024
971d15c
use density projector
simonpintarelli May 15, 2024
715bd20
fix magnetic case
simonpintarelli Jun 10, 2024
7b7ab1c
cleanup
simonpintarelli Jun 11, 2024
4c9e68c
more python fixes
simonpintarelli Jun 11, 2024
28656f7
wfc extrapolation: always re-orthogonalize
simonpintarelli Jun 12, 2024
ebb9f8c
add (simple) copy (duplication) routine for wave functions
simonpintarelli Jun 12, 2024
e047e3c
md extrapolation: fix SKIP_WFC_EXTRAPOLATION, refactor
simonpintarelli Jun 12, 2024
da83c16
SKIP_WFC_EXTRAPOALTION, check value
simonpintarelli Jun 13, 2024
f474b3c
call_sirius -> dump core if `SIRIUS_COREDUMP=1` env is defined
simonpintarelli Jun 13, 2024
11bbf26
format
simonpintarelli Jun 13, 2024
377cb02
format
simonpintarelli Jun 26, 2024
c6f4813
indent pragma
simonpintarelli Jun 27, 2024
8e544e2
increase container build timeout
simonpintarelli Jul 2, 2024
65e8107
cosmetics
simonpintarelli Jul 5, 2024
521049c
compute rotations matrices before for loop
simonpintarelli Jul 8, 2024
8c9ff8f
format
simonpintarelli Jul 8, 2024
7340d1a
add openmp pragma
simonpintarelli Jul 8, 2024
e46cfd5
add missing line
simonpintarelli Jul 8, 2024
50819e9
nlcg cleanup args
simonpintarelli Sep 8, 2024
377f533
TODO try-catch
simonpintarelli Oct 16, 2024
f9becad
typo
simonpintarelli Oct 23, 2024
18a5010
add expected.hpp / c++20
simonpintarelli Oct 23, 2024
ada903c
sync spack recipe
simonpintarelli Oct 23, 2024
7dd4cbc
add ne_diff output
simonpintarelli Oct 24, 2024
e2e057d
change tol_ne=1e-10
simonpintarelli Oct 24, 2024
8a73b65
numpy update (asarray)
simonpintarelli Oct 25, 2024
8d3134f
add fmt
simonpintarelli Oct 25, 2024
a786d9c
python numpy.asarray
simonpintarelli Oct 29, 2024
3ddf7ba
newton minimization refactor
simonpintarelli Nov 23, 2024
3415d35
update sirius.f90
simonpintarelli Dec 17, 2024
85eaa36
return ne_diff
simonpintarelli Dec 17, 2024
c6d4eaf
meaningful tolerance
simonpintarelli Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ if(SIRIUS_CREATE_FORTRAN_BINDINGS)
enable_language(Fortran)
endif()

set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CUDA_STANDARD 17)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CUDA_STANDARD 20)

# This ensures that -std=c++17 is passed to nvcc. See
# https://github.com/electronic-structure/SIRIUS/issues/716 for details.
Expand Down Expand Up @@ -216,6 +216,8 @@ if(SIRIUS_USE_MEMORY_POOL)
find_package(umpire REQUIRED)
endif()

find_package(fmt REQUIRED)

# check if git command exists
find_program(GIT_EXE NAMES git)

Expand Down
2 changes: 1 addition & 1 deletion ci/baseimage.cuda.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ RUN spack install openblas %gcc +fortran

RUN spack install magma %gcc +cuda +fortran ^openblas

RUN spack install nlcglib@master %gcc +cuda
RUN spack install nlcglib@develop %gcc +cuda

# for the MPI hook
RUN echo $(spack find --format='{prefix.lib}' mpich) > /etc/ld.so.conf.d/mpich.conf
Expand Down
10 changes: 10 additions & 0 deletions ci/cscs-daint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ build cuda image mkl:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -41,6 +42,7 @@ build cuda image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
CSCS_REBUILD_POLICY: always
DOCKERFILE: ci/build.Dockerfile
Expand All @@ -52,6 +54,7 @@ build rocm image:
extends: .container-builder
needs: ["build base rocm image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -62,6 +65,7 @@ build elpa cuda image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -72,6 +76,7 @@ build sequential eigen-solver cuda image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -82,6 +87,7 @@ build fp32 cuda image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -92,6 +98,7 @@ build vdwxc cuda image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -103,6 +110,7 @@ build nlcg image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -113,6 +121,7 @@ build clang image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand All @@ -124,6 +133,7 @@ build openmpi image:
extends: .container-builder
needs: ["build base cuda image"]
stage: build
timeout: 4h
variables:
DOCKERFILE: ci/build.Dockerfile
PERSIST_IMAGE_NAME: discard
Expand Down
1 change: 0 additions & 1 deletion python_module/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
find_package(Python3 COMPONENTS Development REQUIRED)
set(CMAKE_CXX_STANDARD 17)
find_package(mpi4py REQUIRED)

# TODO: for some reason PYBIND11 is not happy here; explicit export of PYBIND11_CPP17 is needed for Intel compiler
Expand Down
10 changes: 6 additions & 4 deletions python_module/py_sirius.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
* SPDX-License-Identifier: BSD-3-Clause
*/

#include "k_point/k_point_set.hpp"
#include "context/simulation_context.hpp"
#include "k_point/k_point.hpp"
#include "python_module_includes.hpp"
#include <mpi.h>

Expand Down Expand Up @@ -216,6 +217,7 @@ PYBIND11_MODULE(py_sirius, m)
.def("update", &Simulation_context::update)
.def("use_symmetry", py::overload_cast<>(&Simulation_context::use_symmetry, py::const_))
.def("processing_unit_memory_t", &Simulation_context::processing_unit_memory_t)
.def("spla_context", &Simulation_context::spla_context_ptr)
.def(
"comm", [](Simulation_context& obj) { return make_pycomm(obj.comm()); },
py::return_value_policy::reference_internal)
Expand Down Expand Up @@ -401,8 +403,7 @@ PYBIND11_MODULE(py_sirius, m)
.def("fv_states", &K_point<double>::fv_states, py::return_value_policy::reference_internal)
.def("ctx", &K_point<double>::ctx, py::return_value_policy::reference_internal)
.def("weight", &K_point<double>::weight)
.def("beta_projectors", py::overload_cast<>(&K_point<double>::beta_projectors, py::const_),
py::return_value_policy::reference_internal)
.def("beta_projectors", py::overload_cast<>(&K_point<double>::beta_projectors_ptr, py::const_))
.def("spinor_wave_functions", py::overload_cast<>(&K_point<double>::spinor_wave_functions),
py::return_value_policy::reference_internal);

Expand All @@ -413,7 +414,8 @@ PYBIND11_MODULE(py_sirius, m)
.def(py::init<Simulation_context&, r3::vector<int>, r3::vector<int>, bool>(), py::keep_alive<1, 2>())
.def(py::init<Simulation_context&, std::vector<int>, std::vector<int>, bool>(), py::keep_alive<1, 2>())
.def("initialize", &K_point_set::initialize, py::arg("counts") = std::vector<int>{})
.def("ctx", &K_point_set::ctx, py::return_value_policy::reference_internal)
.def("ctx", static_cast<Simulation_context const& (K_point_set::*)() const>(&K_point_set::ctx),
py::return_value_policy::reference_internal)
.def("unit_cell", &K_point_set::unit_cell, py::return_value_policy::reference_internal)
.def("_num_kpoints", &K_point_set::num_kpoints)
.def("size", [](K_point_set& ks) -> int { return ks.spl_num_kpoints().local_size(); })
Expand Down
33 changes: 19 additions & 14 deletions python_module/py_sirius_operators.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
*/

#include "python_module_includes.hpp"
#include <memory>
#include <string>
#include <iomanip>
#include <complex>
Expand All @@ -25,16 +26,16 @@ using PT = double;
void
init_operators(py::module& m)
{
py::class_<Non_local_operator<PT>>(m, "Non_local_operator")
py::class_<Non_local_operator<PT>, std::shared_ptr<Non_local_operator<PT>>>(m, "Non_local_operator")
.def("get_matrix", &Non_local_operator<PT>::get_matrix<std::complex<double>>);
py::class_<D_operator<PT>, Non_local_operator<PT>>(m, "D_operator");
py::class_<Q_operator<PT>, Non_local_operator<PT>>(m, "Q_operator");
py::class_<D_operator<PT>, Non_local_operator<PT>, std::shared_ptr<D_operator<PT>>>(m, "D_operator");
py::class_<Q_operator<PT>, Non_local_operator<PT>, std::shared_ptr<Q_operator<PT>>>(m, "Q_operator");

py::class_<Hamiltonian0<PT>>(m, "Hamiltonian0")
.def(py::init<Potential&, bool>(), py::keep_alive<1, 2>(), "Potential"_a,
py::arg("precompute_lapw") = false)
.def("Q", &Hamiltonian0<PT>::Q, py::return_value_policy::reference_internal)
.def("D", &Hamiltonian0<PT>::D, py::return_value_policy::reference_internal)
.def("Q", &Hamiltonian0<PT>::Q_ptr)
.def("D", &Hamiltonian0<PT>::D_ptr)
.def("Hk", &Hamiltonian0<PT>::operator(), py::keep_alive<0, 1>())
.def("potential", &Hamiltonian0<PT>::potential, py::return_value_policy::reference_internal);

Expand All @@ -46,8 +47,9 @@ init_operators(py::module& m)
.def_property_readonly("U", &Hamiltonian_k<PT>::U, py::return_value_policy::reference_internal);

py::class_<S_k<complex_double>>(m, "S_k")
.def(py::init<Simulation_context&, const Q_operator<PT>&, const Beta_projectors_base<PT>&, int>(),
py::keep_alive<1, 2>(), py::keep_alive<1, 3>(), py::keep_alive<1, 4>())
.def(py::init<memory_t, std::shared_ptr<spla::Context>, std::shared_ptr<Q_operator<PT> const>,
std::shared_ptr<Beta_projectors_base<PT> const>, int>(),
py::keep_alive<1, 2>())
.def_property_readonly("size", &S_k<complex_double>::size)
.def("apply", [](py::object& obj, py::array_t<complex_double>& X) {
using class_t = S_k<complex_double>;
Expand All @@ -71,9 +73,11 @@ init_operators(py::module& m)
return sk.apply(array, memory_t::host);
});

py::class_<spla::Context, std::shared_ptr<spla::Context>>(m, "splaContext");

py::class_<InverseS_k<complex_double>>(m, "InverseS_k")
.def(py::init<Simulation_context&, const Q_operator<PT>&, const Beta_projectors_base<PT>&, int>(),
py::keep_alive<1, 2>(), py::keep_alive<1, 3>(), py::keep_alive<1, 4>())
.def(py::init<memory_t, std::shared_ptr<spla::Context>, std::shared_ptr<Q_operator<PT> const>,
std::shared_ptr<Beta_projectors_base<PT> const>, int>())
.def_property_readonly("size", &InverseS_k<complex_double>::size)
.def("apply", [](py::object& obj, py::array_t<complex_double>& X) {
using class_t = InverseS_k<complex_double>;
Expand All @@ -98,9 +102,9 @@ init_operators(py::module& m)
});

py::class_<Ultrasoft_preconditioner<complex_double>>(m, "Precond_us")
.def(py::init<Simulation_context&, const Q_operator<PT>&, int, const Beta_projectors_base<PT>&,
const fft::Gvec&>(),
py::keep_alive<1, 2>(), py::keep_alive<1, 3>(), py::keep_alive<1, 5>(), py::keep_alive<1, 6>())
.def(py::init<Simulation_context&, std::shared_ptr<Q_operator<PT> const>, int,
std::shared_ptr<Beta_projectors_base<PT> const>, const fft::Gvec&>(),
py::keep_alive<1, 2>())
.def_property_readonly("size", &Ultrasoft_preconditioner<complex_double>::size)
.def("apply", [](py::object& obj, py::array_t<complex_double>& X) {
using class_t = Ultrasoft_preconditioner<complex_double>;
Expand Down Expand Up @@ -163,12 +167,13 @@ init_operators(py::module& m)
.def("generate_j", py::overload_cast<beta_projectors_coeffs_t<PT>&, int, int>(
&Beta_projector_generator<PT>::generate, py::const_));

py::class_<Beta_projectors_base<PT>>(m, "Beta_projectors_base")
py::class_<Beta_projectors_base<PT>, std::shared_ptr<Beta_projectors_base<PT>>>(m, "Beta_projectors_base")
.def_property_readonly("num_chunks", &Beta_projectors_base<PT>::num_chunks)
.def("make_generator", py::overload_cast<device_t>(&Beta_projectors_base<PT>::make_generator, py::const_),
py::keep_alive<1, 0>());

py::class_<Beta_projectors<PT>, Beta_projectors_base<PT>>(m, "Beta_projectors");
py::class_<Beta_projectors<PT>, Beta_projectors_base<PT>, std::shared_ptr<Beta_projectors<PT>>>(m,
"Beta_projectors");
m.def("apply_U_operator", &apply_U_operator<double>, py::arg("ctx"), py::arg("spin_range"), py::arg("band_range"),
py::arg("hub_wf"), py::arg("phi"), py::arg("u_op"), py::arg("hphi"));

Expand Down
4 changes: 3 additions & 1 deletion python_module/sirius/coefficient_array/coefficient_array.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,9 @@ def sum(self, **kwargs):
""" """
loc_sum = np.array(sum([np.sum(v, **kwargs) for _, v in self.items()]))
reduced = MPI.COMM_WORLD.allreduce(loc_sum, op=MPI.SUM)
return np.ndarray.item(reduced)
if isinstance(reduced, np.ndarray):
return np.ndarray.item(reduced)
return reduced

def log(self, **kwargs):
out = type(self)()
Expand Down
14 changes: 3 additions & 11 deletions python_module/sirius/edft/neugebauer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import numpy as np
from scipy.constants import physical_constants

from ..coefficient_array import diag, inner, l2norm
from ..coefficient_array import diag, inner, l2norm, identity_like
from ..operators import US_Precond, Sinv_operator, S_operator
from ..logger import Logger
from ..py_sirius import sprint_magnetization
Expand Down Expand Up @@ -229,7 +229,6 @@ def run(
tol=1e-10,
kappa=0.3,
tau=0.5,
cgtype="FR",
K=IdentityPreconditioner(),
callback=lambda *args, **kwargs: None,
error_callback=lambda *args, **kwargs: None,
Expand All @@ -242,15 +241,6 @@ def run(
is_converged -- bool
"""

if cgtype == "PR":
cg_update = polak_ribiere
elif cgtype == "FR":
cg_update = fletcher_reeves
elif cgtype == "SD":
cg_update = steepest_descent
else:
raise ValueError("wrong type")

if self.is_ultrasoft:
K = self.K
# TODO cleanup signature of run and don't pass the preconditioner anymore
Expand All @@ -265,6 +255,7 @@ def run(
X = X @ U
# set occupation numbers from band energies
fn, mu = self.M.smearing.fn(ek)

# compute initial free energy
FE, Hx = M(X, fn=fn, mu=mu, ek=ek)
logger("initial F: %.13f" % FE)
Expand All @@ -278,6 +269,7 @@ def run(
SX = self.S @ X
else:
SX = X

XhKHX = SX.H @ (K @ HX)
XhKX = SX.H @ (K @ SX)
LL = _solve(XhKX, XhKHX)
Expand Down
2 changes: 1 addition & 1 deletion python_module/sirius/edft/preconditioner.py
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ def make_kinetic_precond2(kpointset):
N = gkvec.count()

def ekin(i):
return np.sum((np.array(gkvec.gkvec_cart(i))**2))
return np.sum((np.asarray(gkvec.gkvec_cart(i))**2))

def Tp(T):
"""Teter preconditioner."""
Expand Down
8 changes: 3 additions & 5 deletions python_module/sirius/edft/pseudo_hamiltonian.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,17 +83,15 @@ def __call__(self, t):
X_new = self.X + t * self.G_X
eta_new = self.eta + t * self.G_eta
ek, Ul = eta_new.eigh()
X = loewdin(X_new, self.overlap) @ Ul
X_new = loewdin(X_new, self.overlap) @ Ul
fn, mu = self.M.smearing.fn(ek)

# check fn

FE, Hx = self.M(X, fn=fn, mu=mu, ek=ek)
FE, Hx = self.M(X_new, fn=fn, mu=mu, ek=ek)
return SimpleNamespace(
**{
"free_energy": FE,
"Hx": Hx,
"X": X,
"X": X_new,
"fn": fn,
"mu": mu,
"ek": ek,
Expand Down
2 changes: 0 additions & 2 deletions python_module/sirius/nlcg/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ def validate_config(dd):
cg = {
Required("method"): Any(marzari, neugebauer),
Optional("restart"): Any(restart),
Optional("type", default="FR"): Any("FR", "PR", "SD"),
Optional("tol", default=1e-9): float,
Optional("maxiter", default=300): int,
Optional("restart", default=20): int,
Expand Down Expand Up @@ -196,7 +195,6 @@ def run_neugebauer(config, sirius_config, callback, final_callback, error_callba
maxiter=cg_config["maxiter"],
kappa=cg_config["method"]["kappa"],
restart=cg_config["restart"],
cgtype=cg_config["type"],
tau=cg_config["tau"],
callback=callback(kset, E=E),
error_callback=error_callback(kset, E=E),
Expand Down
Loading
Loading