Skip to content

Commit

Permalink
Merge pull request #1504 from veg/develop
Browse files Browse the repository at this point in the history
v 2.5.41
  • Loading branch information
spond authored Aug 5, 2022
2 parents 4fa5a73 + a79e78a commit 87168fd
Show file tree
Hide file tree
Showing 8 changed files with 83 additions and 22 deletions.
5 changes: 5 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,11 @@ endif(NOT DEFINED DEFAULT_WARNING_FLAGS)
#-------------------------------------------------------------------------------
find_package(OpenMP)

# emulate missing OpenMP for testing

#set (OPENMP_FOUND FALSE)
#set (OpenMP_CXX_FLAGS "")

#-------------------------------------------------------------------------------
# default installation prefix
#-------------------------------------------------------------------------------
Expand Down
1 change: 1 addition & 0 deletions res/TemplateBatchFiles/SelectionAnalyses/MEME.bf
Original file line number Diff line number Diff line change
Expand Up @@ -791,6 +791,7 @@ lfunction meme.handle_a_site (lf_fel, lf_bsrel, filter_data, partition_index, pa
utility.getGlobalValue("terms.empirical_bayes_factor") : branch_ebf,
utility.getGlobalValue("terms.branch_selection_attributes") : branch_substitution_information, //TODO: keep this attr?
utility.getGlobalValue("terms.Null"): Null,
utility.getGlobalValue("terms.substitutions") : compressed_substitution_info,
utility.getGlobalValue("terms.simulated"): null_LRT
};
}
Expand Down
41 changes: 29 additions & 12 deletions res/TemplateBatchFiles/SelectionAnalyses/RELAX.bf
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ LoadFunctionLibrary("libv3/models/rate_variation.bf");
utility.SetEnvVariable ("NORMALIZE_SEQUENCE_NAMES", TRUE);
utility.SetEnvVariable ("ASSUME_REVERSIBLE_MODELS", TRUE);
utility.SetEnvVariable ("USE_MEMORY_SAVING_DATA_STRUCTURES", 1e8);
u

//relax.OPTIMIZATION_LOGS = 1;

/*------------------------------------------------------------------------------*/

