Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix BEAST not checkpointing using the BEAUti checkpoint XML block #1221

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

hongsamL
Copy link

@hongsamL hongsamL commented Mar 5, 2025

Fix for the issue of BEAST not generating any checkpoint files if specified via XML.

To test this, I used the YFV.xml example file and added the following checkpointing logger in the mcmc block

<!-- write state of Markov chain to checkpoint file                          -->
<logCheckpoint id="checkpointFileLog" checkpointEvery="100000" checkpointFinal="500000" fileName="YFV.chkpt" overwrite="false"/>

PROBLEM: current behavior

Currently BEAST does not generate any checkpoint files from the BEAUTi XML because:

  1. release_parsers.properties does not have CheckpointLoggerParser

  2. The checkpointOverrule variable is always set to true in BeastMain

 if (Boolean.parseBoolean(System.getProperty("checkpointOverrule", "true"))) {
  BeastCheckpointer.getInstance(null, -1, -1, false);
  Logger.getLogger("dr.apps.beast").info("Overriding checkpointing settings in the provided XML file");
}

Fixing the XML checkpointing

To make BEAST use the checkpointing settings in the XML I did the following:

  1. Add missing CheckpointLoggerParser to release_parsers.properties
  2. Set default checkpointOverrule property to false in BeastMain:
    if (Boolean.parseBoolean(System.getProperty("checkpointOverrule", "false"))) {

Fixing the fix

Changing the default to false opens up a new problem, because the checkpoint overrule needs to now be set to true when the appropriate flags are passed in the command line. So we need to decide on which command line options/flags would result in overruling the XML checkpointing

Below are all of the checkpointing related options and flags I found in BeastMain:

-load_state
-save_stem
-save_at
-save_time
-save_every
-save_state
-full_checkpoint_precision
-force_resume

-full_checkpoint_precision and -force_resume shouldn't overrule the XML settings because they are not specified in the XML block, so I didn't do anything with them.

-load_state and -save_stem should not overrule the XML settings so that one can resume a run from the command line without changing anything. However, they were being ignored and BEAST would always start from scratch with the XML settings instead (would not load the file nor add a checkpoint file stem).

To fix this behavior, I changed the following variables from null in the else block of the BeastCheckpointer constructor:

loadStateFileName = System.getProperty(LOAD_STATE_FILE, null);
stemFileName = System.getProperty(SAVE_STEM, null);

Additionally, I modified the saveState method in BeastCheckpointer.java so that it adds the stem to the checkpoint file name if it exists. The previous version was always saving to a new checkpoint file with name <save stem>_<state number>:

public boolean saveState(MarkovChain markovChain, long state, double lnL) {
	String fileName = "";
	if (stemFileName != null && this.saveStateFileName == null) {
		fileName = stemFileName + "_" + state;
	} else if (stemFileName != null) {
		fileName = stemFileName + "_" + this.saveStateFileName;
	} else {
	...

Thus, I made it so that if any of the remaining options is set, we override the XML specification:

-save_at
-save_time
-save_every
-save_state

Doing this I was able to successfully do the following:

  • Run BEAST from scratch and have it checkpoint using the XML settings
  • Resume a BEAST run from a checkpoint using -load_state <chkp> -save_stem <stem> and have it continue checkpointing using the frequency and filename in the XML settings
  • Run BEAST from scratch overriding the XML checkpointing and checkpoint using command line options
  • Resume a BEAST while overriding settings

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant