Skip to content

Commit

Permalink
Redirect stdout in driver to logfile (#43)
Browse files Browse the repository at this point in the history
  • Loading branch information
timothyas authored Oct 18, 2023
1 parent 8359ae4 commit 5c6a006
Showing 1 changed file with 26 additions and 9 deletions.
35 changes: 26 additions & 9 deletions xesn/driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,22 @@ def run_micro_calibration(self):
# setup the data
self.localtime.start("Setting up Data")
data = XData(**self.config["xdata"])
xda = data.setup(mode="training")
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
xda = data.setup(mode="training")
self.localtime.stop()

# setup ESN
self.localtime.start(f"Building {self.esn_name}")
esn = self.ESN(**self.config[self.esn_name])
esn.build()
self.print_log(str(esn))
self.localtime.stop()

self.localtime.start(f"Training {self.esn_name}")
esn.train(xda, **self.config["training"])
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
esn.train(xda, **self.config["training"])
self.localtime.stop()

self.localtime.start(f"Storing {self.esn_name} Weights")
Expand Down Expand Up @@ -124,11 +129,19 @@ def run_macro_calibration(self):
# setup the data
self.localtime.start("Setting up Data")
data = XData(**self.config["xdata"])
xda = data.setup(mode="macro_training")
# First macro data sets
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
xda = data.setup(mode="macro_training")

macro_data, indices = self.get_samples(xda=xda, **self.config["macro_training"]["forecast"])
if "sample_indices" not in self.config["macro_training"]["forecast"]:
self.overwrite_config({"macro_training": {"forecast": {"sample_indices": indices}}})
xda = data.setup(mode="training")

# Now training data
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
xda = data.setup(mode="training")
self.localtime.stop()

# create cost function
Expand All @@ -138,10 +151,12 @@ def run_macro_calibration(self):

# optimize
self.localtime.start("Starting Bayesian Optimization")
p_opt = optimize(self.config["macro_training"]["parameters"],
self.config["macro_training"]["transformations"],
cf,
**self.config["macro_training"]["ego"])
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
p_opt = optimize(self.config["macro_training"]["parameters"],
self.config["macro_training"]["transformations"],
cf,
**self.config["macro_training"]["ego"])
self.localtime.stop()

config_optim = self.config.copy()
Expand Down Expand Up @@ -169,7 +184,9 @@ def run_test(self):
# setup the data
self.localtime.start("Setting up Data")
data = XData(**self.config["xdata"])
xda = data.setup(mode="testing")
with open(self.logfile, 'a') as file:
with redirect_stdout(file):
xda = data.setup(mode="testing")
self.localtime.stop()

# pull samples from data
Expand Down

0 comments on commit 5c6a006

Please sign in to comment.