Giter Site home page Giter Site logo

iterative-solver's Introduction

iterative-solver

[example workflow]

license

Overview

Implements iterative solvers for linear and non-linear problems and distributed arrays for HPC. The solvers are specialised to work with specific data types, but are also templated on the container allowing for easy integration into existing software.

List of key features:

  • Implements iterative solvers for eigenvalue problem, linear equations, optimisation (L-BFGS) and non-linear equations (DIIS)
  • Novel algorithms including P-space and D-space (see paper)
  • Structured to allow easy addition of new solvers or modification of the current ones without changes to the user's code
  • Templated on container for easy integration into existing programs
    • User defined containers can be used without modification with the help of array handler abstraction
  • Specialised for double and complex value types, so that all heavy numerical operations are only compiled once
  • Provides distributed arrays in memory and on disk for HPC
  • Contains Fortran and C wrappers

Installation

CMake is used to build the library and it can integrate easily with other CMake builds.

include(FetchContent)
FetchContent_Declare(
        iterative-solver
        GIT_REPOSITORY https://github.com/molpro/iterative-solver.git
        GIT_TAG ${COMMIT_HASH_OR_TAG_VALUE})
FetchContent_MakeAvailable(iterative-solver)
target_link_libraries(${YOUR_LIBRARY_NAME} PUBLIC molpro::iterative-solver)

Usage

Interfaces

There is a hierarchy of abstract classes defined in molpro/linalg/itsolv/IterativeSolver.h with IterativeSolver defining the interface for common functionality and LinearEigensystem, LinearEquations, Optimize and NonLinearEquations defining functions that are specific to each type of solver. They are provided to reduce header bloat in user's code.

Each type of solver has at least one implementation class, e.g. LinearEigensystemDavidson in molpro/linalg/itsolv/LinearEigensystemDavidson.h, which implements the full interface. The library is designed to make it easy to add new iterative solvers, so there might be more than one implementation.

Example

The simplest way to use the library is to call solve() and pass a function for getting the action of the matrix on parameter set. Here is an example of using LinearEigensystem with Davidson preconditioner,

#include <molpro/linalg/itsolv/LinearEigensystem.h>
// ...
using molpro::linalg::itsolv::LinearEigensystem;
using R = std::vector<double>;
using Q = std::vector<double>;
LinearEigensystemDavdison<R, Q> solver{};
auto [x, g] = get_initial_parameters_and_action();
solver.set_preconditioner_davidson(get_diagonal_matrix_elements());
solver.solve(x, g, user_specified_action_function);
if (!solver.converged()){
    // deal with the unconverged case
}

More advanced users can copy and modify the code in solve() to tailor it for their own use, see implementation in molpro/linalg/itsolv/IterativeSolverTemplate.h.

Containers and array handlers

In many programs there are special containers for storing the vectors and operating on them. This might be for efficiency reasons, e.g. exploiting symmetry of the problem, or for collecting metadata, e.g. memory usage and operation count. In either case, The code is templated on container types to ease adaptation.

To avoid the code-bloat of header only libraries all of the numerically intensive work is specialised for double and std::complex<double> types. This makes recompilation of IterativeSolver with different container types very fast.

There are 3 types of containers:

  • R — working set container
    • fast access to elements
    • used sparingly to preserve memory
  • Q — slow container
    • slow access to elements
    • used for most of the subspace
    • usually on disk where there is lots of storage space
  • P — sparse container
    • light-weight sparse container (e.g. std::map<size_t, double>)

IterativeSolver does not modify containers directly instead using ArrayHandler for all array related operations. This allows for only modest restrictions on containers:

  • must have a move constructor

  • must have conforming element type (currently double and std::complex<double>, but this can be easily extended)

ArrayHandler is an abstract class used by IterativeSolver to perform copy and linear algebra operations (dot, axpy). iterative-solver provides implementations for Iterable containers (e.g. std::vector), distributed containers (e.g. molpro::linalg::array::DistrArray), and mapped containers (e.g. std::map). However, some users might need/want to provide their own implementations.

