From a6b1c1747360bca7b6cc57d80f976296e245a40d Mon Sep 17 00:00:00 2001 From: Boris Goncharov <39367451+bvgoncharov@users.noreply.github.com> Date: Wed, 24 Apr 2024 06:17:46 -0700 Subject: [PATCH 1/5] writeHotChains must currently be used for resuming --- PTMCMCSampler/PTMCMCSampler.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index 8063ddc..3ff97ed 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -176,7 +176,7 @@ def initialize( thin=10, i0=0, neff=None, - writeHotChains=False, + writeHotChains=True, hotChain=False, ): """ From c10a3fe97855f4bf411c5fa5e47e58e748a9071b Mon Sep 17 00:00:00 2001 From: Boris Goncharov <39367451+bvgoncharov@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:15:43 -0700 Subject: [PATCH 2/5] Showing a warning for resuming the calculation with writeHotChains=False --- PTMCMCSampler/PTMCMCSampler.py | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index 3ff97ed..7012a32 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -1,6 +1,7 @@ import os import sys import time +import warnings import numpy as np @@ -176,7 +177,7 @@ def initialize( thin=10, i0=0, neff=None, - writeHotChains=True, + writeHotChains=False, hotChain=False, ): """ @@ -297,16 +298,26 @@ def initialize( except ValueError as error: print("Reading old chain files failed with error", error) raise Exception("Couldn't read old chain to resume") - self._chainfile = open(self.fname, "a") + if ( self.isave != self.thin and self.resumeLength % (self.isave / self.thin) != 1 # This special case is always OK ): # Initial sample plus blocks of isave/thin - raise Exception( - ( - "Old chain has {0} rows, which is not the initial sample plus a multiple of isave/thin = {1}" - ).format(self.resumeLength, self.isave // self.thin) - ) + if self.MPIrank == 0 or (self.MPIrank != 0 and self.writeHotChains is True): + raise Exception( + ( + "Old chain has {0} rows, which is not the initial sample plus a multiple of isave/thin = {1}" + ).format(self.resumeLength, self.isave // self.thin) + ) + else: + warnings.warn("Neglecting hot chains from the previous run. It is recommended to set writeHotChains=True when resuming a run with multiple temperatures.") + self._chainfile = open(self.fname, "w") + else: + self._chainfile = open(self.fname, "a") + + elif self.MPIrank != 0 and self.writeHotChains is False: + warnings.warn("Neglecting hot chains from the previous run. Please set writeHotChains=True when resuming a run with multiple temperatures.") + self._chainfile = open(self.fname, "w") print( "Resuming with", self.resumeLength, From ca8d94bde74f0dced367a971b4f74aa4b464bad8 Mon Sep 17 00:00:00 2001 From: Boris Goncharov <39367451+bvgoncharov@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:21:59 -0700 Subject: [PATCH 3/5] Typo removal --- PTMCMCSampler/PTMCMCSampler.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index 7012a32..193cb8c 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -314,10 +314,7 @@ def initialize( self._chainfile = open(self.fname, "w") else: self._chainfile = open(self.fname, "a") - - elif self.MPIrank != 0 and self.writeHotChains is False: - warnings.warn("Neglecting hot chains from the previous run. Please set writeHotChains=True when resuming a run with multiple temperatures.") - self._chainfile = open(self.fname, "w") + print( "Resuming with", self.resumeLength, From 90a04d9252af9b54f9e71b08f4151e9b68d60961 Mon Sep 17 00:00:00 2001 From: Boris Goncharov <39367451+bvgoncharov@users.noreply.github.com> Date: Wed, 24 Apr 2024 09:35:19 -0700 Subject: [PATCH 4/5] Logic change in the run resume warning for multiple temperatures --- PTMCMCSampler/PTMCMCSampler.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index 193cb8c..223fa88 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -303,15 +303,15 @@ def initialize( self.isave != self.thin and self.resumeLength % (self.isave / self.thin) != 1 # This special case is always OK ): # Initial sample plus blocks of isave/thin - if self.MPIrank == 0 or (self.MPIrank != 0 and self.writeHotChains is True): + if self.MPIrank != 0 and self.writeHotChains is False: + warnings.warn("Neglecting hot chains from the previous run. It is recommended to set writeHotChains=True when resuming a run with multiple temperatures.") + self._chainfile = open(self.fname, "w") + else: raise Exception( ( "Old chain has {0} rows, which is not the initial sample plus a multiple of isave/thin = {1}" ).format(self.resumeLength, self.isave // self.thin) ) - else: - warnings.warn("Neglecting hot chains from the previous run. It is recommended to set writeHotChains=True when resuming a run with multiple temperatures.") - self._chainfile = open(self.fname, "w") else: self._chainfile = open(self.fname, "a") From 7d07a0520555bbb834b164071564c27bf194ecda Mon Sep 17 00:00:00 2001 From: Boris Goncharov <39367451+bvgoncharov@users.noreply.github.com> Date: Tue, 25 Jun 2024 15:33:57 +0200 Subject: [PATCH 5/5] A special variable to allow resuming without hot chains --- PTMCMCSampler/PTMCMCSampler.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/PTMCMCSampler/PTMCMCSampler.py b/PTMCMCSampler/PTMCMCSampler.py index 223fa88..11f1530 100755 --- a/PTMCMCSampler/PTMCMCSampler.py +++ b/PTMCMCSampler/PTMCMCSampler.py @@ -70,6 +70,8 @@ class PTSampler(object): @param outDir: Full path to output directory for chain files (default = ./chains) @param verbose: Update current run-status to the screen (default=True) @param resume: Resume from a previous chain (still in testing so beware) (default=False) + @param ihcwr: Ignore hot chains when resuming. Note, hot chains will enter a burn-in + phase when resuming (default=False) """ @@ -90,6 +92,7 @@ def __init__( outDir="./chains", verbose=True, resume=False, + ihcwr=False, seed=None, ): # MPI initialization @@ -118,6 +121,7 @@ def __init__( self.outDir = outDir self.verbose = verbose self.resume = resume + self.ignoreHotChainsWhenResuming = ihcwr # setup output file if not os.path.exists(self.outDir): @@ -303,7 +307,7 @@ def initialize( self.isave != self.thin and self.resumeLength % (self.isave / self.thin) != 1 # This special case is always OK ): # Initial sample plus blocks of isave/thin - if self.MPIrank != 0 and self.writeHotChains is False: + if self.MPIrank != 0 and self.writeHotChains is False and self.ignoreHotChainsWhenResuming: warnings.warn("Neglecting hot chains from the previous run. It is recommended to set writeHotChains=True when resuming a run with multiple temperatures.") self._chainfile = open(self.fname, "w") else: