Skip to content

Commit b2b08ae

Browse files
committed
Merge branch 'develop'
2 parents 0d310cb + d55a827 commit b2b08ae

File tree

23 files changed

+1146
-978
lines changed

23 files changed

+1146
-978
lines changed

benchmarks/basic_tests.py

Lines changed: 160 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -933,6 +933,10 @@ def mf6_v5_ies_test():
933933
pst.write(os.path.join(t_d, pst_name))
934934
pyemu.os_utils.start_workers(t_d, exe_path, pst_name, num_workers=15,
935935
master_dir=m_d, worker_root=model_d, port=port)
936+
937+
938+
939+
936940
phidf = pd.read_csv(os.path.join(m_d,pst_name.replace(".pst",".phi.actual.csv")))
937941
assert phidf.shape[0] == pst.control_data.noptmax + 1
938942
for i in range(1,pst.control_data.noptmax+1):
@@ -960,7 +964,16 @@ def mf6_v5_ies_test():
960964
print(i,group,len(pnames),lb_count,pcs.loc[group,"num_at_near_lbound"],ub_count,pcs.loc[group,"num_at_near_ubound"])
961965
assert lb_count == pcs.loc[group,"num_at_near_lbound"]
962966
assert ub_count == pcs.loc[group,"num_at_near_ubound"]
963-
967+
968+
pst.pestpp_options["ies_run_realname"] = "base"
969+
pst.pestpp_options["ies_par_en"] = "{0}.{1}.par.csv".format(pst_name.replace(".pst",""),3)
970+
pst.control_data.noptmax = -2
971+
pst.write(os.path.join(m_d, "test.pst"))
972+
pyemu.os_utils.run("{0} test.pst".format(exe_path),cwd=m_d)
973+
974+
pst.pestpp_options.pop("ies_run_realname")
975+
pst.pestpp_options.pop("ies_par_en")
976+
964977
pst.write(os.path.join(t_d,"freyberg6_run_ies_glm_loc.pst"))
965978

966979
m_d = os.path.join(model_d, "master_ies_glm_covloc")
@@ -1501,6 +1514,28 @@ def sweep_bin_test():
15011514
print(np.abs(diff).max())
15021515
assert np.abs(diff).max() < 1e-7
15031516

1517+
1518+
1519+
pst.pestpp_options.pop("sweep_output_file")
1520+
pst.pestpp_options["save_dense"] = True
1521+
m_d = os.path.join(model_d,"master_sweep_bin_base2")
1522+
pyemu.os_utils.start_workers(t_d, exe_path, "pest_forgive.pst", 10, master_dir=m_d,
1523+
worker_root=model_d,port=port)
1524+
df1 = pd.read_csv(os.path.join(m_d, "pest_forgive.0.obs.csv"),index_col=0)
1525+
assert df1.shape[0] == pe.shape[0]
1526+
m_d = os.path.join(model_d, "master_sweep_bin2")
1527+
pyemu.os_utils.start_workers(t_d, exe_path.replace("-ies", "-swp"), "pest_forgive.pst", 10, master_dir=m_d,
1528+
worker_root=model_d, port=port)
1529+
df2 = pyemu.Matrix.from_binary(os.path.join(m_d,"sweep_out.bin")).to_dataframe()
1530+
print(df2)
1531+
print(df1)
1532+
assert df2.shape == df1.shape
1533+
diff = (df1.values - df2.values)
1534+
print(diff)
1535+
print(diff.max())
1536+
print(np.abs(diff).max())
1537+
assert np.abs(diff).max() < 1e-7
1538+
15041539
#def fail_test():
15051540
# raise Exception("fail please")
15061541

@@ -1814,9 +1849,131 @@ def tenpar_uniform_invest():
18141849
pyemu.os_utils.run("pestpp-ies pest.pst",cwd=new_d)
18151850

18161851

