iterative-solver 0.0
 
Loading...
Searching...
No Matches
IterativeSolver.h
1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_ITERATIVESOLVER_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_ITERATIVESOLVER_H
3#include <molpro/linalg/array/ArrayHandler.h>
4#include <molpro/linalg/array/Span.h>
5#include <molpro/linalg/itsolv/Options.h>
6#include <molpro/linalg/itsolv/Statistics.h>
7#include <molpro/linalg/itsolv/helper.h>
8#include <molpro/linalg/itsolv/subspace/Dimensions.h>
9#include <molpro/linalg/itsolv/wrap.h>
10#include <molpro/linalg/itsolv/Logger.h>
11#include <molpro/linalg/itsolv/Metric.h>
12
13#include <molpro/linalg/array/DistrArray.h>
14#include <molpro/linalg/array/util/Distribution.h>
15
16#include <functional>
17#include <map>
18#include <memory>
19#include <ostream>
20#include <vector>
21
22namespace molpro::profiler {
23class Profiler;
24}
25namespace molpro::linalg::itsolv {
26
27template <typename T>
29 template <typename C>
30 constexpr static std::true_type test(typename C::iterator*);
31
32 template <typename>
33 constexpr static std::false_type test(...);
34
35 constexpr static bool value =
36 std::is_same<std::true_type, decltype(test<typename std::remove_reference<T>::type>(0))>::value;
37};
38
39namespace detail {
40// Divides each action[k] elementwise by (diagonals - shift[k] * metric_diagonals), where metric_diagonals == nullptr
41// stands for a unit metric; if regularise, a small constant is added to the denominator
42template <typename T, typename S,
43 typename = std::enable_if_t<std::is_base_of<molpro::linalg::array::DistrArray, T>::value>>
44void precondition_default(const VecRef<T>& action, const std::vector<S>& shift, const T& diagonals,
45 const T* metric_diagonals, const bool regularise) {
46 // regularisation of the denominator, calibrated for double precision and rescaled to the working precision
47 const auto regulariser = regularise ? precision_scaled<S>(1e-15) : decltype(precision_scaled<S>(1e-15))(0);
48 auto diagonals_local_buffer = diagonals.local_buffer();
49 auto metric_local_buffer = metric_diagonals ? metric_diagonals->local_buffer() : nullptr;
50 for (size_t k = 0; k < action.size(); k++) {
51 auto action_local_buffer = action[k].get().local_buffer();
52 auto& distribution = action[k].get().distribution();
53 auto range = distribution.range(molpro::mpi::rank_global());
54 for (auto i = range.first; i < range.second; i++) {
55 const auto j = i - range.first;
56 const auto scaled_shift = metric_local_buffer ? shift[k] * (*metric_local_buffer)[j] : shift[k];
57 (*action_local_buffer)[j] /= ((*diagonals_local_buffer)[j] - scaled_shift + regulariser);
58 }
59 }
60}
61
62template <class T, typename S>
63void precondition_default(const VecRef<T>& action, const std::vector<S>& shift, const T& diagonals,
64 const T* metric_diagonals, const bool regularise,
65 typename T::iterator* = nullptr // SFINAE
66) {
67 const auto regulariser = regularise ? precision_scaled<S>(1e-15) : decltype(precision_scaled<S>(1e-15))(0);
68 for (size_t k = 0; k < action.size(); k++) {
69 auto a = action[k].get().begin();
70 auto m = metric_diagonals ? metric_diagonals->begin() : decltype(diagonals.begin()){};
71 for (auto d = diagonals.begin(); d != diagonals.end(); ++d, ++a) {
72 const auto scaled_shift = metric_diagonals ? shift[k] * *m++ : shift[k];
73 *a /= (*d - scaled_shift + regulariser);
74 }
75 }
76}
77
78template <typename T, typename S,
79 typename = std::enable_if_t<!std::is_base_of<molpro::linalg::array::DistrArray, T>::value>, class = void>
80void precondition_default(const VecRef<T>& action, const std::vector<S>& shift, const T& diagonals,
81 const T* metric_diagonals, const bool regularise,
82 typename std::enable_if<!has_iterator<T>::value, void*>::type = nullptr // SFINAE
83) {
84 throw std::logic_error("Unimplemented preconditioner");
85}
86} // namespace detail
87
94template <typename T, typename S>
95void precondition_default(const VecRef<T>& action, const std::vector<S>& shift, const T& diagonals) {
96 detail::precondition_default(action, shift, diagonals, static_cast<const T*>(nullptr), true);
97}
98
107template <typename T, typename S>
108void precondition_default(const VecRef<T>& action, const std::vector<S>& shift, const T& diagonals,
109 const T& metric_diagonals) {
110 detail::precondition_default(action, shift, diagonals, &metric_diagonals, true);
111}
112
124template <typename R, typename P = std::map<size_t, typename R::value_type>>
125class Problem {
126public:
127 Problem() = default;
128 virtual ~Problem() = default;
129 using container_t = R;
130 using p_container_t = P;
131 using value_t = typename R::value_type;
132
141 virtual value_t residual(const R& parameters, R& residual) const { return 0; }
142
149 virtual void action(const CVecRef<R>& parameters, const VecRef<R>& action) const { return; }
150
161 virtual bool diagonals(container_t& d) const { return false; }
162
175 virtual void precondition(const VecRef<R>& residual, const std::vector<value_t>& shift) const { return; }
176
187 virtual void precondition(const VecRef<R>& residual, const std::vector<value_t>& shift, const R& diagonals) const {
189 }
190
200 virtual void precondition_with_metric(const VecRef<R>& residual, const std::vector<value_t>& shift,
201 const R& diagonals, const R& metric_diagonals) const {
203 }
204
211 virtual MetricKind metric_kind() const { return MetricKind::Identity; }
212
222
229 virtual void metric_action(const CVecRef<R>& parameters, const VecRef<R>& metric_actions) const {
230 throw std::logic_error("Metric unavailable: unimplemented metric_action() in Problem class");
231 }
232
241 virtual void action_with_metric(const CVecRef<R>& parameters, const VecRef<R>& actions,
242 const VecRef<R>& metric_actions) const {
243 action(parameters, actions);
244 metric_action(parameters, metric_actions);
245 }
246
256 virtual bool metric_diagonals(R& d) const { return false; }
257
265 virtual bool RHS(R& RHS, unsigned int instance) const { return false;}
266
272 virtual std::vector<value_t> pp_action_matrix(const std::vector<P>& pparams) const {
273 if (not pparams.empty())
274 throw std::logic_error("P-space unavailable: unimplemented pp_action_matrix() in Problem class");
275 return std::vector<value_t>(0);
276 }
277
284 virtual void p_action(const std::vector<std::vector<value_t>>& p_coefficients, const CVecRef<P>& pparams,
285 const VecRef<container_t>& actions) const {
286 if (not pparams.empty())
287 throw std::logic_error("P-space unavailable: unimplemented p_action() in Problem class");
288 }
289
295 virtual std::vector<value_t> pp_metric_matrix(const std::vector<P>& pparams) const {
296 if (not pparams.empty())
297 throw std::logic_error("P-space unavailable: unimplemented pp_metric_matrix() in Problem class");
298 return std::vector<value_t>(0);
299 }
300
311 virtual void p_metric_action(const std::vector<std::vector<value_t>>& p_coefficients, const CVecRef<P>& pparams,
312 const VecRef<container_t>& metric_actions) const {
313 if (not pparams.empty())
314 throw std::logic_error("P-space unavailable: unimplemented p_metric_action() in Problem class");
315 }
316
326 virtual bool test_parameters(unsigned int instance, R& parameters) const { return false; }
327};
328
334template <class R, class P = std::map<size_t, typename R::value_type>>
336 using value_type = typename R::value_type;
341 std::function<void(const std::vector<std::vector<value_type>>&, const CVecRef<P>&, const VecRef<R>&)> apply;
342};
343
360template <class R, class Q, class P>
362public:
363 using value_type = typename R::value_type;
367 using VectorP = std::vector<value_type>;
372 using fapply_on_p_type = std::function<void(const std::vector<VectorP>&, const CVecRef<P>&, const VecRef<R>&)>;
374 using fapply_metric_type = std::function<void(const CVecRef<R>&, const VecRef<R>&)>;
376
377 virtual ~IterativeSolver() = default;
378 IterativeSolver() = default;
383
435 virtual bool solve(const VecRef<R>& parameters, const VecRef<R>& actions, const Problem<R>& problem,
436 bool generate_initial_guess = false) = 0;
438 virtual bool solve(R& parameters, R& actions, const Problem<R>& problem, bool generate_initial_guess = false) = 0;
440 virtual bool solve(std::vector<R>& parameters, std::vector<R>& actions, const Problem<R>& problem,
441 bool generate_initial_guess = false) = 0;
444 bool solve(const VecRef<R>& parameters, const VecRef<R>& actions, const Problem<R>&& problem,
447 bool solve(R& parameters, R& actions, const Problem<R>&& problem, bool generate_initial_guess = false) = delete;
449 bool solve(std::vector<R>& parameters, std::vector<R>& actions, const Problem<R>&& problem,
451
478 virtual bool solve(const VecRef<R>& parameters, const VecRef<R>& actions, const VecRef<R>& metric_actions,
479 const Problem<R>& problem, bool generate_initial_guess = false) {
480 throw std::invalid_argument("This solver does not support solving a problem with a metric");
481 }
483 virtual bool solve(R& parameters, R& actions, R& metric_actions, const Problem<R>& problem,
484 bool generate_initial_guess = false) {
485 return solve(wrap_arg(parameters), wrap_arg(actions), wrap_arg(metric_actions), problem, generate_initial_guess);
486 }
488 virtual bool solve(std::vector<R>& parameters, std::vector<R>& actions, std::vector<R>& metric_actions,
489 const Problem<R>& problem, bool generate_initial_guess = false) {
490 return solve(wrap(parameters), wrap(actions), wrap(metric_actions), problem, generate_initial_guess);
491 }
493 bool solve(const VecRef<R>& parameters, const VecRef<R>& actions, const VecRef<R>& metric_actions,
494 const Problem<R>&& problem, bool generate_initial_guess = false) = delete;
496 bool solve(R& parameters, R& actions, R& metric_actions, const Problem<R>&& problem,
497 bool generate_initial_guess = false) = delete;
499 bool solve(std::vector<R>& parameters, std::vector<R>& actions, std::vector<R>& metric_actions,
500 const Problem<R>&& problem, bool generate_initial_guess = false) = delete;
501
505 virtual bool supports_metric(MetricKind kind) const { return kind == MetricKind::Identity; }
506
534 fapply_metric_type apply_metric = {}) {
536 throw std::invalid_argument("This solver does not support a metric");
537 }
539 virtual MetricKind metric_kind() const { return MetricKind::Identity; }
547 virtual void set_check_metric(bool check) {}
549 virtual bool get_check_metric() const { return false; }
550
561 virtual int add_vector(const VecRef<R>& parameters, const VecRef<R>& actions) = 0;
562
563 // FIXME this should be removed in favour of VecRef interface
564 virtual int add_vector(std::vector<R>& parameters, std::vector<R>& action) = 0;
565 virtual int add_vector(R& parameters, R& action, value_type value = 0) = 0;
566
576 virtual int add_vector(const VecRef<R>& parameters, const VecRef<R>& actions, const VecRef<R>& metric_actions) {
577 throw std::invalid_argument("This solver does not support a metric");
578 }
580 virtual int add_vector(std::vector<R>& parameters, std::vector<R>& actions, std::vector<R>& metric_actions) {
581 return add_vector(wrap(parameters), wrap(actions), wrap(metric_actions));
582 }
584 virtual int add_vector(R& parameters, R& actions, R& metric_actions) {
585 return add_vector(wrap_arg(parameters), wrap_arg(actions), wrap_arg(metric_actions));
586 }
587
602 virtual size_t add_p(const CVecRef<P>& pparams, const array::Span<value_type>& pp_action_matrix,
603 const VecRef<R>& parameters, const VecRef<R>& action, fapply_on_p_type apply_p) = 0;
604
616 virtual size_t add_p(const CVecRef<P>& pparams, const array::Span<value_type>& pp_action_matrix,
617 const VecRef<R>& parameters, const VecRef<R>& action, fapply_on_p_type apply_p,
618 const PSpaceMetric& metric) {
619 throw std::invalid_argument("This solver does not support a metric");
620 }
621
622 // FIXME Is this needed?
623 virtual void clearP() = 0;
624
634 virtual void solution(const std::vector<int>& roots, const VecRef<R>& parameters, const VecRef<R>& residual) = 0;
635
637 virtual void solution_params(const std::vector<int>& roots, const VecRef<R>& parameters) = 0;
638
640 virtual size_t end_iteration(const VecRef<R>& parameters, const VecRef<R>& residual) = 0;
641
646 virtual void finalize() = 0;
647
651 virtual bool end_iteration_needed() = 0;
652
663 virtual std::vector<size_t> suggest_p(const CVecRef<R>& solution, const CVecRef<R>& residual, size_t max_number,
665
666 virtual void solution(const std::vector<int>& roots, std::vector<R>& parameters, std::vector<R>& residual) = 0;
667 virtual void solution(R& parameters, R& residual) = 0;
668 virtual void solution_params(const std::vector<int>& roots, std::vector<R>& parameters) = 0;
669 virtual void solution_params(R& parameters) = 0;
670 virtual size_t end_iteration(std::vector<R>& parameters, std::vector<R>& action) = 0;
671 virtual size_t end_iteration(R& parameters, R& action) = 0;
672
676 virtual const std::vector<int>& working_set() const = 0;
679 virtual std::vector<scalar_type> working_set_eigenvalues() const {
680 return std::vector<scalar_type>(working_set().size(), 0);
681 }
684 virtual size_t n_roots() const = 0;
685 virtual void set_n_roots(size_t nroots) = 0;
687 virtual const std::vector<value_type_abs>& errors() const = 0;
688 virtual const Statistics& statistics() const = 0;
690 virtual void report(std::ostream& cout, bool endl = true) const = 0;
692 virtual void report() const = 0;
693
702 [[deprecated("Set the verbosity on the logger directly")]]
703 virtual void set_verbosity(Verbosity v) = 0;
704 virtual void set_verbosity(int v) = 0;
705 [[deprecated("Query the logger directly")]]
706 virtual Verbosity get_verbosity() const = 0;
707 virtual void set_max_iter(int n) = 0;
708 virtual int get_max_iter() const = 0;
709 virtual void set_max_p(int n) = 0;
710 virtual int get_max_p() const = 0;
712 virtual value_type_abs get_p_threshold() const = 0;
713 virtual const subspace::Dimensions& dimensions() const = 0;
714 // FIXME Missing parameters: SVD threshold
717 virtual void set_options(const Options& options) = 0;
720 virtual std::shared_ptr<Options> get_options() const = 0;
725 virtual scalar_type value() const = 0;
730 virtual bool nonlinear() const = 0;
740 virtual void set_profiler(std::shared_ptr<molpro::profiler::Profiler> profiler) = 0;
741 virtual const std::shared_ptr<molpro::profiler::Profiler>& profiler() const = 0;
746 virtual void set_logger(std::shared_ptr<Logger> logger) = 0;
747 virtual Logger &logger() = 0;
761 virtual bool test_problem(const Problem<R>& problem, R& v0, R& v1, int verbosity = 0,
762 value_type_abs threshold = 1e-5) const = 0;
763};
764
769template <class R, class Q, class P>
770class LinearEigensystem : public IterativeSolver<R, Q, P> {
771public:
774 virtual std::vector<scalar_type> eigenvalues() const = 0;
776 virtual void set_hermiticity(bool hermitian) = 0;
778 virtual bool get_hermiticity() const = 0;
779};
780
781template <class R, class Q, class P>
782class LinearEquations : public IterativeSolver<R, Q, P> {
783public:
785 virtual void add_equations(const CVecRef<R>& rhs) = 0;
786 virtual void add_equations(const std::vector<R>& rhs) = 0;
787 virtual void add_equations(const R& rhs) = 0;
788 virtual CVecRef<Q> rhs() const = 0;
790 virtual void set_hermiticity(bool hermitian) = 0;
792 virtual bool get_hermiticity() const = 0;
793};
794
797template <class R, class Q, class P>
798class Optimize : public IterativeSolver<R, Q, P> {};
799
801template <class R, class Q, class P>
802class NonLinearEquations : public IterativeSolver<R, Q, P> {};
803
804} // namespace molpro::linalg::itsolv
805
806#endif // LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_ITERATIVESOLVER_H
decltype(value_type_L{} *value_type_R{}) value_type
Definition ArrayHandler.h:182
decltype(check_abs< value_type >()) value_type_abs
Definition ArrayHandler.h:183
Non-owning container taking a pointer to the data buffer and its size and exposing routines for itera...
Definition Span.h:31
Base class defining the interface common to all iterative solvers.
Definition IterativeSolver.h:361
typename R::value_type value_type
The underlying type of elements of vectors.
Definition IterativeSolver.h:363
virtual void set_check_metric(bool check)
Sets whether add_p() and add_vector() check that the metric is Hermitian and, for the positive (semi)...
Definition IterativeSolver.h:547
virtual void set_profiler(molpro::profiler::Profiler &profiler)=0
Attach a profiler in order to collect performance data.
virtual void report() const =0
Writes a report to std::cout.
virtual bool get_check_metric() const
Whether the metric is checked, see set_check_metric()
Definition IterativeSolver.h:549
IterativeSolver(const IterativeSolver< R, Q, P > &)=delete
virtual int add_vector(R &parameters, R &actions, R &metric_actions)
Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_me...
Definition IterativeSolver.h:584
typename array::ArrayHandler< R, R >::value_type_abs value_type_abs
Definition IterativeSolver.h:366
virtual scalar_type value() const =0
Report the function value for the current optimum solution.
virtual size_t add_p(const CVecRef< P > &pparams, const array::Span< value_type > &pp_action_matrix, const VecRef< R > &parameters, const VecRef< R > &action, fapply_on_p_type apply_p, const PSpaceMetric &metric)
Like add_p(const CVecRef.
Definition IterativeSolver.h:616
virtual size_t end_iteration(R &parameters, R &action)=0
virtual void set_verbosity(Verbosity v)=0
virtual int add_vector(R &parameters, R &action, value_type value=0)=0
virtual void set_convergence_threshold_value(value_type_abs thresh)=0
Sets the value convergence threshold.
virtual void report(std::ostream &cout, bool endl=true) const =0
Writes a report to cout output stream.
virtual std::vector< size_t > suggest_p(const CVecRef< R > &solution, const CVecRef< R > &residual, size_t max_number, value_type_abs threshold)=0
Get the solver's suggestion of which degrees of freedom would be best to add to the P-space.
IterativeSolver(IterativeSolver< R, Q, P > &&) noexcept=default
typename array::ArrayHandler< R, Q >::value_type scalar_type
Definition IterativeSolver.h:365
virtual void solution(const std::vector< int > &roots, const VecRef< R > &parameters, const VecRef< R > &residual)=0
Construct solution and residual for a given set of roots.
virtual bool solve(const VecRef< R > &parameters, const VecRef< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false)=0
Simplified one-call solver.
virtual const subspace::Dimensions & dimensions() const =0
virtual void set_n_roots(size_t nroots)=0
bool solve(std::vector< R > &parameters, std::vector< R > &actions, std::vector< R > &metric_actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
A temporary problem is rejected, as the solver keeps references to the problem beyond solve()
virtual void solution_params(const std::vector< int > &roots, const VecRef< R > &parameters)=0
Constructs parameters of selected roots; throws like solution()
virtual void set_convergence_threshold(value_type_abs thresh)=0
Sets the convergence threshold.
virtual bool test_problem(const Problem< R > &problem, R &v0, R &v1, int verbosity=0, value_type_abs threshold=1e-5) const =0
Test a supplied problem class.
std::function< void(const std::vector< VectorP > &, const CVecRef< P > &, const VecRef< R > &)> fapply_on_p_type
Definition IterativeSolver.h:372
virtual bool nonlinear() const =0
Report whether the class is a non-linear solver.
virtual void set_p_threshold(value_type_abs thresh)=0
virtual value_type_abs convergence_threshold() const =0
Reports the convergence threshold.
virtual int add_vector(const VecRef< R > &parameters, const VecRef< R > &actions)=0
Take, typically, a current solution and residual, and add it to the solution space.
virtual value_type_abs get_p_threshold() const =0
virtual int add_vector(const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions)
Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_me...
Definition IterativeSolver.h:576
virtual void set_options(const Options &options)=0
virtual int add_vector(std::vector< R > &parameters, std::vector< R > &actions, std::vector< R > &metric_actions)
Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_me...
Definition IterativeSolver.h:580
virtual void solution_params(R &parameters)=0
std::vector< value_type > VectorP
Definition IterativeSolver.h:369
bool solve(const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
A temporary problem is rejected, as the solver keeps references to the problem beyond solve()
std::function< void(const CVecRef< R > &, const VecRef< R > &)> fapply_metric_type
Function type for applying the metric to a set of vectors (first argument), writing the results into ...
Definition IterativeSolver.h:374
virtual const std::shared_ptr< molpro::profiler::Profiler > & profiler() const =0
virtual bool solve(R &parameters, R &actions, R &metric_actions, const Problem< R > &problem, bool generate_initial_guess=false)
Simplified one-call solver for problems that may have a metric, e.g. the generalised eigenproblem A v...
Definition IterativeSolver.h:483
virtual int add_vector(std::vector< R > &parameters, std::vector< R > &action)=0
virtual size_t add_p(const CVecRef< P > &pparams, const array::Span< value_type > &pp_action_matrix, const VecRef< R > &parameters, const VecRef< R > &action, fapply_on_p_type apply_p)=0
Add P-space vectors to the expansion set for linear methods.
virtual void solution(const std::vector< int > &roots, std::vector< R > &parameters, std::vector< R > &residual)=0
virtual void set_profiler(std::shared_ptr< molpro::profiler::Profiler > profiler)=0
Attach a profiler in order to collect performance data.
virtual void solution(R &parameters, R &residual)=0
virtual Verbosity get_verbosity() const =0
virtual MetricStorage metric_storage() const
How the actions of the metric declared with set_metric() are obtained.
Definition IterativeSolver.h:541
IterativeSolver< R, Q, P > & operator=(const IterativeSolver< R, Q, P > &)=delete
virtual std::vector< scalar_type > working_set_eigenvalues() const
Definition IterativeSolver.h:679
virtual MetricKind metric_kind() const
The kind of metric declared with set_metric()
Definition IterativeSolver.h:539
virtual bool end_iteration_needed()=0
signal whether end_iteration should be called
virtual size_t end_iteration(const VecRef< R > &parameters, const VecRef< R > &residual)=0
Behaviour depends on the solver.
virtual std::shared_ptr< Options > get_options() const =0
virtual void set_logger(std::shared_ptr< Logger > logger)=0
Set the logger instance that shall be used.
virtual void solution_params(const std::vector< int > &roots, std::vector< R > &parameters)=0
virtual bool supports_metric(MetricKind kind) const
Whether the solver supports a metric of the given kind. MetricKind::Identity is always supported.
Definition IterativeSolver.h:505
virtual value_type_abs convergence_threshold_value() const =0
Reports the value convergence threshold.
virtual bool solve(std::vector< R > &parameters, std::vector< R > &actions, std::vector< R > &metric_actions, const Problem< R > &problem, bool generate_initial_guess=false)
Simplified one-call solver for problems that may have a metric, e.g. the generalised eigenproblem A v...
Definition IterativeSolver.h:488
virtual void set_metric(MetricKind kind, MetricStorage storage=MetricStorage::Stored, fapply_metric_type apply_metric={})
Declares the metric M of a generalised problem, e.g. the eigenproblem A v = lambda M v,...
Definition IterativeSolver.h:533
virtual const std::vector< value_type_abs > & errors() const =0
Errors are norms of the residuals, so they are real even when the problem is complex.
virtual const Statistics & statistics() const =0
virtual size_t end_iteration(std::vector< R > &parameters, std::vector< R > &action)=0
bool solve(R &parameters, R &actions, R &metric_actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
A temporary problem is rejected, as the solver keeps references to the problem beyond solve()
virtual size_t n_roots() const =0
virtual const std::vector< int > & working_set() const =0
Working set of roots that are not yet converged.
Interface for a specific iterative solver, it can add special member functions or variables.
Definition IterativeSolver.h:770
virtual bool get_hermiticity() const =0
Gets hermiticity of kernel, if true than it is hermitian, otherwise it is not.
virtual void set_hermiticity(bool hermitian)=0
Sets hermiticity of kernel.
virtual std::vector< scalar_type > eigenvalues() const =0
The calculated eigenvalues of the subspace matrix.
Definition IterativeSolver.h:782
virtual void add_equations(const CVecRef< R > &rhs)=0
virtual void add_equations(const std::vector< R > &rhs)=0
virtual bool get_hermiticity() const =0
Gets hermiticity of kernel, if true than it is hermitian, otherwise it is not.
virtual CVecRef< Q > rhs() const =0
virtual void set_hermiticity(bool hermitian)=0
Sets hermiticity of kernel.
virtual void add_equations(const R &rhs)=0
Logger class implementation. Provides (customizable) logging functionalities.
Definition Logger.h:370
Solves non-linear system of equations using methods such as DIIS.
Definition IterativeSolver.h:802
Definition IterativeSolver.h:798
Abstract class defining the problem-specific interface for the simplified solver interface to Iterati...
Definition IterativeSolver.h:125
virtual MetricKind metric_kind() const
The kind of metric M of the problem. Anything other than MetricKind::Identity turns the eigenproblem ...
Definition IterativeSolver.h:211
virtual void action(const CVecRef< R > &parameters, const VecRef< R > &action) const
Calculate the action of the kernel matrix on a set of parameters. Used by linear solvers,...
Definition IterativeSolver.h:149
R container_t
Definition IterativeSolver.h:129
virtual MetricStorage metric_storage() const
How IterativeSolver::solve() obtains the actions of the metric on its subspace vectors,...
Definition IterativeSolver.h:221
P p_container_t
Definition IterativeSolver.h:130
virtual void precondition(const VecRef< R > &residual, const std::vector< value_t > &shift) const
Apply preconditioning to a residual vector in order to predict a step towards the solution.
Definition IterativeSolver.h:175
typename R::value_type value_t
Definition IterativeSolver.h:131
virtual bool metric_diagonals(R &d) const
Provide the diagonal elements of the metric. For a problem with a metric that provides diagonals(),...
Definition IterativeSolver.h:256
virtual void p_metric_action(const std::vector< std::vector< value_t > > &p_coefficients, const CVecRef< P > &pparams, const VecRef< container_t > &metric_actions) const
Calculate the action of the metric on a set of vectors in the P space, for a problem with a metric (m...
Definition IterativeSolver.h:311
virtual bool diagonals(container_t &d) const
Optionally provide the diagonal elements of the underlying kernel. If implemented and returning true,...
Definition IterativeSolver.h:161
virtual void precondition_with_metric(const VecRef< R > &residual, const std::vector< value_t > &shift, const R &diagonals, const R &metric_diagonals) const
Apply preconditioning to a residual vector of a generalised eigenproblem. Used instead of preconditio...
Definition IterativeSolver.h:200
virtual void p_action(const std::vector< std::vector< value_t > > &p_coefficients, const CVecRef< P > &pparams, const VecRef< container_t > &actions) const
Calculate the action of the kernel matrix on a set of vectors in the P space.
Definition IterativeSolver.h:284
virtual std::vector< value_t > pp_action_matrix(const std::vector< P > &pparams) const
Calculate the kernel matrix in the P space.
Definition IterativeSolver.h:272
virtual void action_with_metric(const CVecRef< R > &parameters, const VecRef< R > &actions, const VecRef< R > &metric_actions) const
Calculate the actions of the kernel and of the metric on a set of parameters together....
Definition IterativeSolver.h:241
virtual void metric_action(const CVecRef< R > &parameters, const VecRef< R > &metric_actions) const
Calculate the action of the metric on a set of parameters. Called only if metric_kind() is not Metric...
Definition IterativeSolver.h:229
virtual value_t residual(const R &parameters, R &residual) const
Calculate the residual vector. Used by non-linear solvers (NonLinearEquations, Optimize) only.
Definition IterativeSolver.h:141
virtual bool test_parameters(unsigned int instance, R &parameters) const
Provide values of R vectors for testing the problem class. For use in a non-linear solver,...
Definition IterativeSolver.h:326
virtual bool RHS(R &RHS, unsigned int instance) const
Return the inhomogeneous part of a linear equation system.
Definition IterativeSolver.h:265
virtual void precondition(const VecRef< R > &residual, const std::vector< value_t > &shift, const R &diagonals) const
Apply preconditioning to a residual vector in order to predict a step towards the solution.
Definition IterativeSolver.h:187
virtual std::vector< value_t > pp_metric_matrix(const std::vector< P > &pparams) const
Calculate the metric matrix in the P space, for a problem with a metric (metric_kind())
Definition IterativeSolver.h:295
void precondition_default(const VecRef< T > &action, const std::vector< S > &shift, const T &diagonals, const T *metric_diagonals, const bool regularise)
Definition IterativeSolver.h:44
4-parameter interpolation of a 1-dimensional function given two points for which function values and ...
Definition helper.h:14
auto wrap_arg(T &&arg, S &&... args) -> std::enable_if_t< std::conjunction_v< std::is_same< decay_t< T >, decay_t< S > >... >, VecRef< decay_t< T > > >
Constructs a vector of reference wrappers with provided arguments.
Definition wrap.h:135
std::unique_ptr< LinearEigensystem< R, Q, P > > create_LinearEigensystem(const LinearEigensystemOptions &options, const std::shared_ptr< ArrayHandlers< R, Q, P > > &handlers=std::make_shared< molpro::linalg::itsolv::ArrayHandlers< R, Q, P > >())
Definition SolverFactory.h:111
auto wrap(ForwardIt begin, ForwardIt end)
Takes a begin and end iterators and returns a vector of references to each element.
Definition wrap.h:32
std::vector< std::reference_wrapper< const A > > CVecRef
Definition wrap.h:14
void precondition_default(const VecRef< T > &action, const std::vector< S > &shift, const T &diagonals)
Davidson preconditioner: divides each action[k] elementwise by (diagonals - shift[k])
Definition IterativeSolver.h:95
MetricStorage
How a solver obtains the actions of a metric on its subspace vectors, see IterativeSolver::set_metric...
Definition Metric.h:21
@ Stored
the actions of the metric on all subspace vectors are kept
std::vector< std::reference_wrapper< A > > VecRef
Definition wrap.h:11
Verbosity
Specifies how much detail IterativeSolver::solve should write to output.
Definition Options.h:12
MetricKind
The kind of metric M of a generalised problem, such as the eigenproblem A v = lambda M v.
Definition Metric.h:13
@ Identity
M = 1, i.e. no metric.
const std::shared_ptr< const molpro::Options > options()
Get the Options object associated with iterative-solver.
Definition linalg_options.cpp:4
profiler::Profiler Profiler
Access point for different options in iterative solvers.
Definition Options.h:20
The metric of a problem in the P space, for IterativeSolver::add_p()
Definition IterativeSolver.h:335
array::Span< value_type > pp_matrix
the metric matrix in the P space, in the layout of the kernel matrix given to add_p(),...
Definition IterativeSolver.h:338
std::function< void(const std::vector< std::vector< value_type > > &, const CVecRef< P > &, const VecRef< R > &)> apply
Definition IterativeSolver.h:341
typename R::value_type value_type
Definition IterativeSolver.h:336
Information about performance of IterativeSolver instance.
Definition Statistics.h:10
Definition IterativeSolver.h:28
static constexpr bool value
Definition IterativeSolver.h:35
static constexpr std::true_type test(typename C::iterator *)
static constexpr std::false_type test(...)