Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
jtwhite79 committed Oct 11, 2020
2 parents 86c8a4b + fe9ad3f commit 015fa71
Show file tree
Hide file tree
Showing 21 changed files with 520 additions and 558 deletions.
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
<p align="center">
<img src="documentation/pestpplogo.png" alt="pestpplogo image">
</p>
# PEST++

## Tools for non-intrusive and scalable parameter estimation and uncertainty quantification
Expand Down
46 changes: 46 additions & 0 deletions benchmarks/basic_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -953,6 +953,51 @@ def mf6_v5_glm_test():
assert oe.shape[0] == pst.pestpp_options["glm_num_reals"],"{0},{1}".\
format(oe.shape[0],pst.pestpp_options["glm_num_reals"])


def cmdline_test():
model_d = "mf6_freyberg"
local=True
if "linux" in platform.platform().lower() and "10par" in model_d:
#print("travis_prep")
#prep_for_travis(model_d)
local=False

t_d = os.path.join(model_d,"template")
pst_name = "freyberg6_run_glm.pst"
pst = pyemu.Pst(os.path.join(t_d,"freyberg6_run_glm.pst"))
pst.pestpp_options["debug_parse_only"] = True
pst_name = "CmdLine_test.pst" #camel case on purpose for linux testing
pst.write(os.path.join(t_d,pst_name))
pyemu.os_utils.run("{0} {1}".format(exe_path,pst_name),cwd=t_d)
pyemu.os_utils.run("{0} {1} /h :4004".format(exe_path,pst_name),cwd=t_d)
pyemu.os_utils.run("{0} {1} /r /h :4004".format(exe_path.replace("-ies","-glm"),pst_name),cwd=t_d)
pyemu.os_utils.run("{0} {1} /r ".format(exe_path.replace("-ies","-glm"),pst_name),cwd=t_d)

try:
pyemu.os_utils.run("{0} {1} \\h :4004".format(exe_path,pst_name),cwd=t_d)

except:
pass
else:
raise Exception("should have failed")

try:
pyemu.os_utils.run("{0} {1} :4004".format(exe_path,pst_name),cwd=t_d)

except:
pass
else:
raise Exception("should have failed")

try:
pyemu.os_utils.run("{0} {1} /h 4004".format(exe_path,pst_name),cwd=t_d)

except:
pass
else:
raise Exception("should have failed")


if __name__ == "__main__":

#glm_long_name_test()
Expand All @@ -973,3 +1018,4 @@ def mf6_v5_glm_test():
#mf6_v5_sen_test()
#mf6_v5_opt_stack_test()
#mf6_v5_glm_test()
#cmdline_test()
Binary file removed documentation/pestpp5.0.0.docx
Binary file not shown.
Binary file added documentation/pestpp5.0.3.docx
Binary file not shown.
Binary file added documentation/pestpplogo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/libs/common/config_os.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define CONFIG_OS_H_


#define PESTPP_VERSION "5.0.0";
#define PESTPP_VERSION "5.0.3";