1852+
def sweep_large_xfer_test():
1853+
1854+
model_d = "ies_10par_xsec"
1855+
t_d = os.path.join(model_d,"template")
1856+
m_d = os.path.join(model_d,"master_sweep_xfer")
1857+
if os.path.exists(m_d):
1858+
shutil.rmtree(m_d)
1859+
pst = pyemu.Pst(os.path.join(t_d,"pest.pst"))
1860+
num_reals = 3
1861+
pe = pyemu.ParameterEnsemble.from_uniform_draw(pst,num_reals=num_reals)#.loc[:,pst.par_names[:2]]
1862+
1863+
pe.to_csv(os.path.join(t_d,"sweep_in.csv"))
1864+
pe._df.index = pe.index.map(str)
1865+
print(pe.index)
1866+
pe.to_dense(os.path.join(t_d,"sweep_in.bin"))
1867+
1868+
dimen = 1000
1869+
cnames = ["col{0}".format(i) for i in range(dimen)]
1870+
rnames = ["row{0}".format(i) for i in range(dimen)]
1871+
vals = np.random.random((dimen,dimen))
1872+
pyemu.Matrix(x=vals,row_names=rnames,col_names=cnames).to_dense(os.path.join(t_d,"matrix.bin"))
1873+
1874+
pst.pestpp_options["ies_par_en"] = "sweep_in.csv"
1875+
pst.pestpp_options["sweep_forgive"] = True
1876+
pst.pestpp_options["sweep_parameter_file"] = "sweep_in.bin"
1877+
pst.control_data.noptmax = -1
1878+
pst.pestpp_options.pop("ies_num_reals",None)
1879+
pst.write(os.path.join(t_d,"pest_forgive.pst"))
1880+
pst.pestpp_options["sweep_output_file"] = "sweep_out.bin"
1881+
pst.pestpp_options["sweep_chunk"] = 9
1882+
pst.pestpp_options["ies_include_base"] = False
1883+
pst.pestpp_options["panther_transfer_on_finish"] = "matrix.bin"
1884+
pst.write(os.path.join(t_d,"pest_forgive.pst"))
1885+
m_d = os.path.join(model_d,"master_sweep_bin_base")
1886+
1887+
pyemu.os_utils.start_workers(t_d, exe_path.replace("-ies","-swp"), "pest_forgive.pst", 1, master_dir=m_d,
1888+
worker_root=model_d,port=port)
1889+
1890+
for i in range(num_reals):
1891+
fname = os.path.join(m_d,"ftx_{0}.matrix.bin".format(i))
1892+
assert os.path.exists(fname)
1893+
vals2 = pyemu.Matrix.from_binary(fname).x
1894+
diff = np.abs(vals - vals2).sum()
1895+
print(fname,diff)
1896+
assert diff < 1e-10
1897+
1898+
1899+
1900+
def large_fake_test():
1901+
root_d = "large_fake_test"
1902+
if os.path.exists(root_d):
1903+
shutil.rmtree(root_d)
1904+
os.makedirs(root_d)
1905+
t_d = os.path.join(root_d,"template")
1906+
os.makedirs(t_d)
1907+
1908+
npar = 10000
1909+
nobs = 10000
1910+
nzobs = 1000
1911+
1912+
in_name = os.path.join(t_d,"in.dat")
1913+
out_name = os.path.join(t_d,"out.dat")
1914+
1915+
f_in = open(in_name,'w')
1916+
f_tpl = open(in_name+".tpl",'w')
1917+
f_tpl.write("ptf ~\n")
1918+
1919+
for i in range(npar):
1920+
f_in.write("par{0:06d},{0}\n".format(i))
1921+
f_tpl.write("par{0:06d},~ par{0:06d} ~\n".format(i))
1922+
f_tpl.close()
1923+
f_in.close()
1924+
1925+
1926+
f_out = open(out_name,'w')
1927+
f_ins = open(out_name+".ins",'w')
1928+
f_ins.write("pif ~\n")
1929+
for i in range(nobs):
1930+
f_out.write("obs{0:06d},{0}\n".format(i))
1931+
f_ins.write("l1 ~,~ !obs{0:06d}!\n".format(i))
1932+
f_out.close()
1933+
f_ins.close()
1934+
1935+
pst = pyemu.Pst.from_io_files(in_name+".tpl",in_name,out_name+".ins",out_name,pst_path='.')
1936+
obs = pst.observation_data
1937+
obs["weight"] = 0.0
1938+
obs.loc[obs.index[:nzobs],"weight"] = 1.0
1939+
1940+
par = pst.parameter_data
1941+
par["parlbnd"] = 0
1942+
par["parubnd"] = npar
1943+
par["partrans"] = "none"
1944+
1945+
pst.control_data.noptmax = 0
1946+
pst.write(os.path.join(t_d,"test.pst"),version=2)
1947+
#pyemu.utils.helpers.setup_fake_forward_run(pst, new_pst_name, org_cwd='.', bak_suffix='._bak', new_cwd='.')
1948+
pst = pyemu.helpers.setup_fake_forward_run(pst,"fake.pst",org_cwd=t_d,new_cwd=t_d)
1949+
1950+
pst.write(os.path.join(t_d,"fake.pst"),version=2)
1951+
1952+
frun_name = os.path.join(t_d,"fake_forward_run.py")
1953+
lines = open(frun_name,'r').readlines()
1954+
with open(frun_name,'w') as f:
1955+
for line in lines:
1956+
f.write(line)
1957+
f.write("import time\n")
1958+
f.write("time.sleep(10)\n")
1959+
1960+
pyemu.os_utils.run("{0} fake.pst".format(exe_path),cwd=t_d)
1961+
pst.control_data.noptmax = -1
1962+
pst.write(os.path.join(t_d,"fake.pst"),version=2)
1963+
1964+
m_d = t_d.replace("template","master")
1965+
pyemu.os_utils.start_workers(t_d, exe_path, "fake.pst", 5, master_dir=m_d,
1966+
worker_root=root_d,port=port,verbose=True)
1967+
1968+
18171969

