Skip to content

Commit

Permalink
reformatted
Browse files Browse the repository at this point in the history
  • Loading branch information
xuyuon committed Aug 31, 2024
1 parent 3ddc1fc commit 2d3976f
Showing 1 changed file with 52 additions and 24 deletions.
76 changes: 52 additions & 24 deletions src/jimgw/single_event/runManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ def save(self, path: str):
def load_from_path(self, path: str) -> SingleEventRun:
with open(path, "r") as f:
data = yaml.safe_load(f)
if "jim_parameters" in data and "local_sampler_arg" in data["jim_parameters"] and "step_size" in data["jim_parameters"]["local_sampler_arg"]:
data["jim_parameters"]["local_sampler_arg"]["step_size"] = jnp.array(data["jim_parameters"]["local_sampler_arg"]["step_size"])
if (
"jim_parameters" in data
and "local_sampler_arg" in data["jim_parameters"]
and "step_size" in data["jim_parameters"]["local_sampler_arg"]
):
data["jim_parameters"]["local_sampler_arg"]["step_size"] = jnp.array(
data["jim_parameters"]["local_sampler_arg"]["step_size"]
)
return SingleEventRun(**data)

### Initialization functions ###
Expand Down Expand Up @@ -490,54 +496,76 @@ class MultipleEventPERunManager:
"""
Class to manage multiple events run.
"""

run_config_path: str
output_path: str

def __init__(self, run_config_path: str, output_path: str = "output") -> None:
"""
Arguments:
run_config_path (str): load the run configuration from the path.
output_path (str, optional): save the output to this path. Defaults to "output".
"""

self.run_config_path = run_config_path
self.output_path = output_path

def run(self, plot_corner: bool = True, plot_diagnostic: bool = True, save_summary: bool = True):

def run(
self,
plot_corner: bool = True,
plot_diagnostic: bool = True,
save_summary: bool = True,
):
"""
Loop over all the configuration files in the run_config_path and run the PE for each configuration.
"""

if plot_corner and not os.path.exists(self.output_path+"/corner_plots"):
os.makedirs(self.output_path+"/corner_plots")
if plot_diagnostic and not os.path.exists(self.output_path+"/diagnostic_plots"):
os.makedirs(self.output_path+"/diagnostic_plots")
if save_summary and not os.path.exists(self.output_path+"/summaries"):
os.makedirs(self.output_path+"/summaries")
if not os.path.exists(self.output_path+"/error_log"):
os.makedirs(self.output_path+"/error_log")


if plot_corner and not os.path.exists(self.output_path + "/corner_plots"):
os.makedirs(self.output_path + "/corner_plots")
if plot_diagnostic and not os.path.exists(
self.output_path + "/diagnostic_plots"
):
os.makedirs(self.output_path + "/diagnostic_plots")
if save_summary and not os.path.exists(self.output_path + "/summaries"):
os.makedirs(self.output_path + "/summaries")
if not os.path.exists(self.output_path + "/error_log"):
os.makedirs(self.output_path + "/error_log")

config_directory = os.fsencode(self.run_config_path)
for file in os.listdir(config_directory):
filename = os.fsdecode(file)

try:
if filename.endswith(".yaml"):
config_path = os.path.join(self.run_config_path, filename)
run_manager = SingleEventPERunManager(path=config_path)
run_manager.sample()

if plot_corner:
run_manager.plot_corner(self.output_path+"/corner_plots/" + filename + "_corner.jpeg")
run_manager.plot_corner(
self.output_path
+ "/corner_plots/"
+ filename
+ "_corner.jpeg"
)
if plot_diagnostic:
run_manager.plot_diagnostic(self.output_path+"/diagnostic_plots/" + filename + "_diagnostic.jpeg")
run_manager.plot_diagnostic(
self.output_path
+ "/diagnostic_plots/"
+ filename
+ "_diagnostic.jpeg"
)
if save_summary:
run_manager.save_summary(self.output_path+"/summaries/" + filename + "_summary.txt")

run_manager.save_summary(
self.output_path + "/summaries/" + filename + "_summary.txt"
)

except Exception as e:
orig_stdout = sys.stdout
sys.stdout = open(self.output_path+"/error_log/"+filename+"error_log.txt", "wt")
sys.stdout = open(
self.output_path + "/error_log/" + filename + "error_log.txt", "wt"
)
print(f"Error in running {filename}. Error: {e}")
sys.stdout.close()
sys.stdout = orig_stdout
continue
continue

0 comments on commit 2d3976f

Please sign in to comment.