<commit_before>//
// Created by david on 2019-06-24.
//

#pragma once

#include <algorithms/class_algorithm_base.h>
#include <tensors/class_tensors_finite.h>
class class_state_finite;
class class_model_finite;
class class_edges_finite;

// class h5pp_table_measurements_finite;
class class_algorithm_finite : public class_algorithm_base {
    public:
    // Inherit the constructor of class_algorithm_base
    using class_algorithm_base::class_algorithm_base;
    explicit class_algorithm_finite(std::shared_ptr<h5pp::File> h5ppFile_, AlgorithmType algo_type);
    //    ~class_algorithm_finite();    // Read comment on implementation
    //    std::unique_ptr<class_state_finite> state;// The finite chain state
    //    std::unique_ptr<class_model_finite> model;// The finite chain model
    //    std::unique_ptr<class_edges_finite> edges;// The finite chain edges
    class_tensors_finite tensors; // State, model and edges

    size_t excited_state_number = 0; /*!< Keeps track of found excited states. Convention: "0" is the biased seed,
                                      * and others become unbiased by randomizing from state 0 (or any other).
                                      * Therefore, this number is only incremented when randomizing the current state*/

    // Control behavior when stuck
    size_t              max_stuck_iters      = 2;     /*!< If stuck for this many sweeps -> stop. */
    size_t              min_saturation_iters = 1;     /*!< If both var and ent saturated  this long -> got_stuck: true */
    size_t              max_saturation_iters = 5;     /*!< If either var or ent saturated this long -> got_stuck: true */

    bool                has_projected        = false; /*!< True if projection has already been tried */
    bool                has_damped           = false; /*!< True if damping of hamiltonian parameters is ongoing */
    size_t              chi_quench_steps     = 0;     /*!< Number of steps left doing chi-quenching */
    size_t              num_chi_quenches     = 0;     /*!< Number of bond dimension quench trials that have occurred */
    size_t              max_chi_quenches     = 2;     /*!< Maximum number of bond dimension quench trials allowed */
    long                chi_lim_quench_ahead = 32;    /*!< Bond dimension during a quench */
    long                chi_lim_quench_trail = 32;    /*!< Bond dimension during a quench */
    size_t              num_perturbations    = 0;     /*!< Number of perturbation trials done */
    size_t              max_perturbations    = 2;     /*!< Maximum number of perturbation trials allowed */
    size_t              perturbation_steps   = 0;     /*!< Number of steps left doing perturbation of MPOs */
    size_t              damping_steps        = 0;     /*!< Number of steps left doing disorder damping of MPOs */
    size_t              num_dampings         = 0;     /*!< Number of damping trials done */
    size_t              max_dampings         = 2;     /*!< Maximum number of damping trials allowed */
    std::vector<double> damping_exponents;            /*!< Exponents for for the damping trials */
    std::optional<OptMode> last_optmode = std::nullopt;
    std::optional<OptSpace> last_optspace = std::nullopt;


    public:
    virtual void run_algorithm() = 0;
    virtual void run_preprocessing() = 0; // Specific for each algorithm type
    virtual void run_postprocessing();
    virtual bool cfg_store_wave_function() = 0;
    virtual void resume() = 0;
    virtual void run_default_task_list() = 0;
    void         try_projection();
    void         try_bond_dimension_quench();
    void         try_hamiltonian_perturbation();<commit_msg>Prolong simulation a bit by increasing max_stuck_iters 2 --> 4  and max_saturation_iters 5 --> 10 to give mitigation routines a better chance of converging<commit_after>//
// Created by david on 2019-06-24.
//

#pragma once

#include <algorithms/class_algorithm_base.h>
#include <tensors/class_tensors_finite.h>
class class_state_finite;
class class_model_finite;
class class_edges_finite;

// class h5pp_table_measurements_finite;
class class_algorithm_finite : public class_algorithm_base {
    public:
    // Inherit the constructor of class_algorithm_base
    using class_algorithm_base::class_algorithm_base;
    explicit class_algorithm_finite(std::shared_ptr<h5pp::File> h5ppFile_, AlgorithmType algo_type);
    //    ~class_algorithm_finite();    // Read comment on implementation
    //    std::unique_ptr<class_state_finite> state;// The finite chain state
    //    std::unique_ptr<class_model_finite> model;// The finite chain model
    //    std::unique_ptr<class_edges_finite> edges;// The finite chain edges
    class_tensors_finite tensors; // State, model and edges

    size_t excited_state_number = 0; /*!< Keeps track of found excited states. Convention: "0" is the biased seed,
                                      * and others become unbiased by randomizing from state 0 (or any other).
                                      * Therefore, this number is only incremented when randomizing the current state*/

    // Control behavior when stuck
    size_t              max_stuck_iters      = 4;     /*!< If stuck for this many sweeps -> stop. */
    size_t              min_saturation_iters = 1;     /*!< If both var and ent saturated  this long -> got_stuck: true */
    size_t              max_saturation_iters = 10;    /*!< If either var or ent saturated this long -> got_stuck: true */

    bool                has_projected        = false; /*!< True if projection has already been tried */
    bool                has_damped           = false; /*!< True if damping of hamiltonian parameters is ongoing */
    size_t              chi_quench_steps     = 0;     /*!< Number of steps left doing chi-quenching */
    size_t              num_chi_quenches     = 0;     /*!< Number of bond dimension quench trials that have occurred */
    size_t              max_chi_quenches     = 2;     /*!< Maximum number of bond dimension quench trials allowed */
    long                chi_lim_quench_ahead = 32;    /*!< Bond dimension during a quench */
    long                chi_lim_quench_trail = 32;    /*!< Bond dimension during a quench */
    size_t              num_perturbations    = 0;     /*!< Number of perturbation trials done */
    size_t              max_perturbations    = 2;     /*!< Maximum number of perturbation trials allowed */
    size_t              perturbation_steps   = 0;     /*!< Number of steps left doing perturbation of MPOs */
    size_t              damping_steps        = 0;     /*!< Number of steps left doing disorder damping of MPOs */
    size_t              num_dampings         = 0;     /*!< Number of damping trials done */
    size_t              max_dampings         = 2;     /*!< Maximum number of damping trials allowed */
    std::vector<double> damping_exponents;            /*!< Exponents for for the damping trials */
    std::optional<OptMode> last_optmode = std::nullopt;
    std::optional<OptSpace> last_optspace = std::nullopt;


    public:
    virtual void run_algorithm() = 0;
    virtual void run_preprocessing() = 0; // Specific for each algorithm type
    virtual void run_postprocessing();
    virtual bool cfg_store_wave_function() = 0;
    virtual void resume() = 0;
    virtual void run_default_task_list() = 0;
    void         try_projection();
    void         try_bond_dimension_quench();
    void         try_hamiltonian_perturbation();
{'fraction_non_alphanumeric': 0.08275493860117458, 'fraction_numerical': 0.01014415376401495, 'mean_word_length': 2.339126559714795, 'pattern_counts': {'":': 0, '<': 57, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4812354', 'n_tokens_mistral': 2163, 'n_tokens_neox': 1993, 'n_words': 658}