18181970

18191971
if __name__ == "__main__":
1972+
large_fake_test()
1973+
exit()
1974+
#sweep_large_xfer_test()
1975+
#sweep_bin_test()
1976+
#exit()
18201977
# mf6_v5_sen_test()
18211978
#tie_by_group_test()
18221979
#tenpar_uniform_invest()
@@ -1881,6 +2038,6 @@ def tenpar_uniform_invest():
18812038
#fr_fail_test()
18822039
#tplins1_test()
18832040

1884-
mf6_v5_glm_test()
2041+
#mf6_v5_glm_test()
18852042
mf6_v5_ies_test()
1886-
mf6_v5_sen_test()
2043+
#mf6_v5_sen_test()

benchmarks/ies_10par_xsec/template/pest.pst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ pcf
66
1.000000E-01 -4.000000E+00 3.000000E-01 3.000000E-02 10 999 lamforgive noderforgive
77
5.000000E+00 5.000000E+00 1.000000E-03 0 0
88
1.000000E-01 1 1.100000E+00 noaui nosenreuse noboundscale
9-
2 5.000000E-03 4 4 5.000000E-03 4 0.000000E+00 1 -1.000000E+00
9+
1 5.000000E-03 4 4 5.000000E-03 4 0.000000E+00 1 -1.000000E+00
1010
1 1 1 0 jcosave verboserec jcosaveitn reisaveitn parsaveitn noparsaverun
1111
* singular value decomposition
1212
1
@@ -57,3 +57,4 @@ mfnwt ./10par_xsec.nam
5757
.\strt_Layer_1.ref.tpl .\strt_Layer_1.ref
5858
.\10par_xsec.hds.ins .\10par_xsec.hds
5959
++panther_transfer_on_finish(10par_xsec.hds,10par_xsec.list)
60+
++ies_num_reals(5)

0 commit comments

Comments
 (0)