Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat dsi_pyworker #559

Merged
merged 70 commits into from
Dec 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
3be6bcd
initial gpr setup helper
jtwhite79 Nov 1, 2023
c7ee665
Merge branch 'develop' of https://github.com/pypest/pyemu into feat_gpr
jtwhite79 Nov 1, 2023
69570d0
more work on gpr prototype
jtwhite79 Nov 1, 2023
aa3cc50
more work on gpr emulator
jtwhite79 Nov 8, 2023
ea7edbd
more gpr
jtwhite79 Nov 8, 2023
b5bb086
more dev and exp with gpr
jtwhite79 Nov 12, 2023
b56ab81
Merge branch 'develop' of https://github.com/pypest/pyemu into feat_gpr
jtwhite79 Apr 16, 2024
60433cc
more thresh testing
jtwhite79 Apr 16, 2024
e1755e0
env
jtwhite79 Apr 22, 2024
006d523
xfer pi from base to gpr interface
jtwhite79 Apr 22, 2024
f9ba3c7
merge
jtwhite79 Sep 3, 2024
6dee76a
starting on py worker
jtwhite79 Nov 1, 2024
542348a
starting on py worker
jtwhite79 Nov 1, 2024
a781836
more
jtwhite79 Nov 1, 2024
26965fd
initailization rough'd in
jtwhite79 Nov 1, 2024
126bcfd
more
jtwhite79 Nov 2, 2024
91a0f99
refactor to listen fxn, prep for threading
jtwhite79 Nov 3, 2024
c8b0774
more
jtwhite79 Nov 4, 2024
c78377c
merge
jtwhite79 Nov 11, 2024
613385c
fix for long names in a binary file
jtwhite79 Nov 12, 2024
85907a2
Merge remote-tracking branch 'origin/feat_ppu3' into feat_gpr
jtwhite79 Nov 12, 2024
1338d47
merge
jtwhite79 Nov 12, 2024
274e29b
test undo to_coo
jtwhite79 Nov 12, 2024
29f5de5
merge ppu3
jtwhite79 Nov 15, 2024
df4f5f5
Merge branch 'feat_ppu3' of https://github.com/jtwhite79/pyemu into f…
jtwhite79 Nov 18, 2024
87a30f6
Merge branch 'feat_ppu3' of https://github.com/jtwhite79/pyemu into f…
jtwhite79 Nov 18, 2024
fe3609c
added initial placeholder pypestworker invest function
jtwhite79 Nov 18, 2024
e725bfc
working on gpr tests
jtwhite79 Nov 19, 2024
3d7d00b
added gpr notebook
jtwhite79 Nov 19, 2024
9ecef8b
more work on hosaki
jtwhite79 Nov 20, 2024
caf43e3
more work on gpr
jtwhite79 Nov 25, 2024
499c6a3
added shortened zdt1 test, trying to speed up gpr hosaki notebook
jtwhite79 Nov 25, 2024
efba796
shortening gpr tests more
jtwhite79 Nov 25, 2024
f51b3db
fix for parallel tests
jtwhite79 Nov 25, 2024
c8b6a77
switched constr gpr test to serial
jtwhite79 Nov 25, 2024
dc6fa9c
more
jtwhite79 Nov 26, 2024
6ee7619
docstrings
jtwhite79 Nov 26, 2024
727ed36
Merge branch 'feat_gpr' of https://github.com/jtwhite79/pyemu into fe…
jtwhite79 Nov 26, 2024
f96fb81
Merge branch 'develop' of https://github.com/jtwhite79/pyemu into fea…
jtwhite79 Nov 26, 2024
52f0061
merge with feat_gpr
jtwhite79 Nov 26, 2024
61ba55c
more work on pypestworker, added test
jtwhite79 Nov 26, 2024
8930216
longer time
jtwhite79 Nov 26, 2024
0538383
shortened timeouts again but added netpack.recv_all() to help
jtwhite79 Nov 27, 2024
b8b4ef9
added multiple pyworker test
jtwhite79 Nov 27, 2024
e5b191f
more work on pyworker test
jtwhite79 Nov 27, 2024
04a16c5
timeout
jtwhite79 Nov 27, 2024
699a6ea
longer default timeout, removed start_workers from pyworker test to a…
jtwhite79 Nov 27, 2024
d53baf8
added try-catch-reconnect
jtwhite79 Nov 27, 2024
f22d6a8
fix
jtwhite79 Nov 27, 2024
aeff898
fix
jtwhite79 Nov 27, 2024
4a440e5
working on ppw gpr worker
jtwhite79 Nov 28, 2024
c222aaa
added gpr ppw test:
jtwhite79 Nov 28, 2024
1afb43d
more work on gpr ppw fxn
jtwhite79 Nov 29, 2024
cc99529
added ppw options to start_workers
jtwhite79 Nov 29, 2024
b23c72b
reworked gpr notebook to use ppw, omg sooo much better
jtwhite79 Nov 29, 2024
56a26a2
even longer timeout for ends tests
jtwhite79 Nov 29, 2024
a27144d
a few tweaks to the gpr hosaki notebook
jtwhite79 Nov 29, 2024
7608321
fix for notebook with really short runs being timed out
jtwhite79 Nov 29, 2024
487c57d
time out protection in zdt1 gpr test
jtwhite79 Nov 29, 2024
4fc0ab1
less mem in ac draw test
jtwhite79 Nov 30, 2024
b424194
more test opt
jtwhite79 Nov 30, 2024
b1fa1e2
trying again
jtwhite79 Nov 30, 2024
4d62ba8
turning off constr gpr test for now
jtwhite79 Dec 1, 2024
2611706
update get_pestpp test
jtwhite79 Dec 2, 2024
bdaee9a
more work on get_pestpp for mac:
jtwhite79 Dec 2, 2024
ef54cc3
comment out print funx
rhugman Dec 6, 2024
d1c7cad
Merge branch 'feat_pyworker' of https://github.com/jtwhite79/pyemu in…
rhugman Dec 6, 2024
e8345e6
dsi pyworker funxs'
rhugman Dec 6, 2024
6ea3190
switch dsi tests to use pyworker
rhugman Dec 6, 2024
fa09035
Merge branch 'develop' into feat_pyworker
briochh Dec 10, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 13 additions & 3 deletions autotest/la_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,8 @@ def ends_freyberg_test(tmp_path):
def ends_run_freyberg_dsi(tmp_d, nst=False, nst_extrap=None, ztz=False, energy=1.0):
import pyemu
import os
import pandas as pd
import numpy as np
test_d = "ends_master"
test_d = setup_tmp(test_d, tmp_d)
case = "freyberg6_run_ies"
Expand Down Expand Up @@ -627,11 +629,19 @@ def ends_run_freyberg_dsi(tmp_d, nst=False, nst_extrap=None, ztz=False, energy=1
pst.pestpp_options["overdue_giveup_fac"] = 100000000
pst.write(os.path.join(t_d,"dsi.pst"),version=2)
#pyemu.os_utils.run("pestpp-ies dsi.pst",cwd=t_d)

pvals = pd.read_csv(os.path.join(t_d,"dsi_pars.csv"),index_col=0)
pmat = np.load(os.path.join(t_d,"dsi_proj_mat.npy"))
ovals = pd.read_csv(os.path.join(t_d,"dsi_pr_mean.csv"),index_col=0)


m_d = t_d.replace("template","master")
port = _get_port()
pyemu.os_utils.start_workers(t_d, ies_exe_path,"dsi.pst",
worker_root=tmp_d,
master_dir=m_d, num_workers=10, port=port)
master_dir=m_d, num_workers=10, port=port,
ppw_function=pyemu.helpers.dsi_pyworker,
ppw_kwargs={"pmat":pmat,"ovals":ovals,"pvals":pvals})
#read in the results
oe = pyemu.ObservationEnsemble.from_csv(pst=pst, filename=os.path.join(m_d,"dsi.0.obs.csv"))
assert oe.shape[0]==50, f"{50-oe.shape[0]} failed runs"
Expand Down Expand Up @@ -741,8 +751,8 @@ def dsi_normscoretransform_test():

