Skip to content

Commit

Permalink
add verbose option and update seed per parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
martinvonk committed Sep 27, 2024
1 parent 4f8ed48 commit 34e8bc9
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions pastas_plugins/pest/solver.py
Original file line number Diff line number Diff line change
Expand Up @@ -230,9 +230,9 @@ def setup_files(self, version: int = 2):
with (self.temp_ws / "observation_index.json").open("w") as f:
json.dump(obj=self.observation_index, fp=f, default=str)

def run(self, arg_str: str = ""):
def run(self, arg_str: str = "", silent: bool = False):
pyemu.os_utils.run(
f"{self.exe_name.name} pest.pst{arg_str}", cwd=self.pf.new_d, verbose=True
f"{self.exe_name.name} pest.pst{arg_str}", cwd=self.pf.new_d, verbose=silent
)


Expand Down Expand Up @@ -406,7 +406,7 @@ def __init__(
self.computername = get_computername()
copy_file(self.exe_agent, self.temp_ws) # copy agent executable

def solve(self, **kwargs) -> Tuple[bool, np.ndarray, np.ndarray]:
def solve(self, silent: bool = False, **kwargs) -> Tuple[bool, np.ndarray, np.ndarray]:
"""
Solve the optimization problem using the pest_hp solver.
Expand All @@ -431,8 +431,8 @@ def solve(self, **kwargs) -> Tuple[bool, np.ndarray, np.ndarray]:
self.setup_files(version=1)
# start consecutive thread for pest_hp and agent_hp excutable
threads = [
Thread(target=self.run, args=(f" /h :{self.port_number}",)),
Thread(target=self.run_agent),
Thread(target=self.run, args=(f" /h :{self.port_number}", silent)),
Thread(target=self.run_agent, args=(silent,)),
]
for t in threads:
t.start()
Expand All @@ -455,7 +455,7 @@ def solve(self, **kwargs) -> Tuple[bool, np.ndarray, np.ndarray]:
stderr = np.full_like(optimal, np.nan)
return True, optimal, stderr

def run_agent(self):
def run_agent(self, silent: bool = False):
"""
Executes the agent using the specified executable and configuration.
This method runs the agent with the given executable name, pest control file,
Expand All @@ -466,7 +466,7 @@ def run_agent(self):
pyemu.os_utils.run(
f"{self.exe_agent.name} pest.pst /h {self.computername}:{self.port_number}",
cwd=self.pf.new_d,
verbose=True,
verbose=silent,
)


Expand Down Expand Up @@ -551,6 +551,7 @@ def run_ensembles(
Literal["norm", "truncnorm", "uniform"]
] = None,
pestpp_options: Optional[Dict] = None,
silent: bool = False,
) -> None:
"""
Run ensemble simulations using pestpp-ies.
Expand Down Expand Up @@ -617,6 +618,8 @@ def run_ensembles(
worker_root=self.master_ws.parent, # where to deploy the agent directories; relative to where python is running
port=self.port_number, # the port to use for communication
master_dir=self.master_ws, # the manager directory
verbose=silent,
silent_master=silent,
)

phidf = pd.read_csv(self.master_ws / "pest.phi.meas.csv", index_col=0)
Expand Down Expand Up @@ -779,7 +782,7 @@ def write_ensemble_parameter_distribution(
method=method,
seed=seed,
)
seed += 1 if method == "uniform" else 0
seed += 1
par_df[pname] = rvs
if ies_add_base:
par_df.loc[self.ies_num_reals - 1] = pst.parameter_data.loc[
Expand Down Expand Up @@ -1111,6 +1114,7 @@ def __init__(
def start(
self,
pestpp_options: Optional[Dict] = None,
silent: bool = False
) -> None:
"""
Start the PESTPP-SEN analysis.
Expand Down Expand Up @@ -1146,6 +1150,8 @@ def start(
worker_root=self.master_ws.parent, # where to deploy the agent directories; relative to where python is running
port=self.port_number, # the port to use for communication
master_dir=self.master_ws, # the manager directory
verbose=silent,
silent_master=silent,
)

def solve() -> None:
Expand Down

0 comments on commit 34e8bc9

Please sign in to comment.