#if defined(_WIN32) || defined(_WIN64)
#define OS_WIN
Expand Down
156 changes: 154 additions & 2 deletions src/libs/common/utilities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -624,7 +624,7 @@ void thread_exceptions::rethrow()
}
catch (const std::exception& e)
{
ss << e.what() << ", ";
ss << e.what() << " ";
}
}
throw runtime_error(ss.str());
Expand Down Expand Up @@ -1428,7 +1428,159 @@ string get_time_string_short()
}


} // end of namespace pest_utils
CmdLine::CmdLine(int argc, char* argv[]) :
ctl_file_name(""), panther_host_name(""), panther_port(""),
runmanagertype(RunManagerType::SERIAL),org_cmdline_str(""),
restart(false),jac_restart(false)
{
for (int i = 0; i < argc; ++i)
{
org_cmdline_str.append(" ");
org_cmdline_str.append(argv[i]);
}
cout << "...processing command line: '" << org_cmdline_str << "'" << endl;
vector<string> org_cmdline_vec(argc);
copy(argv, argv + argc, org_cmdline_vec.begin());
vector<string> lower_cmdline_vec = org_cmdline_vec;
for (vector<string>::iterator it = lower_cmdline_vec.begin(); it != lower_cmdline_vec.end(); ++it)
{
transform(it->begin(), it->end(), it->begin(), ::tolower);
}

if (org_cmdline_vec.size() >= 2)
{
ctl_file_name = org_cmdline_vec[1];
}
else
{
throw_cmdline_error("too few args, no control file name found");
}

//check for shitty restar flags
vector<string> temp, temp_lower;
for (int i = 0; i < lower_cmdline_vec.size(); i++)
{
if (lower_cmdline_vec[i] == "/r")
{
restart = true;
}
else if (lower_cmdline_vec[i] == "/j")
{
if (restart)
throw_cmdline_error("both '/r' and '/j' supplied");
jac_restart = true;
}
else
{
temp.push_back(org_cmdline_vec[i]);
temp_lower.push_back(lower_cmdline_vec[i]);
}
}
org_cmdline_vec = temp;
lower_cmdline_vec = temp_lower;


if ((lower_cmdline_vec.size() == 3) || (lower_cmdline_vec.size() > 4))
{
throw_cmdline_error("wrong number of args, expecting 2 (serial run mgr) or 4 (parallel run mgr)");
}

//serial run mgr...done
if (lower_cmdline_vec.size() == 2)
{
cout << "...using serial run manager" << endl;
return;
}

//check for various run mgr options
string third_arg = lower_cmdline_vec[2];
if (third_arg == "/e")
{
cout << "...using external run manager" << endl;
runmanagertype = RunManagerType::EXTERNAL;
}
else if (third_arg == "/g")
{
cout << "...using genie run manager" << endl;
runmanagertype = RunManagerType::GENIE;
}
else if (third_arg == "/h")
{
//assume worker, but check for master later...
runmanagertype = RunManagerType::PANTHER_WORKER;
}
else
{
throw_cmdline_error("unrecognized commandline arg '" + third_arg + "', expecting '/h','/e','/g'");
}

if (runmanagertype == RunManagerType::PANTHER_WORKER)
{
string forth_arg = org_cmdline_vec[3];
if (forth_arg.find(":") == string::npos)
{
throw_cmdline_error("panther master/worker arg '" + forth_arg + "' doesn't have a ':' char");
}
if (forth_arg[0] == ':')
{
//panther master
runmanagertype = RunManagerType::PANTHER_MASTER;
panther_port = forth_arg.substr(1);
try
{
int test = stoi(panther_port);
}
catch (...)
{
throw_cmdline_error("error casting master port number '" + panther_port + "' to int");
}
cout << "...using panther run manager in master mode using port " << panther_port << endl;
}
else
{
//panther worker
vector<string> tokens;
tokenize(forth_arg, tokens, ":");
if (tokens.size() != 2)
throw_cmdline_error("wrong number of colon-delimited tokens in panther worker arg '" + forth_arg);
panther_host_name = tokens[0];
panther_port = tokens[1];
try
{
int test = stoi(panther_port);
}
catch (...)
{
throw_cmdline_error("error casting master port number '" + panther_port + "' to int");
}
cout << "...using panther run manager in worker mode using hostname '" << panther_host_name << "' and port " << panther_port << endl;
}
}
return;

}


void CmdLine::throw_cmdline_error(string message)
{
cerr << "--------------------------------------------------------" << endl;
cerr << "COMMAND LINE ERROR: " << message << endl;
cerr << "usage:" << endl << endl;
cerr << " serial run manager:" << endl;
cerr << " pestpp-xxx control_file.pst" << endl << endl;
cerr << " PANTHER master:" << endl;
cerr << " pestpp-xxx control_file.pst /H :port" << endl << endl;
cerr << " PANTHER worker:" << endl;
cerr << " pestpp-xxx control_file.pst /H hostname:port " << endl << endl;

cerr << " additional options can be found in the PEST++ users manual" << endl;
cerr << "--------------------------------------------------------" << endl;
exit(1);
}

