iterative-solver 0.0
 
Loading...
Searching...
No Matches
molpro::linalg::itsolv::IterativeSolver< R, Q, P > Class Template Referenceabstract

Base class defining the interface common to all iterative solvers. More...

#include <IterativeSolver.h>

Inheritance diagram for molpro::linalg::itsolv::IterativeSolver< R, Q, P >:

Detailed Description

template<class R, class Q, class P>
class molpro::linalg::itsolv::IterativeSolver< R, Q, P >

Base class defining the interface common to all iterative solvers.

As well as through the interface, some behaviour (profiling, and tuning of BLAS operations) is influenced by the contents of a global molpro::Options object, which defaults to molpro::Options("ITERATIVE-SOLVER", "").

Template Parameters
Rcontainer for "working-set" vectors. These are typically implemented in memory, and are created by the client program. R vectors are never created inside IterativeSolver.
Qcontainer for other vectors. These are typically implemented on backing store and/or distributed across processors. IterativeSolver constructs a number of instances of Q containers to store history.
Pa class that specifies the definition of a single P-space vector, which is a strictly sparse vector in the underlying space.

Public Types

using value_type = typename R::value_type
 The underlying type of elements of vectors.
 
using scalar_type = typename array::ArrayHandler< R, Q >::value_type
 
using value_type_abs = typename array::ArrayHandler< R, R >::value_type_abs
 
using VectorP = std::vector< value_type >
 
using fapply_on_p_type = std::function< void(const std::vector< VectorP > &, const CVecRef< P > &, const VecRef< R > &)>
 
using fapply_metric_type = std::function< void(const CVecRef< R > &, const VecRef< R > &)>
 Function type for applying the metric to a set of vectors (first argument), writing the results into the second.
 
using PSpaceMetric = itsolv::PSpaceMetric< R, P >
 

Public Member Functions

virtual ~IterativeSolver ()=default
 
 IterativeSolver ()=default
 
 IterativeSolver (const IterativeSolver< R, Q, P > &)=delete
 
IterativeSolver< R, Q, P > & operator= (const IterativeSolver< R, Q, P > &)=delete
 
 IterativeSolver (IterativeSolver< R, Q, P > &&) noexcept=default
 
IterativeSolver< R, Q, P > & operator= (IterativeSolver< R, Q, P > &&) noexcept=default
 
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 bool solve (R &parameters, R &actions, const Problem< R > &problem, bool generate_initial_guess=false)=0
 Simplified one-call solver.
 
virtual bool solve (std::vector< R > &parameters, std::vector< R > &actions, const Problem< R > &problem, bool generate_initial_guess=false)=0
 Simplified one-call solver.
 
