1#ifndef LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DSPACERESETTER_H
2#define LINEARALGEBRA_SRC_MOLPRO_LINALG_ITSOLV_DSPACERESETTER_H
3#include <molpro/linalg/itsolv/IterativeSolver.h>
4#include <molpro/linalg/itsolv/propose_rspace.h>
5#include <molpro/linalg/itsolv/qspace_options.h>
6#include <molpro/linalg/itsolv/subspace/Dimensions.h>
7#include <molpro/linalg/itsolv/subspace/IXSpace.h>
8#include <molpro/linalg/itsolv/subspace/QSpace.h>
9#include <molpro/linalg/itsolv/subspace/gram_schmidt.h>
10#include <molpro/linalg/itsolv/subspace/util.h>
11#include <molpro/linalg/itsolv/util.h>
25template <
class R,
class Q,
class P,
typename value_type>
28 logger.
trace(
"resize_qspace()");
35template <
class R,
class Q,
class P,
typename value_type,
typename Index>
37 std::vector<Index> indices) {
40 std::sort(begin(indices), end(indices), std::greater<Index>());
41 for (
auto i : indices) {
54template <
class R,
class Q>
57 logger.
trace(
"max_overlap_with_R()");
64 auto ov = std::vector<typename array::ArrayHandler<R, Q>::value_type_abs>{};
66 ov.push_back(std::abs(overlap(
i,
j)));
67 auto it_max = std::max_element(
ov.begin(),
ov.end());
70 ", with overlap = " + std::to_string(*
it_max));
96 std::numeric_limits<std::size_t>::max();
121 template <
class R,
class P,
typename value_type,
typename value_type_abs>
125 logger.
trace(
"DSpaceResetter::run()");
133 logger.
debug(
"constructing solutions");
139 norm_thresh, svd_thresh, logger);
141 for (
size_t i = 0;
i <
nC; ++
i)
143 auto roots = std::vector<int>(
nC);
144 std::iota(begin(roots), end(roots), 0);
149 for (
size_t i = 0;
i <
dims.nD; ++
i)
155 for (
size_t i = 0;
i <
nR; ++
i) {
Enhances various operations between pairs of arrays and allows dynamic code injection with uniform in...
Definition ArrayHandler.h:163
Class, containing a collection of array handlers used in IterativeSolver Provides a Builder sub-class...
Definition ArrayHandlers.h:25
Logger class implementation. Provides (customizable) logging functionalities.
Definition Logger.h:370
void trace(std::string_view message, const Ts &...args) const
Definition Logger.h:463
void debug(std::string_view message, const Ts &...args) const
Definition Logger.h:468
Resets D space constructing full solutions as the new working set, removing instabilities from Q spac...
Definition DSpaceResetter.h:92
std::size_t m_max_Qsize_after_reset
maximum size of Q space after reset
Definition DSpaceResetter.h:95
DSpaceResetter(std::size_t nreset, std::size_t max_Qsize)
Definition DSpaceResetter.h:101
auto get_nreset() const
Definition DSpaceResetter.h:112
bool do_reset(size_t iter, const subspace::Dimensions &dims)
Whether reset operation should be run.
Definition DSpaceResetter.h:104
std::list< Q > solution_params
all current solutions that will be moved to the Q space
Definition DSpaceResetter.h:97
void set_max_Qsize(size_t i)
Definition DSpaceResetter.h:113
bool in_progress() const
Whether a reset has started and not all solutions have been moved into the Q space yet.
Definition DSpaceResetter.h:109
std::vector< int > run(const VecRef< R > &rparams, subspace::IXSpace< R, Q, P > &xspace, const subspace::Matrix< value_type > &solutions, const value_type_abs norm_thresh, const value_type_abs svd_thresh, ArrayHandlers< R, Q, P > &handlers, Logger &logger)
Run the reset operation.
Definition DSpaceResetter.h:122
std::size_t m_nreset
reset D space every n iterations, 0 for never
Definition DSpaceResetter.h:94
void set_nreset(size_t i)
Definition DSpaceResetter.h:111
auto get_max_Qsize() const
Definition DSpaceResetter.h:114
Full subspace.
Definition IXSpace.h:21
SubspaceData< value_type > data
Equation data in the subspace.
Definition IXSpace.h:30
virtual CVecRef< Q > cparamsq() const =0
virtual void eraseq(size_t i)=0
Removes parameter i from Q subspace.
virtual void update_dspace(VecRef< Q > ¶ms, VecRef< Q > &actions, const VecRef< Q > &metric_actions={}, const std::vector< size_t > &q_delete={}, const Matrix< value_type > &coefficients={})=0
Replaces the old D space and the Q vectors q_delete by new D vectors, which are linear combinations o...
virtual CVecRef< Q > cparamsd() const =0
virtual const Dimensions & dimensions() const =0
Matrix container that allows simple data access, slicing, copying and resizing without loosing data.
Definition Matrix.h:32
void remove_col(index_type col)
removes a column from the matrix
Definition Matrix.h:154
index_type cols() const
Definition Matrix.h:170
auto stable_projected_solutions(const subspace::Matrix< value_type > &solutions, const subspace::Matrix< value_type > &overlap, const subspace::Dimensions &dims, const std::vector< std::size_t > &remove_qspace, const value_type_abs norm_thresh, const value_type_abs svd_thresh, Logger &logger)
Projects solutions onto Q_{delete} and the current D space, and transforms them to a normalised set w...
Definition propose_rspace.h:251
Definition helper-dispatch.h:224
void erase_qspace(subspace::IXSpace< R, Q, P > &xspace, subspace::Matrix< value_type > &solutions, std::vector< Index > indices)
Erases Q parameters with the given indices together with the corresponding columns of a solutions mat...
Definition DSpaceResetter.h:36
auto max_overlap_with_R(const CVecRef< R > &rparams, const CVecRef< Q > &qparams, array::ArrayHandler< R, Q > &handler, Logger &logger)
Returns list of Q indices with maximum overlap to R parameters, sorted in descending order.
Definition DSpaceResetter.h:55
subspace::Matrix< value_type > contribution_solutions(const subspace::Matrix< value_type > &solutions, const subspace::IXSpace< R, Q, P > &xspace)
The solutions scaled to unit length, as needed wherever thresholds apply to their coefficients or to ...
Definition propose_rspace.h:367
void resize_qspace(subspace::IXSpace< R, Q, P > &xspace, const subspace::Matrix< value_type > &solutions, std::size_t max_size, Logger &logger)
Removes Q parameters that have smallest contribution to any solution until Q space size is within lim...
Definition DSpaceResetter.h:26
std::vector< std::size_t > limit_qspace_size(const subspace::Dimensions &dims, const QSpaceOptions &opts, const subspace::Matrix< value_type > &solutions, Logger &logger)
Ensures that size Q space is within limit by proposing Q parameters for deletion.
Definition propose_rspace.h:383
auto overlap(const CVecRef< R > &left, const CVecRef< Q > &right, array::ArrayHandler< Z, W > &handler) -> std::enable_if_t< detail::Z_and_W_are_one_of_R_and_Q< R, Q, Z, W >, Matrix< typename array::ArrayHandler< Z, W >::value_type > >
Calculates overlap matrix between left and right vectors.
Definition util.h:57
Q construct_zeroed_copy(const R ¶m, array::ArrayHandler< Q, R > &handler)
Copy R parameter to Q and zero it. This ensures same size and distribution of the copy.
Definition util.h:60
void construct_solutions(const VecRef< R > ¶ms, const std::vector< int > &roots, const subspace::Matrix< value_type > &solutions, const CVecRef< P > &pparams, const CVecRef< Q > &qparams, const CVecRef< Q > &dparams, size_t oP, size_t oQ, size_t oD, array::ArrayHandler< R, R > &handler_rr, array::ArrayHandler< R, P > &handler_rp, array::ArrayHandler< R, Q > &handler_rq)
Construct solutions.
Definition util.h:82
auto cwrap(ForwardIt begin, ForwardIt end)
Takes a begin and end iterators and returns a vector of references to each element.
Definition wrap.h:52
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
std::vector< std::reference_wrapper< A > > VecRef
Definition wrap.h:11
Definition Dimensions.h:9
size_t nD
Definition Dimensions.h:14
size_t nQ
Definition Dimensions.h:13
size_t nP
Definition Dimensions.h:12
size_t oQ() const
offset of the Q block
Definition Dimensions.h:18
size_t nX() const
total size of the X space
Definition Dimensions.h:16