// end of namespace pest_utils
}




Expand Down
16 changes: 16 additions & 0 deletions src/libs/common/utilities.h
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,22 @@ string get_time_string();
string get_time_string_short();


class CmdLine {

public:
enum class RunManagerType { SERIAL, PANTHER_MASTER, PANTHER_WORKER, GENIE, EXTERNAL };
CmdLine(int argc, char* argv[]);
string ctl_file_name;
string panther_host_name;
string org_cmdline_str;
string panther_port;
bool jac_restart;
bool restart;
RunManagerType runmanagertype;
private:
void throw_cmdline_error(string message);

};

} // end namespace pest_utils
#endif /* UTILITIES_H_ */
4 changes: 2 additions & 2 deletions src/libs/pestpp_common/Ensemble.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2207,12 +2207,12 @@ void ParameterEnsemble::save_fixed()
}
}
// add the "base" if its not in the real names already
if (find(real_names.begin(), real_names.end(), base_name) == real_names.end())
if (find(real_names.begin(), real_names.end(), BASE_REAL_NAME) == real_names.end())
{
Parameters pars = pest_scenario_ptr->get_ctl_parameters();
for (auto fname : fixed_names)
{
pair<string, string> key(base_name, fname);
pair<string, string> key(BASE_REAL_NAME, fname);
fixed_map[key] = pars[fname];
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/libs/pestpp_common/Ensemble.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "PerformanceLog.h"


const string BASE_REAL_NAME = "BASE";

class Ensemble
{
Expand Down Expand Up @@ -102,7 +103,6 @@ class Ensemble
//ObjectiveFunc *obj_func_ptr;
//OutputFileWriter &output_file_writer;
//PerformanceLog *performance_log;
string base_name = "BASE";
Eigen::MatrixXd reals;
vector<string> var_names;
vector<string> real_names;
Expand Down
8 changes: 4 additions & 4 deletions src/libs/pestpp_common/EnsembleMethodUtils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1009,11 +1009,11 @@ void save_base_real_par_rei(Pest& pest_scenario, ParameterEnsemble& pe, Observat
{
stringstream ss;
map<string, int> vmap = pe.get_real_map();
if (vmap.find("BASE") != vmap.end())
if (vmap.find(BASE_REAL_NAME) != vmap.end())
{
ParamTransformSeq pts = pest_scenario.get_base_par_tran_seq();
Parameters pars;
pars.update(pe.get_var_names(), eigenvec_2_stlvec(pe.get_real_vector("BASE")));
pars.update(pe.get_var_names(), eigenvec_2_stlvec(pe.get_real_vector(BASE_REAL_NAME)));
if (pe.get_trans_status() == ParameterEnsemble::transStatus::NUM)
pts.numeric2ctl_ip(pars);
// save parameters to .par file
Expand All @@ -1025,14 +1025,14 @@ void save_base_real_par_rei(Pest& pest_scenario, ParameterEnsemble& pe, Observat
file_manager.close_file("par");

vmap = oe.get_real_map();
if (vmap.find("BASE") == vmap.end())
if (vmap.find(BASE_REAL_NAME) == vmap.end())
{
//message(2, "unable to find 'BASE' realization in obs ensemble for saving .base.rei file, continuing...");
}
else
{
Observations obs;
obs.update(oe.get_var_names(), eigenvec_2_stlvec(oe.get_real_vector("BASE")));
obs.update(oe.get_var_names(), eigenvec_2_stlvec(oe.get_real_vector(BASE_REAL_NAME)));
ObjectiveFunc obj_func(&(pest_scenario.get_ctl_observations()), &(pest_scenario.get_ctl_observation_info()), &(pest_scenario.get_prior_info()));
// save new residuals to .rei file
ss.str("");
Expand Down
Loading

0 comments on commit 015fa71

Please sign in to comment.