bool solve (const VecRef< R > &parameters, const VecRef< R > &actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
 
bool solve (R &parameters, R &actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
 
bool solve (std::vector< R > &parameters, std::vector< R > &actions, const Problem< R > &&problem, bool generate_initial_guess=false)=delete
 
virtual bool solve (const VecRef< R > &parameters, const VecRef< R > &actions, const VecRef< 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 = lambda M v.
 
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 = lambda M v.
 
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 = lambda M v.
 
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()
 
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()
 
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 bool supports_metric (MetricKind kind) const
 Whether the solver supports a metric of the given kind. MetricKind::Identity is always supported.
 
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, for the stepwise interface. solve() calls it itself.
 
virtual MetricKind metric_kind () const
 The kind of metric declared with set_metric()
 
virtual MetricStorage metric_storage () const
 How the actions of the metric declared with set_metric() are obtained.
 
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)definite kinds, positive (semi)definite on the subspace (default: true). The checks cost a few operations on vectors in every iteration.
 
virtual bool get_check_metric () const
 Whether the metric is checked, see set_check_metric()
 
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 int add_vector (std::vector< R > &parameters, std::vector< R > &action)=0
 
virtual int add_vector (R &parameters, R &action, value_type value=0)=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_metric()
 
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_metric()
 
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_metric()
 
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 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.
 
virtual void clearP ()=0
 
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 void solution_params (const std::vector< int > &roots, const VecRef< R > &parameters)=0
 Constructs parameters of selected roots; throws like solution()
 
virtual size_t end_iteration (const VecRef< R > &parameters, const VecRef< R > &residual)=0
 Behaviour depends on the solver.
 
virtual void finalize ()=0
 
virtual bool end_iteration_needed ()=0
 signal whether end_iteration should be called
 
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.
 
virtual void solution (const std::vector< int > &roots, std::vector< R > &parameters, std::vector< R > &residual)=0
 
virtual void solution (R &parameters, R &residual)=0
 
virtual void solution_params (const std::vector< int > &roots, std::vector< R > &parameters)=0
 
virtual void solution_params (R &parameters)=0
 
virtual size_t end_iteration (std::vector< R > &parameters, std::vector< R > &action)=0
 
virtual size_t end_iteration (R &parameters, R &action)=0
 
virtual const std::vector< int > & working_set () const =0
 Working set of roots that are not yet converged.
 
virtual std::vector< scalar_type > working_set_eigenvalues () const
 
virtual size_t n_roots () const =0
 
virtual void set_n_roots (size_t nroots)=0
 
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 void report (std::ostream &cout, bool endl=true) const =0
 Writes a report to cout output stream.
 
virtual void report () const =0
 Writes a report to std::cout.
 
virtual void set_convergence_threshold (value_type_abs thresh)=0
 Sets the convergence threshold.
 
virtual value_type_abs convergence_threshold () const =0
 Reports the convergence threshold.
 
virtual void set_convergence_threshold_value (value_type_abs thresh)=0
 Sets the value convergence threshold.
 
virtual value_type_abs convergence_threshold_value () const =0
 Reports the value convergence threshold.
 
virtual void set_verbosity (Verbosity v)=0
 
virtual void set_verbosity (int v)=0
 
virtual Verbosity get_verbosity () const =0
 
virtual void set_max_iter (int n)=0
 
virtual int get_max_iter () const =0
 
virtual void set_max_p (int n)=0
 
virtual int get_max_p () const =0
 
virtual void set_p_threshold (value_type_abs thresh)=0
 
virtual value_type_abs get_p_threshold () const =0
 
virtual const subspace::Dimensions & dimensions () const =0
 
virtual void set_options (const Options &options)=0
 
virtual std::shared_ptr< Options > get_options () const =0
 
virtual scalar_type value () const =0
 Report the function value for the current optimum solution.
 
virtual bool nonlinear () const =0
 Report whether the class is a non-linear solver.
 
virtual void set_profiler (molpro::profiler::Profiler &profiler)=0
 Attach a profiler in order to collect performance data.
 
virtual void set_profiler (std::shared_ptr< molpro::profiler::Profiler > profiler)=0
 Attach a profiler in order to collect performance data.
 
virtual const std::shared_ptr< molpro::profiler::Profiler > & profiler () const =0
 
virtual void set_logger (std::shared_ptr< Logger > logger)=0
 Set the logger instance that shall be used.
 
virtual Logger & logger ()=0
 
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.
 

Member Typedef Documentation

◆ fapply_metric_type

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::fapply_metric_type = std::function<void(const CVecRef<R>&, const VecRef<R>&)>

Function type for applying the metric to a set of vectors (first argument), writing the results into the second.

◆ fapply_on_p_type

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::fapply_on_p_type = std::function<void(const std::vector<VectorP>&, const CVecRef<P>&, const VecRef<R>&)>

Function type for applying matrix to the P space vectors and accumulating result in a residual

◆ PSpaceMetric

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::PSpaceMetric = itsolv::PSpaceMetric<R, P>

◆ scalar_type

The type of scalar products of vectors

◆ value_type

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::value_type = typename R::value_type

The underlying type of elements of vectors.

◆ value_type_abs

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::value_type_abs = typename array::ArrayHandler<R, R>::value_type_abs

◆ VectorP

template<class R , class Q , class P >
using molpro::linalg::itsolv::IterativeSolver< R, Q, P >::VectorP = std::vector<value_type>

type for vectors projected on to P space, each element is a coefficient for the corresponding P space parameter

Constructor & Destructor Documentation

◆ ~IterativeSolver()

template<class R , class Q , class P >
virtual molpro::linalg::itsolv::IterativeSolver< R, Q, P >::~IterativeSolver ( )
virtualdefault

◆ IterativeSolver() [1/3]

template<class R , class Q , class P >
molpro::linalg::itsolv::IterativeSolver< R, Q, P >::IterativeSolver ( )
default

◆ IterativeSolver() [2/3]

template<class R , class Q , class P >
molpro::linalg::itsolv::IterativeSolver< R, Q, P >::IterativeSolver ( const IterativeSolver< R, Q, P > &  )
delete

◆ IterativeSolver() [3/3]

template<class R , class Q , class P >
molpro::linalg::itsolv::IterativeSolver< R, Q, P >::IterativeSolver ( IterativeSolver< R, Q, P > &&  )
defaultnoexcept

Member Function Documentation

◆ add_p() [1/2]

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::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 
)
pure virtual

Add P-space vectors to the expansion set for linear methods.

Note
the apply_p function is stored and used by the solver internally.
Parameters
Pparamsthe vectors to add. Each Pvector specifies a sparse vector in the underlying space. The size of the P space must be at least the number of roots to be sought.
pp_action_matrixMatrix projected onto the existing+new, new P space. It should be provided as a 1-dimensional array, with the existing+new index running fastest.
parametersUsed as scratch working space
actionOn exit, the residual of the interpolated solution. The contribution from the new, and any existing, P parameters is missing, and should be added in subsequently.
apply_pA function that evaluates the action of the matrix on vectors in the P space
Returns
The number of vectors contained in parameters, action, parametersP

◆ add_p() [2/2]

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::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 
)
inlinevirtual