if __name__ == "__main__":
#dsi_normscoretransform_test()
ends_freyberg_test("temp")
#ends_freyberg_dsi_test("temp")
#ends_freyberg_test("temp")
ends_freyberg_dsi_test("temp")
#ends_freyberg_dev()
#ends_freyberg_dsi_test("temp")
#plot_freyberg_dsi()
Expand Down
2 changes: 1 addition & 1 deletion pyemu/eds.py
Original file line number Diff line number Diff line change
Expand Up @@ -732,7 +732,7 @@ def dsi_forward_run():
vals[np.where(log_trans==1)] = 10**vals[np.where(log_trans==1)]
vals-= offset
sim_vals.loc[:,'mn'] = vals
print(sim_vals)
#print(sim_vals)
sim_vals.to_csv("dsi_sim_vals.csv")

self.logger.log("test run")
Expand Down
112 changes: 112 additions & 0 deletions pyemu/utils/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -4405,6 +4405,118 @@ def gpr_forward_run():
mdf.loc[:,["output_name","sim","sim_std"]].to_csv("gpr_output.csv",index=False)
return mdf


def dsi_forward_run(pmat=None,ovals=None,pvals=None,
write_csv=True

):

if pvals is None:
pvals = pd.read_csv("dsi_pars.csv",index_col=0)
if pmat is None:
pmat = np.load("dsi_proj_mat.npy")
if ovals is None:
ovals = pd.read_csv("dsi_pr_mean.csv",index_col=0)