Citing

Any publications resulting from this work should cite relevant papers in CITE.txt

List of Contributors

Peter Knowles

Marat Sibaev

Iakov Polyak

Rob Welch

iterative-solver's People

Contributors

pjknowles avatar msibaev avatar rob-welch avatar ajmay81 avatar andhessel avatar yapolyak avatar

Watchers

 avatar  avatar

iterative-solver's Issues

Fails to diagonalise matrix {{1,1},{1,1}}

In GitLab by @molpro on Nov 20, 2018, 10:18

Created by: Anonymous

This is a contrived special matrix, but quite likely to happen during testing. It's worth making sure it works.

Lowest energy determinant 1[0.1]|[0.1] with energy 1.00000000
Davidson eigensolver, maximum iterations=1000; number of states=2; energy threshold=1.0e-08
removing singular value 0.00000000 by deleting redundant expansion vector 0; new subspace size 18446744073709551615Q + 2P
terminate called after throwing an instance of 'std::logic_error'
what(): invalid index
Signal: SIGABRT (Aborted)

Incorrect call of mkstemp generates resource leak

In GitLab by @molpro on Oct 29, 2019, 15:03

From David Kreplin:

maybe you remember, I once told you that there is problem with the caching in the PagedVector class.
Molpro randomly crashes with the error message "Cannot open cache file tmpfile....."

I did some debugging and I found the problem and a possible fix.

The problem is located in line 235-238 in PagedVector.h:

char* tmpname = strdup("tmpfileXXXXXX");
mkstemp(tmpname);
m_file.open(tmpname, std::ios::out | std::ios::in | std::ios::binary);
if (!m_file.is_open()) throw std::runtime_error(std::string("Cannot open cache file ") + tmpname);

The command mkstemp already opens the file (and return a descriptor for the file).
This file is again opened with the m_file.open command and only reference stored in m_file is closed later.
The link created by mkstemp is never closed and the reason for the crash is "Too much open files".

A easy fix would be:

ifile = mkstemp(tmpname);
close(ifile)
m_file.open(tmpname, std::ios::out | std::ios::in | std::ios::binary);
if (!m_file.is_open()) throw std::runtime_error(std::string("Cannot open cache file ") + tmpname);

This solves the problem, however, it is in principle possible to attach the link created by mkstemp to a fstream.
This is not possible with the fstream you implemented, but other file streams do support this feature.

Best wishes,
David

Duplicate #include <LinearAlgebra.h>

In GitLab by @molpro on Oct 26, 2018, 14:39

Created by: Anonymous

In "IterativeSolver.h" there are
#include "LinearAlgebra.h"
and
#include <LinearAlgebra.h>

This is just a typo as far as I can see, and becomes confusing when coupled with symmetry_matrix, which also has a "LinearAlgebra.h" header.

Seems best to delete the second include.

Full templating incomplete

In GitLab by @molpro on May 24, 2018, 11:19

Created by: Anonymous

... in particular, the typing of eigenvectors, eigenvalues, which might be complex

Improved PagedVector by moving synchronisation away from axpy() and using... - [merged]

In GitLab by @molpro on Oct 31, 2019, 14:56

Merges fix-3 -> master

Improved PagedVector by moving synchronisation away from axpy() and using replicated vectors more efficiently.

  • Only modified parts related to replicated and not io vectors. May need further modifications for those.
  • Need to add (optional) arguments to wrapper subroutines in IterativeSolver.cpp to control synchronisation.

Bugfix/6 - [merged]

In GitLab by @molpro on Nov 22, 2018, 15:53

Merges bugfix/6 -> master

Created by: Anonymous

  • Set up test case for issue #6
  • Issue #6 : now test for singularities on the overlap matrix, not target matrix, in the case of eigenproblem. Also manage the case where an added expansion vector set is redundant with itself but not with existing vectors. Also add google test framework. Still to sort out: orthogonality of eigenvectors when degeneracy.
  • Fix issue #6 and other instability problems.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.