Like add_p(const CVecRef.

&, const array::Span<value_type>&, const VecRef<R>&, const VecRef<R>&, fapply_on_p_type), for a problem with a metric declared with set_metric(), which this overload requires.

Parameters
pparamsthe vectors to add, as for the other overload
pp_action_matrixthe kernel matrix in the P space, as for the other overload
parametersUsed as scratch working space
actionOn exit, the residual of the interpolated solution, missing the contributions from the P space
apply_pA function that adds the action of the kernel on vectors in the P space
metricthe metric in the P space
Returns
The number of vectors contained in parameters, action, parametersP

◆ add_vector() [1/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( const VecRef< R > &  parameters,
const VecRef< R > &  actions 
)
pure virtual

Take, typically, a current solution and residual, and add it to the solution space.

Parameters
parametersOn input, the current solution or expansion vector. On exit, undefined.
actionsOn input, the residual for parameters (non-linear), or action of matrix on parameters (linear). On exit, a vector set that should be preconditioned before returning to end_iteration().
valueThe value of the objective function for parameters. Used only in Optimize classes.
Returns
The size of the new working set. In non-linear optimisation, the special value -1 can also be returned, indicating that preconditioning should not be carried out on action.

◆ add_vector() [2/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( const VecRef< R > &  parameters,
const VecRef< R > &  actions,
const VecRef< R > &  metric_actions 
)
inlinevirtual

Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_metric()

Parameters
parametersOn input, the current solution or expansion vector. On exit, undefined.
actionsOn input, the action of the kernel on parameters. On exit, a vector set that should be preconditioned before returning to end_iteration().
metric_actionsOn input, the action of the metric on parameters. On exit, undefined.
Returns
The size of the new working set.

◆ add_vector() [3/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( R &  parameters,
R &  action,
value_type  value = 0 
)
pure virtual

◆ add_vector() [4/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( R &  parameters,
R &  actions,
R &  metric_actions 
)
inlinevirtual

Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_metric()

Parameters
parametersOn input, the current solution or expansion vector. On exit, undefined.
actionsOn input, the action of the kernel on parameters. On exit, a vector set that should be preconditioned before returning to end_iteration().
metric_actionsOn input, the action of the metric on parameters. On exit, undefined.
Returns
The size of the new working set.

◆ add_vector() [5/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( std::vector< R > &  parameters,
std::vector< R > &  action 
)
pure virtual

◆ add_vector() [6/6]

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::add_vector ( std::vector< R > &  parameters,
std::vector< R > &  actions,
std::vector< R > &  metric_actions 
)
inlinevirtual

Like add_vector(const VecRef<R>&, const VecRef<R>&), for a problem with a metric declared with set_metric()

Parameters
parametersOn input, the current solution or expansion vector. On exit, undefined.
actionsOn input, the action of the kernel on parameters. On exit, a vector set that should be preconditioned before returning to end_iteration().
metric_actionsOn input, the action of the metric on parameters. On exit, undefined.
Returns
The size of the new working set.

◆ clearP()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::clearP ( )
pure virtual

◆ convergence_threshold()

template<class R , class Q , class P >
virtual value_type_abs molpro::linalg::itsolv::IterativeSolver< R, Q, P >::convergence_threshold ( ) const
pure virtual

Reports the convergence threshold.

◆ convergence_threshold_value()

template<class R , class Q , class P >
virtual value_type_abs molpro::linalg::itsolv::IterativeSolver< R, Q, P >::convergence_threshold_value ( ) const
pure virtual

Reports the value convergence threshold.

◆ dimensions()

template<class R , class Q , class P >
virtual const subspace::Dimensions & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::dimensions ( ) const
pure virtual

◆ end_iteration() [1/3]

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::end_iteration ( const VecRef< R > &  parameters,
const VecRef< R > &  residual 
)
pure virtual

Behaviour depends on the solver.

◆ end_iteration() [2/3]

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::end_iteration ( R &  parameters,
R &  action 
)
pure virtual

◆ end_iteration() [3/3]

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::end_iteration ( std::vector< R > &  parameters,
std::vector< R > &  action 
)
pure virtual

◆ end_iteration_needed()

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::end_iteration_needed ( )
pure virtual

signal whether end_iteration should be called

◆ errors()

template<class R , class Q , class P >
virtual const std::vector< value_type_abs > & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::errors ( ) const
pure virtual

Errors are norms of the residuals, so they are real even when the problem is complex.

◆ finalize()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::finalize ( )
pure virtual

Callback invoked once the solver iterations are done but before the solve function returns to the caller. Behaviour depends on the solver.

◆ get_check_metric()

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_check_metric ( ) const
inlinevirtual

Whether the metric is checked, see set_check_metric()

◆ get_max_iter()

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_max_iter ( ) const
pure virtual

◆ get_max_p()

template<class R , class Q , class P >
virtual int molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_max_p ( ) const
pure virtual

◆ get_options()

template<class R , class Q , class P >
virtual std::shared_ptr< Options > molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_options ( ) const
pure virtual

Return all options. This is no different than using getters, but can be used with forward declaration.

◆ get_p_threshold()

template<class R , class Q , class P >
virtual value_type_abs molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_p_threshold ( ) const
pure virtual

◆ get_verbosity()

template<class R , class Q , class P >
virtual Verbosity molpro::linalg::itsolv::IterativeSolver< R, Q, P >::get_verbosity ( ) const
pure virtual

◆ logger()

template<class R , class Q , class P >
virtual Logger & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::logger ( )
pure virtual

◆ metric_kind()

template<class R , class Q , class P >
virtual MetricKind molpro::linalg::itsolv::IterativeSolver< R, Q, P >::metric_kind ( ) const
inlinevirtual

The kind of metric declared with set_metric()

◆ metric_storage()

template<class R , class Q , class P >
virtual MetricStorage molpro::linalg::itsolv::IterativeSolver< R, Q, P >::metric_storage ( ) const
inlinevirtual

How the actions of the metric declared with set_metric() are obtained.

◆ n_roots()

template<class R , class Q , class P >
virtual size_t molpro::linalg::itsolv::IterativeSolver< R, Q, P >::n_roots ( ) const
pure virtual

Total number of roots we are solving for, including the ones that are already converged

◆ nonlinear()

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::nonlinear ( ) const
pure virtual

Report whether the class is a non-linear solver.

Returns

◆ operator=() [1/2]

template<class R , class Q , class P >
IterativeSolver< R, Q, P > & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::operator= ( const IterativeSolver< R, Q, P > &  )
delete

◆ operator=() [2/2]

template<class R , class Q , class P >
IterativeSolver< R, Q, P > & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::operator= ( IterativeSolver< R, Q, P > &&  )
defaultnoexcept

◆ profiler()

template<class R , class Q , class P >
virtual const std::shared_ptr< molpro::profiler::Profiler > & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::profiler ( ) const
pure virtual

◆ report() [1/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::report ( ) const
pure virtual

Writes a report to std::cout.

◆ report() [2/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::report ( std::ostream &  cout,
bool  endl = true 
) const
pure virtual

Writes a report to cout output stream.

◆ set_check_metric()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_check_metric ( bool  check)
inlinevirtual

Sets whether add_p() and add_vector() check that the metric is Hermitian and, for the positive (semi)definite kinds, positive (semi)definite on the subspace (default: true). The checks cost a few operations on vectors in every iteration.

◆ set_convergence_threshold()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_convergence_threshold ( value_type_abs  thresh)
pure virtual

Sets the convergence threshold.

◆ set_convergence_threshold_value()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_convergence_threshold_value ( value_type_abs  thresh)
pure virtual

Sets the value convergence threshold.

◆ set_logger()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_logger ( std::shared_ptr< Logger >  logger)
pure virtual

Set the logger instance that shall be used.

Parameters
logger

◆ set_max_iter()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_max_iter ( int  n)
pure virtual

◆ set_max_p()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_max_p ( int  n)
pure virtual

◆ set_metric()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_metric ( MetricKind  kind,
MetricStorage  storage = MetricStorage::Stored,
fapply_metric_type  apply_metric = {} 
)
inlinevirtual

Declares the metric M of a generalised problem, e.g. the eigenproblem A v = lambda M v, for the stepwise interface. solve() calls it itself.

It has to be called before the first add_p() or add_vector(). On a non-empty subspace it may only be called again with the same kind and storage, replacing apply_metric. Throws if the solver does not support kind.

Once a metric other than the identity is declared, every add_vector() has to give the actions of the metric. Solutions are then normalised such that |<x|M|x>| = 1, and their residuals are A x - lambda M x. The errors are the norms of the residuals of the solutions scaled to unit length, |A x - lambda M x| / |x|, which do not depend on the scale of M and are the same as without a metric if M is the identity.

add_p() and add_vector() throw std::runtime_error if the actions of the metric show that it is not Hermitian or, for the positive (semi)definite kinds, that it is not positive (semi)definite, unless switched off with set_check_metric(). These checks see the metric only on the subspace, so that, e.g., an indefinite metric is noticed only once one of its negative directions enters the subspace; test_problem() checks the metric of a Problem more directly. The metric matrix of the P space is checked before the P space is added, but the vectors given to add_vector() are part of the subspace when the check of positivity fails.

Parameters
kindthe kind of metric
storagehow the solver obtains the actions of the metric on its subspace vectors: with MetricStorage::Stored it keeps those given to add_vector(); with MetricStorage::OnTheFly, which is worthwhile where the metric is cheap to apply, it keeps none, and calls apply_metric on the solutions whenever it constructs residuals instead. Irrelevant for MetricKind::Identity.
apply_metricapplies the metric, given exactly for MetricStorage::OnTheFly; it has to remain valid as long as residuals are constructed

◆ set_n_roots()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_n_roots ( size_t  nroots)
pure virtual

◆ set_options()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_options ( const Options &  options)
pure virtual

Set all spcecified options. This is no different than using setters, but can be used with forward declaration.

◆ set_p_threshold()

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_p_threshold ( value_type_abs  thresh)
pure virtual

◆ set_profiler() [1/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_profiler ( molpro::profiler::Profiler &  profiler)
pure virtual

Attach a profiler in order to collect performance data.

Parameters
profilerThe profiler to use. It is not owned by the solver and must outlive it.

◆ set_profiler() [2/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_profiler ( std::shared_ptr< molpro::profiler::Profiler >  profiler)
pure virtual

Attach a profiler in order to collect performance data.

Parameters
profilerThe profiler to use. The solver shares ownership of it, so it stays valid for the solver's lifetime.

◆ set_verbosity() [1/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_verbosity ( int  v)
pure virtual

◆ set_verbosity() [2/2]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::set_verbosity ( Verbosity  v)
pure virtual

◆ solution() [1/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution ( const std::vector< int > &  roots,
const VecRef< R > &  parameters,
const VecRef< R > &  residual 
)
pure virtual

Construct solution and residual for a given set of roots.

For a problem solved with solve() whose metric is applied on the fly (Problem::metric_storage()), this applies the metric through the problem, which therefore has to be still alive.

Exceptions
std::logic_errorif called between an end_iteration() that reset the D space and the next add_vector(), when the subspace does not hold the solutions; they are in the parameters returned by end_iteration() instead

◆ solution() [2/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution ( const std::vector< int > &  roots,
std::vector< R > &  parameters,
std::vector< R > &  residual 
)
pure virtual

◆ solution() [3/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution ( R &  parameters,
R &  residual 
)
pure virtual

◆ solution_params() [1/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution_params ( const std::vector< int > &  roots,
const VecRef< R > &  parameters 
)
pure virtual

Constructs parameters of selected roots; throws like solution()

◆ solution_params() [2/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution_params ( const std::vector< int > &  roots,
std::vector< R > &  parameters 
)
pure virtual

◆ solution_params() [3/3]

template<class R , class Q , class P >
virtual void molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solution_params ( R &  parameters)
pure virtual

◆ solve() [1/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( const VecRef< R > &  parameters,
const VecRef< R > &  actions,
const Problem< R > &&  problem,
bool  generate_initial_guess = false 
)
delete

A temporary problem is rejected, as the solver may keep references to the problem beyond solve(), e.g. for a P space

◆ solve() [2/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( const VecRef< R > &  parameters,
const VecRef< R > &  actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
pure virtual

Simplified one-call solver.

Parameters
parametersA set of scratch vectors. On entry, these vectors should be filled with starting guesses. Where possible, the number of vectors should be equal to the number of solutions sought, but a smaller array is permitted.
actionsA set of scratch vectors. It should have the same size as parameters.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if solutions for all n_roots() roots were found and have converged

If a P space is used (max_p > 0, diagonal elements are available and the selected P space is at least as large as the number of roots), the initial subspace is the P space alone, and neither the contents of parameters on entry nor a generated initial guess are used. If max_p > 0 and diagonal elements are available but the selected P space is smaller than the number of roots, no P space is used and the initial guess is generated from the diagonal elements, irrespective of generate_initial_guess; the contents of parameters on entry are not used in this case either.

Starting vectors, whether generated or taken from parameters, are only used for the roots in the working set, at most one per root. On a solver that is used again after an earlier solve(), roots that have already converged are not in the working set, so fewer guesses, or none at all, are generated.

A problem with a metric (Problem::metric_kind() other than MetricKind::Identity) has to be solved with the overload taking buffers for the actions of the metric; this one throws for it.

The solver may keep references to problem for later calls such as solution(), e.g. for a P space, so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

An iteration that resets the D space leaves no solutions to return (see solution()). If this happens in the last of max_iter iterations, solve() goes on until the vectors of the reset are in the subspace, which takes one more action per root.

◆ solve() [3/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::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()

◆ solve() [4/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( const VecRef< R > &  parameters,
const VecRef< R > &  actions,
const VecRef< R > &  metric_actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
inlinevirtual

Simplified one-call solver for problems that may have a metric, e.g. the generalised eigenproblem A v = lambda M v.

Parameters
parametersA set of scratch vectors, as for solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool)
actionsA set of scratch vectors. It should have the same size as parameters.
metric_actionsA set of scratch vectors, of the same size as parameters. The solver uses them for the actions of the metric on new expansion vectors, which it needs also when the metric is applied on the fly, as scratch space, and to hand the diagonal elements of the metric to the preconditioner.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if the solution was found

Behaves like solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool), and for a problem without a metric exactly so. For a problem with a metric, set_metric() is called with Problem::metric_kind() (throwing if the solver does not support it) and Problem::metric_storage(), with, for MetricStorage::OnTheFly, a function calling Problem::metric_action(). The actions of kernel and metric are calculated together by Problem::action_with_metric(). If the problem provides diagonals(), it has to provide metric_diagonals() too; both are passed to the preconditioner, and a generated initial guess and the P space are selected from the lowest ratios of the diagonal elements of the kernel and the metric. A P space additionally needs Problem::pp_metric_matrix() and, unless the metric is applied on the fly, Problem::p_metric_action().

The solver keeps references to problem for later calls such as solution(), so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

◆ solve() [5/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( R &  parameters,
R &  actions,
const Problem< R > &&  problem,
bool  generate_initial_guess = false 
)
delete

A temporary problem is rejected, as the solver may keep references to the problem beyond solve(), e.g. for a P space

◆ solve() [6/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( R &  parameters,
R &  actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
pure virtual

Simplified one-call solver.

Parameters
parametersA set of scratch vectors. On entry, these vectors should be filled with starting guesses. Where possible, the number of vectors should be equal to the number of solutions sought, but a smaller array is permitted.
actionsA set of scratch vectors. It should have the same size as parameters.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if solutions for all n_roots() roots were found and have converged

If a P space is used (max_p > 0, diagonal elements are available and the selected P space is at least as large as the number of roots), the initial subspace is the P space alone, and neither the contents of parameters on entry nor a generated initial guess are used. If max_p > 0 and diagonal elements are available but the selected P space is smaller than the number of roots, no P space is used and the initial guess is generated from the diagonal elements, irrespective of generate_initial_guess; the contents of parameters on entry are not used in this case either.

Starting vectors, whether generated or taken from parameters, are only used for the roots in the working set, at most one per root. On a solver that is used again after an earlier solve(), roots that have already converged are not in the working set, so fewer guesses, or none at all, are generated.

A problem with a metric (Problem::metric_kind() other than MetricKind::Identity) has to be solved with the overload taking buffers for the actions of the metric; this one throws for it.

The solver may keep references to problem for later calls such as solution(), e.g. for a P space, so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

An iteration that resets the D space leaves no solutions to return (see solution()). If this happens in the last of max_iter iterations, solve() goes on until the vectors of the reset are in the subspace, which takes one more action per root.

◆ solve() [7/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::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()

◆ solve() [8/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( R &  parameters,
R &  actions,
R &  metric_actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
inlinevirtual

Simplified one-call solver for problems that may have a metric, e.g. the generalised eigenproblem A v = lambda M v.

Parameters
parametersA set of scratch vectors, as for solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool)
actionsA set of scratch vectors. It should have the same size as parameters.
metric_actionsA set of scratch vectors, of the same size as parameters. The solver uses them for the actions of the metric on new expansion vectors, which it needs also when the metric is applied on the fly, as scratch space, and to hand the diagonal elements of the metric to the preconditioner.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if the solution was found

Behaves like solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool), and for a problem without a metric exactly so. For a problem with a metric, set_metric() is called with Problem::metric_kind() (throwing if the solver does not support it) and Problem::metric_storage(), with, for MetricStorage::OnTheFly, a function calling Problem::metric_action(). The actions of kernel and metric are calculated together by Problem::action_with_metric(). If the problem provides diagonals(), it has to provide metric_diagonals() too; both are passed to the preconditioner, and a generated initial guess and the P space are selected from the lowest ratios of the diagonal elements of the kernel and the metric. A P space additionally needs Problem::pp_metric_matrix() and, unless the metric is applied on the fly, Problem::p_metric_action().

The solver keeps references to problem for later calls such as solution(), so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

◆ solve() [9/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( std::vector< R > &  parameters,
std::vector< R > &  actions,
const Problem< R > &&  problem,
bool  generate_initial_guess = false 
)
delete

A temporary problem is rejected, as the solver may keep references to the problem beyond solve(), e.g. for a P space

◆ solve() [10/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( std::vector< R > &  parameters,
std::vector< R > &  actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
pure virtual

Simplified one-call solver.

Parameters
parametersA set of scratch vectors. On entry, these vectors should be filled with starting guesses. Where possible, the number of vectors should be equal to the number of solutions sought, but a smaller array is permitted.
actionsA set of scratch vectors. It should have the same size as parameters.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if solutions for all n_roots() roots were found and have converged

If a P space is used (max_p > 0, diagonal elements are available and the selected P space is at least as large as the number of roots), the initial subspace is the P space alone, and neither the contents of parameters on entry nor a generated initial guess are used. If max_p > 0 and diagonal elements are available but the selected P space is smaller than the number of roots, no P space is used and the initial guess is generated from the diagonal elements, irrespective of generate_initial_guess; the contents of parameters on entry are not used in this case either.

Starting vectors, whether generated or taken from parameters, are only used for the roots in the working set, at most one per root. On a solver that is used again after an earlier solve(), roots that have already converged are not in the working set, so fewer guesses, or none at all, are generated.

A problem with a metric (Problem::metric_kind() other than MetricKind::Identity) has to be solved with the overload taking buffers for the actions of the metric; this one throws for it.

The solver may keep references to problem for later calls such as solution(), e.g. for a P space, so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

An iteration that resets the D space leaves no solutions to return (see solution()). If this happens in the last of max_iter iterations, solve() goes on until the vectors of the reset are in the subspace, which takes one more action per root.

◆ solve() [11/12]

template<class R , class Q , class P >
bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::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()

◆ solve() [12/12]

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::solve ( std::vector< R > &  parameters,
std::vector< R > &  actions,
std::vector< R > &  metric_actions,
const Problem< R > &  problem,
bool  generate_initial_guess = false 
)
inlinevirtual

Simplified one-call solver for problems that may have a metric, e.g. the generalised eigenproblem A v = lambda M v.

Parameters
parametersA set of scratch vectors, as for solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool)
actionsA set of scratch vectors. It should have the same size as parameters.
metric_actionsA set of scratch vectors, of the same size as parameters. The solver uses them for the actions of the metric on new expansion vectors, which it needs also when the metric is applied on the fly, as scratch space, and to hand the diagonal elements of the metric to the preconditioner.
problemA Problem object defining the problem to be solved
generate_initial_guessWhether to start with a guess based on diagonal elements (true) or on the contents of parameters (false)
Returns
true if the solution was found

Behaves like solve(const VecRef<R>&, const VecRef<R>&, const Problem<R>&, bool), and for a problem without a metric exactly so. For a problem with a metric, set_metric() is called with Problem::metric_kind() (throwing if the solver does not support it) and Problem::metric_storage(), with, for MetricStorage::OnTheFly, a function calling Problem::metric_action(). The actions of kernel and metric are calculated together by Problem::action_with_metric(). If the problem provides diagonals(), it has to provide metric_diagonals() too; both are passed to the preconditioner, and a generated initial guess and the P space are selected from the lowest ratios of the diagonal elements of the kernel and the metric. A P space additionally needs Problem::pp_metric_matrix() and, unless the metric is applied on the fly, Problem::p_metric_action().

The solver keeps references to problem for later calls such as solution(), so problem has to outlive them; a further call of solve() replaces them. A temporary problem is therefore rejected at compile time.

◆ statistics()

template<class R , class Q , class P >
virtual const Statistics & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::statistics ( ) const
pure virtual

◆ suggest_p()

template<class R , class Q , class P >
virtual std::vector< size_t > molpro::linalg::itsolv::IterativeSolver< R, Q, P >::suggest_p ( const CVecRef< R > &  solution,
const CVecRef< R > &  residual,
size_t  max_number,
value_type_abs  threshold 
)
pure virtual

Get the solver's suggestion of which degrees of freedom would be best to add to the P-space.

Parameters
solutionCurrent solution
residualCurrent residual
max_numberSuggest no more than this number
thresholdSuggest only axes for which the current residual and update indicate an energy improvement in the next iteration of this amount or more.
Returns

◆ supports_metric()

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::supports_metric ( MetricKind  kind) const
inlinevirtual

Whether the solver supports a metric of the given kind. MetricKind::Identity is always supported.

◆ test_problem()

template<class R , class Q , class P >
virtual bool molpro::linalg::itsolv::IterativeSolver< R, Q, P >::test_problem ( const Problem< R > &  problem,
R &  v0,
R &  v1,
int  verbosity = 0,
value_type_abs  threshold = 1e-5 
) const
pure virtual

Test a supplied problem class.

For a linear problem, checks that the actions of the kernel and, if there is one, of the metric are linear, and that the metric is Hermitian and, for the positive (semi)definite kinds, positive (semi)definite on the test parameters.

Parameters
problem
v0
v1
verbosity
threshold
Returns
false if errors were found, otherwise true

◆ value()

template<class R , class Q , class P >
virtual scalar_type molpro::linalg::itsolv::IterativeSolver< R, Q, P >::value ( ) const
pure virtual

Report the function value for the current optimum solution.

Returns

◆ working_set()

template<class R , class Q , class P >
virtual const std::vector< int > & molpro::linalg::itsolv::IterativeSolver< R, Q, P >::working_set ( ) const
pure virtual

Working set of roots that are not yet converged.

◆ working_set_eigenvalues()

template<class R , class Q , class P >
virtual std::vector< scalar_type > molpro::linalg::itsolv::IterativeSolver< R, Q, P >::working_set_eigenvalues ( ) const
inlinevirtual

The calculated eigenvalues for roots in the working set (eigenvalue problems) or zero (otherwise)