try:
offset = np.load("dsi_obs_offset.npy")
except:
#print("no offset file found, assuming no offset")
offset = np.zeros(ovals.shape[0])
try:
log_trans = np.load("dsi_obs_log.npy")
except:
#print("no log-tansform file found, assuming no log-transform")
log_trans = np.zeros(ovals.shape[0])

try:
backtransformvals = np.load("dsi_obs_backtransformvals.npy")
backtransformobsnmes = np.load("dsi_obs_backtransformobsnmes.npy",allow_pickle=True)
backtransform=True
except:
#print("no back-transform file found, assuming no back-transform")
backtransform=False


sim_vals = ovals + np.dot(pmat,pvals.values)

if backtransform:
#print("applying back-transform")
obsnmes = np.unique(backtransformobsnmes)
back_vals = [
inverse_normal_score_transform(
backtransformvals[np.where(backtransformobsnmes==o)][:,1],
backtransformvals[np.where(backtransformobsnmes==o)][:,0],
sim_vals.loc[o].mn,
extrap=None
)[0]
for o in obsnmes
]
sim_vals.loc[obsnmes,'mn'] = back_vals

#print("reversing offset and log-transform")
assert log_trans.shape[0] == sim_vals.mn.values.shape[0], f"log transform shape mismatch: {log_trans.shape[0]},{sim_vals.mn.values.shape[0]}"
assert offset.shape[0] == sim_vals.mn.values.shape[0], f"offset transform shape mismatch: {offset.shape[0]},{sim_vals.mn.values.shape[0]}"
vals = sim_vals.mn.values
vals[np.where(log_trans==1)] = 10**vals[np.where(log_trans==1)]
vals-= offset
sim_vals.loc[:,'mn'] = vals
#print(sim_vals)
if write_csv:
sim_vals.to_csv("dsi_sim_vals.csv")
return sim_vals


def dsi_pyworker(pst,host,port,pmat=None,ovals=None,pvals=None):

import os
import pandas as pd
import numpy as np


# if explicit args werent passed, get the default ones...
if pvals is None:
pvals = pd.read_csv("dsi_pars.csv",index_col=0)
if pmat is None:
pmat = np.load("dsi_proj_mat.npy")
if ovals is None:
ovals = pd.read_csv("dsi_pr_mean.csv",index_col=0)


ppw = PyPestWorker(pst,host,port,verbose=False)

# we can only get parameters once the worker has initialize and
# is ready to run, so getting the first of pars here
# essentially blocks until the worker is ready
parameters = ppw.get_parameters()
# if its None, the master already quit...
if parameters is None:
return

obs = ppw._pst.observation_data.copy()
# align the obsval series with the order sent from the master
obs = obs.loc[ppw.obs_names,"obsval"]

while True:
# map the current par values in parameters into the
# df needed to run the emulator
pvals.parval1 = parameters.loc[pvals.index]
# do the emulation
simdf = dsi_forward_run(pmat=pmat,ovals=ovals,pvals=pvals,write_csv=False)

# replace the emulated quantites in the obs series
obs.loc[simdf.index] = simdf.mn.values

#send the obs series to the master
ppw.send_observations(obs.values)

#try to get more pars
parameters = ppw.get_parameters()
# if None, we are done
if parameters is None:
break


def randrealgen_optimized(nreal, tol=1e-7, max_samples=1000000):
"""
Generate a set of random realizations with a normal distribution.
Expand Down
Loading