From 84abb0307d20c8f4b2d743910a29e1acdc6b00a8 Mon Sep 17 00:00:00 2001 From: jwhite Date: Tue, 26 Mar 2024 16:42:16 -0600 Subject: [PATCH] added sweep bin test --- benchmarks/basic_tests.py | 49 ++++++++++++++++++- .../ies_10par_xsec/template/10par_xsec.hds | 2 - .../ies_10par_xsec/template/hk_Layer_1.ref | 1 - .../nested/really/deep/hk_Layer_1.ref | 1 - .../ies_10par_xsec/template/strt_Layer_1.ref | 1 - src/programs/sweep/sweep.cpp | 2 +- 6 files changed, 49 insertions(+), 7 deletions(-) diff --git a/benchmarks/basic_tests.py b/benchmarks/basic_tests.py index 331db4445..a9eec28e5 100644 --- a/benchmarks/basic_tests.py +++ b/benchmarks/basic_tests.py @@ -187,6 +187,8 @@ def sweep_forgive_test(): assert diff.max().max() == 0.0 + + def inv_regul_test(): model_d = "ies_10par_xsec" @@ -1437,11 +1439,56 @@ def run(): pyemu.os_utils.start_workers(t_d, exe_path, pst_name, num_workers=15, worker_root=model_d, port=4004) +def sweep_bin_test(): + + model_d = "ies_10par_xsec" + t_d = os.path.join(model_d,"template") + m_d = os.path.join(model_d,"master_sweep_bin") + if os.path.exists(m_d): + shutil.rmtree(m_d) + pst = pyemu.Pst(os.path.join(t_d,"pest.pst")) + pe = pyemu.ParameterEnsemble.from_uniform_draw(pst,num_reals=50)#.loc[:,pst.par_names[:2]] + + pe.to_csv(os.path.join(t_d,"sweep_in.csv")) + pe._df.index = pe.index.map(str) + print(pe.index) + pe.to_dense(os.path.join(t_d,"sweep_in.bin")) + pst.pestpp_options["ies_par_en"] = "sweep_in.csv" + pst.pestpp_options["sweep_forgive"] = True + pst.pestpp_options["sweep_parameter_file"] = "sweep_in.bin" + pst.control_data.noptmax = -1 + pst.pestpp_options.pop("ies_num_reals",None) + pst.write(os.path.join(t_d,"pest_forgive.pst")) + pst.pestpp_options["sweep_output_file"] = "sweep_out.bin" + pst.pestpp_options["sweep_chunk"] = 9 + pst.pestpp_options["ies_include_base"] = False + pst.write(os.path.join(t_d,"pest_forgive.pst")) + m_d = os.path.join(model_d,"master_sweep_bin_base") + pyemu.os_utils.start_workers(t_d, exe_path, "pest_forgive.pst", 10, master_dir=m_d, + worker_root=model_d,port=port) + df1 = pd.read_csv(os.path.join(m_d, "pest_forgive.0.obs.csv"),index_col=0) + assert df1.shape[0] == pe.shape[0] + m_d = os.path.join(model_d, "master_sweep_bin") + pyemu.os_utils.start_workers(t_d, exe_path.replace("-ies", "-swp"), "pest_forgive.pst", 10, master_dir=m_d, + worker_root=model_d, port=port) + df2 = pyemu.Matrix.from_binary(os.path.join(m_d,"sweep_out.bin")).to_dataframe() + print(df2) + print(df1) + assert df2.shape == df1.shape + diff = (df1.values - df2.values) + print(diff) + print(diff.max()) + print(np.abs(diff).max()) + assert np.abs(diff).max() < 1e-7 + + + if __name__ == "__main__": #run() #mf6_v5_ies_test() #prep_ends() - mf6_v5_sen_test() + sweep_bin_test() + #mf6_v5_sen_test() #shutil.copy2(os.path.join("..","exe","windows","x64","Debug","pestpp-glm.exe"),os.path.join("..","bin","win","pestpp-glm.exe")) #shutil.copy2(os.path.join("..", "exe", "windows", "x64", "Debug", "pestpp-ies.exe"), # os.path.join("..", "bin", "win", "pestpp-ies.exe")) diff --git a/benchmarks/ies_10par_xsec/template/10par_xsec.hds b/benchmarks/ies_10par_xsec/template/10par_xsec.hds index fa6fa39b2..e69de29bb 100644 --- a/benchmarks/ies_10par_xsec/template/10par_xsec.hds +++ b/benchmarks/ies_10par_xsec/template/10par_xsec.hds @@ -1,2 +0,0 @@ - 1.000 1.200 1.400 1.600 1.800 2.000 2.200 2.400 2.600 2.800 - 1.000 1.400 1.800 2.200 2.600 3.000 3.400 3.800 4.200 4.600 diff --git a/benchmarks/ies_10par_xsec/template/hk_Layer_1.ref b/benchmarks/ies_10par_xsec/template/hk_Layer_1.ref index 078687bf9..e69de29bb 100644 --- a/benchmarks/ies_10par_xsec/template/hk_Layer_1.ref +++ b/benchmarks/ies_10par_xsec/template/hk_Layer_1.ref @@ -1 +0,0 @@ - 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 diff --git a/benchmarks/ies_10par_xsec/template/nested/really/deep/hk_Layer_1.ref b/benchmarks/ies_10par_xsec/template/nested/really/deep/hk_Layer_1.ref index 078687bf9..e69de29bb 100644 --- a/benchmarks/ies_10par_xsec/template/nested/really/deep/hk_Layer_1.ref +++ b/benchmarks/ies_10par_xsec/template/nested/really/deep/hk_Layer_1.ref @@ -1 +0,0 @@ - 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 2.500000000000 diff --git a/benchmarks/ies_10par_xsec/template/strt_Layer_1.ref b/benchmarks/ies_10par_xsec/template/strt_Layer_1.ref index 5fd4b9532..e69de29bb 100644 --- a/benchmarks/ies_10par_xsec/template/strt_Layer_1.ref +++ b/benchmarks/ies_10par_xsec/template/strt_Layer_1.ref @@ -1 +0,0 @@ - 1.00000000000000 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 1.000000E+00 diff --git a/src/programs/sweep/sweep.cpp b/src/programs/sweep/sweep.cpp index 9ae0fd476..4740ed386 100644 --- a/src/programs/sweep/sweep.cpp +++ b/src/programs/sweep/sweep.cpp @@ -835,7 +835,6 @@ int main(int argc, char* argv[]) { //Parameters temp = base_trans_seq.active_ctl2model_cp(par); irun_ids.push_back(run_manager_ptr->add_run(base_trans_seq.active_ctl2model_cp(par))); - break; } //make some runs @@ -871,6 +870,7 @@ int main(int argc, char* argv[]) // clean up obs_stream.close(); + par_stream.close(); delete run_manager_ptr; string case_name = file_manager.get_base_filename();