diff --git a/src/libs/common/config_os.h b/src/libs/common/config_os.h index 5db265bc..d71e20c5 100644 --- a/src/libs/common/config_os.h +++ b/src/libs/common/config_os.h @@ -2,7 +2,7 @@ #define CONFIG_OS_H_ -#define PESTPP_VERSION "5.2.4"; +#define PESTPP_VERSION "5.2.5"; #if defined(_WIN32) || defined(_WIN64) #define OS_WIN diff --git a/src/libs/common/system_variables.cpp b/src/libs/common/system_variables.cpp index 41d16889..1a8efc54 100644 --- a/src/libs/common/system_variables.cpp +++ b/src/libs/common/system_variables.cpp @@ -46,8 +46,6 @@ const std::string OperSys::DIR_SEP = "/"; const std::string OperSys::COMMAND_LINE_APPEND = " & "; #endif -const int OperSys::thread_sleep_milli_secs=1000; - using namespace std; void OperSys::string2pathname(string &s) diff --git a/src/libs/common/system_variables.h b/src/libs/common/system_variables.h index a8fdfa74..a58fe329 100644 --- a/src/libs/common/system_variables.h +++ b/src/libs/common/system_variables.h @@ -25,8 +25,6 @@ class OperSys { public: - //const static int thread_sleep_secs = 1; - static const int thread_sleep_milli_secs; static const std::string DIR_SEP; static const std::string COMMAND_LINE_APPEND; void string2pathname(std::string &s); diff --git a/src/libs/pestpp_common/Ensemble.cpp b/src/libs/pestpp_common/Ensemble.cpp index 853f191b..d7df5fc9 100644 --- a/src/libs/pestpp_common/Ensemble.cpp +++ b/src/libs/pestpp_common/Ensemble.cpp @@ -4299,14 +4299,86 @@ void FixedParInfo::add_realization(string rname, Eigen::VectorXd& rvals, vector< map v; for (int i = 0; i < rvals.size(); i++) v[pnames[i]] = rvals[i]; + map::iterator end = v.end(); for (auto& name : fixed_names) { - if (v.find(name) == v.end()) + if (v.find(name) == end) throw runtime_error("FixedParInfo::add_realization(): fixed name '" + name + "' not in pnames"); fixed_info.at(name)[rname] = v.at(name); } } +vector FixedParInfo::get_real_names() +{ + if (!initialized) + { + return vector(); + } + if (fixed_names.size() == 0) + { + return vector(); + } + vector rnames; + for (auto& fi : fixed_info) + { + for (auto& ri : fi.second) + { + rnames.push_back(ri.first); + } + } + return rnames; + +} + +void FixedParInfo::add_realizations(map>& other_fixed_info) +{ + if (!initialized) + { + throw runtime_error("FixedParInfo::update_realizations: not initialized"); + } + if (fixed_names.size() == 0) + { + //this needs to be error checked.. + fixed_info = other_fixed_info; + return; + } + map>::iterator end = fixed_info.end(); + for (auto& ofi : other_fixed_info) + { + if (fixed_info.find(ofi.first) == end) + { + throw runtime_error("FixedParInfo::add_realizations() error: pname "+ofi.first+" not in fixed_info"); + } + for (auto& ori : ofi.second) + { + //probably should error check this also to make sure other_fixed_info isnt replacing things... + fixed_info.at(ofi.first)[ori.first] = ori.second; + } + } +} + + +void FixedParInfo::add_realization(string rname, map& rvals) +{ + if (!initialized) + { + throw runtime_error("FixedParInfo::add_realization(): not initialized"); + } + if (fixed_names.size() == 0) + { + return; + } + map::iterator end = rvals.end(); + for (auto& name : fixed_names) + { + if (rvals.find(name) == end) + throw runtime_error("FixedParInfo::add_realization(): fixed name '" + name + "' not in pnames"); + fixed_info.at(name)[rname] = rvals.at(name); + } + + +} + void FixedParInfo::keep_realizations(const vector& keep) { if (!initialized) @@ -4342,6 +4414,7 @@ void FixedParInfo::keep_realizations(const vector& keep) } } + void FixedParInfo::update_realizations(const vector& other_var_names, const vector& other_real_names, const Eigen::MatrixXd& other_mat) { if (!initialized) diff --git a/src/libs/pestpp_common/Ensemble.h b/src/libs/pestpp_common/Ensemble.h index a742a7f7..ee735338 100644 --- a/src/libs/pestpp_common/Ensemble.h +++ b/src/libs/pestpp_common/Ensemble.h @@ -144,12 +144,18 @@ class FixedParInfo vector get_real_fixed_values(const string& rname, vector& pnames); map get_real_fixed_values(const string& rname); void add_realization(string rname, Eigen::VectorXd& rvals, vector& pnames); + void add_realization(string rname, map& rvals); void keep_realizations(const vector& keep); void update_realizations(const vector& other_var_names, const vector& other_real_names, const Eigen::MatrixXd& other_mat); + void add_realizations(map>& other_fixed_info); void update_par_values(const map& pval_map); void clear() { fixed_info.clear(); fixed_names.clear(); } void fill_fixed(map& fixed_map, vector& rnames); int get_map_size() {return fixed_info.size();} + vector get_real_names(); + vector get_fixed_names() {return fixed_names;} + map> get_fixed_info_map() {return fixed_info;} + private: bool initialized; vector fixed_names; diff --git a/src/libs/pestpp_common/EnsembleMethodUtils.cpp b/src/libs/pestpp_common/EnsembleMethodUtils.cpp index 6421af0a..5deb3624 100644 --- a/src/libs/pestpp_common/EnsembleMethodUtils.cpp +++ b/src/libs/pestpp_common/EnsembleMethodUtils.cpp @@ -581,11 +581,12 @@ void EnsembleSolver::initialize_for_mm_solve() } mat = base_oe.get_eigen(oe_real_names, obs_names); + mat.transposeInPlace(); Observations ctl_obs = pest_scenario.get_ctl_observations(); - Eigen::VectorXd ovals = ctl_obs.get_data_eigen_vec(obs_names); + Eigen::ArrayXd ovals = ctl_obs.get_data_eigen_vec(obs_names).array(); for (int i = 0; i < oe_real_names.size(); i++) { - obs_err_map[oe_real_names[i]] = mat.row(i).array() - ovals.array(); + obs_err_map[oe_real_names[i]] = mat.col(i).array() - ovals; } mat = ph.get_par_resid_subset(pe,pe_real_names); @@ -5470,10 +5471,11 @@ void EnsembleMethod::initialize(int cycle, bool run, bool use_existing) if (ppo->get_ies_use_mda()) { + message(1, "using multiple-data-assimilation algorithm"); int noptmax = pest_scenario.get_control_info().noptmax; if (noptmax > 0) { - message(0, "using multiple-data-assimilation algorithm"); + if (ppo->get_ies_no_noise()) { throw_em_error("'no noise'is not compatible with 'use_mda' as this solution relies on noise draws"); @@ -5482,7 +5484,7 @@ void EnsembleMethod::initialize(int cycle, bool run, bool use_existing) } else { - message(0, "using glm algorithm"); + message(1, "using glm algorithm"); } verbose_level = pest_scenario.get_pestpp_options_ptr()->get_ies_verbose_level(); @@ -6347,7 +6349,7 @@ void EnsembleMethod::check_and_fill_phi_factors(map>& grou } ss.str(""); ss << "checking phi factors in file " << fname; - message(0,ss.str()); + message(1,ss.str()); ; if (pest_scenario.get_pestpp_options().get_ies_phi_factors_by_real()) { @@ -9155,7 +9157,7 @@ vector EnsembleMethod::detect_prior_data_conflict(bool save) in_conflict.push_back(oname); dist = max((smin - omax), (omin - smax)); - pdccsv << oname << "," << omn << "," << ostd << "," << omin << "," << omax << "," << omin_stat << "," + pdccsv << pest_utils::lower_cp(oname) << "," << omn << "," << ostd << "," << omin << "," << omax << "," << omin_stat << "," << omax_stat; pdccsv << "," << smn << "," << sstd << "," << smin << "," << smax << "," << smin_stat << "," << smax_stat << "," << dist << endl; diff --git a/src/libs/pestpp_common/MOEA.cpp b/src/libs/pestpp_common/MOEA.cpp index cc34908c..9b160eb1 100644 --- a/src/libs/pestpp_common/MOEA.cpp +++ b/src/libs/pestpp_common/MOEA.cpp @@ -1123,7 +1123,8 @@ map> MOEA::obj_func_report(ParameterEnsemble& _dp, O int max_len = get_max_len_obj_name(); string dir; - frec << left << setw(max_len) << "objective function" << right << setw(12) << "direction" << setw(15) << "mean" << setw(15) << "std dev" << setw(15) << "min" << setw(15) << "max" << endl; + frec << left << setw(max_len) << "objective function" << right << setw(10) << "direction" << setw(13) << "mean"; + frec << setw(13) << "std dev" << setw(13) << "min" << setw(13) << "max" << setw(13) << "knee" << endl; frec << endl << setprecision(7); for (auto obs_obj : obs_obj_names) { @@ -1133,11 +1134,13 @@ map> MOEA::obj_func_report(ParameterEnsemble& _dp, O if (obj_dir_mult[obs_obj] == -1) dir = "maximize"; - frec << right << setw(12) << dir; - frec << right << setw(15) << summary[obs_obj]["mean"]; - frec << setw(15) << summary[obs_obj]["std"]; - frec << setw(15) << summary[obs_obj]["min"]; - frec << setw(15) << summary[obs_obj]["max"] << endl; + frec << right << setw(10) << dir; + frec << right << setw(13) << summary[obs_obj]["mean"]; + frec << setw(13) << summary[obs_obj]["std"]; + frec << setw(13) << summary[obs_obj]["min"]; + frec << setw(13) << summary[obs_obj]["max"] ; + frec << setw(13) << summary[obs_obj]["knee"]; + frec << endl; } @@ -1147,11 +1150,13 @@ map> MOEA::obj_func_report(ParameterEnsemble& _dp, O dir = "minimize"; if (obj_dir_mult[pi_obj] == -1) dir = "maximize"; - frec << right << setw(12) << dir; - frec << right << setw(15) << summary[pi_obj]["mean"]; - frec << setw(15) << summary[pi_obj]["std"]; - frec << setw(15) << summary[pi_obj]["min"]; - frec << setw(15) << summary[pi_obj]["max"] << endl; + frec << right << setw(10) << dir; + frec << right << setw(13) << summary[pi_obj]["mean"]; + frec << setw(13) << summary[pi_obj]["std"]; + frec << setw(13) << summary[pi_obj]["min"]; + frec << setw(13) << summary[pi_obj]["max"]; + frec << setw(13) << summary[pi_obj]["knee"]; + frec << endl; } @@ -1171,12 +1176,14 @@ map> MOEA::obj_func_change_report(map tags{ "mean","max","min" }; + ss << left << setw(max_len) << "objective function" << right << setw(12) << "mean change"; + ss << setw(12) << "% change"; + ss << setw(12) << "max change" << setw(12) << "% change"; + ss << setw(12) << "min change" << setw(12) << "% change"; + ss << setw(12) << "knee change" << setw(12) << "% change"; + ss << endl; + + vector tags{ "mean","max","min","knee" }; for (auto obs_obj : obs_obj_names) { change_summary[obs_obj] = map(); @@ -1194,8 +1201,8 @@ map> MOEA::obj_func_change_report(map> MOEA::obj_func_change_report(map> MOEA::get_obj_func_summary_stats(ParameterEnsem map var_map = _op.get_var_map(); map sum; map> summary_stats; + string opt_member_name; + pair p = get_optimal_solution(_dp,_op,opt_member_name); for (auto obs_obj : obs_obj_names) { sum.clear(); @@ -1246,6 +1255,7 @@ map> MOEA::get_obj_func_summary_stats(ParameterEnsem sum["std"] = std_map[obs_obj]; sum["min"] = _op.get_eigen_ptr()->col(var_map[obs_obj]).minCoeff(); sum["max"] = _op.get_eigen_ptr()->col(var_map[obs_obj]).maxCoeff(); + sum["knee"] = p.second[obs_obj]; summary_stats[obs_obj] = sum; } _dp.update_var_map(); @@ -1277,36 +1287,37 @@ map> MOEA::get_obj_func_summary_stats(ParameterEnsem for (auto pi_obj : pi_obj_names) { - + sim_res = prior_info_ptr->get_pi_rec(pi_obj).calc_sim_and_resid(p.first); vec = stlvec_2_eigenvec(pi_vals[pi_obj]); sum.clear(); sum["mean"] = vec.mean(); sum["std"] = sqrt((vec.array() - vec.mean()).pow(2).sum() / (vec.size() - 1)); sum["min"] = vec.minCoeff(); sum["max"] = vec.maxCoeff(); + sum["knee"] = sim_res.first; summary_stats[pi_obj] = sum; } - //calculate relative hyper volumes - //first form the ideal solution vector - Eigen::VectorXd ideal(summary_stats.size()); - int i=0; - for (auto& oname : obs_obj_names) - { - if (obj_dir_mult[oname] == 1) - ideal[i] = summary_stats.at(oname).at("min"); - else - ideal[i] = summary_stats.at(oname).at("max"); - i++; - } - for (auto& pname : pi_obj_names) - { - if (obj_dir_mult[pname] == 1) - ideal[i] = summary_stats.at(pname).at("min"); - else - ideal[i] = summary_stats.at(pname).at("max"); - i++; - } +// //calculate relative hyper volumes +// //first form the ideal solution vector +// Eigen::VectorXd ideal(summary_stats.size()); +// int i=0; +// for (auto& oname : obs_obj_names) +// { +// if (obj_dir_mult[oname] == 1) +// ideal[i] = summary_stats.at(oname).at("min"); +// else +// ideal[i] = summary_stats.at(oname).at("max"); +// i++; +// } +// for (auto& pname : pi_obj_names) +// { +// if (obj_dir_mult[pname] == 1) +// ideal[i] = summary_stats.at(pname).at("min"); +// else +// ideal[i] = summary_stats.at(pname).at("max"); +// i++; +// } return summary_stats; @@ -2722,6 +2733,30 @@ ParameterEnsemble MOEA::generate_population() new_pop.append_other_rows(p); } + if ((pest_scenario.get_pestpp_options().get_mou_shuffle_fixed_pars()) && (new_pop.get_fixed_info().get_map_size() > 0)) + { + + vector real_names = new_pop.get_real_names(); + vector fixed_names = new_pop.get_fixed_info().get_fixed_names(); + + vector ireals; + for (int i=0;i t; + for (int i=0;i(&t[0],t.size()); + //cout << name1 << ", " << new_fixed.row(i) << endl; + } + new_pop.get_fixed_info().update_realizations(fixed_names,real_names,new_fixed); + } return new_pop; @@ -2735,6 +2770,7 @@ void MOEA::fill_populations_from_maps(ParameterEnsemble& new_dp, ObservationEnse rnames.push_back(entry.first); } new_dp.reserve(rnames,dp.get_var_names()); + map rmap = new_dp.get_real_map(); for (auto& ridx : rmap) { @@ -2813,6 +2849,11 @@ void MOEA::iterate_to_solution() //append offspring dp and (risk-shifted) op to make new dp and op containers new_dp.append_other_rows(dp); + if (dp.get_fixed_info().get_map_size() > 0) + { + map> fi = dp.get_fixed_info().get_fixed_info_map(); + new_dp.get_fixed_info().add_realizations(fi); + } new_op.append_other_rows(op); } if (find(gen_types.begin(),gen_types.end(),MouGenType::PSO) != gen_types.end()) { @@ -3419,12 +3460,17 @@ ParameterEnsemble MOEA::generate_pso_population(int num_members, ParameterEnsemb current_pso_lineage_map.clear(); string new_name; vector new_names; + map primary_parent_map; + ofstream& lin = file_manager.get_ofstream(lineage_tag); for (auto real_name : new_dp.get_real_names()) { new_name = get_new_member_name("pso"); new_name = get_new_member_name("pso"); current_pso_lineage_map[real_name] = new_name; new_names.push_back(new_name); + primary_parent_map[new_name] = real_name; + lin << new_name << "," << real_name << ",," << endl; + } cur_velocity.set_real_names(new_names); pso_velocity = cur_velocity; @@ -3440,6 +3486,15 @@ ParameterEnsemble MOEA::generate_pso_population(int num_members, ParameterEnsemb keep.push_back(new_names[i]); new_dp.keep_rows(keep,true); pso_velocity.keep_rows(keep,true); + } + if (_dp.get_fixed_info().get_map_size() > 0) { + vector fi_fixed_names = _dp.get_fixed_info().get_fixed_names(); + new_dp.get_fixed_info().set_fixed_names(fi_fixed_names); + map fi; + for (auto &p : primary_parent_map) { + fi = _dp.get_fixed_info().get_real_fixed_values(p.second); + new_dp.get_fixed_info().add_realization(p.first, fi); + } } return new_dp; } @@ -3617,6 +3672,7 @@ ParameterEnsemble MOEA::generate_simplex_population(int num_members, ParameterEn int i_newreal = 0; + map primary_parent_map; for (int k=0;k 0) { + vector fi_fixed_names = _dp.get_fixed_info().get_fixed_names(); + new_dp.get_fixed_info().set_fixed_names(fi_fixed_names); + map fi; + for (auto &p : primary_parent_map) { + fi = _dp.get_fixed_info().get_real_fixed_values(p.second); + new_dp.get_fixed_info().add_realization(p.first, fi); + } + } return new_dp; } @@ -3699,6 +3765,7 @@ ParameterEnsemble MOEA::generate_diffevol_population(int num_members, ParameterE bts.ctl2numeric_ip(ubnd); int tries = 0; int i = 0; + map primary_parent_map; while (i < num_members) { selected = selection(4, _dp, mattype); @@ -3759,6 +3826,7 @@ ParameterEnsemble MOEA::generate_diffevol_population(int num_members, ParameterE continue; new_name = get_new_member_name("de"); new_member_names.push_back(new_name); + primary_parent_map[new_name] = real_names[selected[0]]; lin << new_name; for (auto idx : selected) lin << "," << real_names[idx]; @@ -3771,6 +3839,18 @@ ParameterEnsemble MOEA::generate_diffevol_population(int num_members, ParameterE new_dp.set_trans_status(ParameterEnsemble::transStatus::NUM); new_dp.enforce_bounds(performance_log, false); + //transfer any fixed par info + if (_dp.get_fixed_info().get_map_size() > 0) + { + vector fi_fixed_names = _dp.get_fixed_info().get_fixed_names(); + new_dp.get_fixed_info().set_fixed_names(fi_fixed_names); + map fi; + for (auto& p : primary_parent_map) + { + fi = _dp.get_fixed_info().get_real_fixed_values(p.second); + new_dp.get_fixed_info().add_realization(p.first,fi); + } + } return new_dp; } @@ -3805,6 +3885,7 @@ ParameterEnsemble MOEA::generate_pm_population(int num_members, ParameterEnsembl if (var_map.find(MR_NAME) != var_map.end()) adaptive_mr = true; double mut_prob = org_mut_prob; + map primary_parent_map; while (imember < num_members) { selected = selection(1, _dp, mattype); @@ -3826,12 +3907,22 @@ ParameterEnsemble MOEA::generate_pm_population(int num_members, ParameterEnsembl lin << new_name; for (auto idx : selected) lin << "," << real_names[idx]; - lin << endl; + lin << endl; + primary_parent_map[new_name] = real_names[selected[0]]; } ParameterEnsemble tmp_dp(&pest_scenario, &rand_gen, new_reals, new_member_names, _dp.get_var_names()); tmp_dp.set_trans_status(ParameterEnsemble::transStatus::NUM); tmp_dp.enforce_bounds(performance_log,false); + if (_dp.get_fixed_info().get_map_size() > 0) { + vector fi_fixed_names = _dp.get_fixed_info().get_fixed_names(); + tmp_dp.get_fixed_info().set_fixed_names(fi_fixed_names); + map fi; + for (auto &p : primary_parent_map) { + fi = _dp.get_fixed_info().get_real_fixed_values(p.second); + tmp_dp.get_fixed_info().add_realization(p.first, fi); + } + } return tmp_dp; } @@ -3927,6 +4018,7 @@ ParameterEnsemble MOEA::generate_sbx_population(int num_members, ParameterEnsemb bool adaptive_cr = false; if (var_map.find(CR_NAME) != var_map.end()) adaptive_cr = true; + map primary_parent_map; while (i_member < num_members) { selected = selection(2, _dp, mattype); @@ -3965,6 +4057,7 @@ ParameterEnsemble MOEA::generate_sbx_population(int num_members, ParameterEnsemb new_name = get_new_member_name("sbx"); lin << new_name << "," << real_names[p1_idx] << "," << real_names[p2_idx] << endl; new_member_names.push_back(new_name); + primary_parent_map[new_name] = real_names[p1_idx]; //cout << i_member << "," << p1_idx << "," << p2_idx << new_names[new_names.size() -1] << endl; i_member++; tries++; @@ -3980,6 +4073,15 @@ ParameterEnsemble MOEA::generate_sbx_population(int num_members, ParameterEnsemb //generate_pm_population(tmp_dp.shape().first, tmp_dp); tmp_dp.enforce_bounds(performance_log,false); + if (_dp.get_fixed_info().get_map_size() > 0) { + vector fi_fixed_names = _dp.get_fixed_info().get_fixed_names(); + tmp_dp.get_fixed_info().set_fixed_names(fi_fixed_names); + map fi; + for (auto &p : primary_parent_map) { + fi = _dp.get_fixed_info().get_real_fixed_values(p.second); + tmp_dp.get_fixed_info().add_realization(p.first, fi); + } + } return tmp_dp; } diff --git a/src/libs/pestpp_common/pest_data_structs.cpp b/src/libs/pestpp_common/pest_data_structs.cpp index 2f531725..45fbb59b 100644 --- a/src/libs/pestpp_common/pest_data_structs.cpp +++ b/src/libs/pestpp_common/pest_data_structs.cpp @@ -1472,6 +1472,13 @@ bool PestppOptions::assign_mou_value_by_key(const string& key, const string& val mou_use_multigen = pest_utils::parse_string_arg_to_bool(value); return true; } + else if (key == "MOU_SHUFFLE_FIXED_PARS") + { + mou_shuffle_fixed_pars = pest_utils::parse_string_arg_to_bool(value); + return true; + } + + return false; } @@ -1703,6 +1710,7 @@ void PestppOptions::summary(ostream& os) const } os << "mou_simplex_mutation: " << mou_simplex_mutation << endl; os << "mou_use_multigen:" << mou_use_multigen << endl; + os << "mou_shuffle_fixed_pars: " << mou_shuffle_fixed_pars << endl; os << endl << "...shared pestpp-ies/pestpp-da options:" << endl; @@ -1888,6 +1896,7 @@ void PestppOptions::set_defaults() set_mou_simplex_factors(vector{0.5, 0.6, 0.7, 0.8}); set_mou_simplex_mutation(false); set_mou_use_multigen(false); + set_mou_shuffle_fixed_pars(false); set_ies_par_csv(""); set_ies_obs_csv(""); diff --git a/src/libs/pestpp_common/pest_data_structs.h b/src/libs/pestpp_common/pest_data_structs.h index 9cabc88b..a6a8e9b1 100644 --- a/src/libs/pestpp_common/pest_data_structs.h +++ b/src/libs/pestpp_common/pest_data_structs.h @@ -420,6 +420,8 @@ class PestppOptions { void set_mou_simplex_mutation(bool _flag) {mou_simplex_mutation = _flag;} bool get_mou_use_multigen() const {return mou_use_multigen;} void set_mou_use_multigen(bool _flag) {mou_use_multigen = _flag;} + bool get_mou_shuffle_fixed_pars() const {return mou_shuffle_fixed_pars;} + void set_mou_shuffle_fixed_pars(bool _flag) {mou_shuffle_fixed_pars = _flag;} string get_ies_par_csv()const { return ies_par_csv; } void set_ies_par_csv(string _ies_par_csv) { ies_par_csv = _ies_par_csv; } @@ -749,6 +751,7 @@ class PestppOptions { vector mou_simplex_factors; bool mou_simplex_mutation; bool mou_use_multigen; + bool mou_shuffle_fixed_pars; int ies_subset_size; string ies_par_csv; diff --git a/src/libs/run_managers/abstract_base/model_interface.cpp b/src/libs/run_managers/abstract_base/model_interface.cpp index 6dc0ad3b..7e9916b9 100644 --- a/src/libs/run_managers/abstract_base/model_interface.cpp +++ b/src/libs/run_managers/abstract_base/model_interface.cpp @@ -212,7 +212,6 @@ void ModelInterface::run(Parameters* pars, Observations* obs) pest_utils::thread_flag terminate(false); pest_utils::thread_flag finished(false); - run(&terminate, &finished, run_exception, pars, obs); if (run_exception) { @@ -697,8 +696,8 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_ DWORD exitcode; while (true) { - //sleep - std::this_thread::sleep_for(std::chrono::milliseconds(OperSys::thread_sleep_milli_secs)); + //sleep + std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms)); //check if process is still active GetExitCodeProcess(pi.hProcess, &exitcode); //if the process ended, break @@ -730,6 +729,7 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_ break; } + } //jump out of the for loop if terminated if (term_break) break; @@ -748,9 +748,8 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_ int command_pid = start(cmd_string); while (true) { - //sleep - std::this_thread::sleep_for(std::chrono::milliseconds(OperSys::thread_sleep_milli_secs)); - //check if process is still active + std::this_thread::sleep_for(std::chrono::milliseconds(sleep_ms)); + //check if process is still active int status = 0; pid_t exit_code = waitpid(command_pid, &status, WNOHANG); //if the process ended, break @@ -763,7 +762,7 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_ } else if (exit_code != 0) { - break; + break; } //check for termination flag if (terminate->get()) @@ -780,6 +779,8 @@ void ModelInterface::run(pest_utils::thread_flag* terminate, pest_utils::thread_ term_break = true; break; } + //sleep + } //jump out of the for loop if terminated if (term_break) break; diff --git a/src/libs/run_managers/abstract_base/model_interface.h b/src/libs/run_managers/abstract_base/model_interface.h index d9bbf713..93d64edf 100644 --- a/src/libs/run_managers/abstract_base/model_interface.h +++ b/src/libs/run_managers/abstract_base/model_interface.h @@ -112,9 +112,11 @@ class ModelInterface{ void set_fill_tpl_zeros(bool _flag) { fill_tpl_zeros = _flag; } void set_tpl_force_decimal(bool _flag) {tpl_force_decimal = _flag;} void set_num_threads(int _num_threads) { num_threads = _num_threads; } + void set_sleep_ms(int _sleep_ms){sleep_ms = _sleep_ms;} private: int num_threads; + int sleep_ms; //Pest* pest_scenario_ptr; vector templatefiles; vector instructionfiles; diff --git a/src/libs/run_managers/serial/RunManagerSerial.cpp b/src/libs/run_managers/serial/RunManagerSerial.cpp index 88b5f7bb..d5d7a2ce 100644 --- a/src/libs/run_managers/serial/RunManagerSerial.cpp +++ b/src/libs/run_managers/serial/RunManagerSerial.cpp @@ -49,7 +49,7 @@ RunManagerSerial::RunManagerSerial(const vector _comline_vec, mi.set_fill_tpl_zeros(fill_tpl_zeros); mi.set_num_threads(_num_threads); mi.set_tpl_force_decimal(tpl_force_decimal); - + mi.set_sleep_ms(5); cout << " starting serial run manager ..." << endl << endl; mgr_type = RUN_MGR_TYPE::SERIAL; } diff --git a/src/libs/run_managers/yamr/PantherAgent.cpp b/src/libs/run_managers/yamr/PantherAgent.cpp index 1cffcd6a..5137dba5 100644 --- a/src/libs/run_managers/yamr/PantherAgent.cpp +++ b/src/libs/run_managers/yamr/PantherAgent.cpp @@ -151,7 +151,7 @@ void PANTHERAgent::process_ctl_file(const string &ctl_filename) mi.set_fill_tpl_zeros(pest_scenario.get_pestpp_options().get_fill_tpl_zeros()); mi.set_tpl_force_decimal(pest_scenario.get_pestpp_options().get_tpl_force_decimal()); mi.set_num_threads(pest_scenario.get_pestpp_options().get_num_tpl_ins_threads()); - + mi.set_sleep_ms(500); restart_on_error = pest_scenario.get_pestpp_options().get_panther_agent_restart_on_error(); max_time_without_master_ping_seconds = pest_scenario.get_pestpp_options().get_panther_agent_no_ping_timeout_secs(); FileManager fm("panther_agent"); @@ -538,6 +538,7 @@ std::pair PANTHERAgent::run_model(Parameters & void PANTHERAgent::run_async(pest_utils::thread_flag* terminate, pest_utils::thread_flag* finished, exception_ptr& run_exception, Parameters* pars, Observations* obs) { + mi.set_sleep_ms(300); mi.run(terminate,finished,run_exception, pars, obs); } @@ -1132,7 +1133,7 @@ void PANTHERAgent::start_impl(const string &host, const string &port) ss.str(""); ss << "frozen"; report(ss.str(), true); - w_sleep(30 * 1000); + w_sleep(3000); if (quit_file_found()) { report("pest.stp file found, resetting panther_agent_freeze_on_fail and continuing...", true); diff --git a/src/libs/run_managers/yamr/RunManagerPanther.cpp b/src/libs/run_managers/yamr/RunManagerPanther.cpp index d7cf0a48..1ad2eef0 100644 --- a/src/libs/run_managers/yamr/RunManagerPanther.cpp +++ b/src/libs/run_managers/yamr/RunManagerPanther.cpp @@ -1006,7 +1006,7 @@ void RunManagerPanther::close_agents() sock_nums.push_back(si.first); for (auto si : sock_nums) close_agent(si); - w_sleep(2000); + w_sleep(100); } }