@@ -64,10 +64,10 @@ def basic_sqp_test():
6464
6565 assert os .path .exists (os .path .join (m_d ,"freyberg6_run_sqp.0.par.csv" ))
6666 df = pd .read_csv (os .path .join (m_d ,"freyberg6_run_sqp.0.par.csv" ),index_col = 0 )
67- assert df .shape == (pst .pestpp_options ["sqp_num_reals" ],pst .npar ),str (df .shape )
67+ assert df .shape == (pst .pestpp_options ["sqp_num_reals" ] + 1 ,pst .npar ),str (df .shape )
6868 assert os .path .exists (os .path .join (m_d ,"freyberg6_run_sqp.0.obs.csv" ))
6969 df = pd .read_csv (os .path .join (m_d ,"freyberg6_run_sqp.0.obs.csv" ),index_col = 0 )
70- assert df .shape == (pst .pestpp_options ["sqp_num_reals" ],pst .nobs ),str (df .shape )
70+ assert df .shape == (pst .pestpp_options ["sqp_num_reals" ] + 1 ,pst .nobs + pst . nprior ),str (df .shape )
7171
7272
7373def rosenbrock_setup (version ,initial_decvars = 1.6 ,constraints = False ,constraint_exp = "one_linear" ):
@@ -328,54 +328,64 @@ def dewater_basic_test():
328328 pst .write (os .path .join (t_d ,case + ".pst" ))
329329 #pyemu.os_utils.run("{0} {1}.pst".format(exe_path,case),cwd=t_d)
330330 m_d = os .path .join (model_d , "master2" )
331- pyemu .os_utils .start_workers (t_d , exe_path , case + ".pst" , num_workers = 10 , worker_root = model_d ,
332- master_dir = m_d )
333- assert os .path .exists (os .path .join (m_d , case + ".base.par" ))
334- assert os .path .exists (os .path .join (m_d , case + ".base.rei" ))
335- assert os .path .exists (os .path .join (m_d , case + ".0.jcb" ))
336- assert os .path .exists (os .path .join (m_d , case + ".1.jcb" ))
337- assert os .path .exists (os .path .join (m_d , case + ".2.jcb" ))
331+ # pyemu.os_utils.start_workers(t_d, exe_path, case + ".pst", num_workers=10, worker_root=model_d,
332+ # master_dir=m_d)
333+ # assert os.path.exists(os.path.join(m_d, case + ".base.par"))
334+ # assert os.path.exists(os.path.join(m_d, case + ".base.rei"))
335+ # assert os.path.exists(os.path.join(m_d, case + ".0.jcb"))
336+ # assert os.path.exists(os.path.join(m_d, case + ".1.jcb"))
337+ # assert os.path.exists(os.path.join(m_d, case + ".2.jcb"))
338338
339339 pst .pestpp_options ["sqp_num_reals" ] = 50
340- pst .control_data .noptmax = 3
340+ pst .control_data .noptmax = 2
341341 pst .write (os .path .join (t_d , case + ".pst" ))
342342 # pyemu.os_utils.run("{0} {1}.pst".format(exe_path,case),cwd=t_d)
343343 m_d = os .path .join (model_d , "master2_enopt" )
344344 pyemu .os_utils .start_workers (t_d , exe_path , case + ".pst" , num_workers = 20 , worker_root = model_d ,
345345 master_dir = m_d )
346346
347+ for i in range (pst .control_data .noptmax + 1 ):
348+ assert os .path .exists (os .path .join (m_d , case + ".{0}.base.par" .format (i )))
349+ assert os .path .exists (os .path .join (m_d , case + ".{0}.base.rei" .format (i )))
350+ assert os .path .exists (os .path .join (m_d , case + ".{0}.obs.csv" .format (i )))
351+ assert os .path .exists (os .path .join (m_d , case + ".{0}.par.csv" .format (i )))
352+
347353
348354
349- def dewater_slp_opt_test ():
350- model_d = "dewater"
351- local = True
352- if "linux" in platform .platform ().lower () and "10par" in model_d :
353- # print("travis_prep")
354- # prep_for_travis(model_d)
355- local = False
355+ # def dewater_slp_opt_test():
356+ # model_d = "dewater"
357+ # local = True
358+ # if "linux" in platform.platform().lower() and "10par" in model_d:
359+ # # print("travis_prep")
360+ # # prep_for_travis(model_d)
361+ # local = False
356362
357- t_d = os .path .join (model_d , "template" )
363+ # t_d = os.path.join(model_d, "template")
358364
359- case = "dewater_pest.base"
360- pst = pyemu .Pst (os .path .join (t_d , case + ".pst" ))
361- par = pst .parameter_data
362- dv_pars = par .loc [par .pargp == "q" , "parnme" ].tolist ()[:3 ]
365+ # case = "dewater_pest.base"
366+ # pst = pyemu.Pst(os.path.join(t_d, case + ".pst"))
367+ # par = pst.parameter_data
368+ # dv_pars = par.loc[par.pargp == "q", "parnme"].tolist()[:3]
363369
364- pst .add_pi_equation (par_names = dv_pars , pilbl = "eq3" , rhs = 1000 , obs_group = "less_than" )
365- pst .pestpp_options = {}
366- pst .pestpp_options ["opt_dec_var_groups" ] = "q"
367- pst .control_data .noptmax = 1
368- print (pst .prior_information )
369- pst .write (os .path .join (t_d , "test_opt.pst" ))
370- pyemu .os_utils .run ("{0} {1}.pst" .format (exe_path .replace ("-sqp" ,"-opt" ), "test_opt.pst" ), cwd = t_d )
371-
372-
373- pst .parrep (os .path .join (t_d ,"test_opt.par" ))
374- pst .pestpp_options ["hotstart_resfile" ] = "test_opt.1.sim.rei"
375- pst .pestpp_options ["base_jacobian" ] = "test_opt.1.jcb"
376- pst .control_data .noptmax = 1
377- pst .write (os .path .join (t_d ,"test_sqp.pst" ))
378- pyemu .os_utils .run ("{0} {1}.pst" .format (exe_path , "test_sqp.pst" ), cwd = t_d )
370+ # pst.add_pi_equation(par_names=dv_pars, pilbl="eq3", rhs=1000, obs_group="less_than")
371+ # pst.pestpp_options = {}
372+ # pst.pestpp_options["opt_dec_var_groups"] = "q"
373+ # pst.control_data.noptmax = 1
374+ # print(pst.prior_information)
375+ # pst.write(os.path.join(t_d, "test_opt.pst"))
376+ # pyemu.os_utils.run("{0} {1}.pst".format(exe_path.replace("-sqp", "-opt"), "test_opt"), cwd=t_d)
377+
378+ # pst = pyemu.Pst(os.path.join(t_d, case + ".pst"))
379+ # pst.add_pi_equation(par_names=dv_pars, pilbl="eq3", rhs=1000, obs_group="less_than")
380+ # pst.pestpp_options = {}
381+ # pst.pestpp_options["opt_dec_var_groups"] = "q"
382+
383+ # pst.parrep(os.path.join(t_d,"test_opt.par"))
384+ # pst.pestpp_options["hotstart_resfile"] = "test_opt.1.sim.rei"
385+ # pst.pestpp_options["base_jacobian"] = "test_opt.1.jcb"
386+ # pst.control_data.noptmax = 1
387+ # pst.write(os.path.join(t_d,"test_sqp.pst"))
388+ # pyemu.os_utils.run("{0} {1}.pst".format(exe_path, "test_sqp"), cwd=t_d)
379389
380390
381391def rosenc_test ():
@@ -567,16 +577,79 @@ def plot_rosen(m_d):
567577 "-i iter_%03d.png -vf scale=480X480 -y out.gif" ,cwd = m_d )
568578
569579
580+ def mf6_phiobs_invest ():
581+ model_d = "mf6_freyberg"
582+
583+ org_t_d = os .path .join (".." ,"benchmarks" ,model_d ,"template" )
584+ t_d = os .path .join (model_d ,"template" )
585+ if os .path .exists (t_d ):
586+ shutil .rmtree (t_d )
587+ shutil .copytree (org_t_d ,t_d )
588+ pst = pyemu .Pst (os .path .join (t_d ,"freyberg6_run_ies.pst" ))
589+ pst .control_data .noptmax = 0
590+ pst .write (os .path .join (t_d ,"pest.pst" ),version = 2 )
591+ pyemu .os_utils .run ("{0} pest.pst" .format (exe_path .replace ("-sqp" ,"-ies" )),cwd = t_d )
592+ pst = pyemu .helpers .add_phi_as_obs ("pest.pst" ,pst_path = t_d )
593+
594+ pst .pestpp_options ["opt_objective_function" ] = "composite"
595+ pst .observation_data .loc ["composite" ,"obgnme" ] = "less_than"
596+ lbdf = pst .add_pars_as_obs (pst_path = t_d ,par_sigma_range = 4 ,name_prefix = "parlbnd-" )
597+ ubdf = pst .add_pars_as_obs (pst_path = t_d ,par_sigma_range = 4 ,name_prefix = "parubnd-" )
598+ obs = pst .observation_data
599+ print (obs .loc [lbdf .index ,"greater_than" ])
600+ obs .loc [lbdf .index ,"obgnme" ] = "greater_than_parbound"
601+ wpar = [w for w in lbdf .index if "wel" in w ]
602+ obs .loc [wpar ,"weight" ] = 0
603+
604+ obs .loc [lbdf .index ,"obsval" ] = obs .loc [lbdf .index ,"greater_than" ]
605+ obs .loc [ubdf .index ,"obgnme" ] = "less_than_parbound"
606+ wpar = [w for w in ubdf .index if "wel" in w ]
607+ obs .loc [wpar ,"weight" ] = 0
608+
609+ obs .loc [ubdf .index ,"obsval" ] = obs .loc [ubdf .index ,"less_than" ]
610+ par = pst .parameter_data
611+ org_parval1 = par .parval1 .copy ()
612+ par ["parval1" ] = par ["parlbnd" ]
613+ pyemu .helpers .zero_order_tikhonov (pst )
614+ par = pst .parameter_data
615+ par ["parval1" ] = org_parval1
616+ pi = pst .prior_information
617+ pi ["weight" ] = 0
618+ wpi = [w for w in pi .index if "wel" in w ]
619+ assert len (wpi ) > 0
620+ pi .loc [wpi ,"weight" ] = 1.0
621+ pi .loc [wpi ,"obgnme" ] = 'greater_than'
622+ #pi.loc[wpi,"obsval"] = np.log10(par.loc[wpi,"parlbnd"].values)
623+
624+ pst .dialate_par_bounds (1.5 )
625+
626+ pst .control_data .noptmax = 0
627+ pst .write (os .path .join (t_d ,"pest.pst" ),version = 2 )
628+ pyemu .os_utils .run ("{0} pest.pst" .format (exe_path ),cwd = t_d )
629+
630+ pst .control_data .noptmax = 10
631+ pst .pestpp_options ["sqp_num_reals" ] = 10
632+ pst .write (os .path .join (t_d ,"pest.pst" ),version = 2 )
633+ m_d = os .path .join (model_d ,"master_sqp" )
634+ pyemu .os_utils .start_workers (t_d ,exe_path ,"pest.pst" ,num_workers = 10 ,
635+ master_dir = m_d ,
636+ worker_root = model_d )
637+
638+
639+
640+
570641if __name__ == "__main__" :
571642
572643 #if not os.path.exists(os.path.join("..","bin")):
573644 # os.mkdir(os.path.join("..","bin"))
574645 #shutil.copy2(os.path.join("..","exe","windows","x64","Debug","pestpp-sqp.exe"),os.path.join("..","bin","pestpp-sqp.exe"))
575- basic_sqp_test ()
646+ # basic_sqp_test()
576647 #rosenbrock_single_linear_constraint(nit=1)
577648 #dewater_basic_test()
578- # dewater_slp_opt_test()
649+ dewater_slp_opt_test ()
579650 #rosenc_test()
580651 #m_d = rosenc_test()
581652 #m_d = os.path.join("mou_tests","master_rosenc_enopt")
582653 #plot_rosen(m_d)
654+ #mf6_freyberg_test()
655+ #mf6_phiobs_invest()
0 commit comments