Skip to content

Commit

Permalink
better logging of checkpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
uym2 committed Jul 19, 2024
1 parent 3598d14 commit 8050c43
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 6 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
* LAML version 0.0.5
* better checkpoint logging
* LAML version 0.0.4
* add functionalities to create character matrices from fastq files (borrowed from a module of Cassiopeia)
* handle mismatch between character matrix and prior pickle
Expand Down
8 changes: 4 additions & 4 deletions laml_libs/Topology_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def __accept_proposal__(self,curr_score,new_score,t):
p = min(exp((new_score-curr_score-1e-12)/T),1)
return random() < p

def search(self,resolve_polytomies=True,maxiter=100,verbose=False,nreps=1,strategy=DEFAULT_STRATEGY,checkpoint_file="laml_topo_search._ckpt.txt"):
def search(self,resolve_polytomies=True,maxiter=100,verbose=False,nreps=1,strategy=DEFAULT_STRATEGY,checkpoint_file=None):
original_topos = self.treeTopoList
original_params = self.params
#nni_replicates = [(None,None)]*nreps
Expand Down Expand Up @@ -132,7 +132,7 @@ def search(self,resolve_polytomies=True,maxiter=100,verbose=False,nreps=1,strate

return best_trees,best_score,best_params

def __search_one__(self,strategy,maxiter=100,verbose=False,only_marked=False, checkpoint_file="laml_topo_search._ckpt.txt"):
def __search_one__(self,strategy,maxiter=100,verbose=False,only_marked=False, checkpoint_file=None):
# optimize branch lengths and other parameters for the starting tree
mySolver = self.get_solver()
score_tree_strategy = deepcopy(strategy)
Expand Down Expand Up @@ -164,8 +164,8 @@ def __search_one__(self,strategy,maxiter=100,verbose=False,only_marked=False, ch
print("Current score: " + str(curr_score))
stop_time = timeit.default_timer()
print("Runtime (s):", stop_time - start_time)
if nni_iter % 50 == 0:
with open(checkpoint_file, "w") as fout:
if nni_iter % chkpt_freq == 0 and checkpoint_file is not None:
with open(checkpoint_file, "a") as fout:
fout.write(f"NNI Iteration: {nni_iter}\n")
fout.write(f"Current newick tree: {best_trees}\n")
fout.write(f"Current negative-llh: {best_score}\n")
Expand Down
1 change: 1 addition & 0 deletions laml_libs/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@
nni_conv_eps = 1e-15 # additional NNI convergence threshold since conv_eps has several purposes
dmin = 0.005
dmax = 10
chkpt_freq = 10
DEFAULT_STRATEGY={'resolve_search_only':False,'only_marked':False,'ultra_constr':False,'fixed_phi':None,'fixed_nu':None,'local_brlen_opt':True}
3 changes: 1 addition & 2 deletions run_laml.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,8 +212,7 @@ def main():
print("Running topology search in parallel...")
else:
print("Running topology search sequentially...")
randval = int(random.random() * 1000)
checkpoint_file = f"{prefix}._ckpt.{randval}.txt"
checkpoint_file = f"{prefix}_ckpt.txt"
opt_trees,max_score,opt_params = myTopoSearch.search(resolve_polytomies=resolve_polytomies,maxiter=args["maxIters"], verbose=args["verbose"], strategy=my_strategy, nreps=args['randomreps'],checkpoint_file=checkpoint_file)
nllh = -max_score

Expand Down

0 comments on commit 8050c43

Please sign in to comment.