Expand Down Expand Up @@ -386,7 +387,7 @@ if (relax.multi_hit == "None") {
relax.rate_class_arguments = {{relax.synonymous_rate_classes__,relax.rate_classes__}};
} else {

lfunction relax.model.with.GDD (type, code, rates) {
lfunction relax.model.MH.with.GDD (type, code, rates) {
def = relax.model.BS_REL_MH (type, code, rates);
options = {utility.getGlobalValue("terms.rate_variation.bins") : utility.getGlobalValue("relax.synonymous_rate_classes"),
utility.getGlobalValue("terms._namespace") : "relax._shared_srv"};
Expand All @@ -398,7 +399,7 @@ if (relax.multi_hit == "None") {
return def;
}

relax.model_generator = "relax.model.with.GDD";
relax.model_generator = "relax.model.MH.with.GDD";
relax.rate_class_arguments = relax.rate_classes;
}
} else {
Expand Down Expand Up @@ -463,7 +464,6 @@ if (relax.model_set == "All") { // run all the models
selection.io.startTimer (relax.json [terms.json.timers], "General descriptive model fitting", 2);




if (Type (relax.ge_guess) != "Matrix") {

Expand Down Expand Up @@ -507,7 +507,8 @@ if (relax.model_set == "All") { // run all the models
} ,

terms.search_grid : relax.initial_grid,
terms.search_restarts : relax.N.initial_guesses
terms.search_restarts : relax.N.initial_guesses,
terms.run_options.optimization_log : relax.optimization_log_file (".GE-1-log.json")
}
);

Expand All @@ -520,7 +521,8 @@ if (relax.model_set == "All") { // run all the models
relax.model_object_map,
{
terms.run_options.apply_user_constraints: "relax.init.k",
terms.run_options.retain_lf_object : TRUE
terms.run_options.retain_lf_object : TRUE,
terms.run_options.optimization_log : relax.optimization_log_file(".GE-2-log.json")

});

Expand All @@ -534,7 +536,8 @@ if (relax.model_set == "All") { // run all the models
relax.model_object_map,
{
terms.run_options.apply_user_constraints: "relax.init.k",
terms.run_options.retain_lf_object : TRUE
terms.run_options.retain_lf_object : TRUE,
terms.run_options.run_options.optimization_log : relax.optimization_log_file(".GE-log.json")

});
}
Expand Down Expand Up @@ -621,7 +624,7 @@ if (relax.model_set == "All") { // run all the models

/* now fit the two main models for RELAX */

if (relax.analysis_run_mode == relax.kGroupMode) {
if (relax.analysis_run_mode != relax.kGroupMode) {
io.ReportProgressMessageMD ("RELAX", "alt", "Fitting the alternative model to test K != 1");
} else {
io.ReportProgressMessageMD ("RELAX", "alt", "Fitting the alternative model with individual K parameters for " + relax.numbers_of_tested_groups + " branch groups");
Expand Down Expand Up @@ -938,13 +941,17 @@ function relax.FitMainTestPair () {

terms.search_grid : relax.initial_grid,
terms.search_restarts : relax.N.initial_guesses

}
);

}

//fprintf ("/Users/sergei/Desktop/gd.json", CLEAR_FILE, relax.general_descriptive.fit);
//fscanf ("/Users/sergei/Desktop/gd.json", "Raw", relax.general_descriptive.fit);
relax.general_descriptive.fit = Eval (relax.general_descriptive.fit);

relax.alternative_model.fit = estimators.FitLF (relax.filter_names, relax.trees, { "0" : relax.model_map}, relax.general_descriptive.fit, relax.model_object_map, {terms.run_options.retain_lf_object: TRUE});
relax.alternative_model.fit = estimators.FitLF (relax.filter_names, relax.trees, { "0" : relax.model_map}, relax.general_descriptive.fit, relax.model_object_map, {terms.run_options.retain_lf_object: TRUE, terms.run_options.optimization_log : relax.optimization_log_file ( "MainALT-log.json")});
io.ReportProgressMessageMD("RELAX", "alt", "* " + selection.io.report_fit (relax.alternative_model.fit, 9, relax.codon_data_info[terms.data.sample_size]));

KeywordArgument ("save-fit", "Save RELAX alternative model fit to this file (default is not to save)", "/dev/null");
Expand Down Expand Up @@ -997,7 +1004,9 @@ function relax.FitMainTestPair () {
relax.alternative_model.fit.take2 = estimators.FitLF (relax.filter_names, relax.trees, { "0" : relax.model_map},
relax.alternative_model.fit ,
relax.model_object_map,
{terms.run_options.retain_lf_object: TRUE}
{
terms.run_options.retain_lf_object: TRUE,
terms.run_options.optimization_log : relax.optimization_log_file("MainALT-redo-log.json")}
);


Expand Down Expand Up @@ -1121,7 +1130,7 @@ function relax.FitMainTestPair () {


if (relax.LRT[terms.p_value] <= relax.p_threshold) {
if ( relax.numbers_of_tested_groups == 2) {
if ( relax.numbers_of_tested_groups == 2 && relax.analysis_run_mode != relax.kGroupMode) {
if (relax.fitted.K > 1) {
console.log (">Evidence for *intensification of selection* among **test** branches _relative_ to the **reference** branches at P<="+ relax.p_threshold);
} else {
Expand All @@ -1132,7 +1141,7 @@ function relax.FitMainTestPair () {

}
} else {
if ( relax.numbers_of_tested_groups == 2) {
if ( relax.numbers_of_tested_groups == 2 && relax.analysis_run_mode != relax.kGroupMode) {
console.log (">No significant evidence for relaxation (or intensification) of selection among **test** branches _relative_ to the **reference** branches at P<="+ relax.p_threshold);
} else {
console.log (">>No significant evidence for differences of selective pressures among the test groups at P<="+ relax.p_threshold);
Expand Down Expand Up @@ -1712,6 +1721,14 @@ lfunction relax._renormalize (v, distro, mean) {

}

//------------------------------------------------------------------------------
function relax.optimization_log_file (extension) {
if (relax.OPTIMIZATION_LOGS) {
return relax.codon_data_info [terms.json.json] + extension;
}
return None;
}

//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
Expand Down
2 changes: 2 additions & 0 deletions res/TemplateBatchFiles/libv3/all-terms.bf
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,8 @@ namespace terms{
apply_user_constraints = "apply-user-constraints";
optimization_settings = "optimization-settings";
keep_filters = "use-filters";
optimization_log = "optimization_log";

}


Expand Down
18 changes: 14 additions & 4 deletions res/TemplateBatchFiles/libv3/tasks/estimators.bf
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,6 @@ function estimators.SetGlobals2(key2, value) {
}





estimators.ApplyExistingEstimates.set_globals[key3] = {
terms.id: key3,
Expand All @@ -182,11 +180,11 @@ function estimators.SetGlobals2(key2, value) {

__init_value = (initial_values[terms.global])[key3];


if (Type(__init_value) != "AssociativeList") {
__init_value = (initial_values[terms.global])[key2];
}


if (Type(__init_value) == "AssociativeList") {
if (__init_value[terms.fix]) {
estimators.ApplyExistingEstimates.df_correction += parameters.IsIndependent(value);
Expand Down Expand Up @@ -493,7 +491,6 @@ function estimators.ApplyExistingEstimatesToTree (_tree_name, model_descriptions

SetParameter (DEFER_CONSTRAINT_APPLICATION, 1, 0);


estimators.ApplyExistingEstimatesToTree.constraint_count = 0;


Expand Down Expand Up @@ -795,6 +792,11 @@ lfunction estimators.FitLF(data_filter, tree, model_map, initial_values, model_o



optimization_log = utility.Has (run_options, utility.getGlobalValue("terms.run_options.optimization_log"),"String");
if (optimization_log) {
utility.ToggleEnvVariable("PRODUCE_OPTIMIZATION_LOG", 1);
}

if (Type (can_do_restarts) == "AssociativeList") {
io.ReportProgressBar("", "Working on crude initial optimizations");
bestlog = -1e100;
Expand Down Expand Up @@ -827,6 +829,14 @@ lfunction estimators.FitLF(data_filter, tree, model_map, initial_values, model_o
}


if (optimization_log) {
utility.ToggleEnvVariable("PRODUCE_OPTIMIZATION_LOG", None);
utility.ToggleEnvVariable("USE_JSON_FOR_MATRIX", TRUE);

fprintf (run_options[utility.getGlobalValue("terms.run_options.optimization_log")], CLEAR_FILE, ^((&likelihoodFunction) + ".trace"));
utility.ToggleEnvVariable("USE_JSON_FOR_MATRIX", None);
}


if (Type(initial_values) == "AssociativeList") {
utility.ToggleEnvVariable("USE_LAST_RESULTS", None);
Expand Down
2 changes: 1 addition & 1 deletion src/core/global_things.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ namespace hy_global {
kErrorStringDatasetRefIndexError ("Dataset index reference out of range"),
kErrorStringMatrixExportError ("Export matrix called with a non-polynomial matrix argument"),
kErrorStringNullOperand ("Attempting to operate on an undefined value; this is probably the result of an earlier 'soft' error condition"),
kHyPhyVersion = _String ("2.5.40"),
kHyPhyVersion = _String ("2.5.41"),

kNoneToken = "None",
kNullToken = "null",
Expand Down
34 changes: 31 additions & 3 deletions src/core/likefunc.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5464,6 +5464,13 @@ long _LikelihoodFunction::Bracket (long index, hyFloat& left, hyFloat& middle
BufferToConsole (buf);
}
}
if (isnan (left)) {
left = lowerBound;
}
if (isnan (right)) {
right = middle + rightStep;
}

return -2;
} else {
middle=lowerBound+2.*leftStep;
Expand Down Expand Up @@ -5511,6 +5518,12 @@ long _LikelihoodFunction::Bracket (long index, hyFloat& left, hyFloat& middle
BufferToConsole (buf);
}
}
if (isnan (left)) {
left = middle - leftStep;
}
if (isnan (right)) {
right = upperBound;
}
return -2;
} else {
middle=MAX(upperBound-2.0*rightStep,lowerBound+leftStep);
Expand Down Expand Up @@ -6944,13 +6957,14 @@ void _LikelihoodFunction::LocateTheBump (long index,hyFloat gPrecision, hyFlo
right = -INFINITY,
middle = bestVal,
leftValue = NAN,
middleValue = maxSoFar,
rightValue = NAN,
middleValue = maxSoFar,
rightValue = NAN,
bp = 2.*gPrecision,
brentPrec = bracketSetting>0.?bracketSetting:gPrecision,
originalValue = index >= 0 ? GetIthIndependent(index) : 0.;

DetermineLocalUpdatePolicy ();


/*if (optimizatonHistory && ((_AssociativeList*)this->optimizatonHistory->GetByKey("Phases"))->Length() == 2171) {
verbosity_level = 1000;
Expand Down Expand Up @@ -7140,7 +7154,21 @@ void _LikelihoodFunction::LocateTheBump (long index,hyFloat gPrecision, hyFlo
}

if (index >= 0) {
LoggerSingleVariable (index, maxSoFar, bp, brentPrec, outcome != -1 ? right-left : -1., GetIthIndependent(index)-originalValue, bracket_step_count, likeFuncEvalCallCount-inCount-bracket_step_count, matrix_exp_count - inECount);
if (isnan (left) || isnan (right)) {
char buf [256];
snprintf (buf, 256, "\n\t[_LikelihoodFunction::LocateTheBump (index %ld) NAN left or right]", index);
_TerminateAndDump (_String (buf) & "\n" & "\nParameter name " & *GetIthIndependentName(index));
}

LoggerSingleVariable (index,
maxSoFar,
bp,
brentPrec,
outcome != -1 ? right-left : -1.,
GetIthIndependent(index)-originalValue,
bracket_step_count,
likeFuncEvalCallCount-inCount-bracket_step_count,
matrix_exp_count - inECount);
}

oneDFCount += likeFuncEvalCallCount-inCount-bracket_step_count;
Expand Down
2 changes: 0 additions & 2 deletions src/core/tree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2745,7 +2745,6 @@ void _TheTree::ExponentiateMatrices (_List& expNodes, long tc, long catI

_List * computedExponentials = hasExpForm? new _List (matrixQueue.lLength) : nil;

#ifdef _OPENMP
_SimpleList parallel, serial;
isExplicitForm.Each ([&parallel,&serial](long mx_count, unsigned long id) -> void {
if (mx_count < 0) serial << id; else parallel << id;
Expand All @@ -2755,7 +2754,6 @@ void _TheTree::ExponentiateMatrices (_List& expNodes, long tc, long catI
unsigned long cs = cBase<20 ? 10 : (cBase < 60 ? 5 : 2);

//printf ("_TheTree::ExponentiateMatrices %d total, %d no update, (block update %d)\n", parallel.lLength, serial.lLength, nt);
#endif

if (parallel.lLength) {
#ifdef _OPENMP
Expand Down

1 comment on commit 87168fd

@kjlevitz
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Performance Alert ⚠️

Possible performance regression was detected for benchmark 'Benchmark.js Benchmark'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 2.

Benchmark suite Current: 87168fd Previous: a79e78a Ratio
GARD.wbf Infinity secs/op (±0.000000%) null secs/op (±0.000000%) Infinity

This comment was automatically generated by workflow using github-action-benchmark.

CC: @klevitz

Please sign in to comment.