Skip to content

Commit

Permalink
Bug fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
spond committed Jan 28, 2019
1 parent b97cb94 commit 040e098
Show file tree
Hide file tree
Showing 10 changed files with 60 additions and 54 deletions.
26 changes: 9 additions & 17 deletions res/TemplateBatchFiles/SM-2019.bf
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,9 @@ utility.ForEachPair (sm.partitions , "_key_", "_value_", '
');


sm.bootstrap = trees.BootstrapSupport (sm.tree);
sm.replicates = io.PromptUser(">How many bootstrap replicates", 100, 1, 1000000, TRUE);

sm.bootstrap = trees.BootstrapSupport (sm.tree);
sm.bootstrap_weighting = {"default" : 0.2};

if (utility.Array1D (sm.bootstrap )) {
Expand All @@ -68,16 +69,8 @@ if (utility.Array1D (sm.bootstrap )) {

}

/*
sm.method = io.SelectAnOption ({"Standard" : "Permute leaf labels freely (unconstrained)",
"Restricted" : "Permute leaf labels in subtrees defined by randomly chosen internal branches (rate 1/4)"},
"Resampling method"
);
*/


sm.replicates = io.PromptUser(">How many bootstrap replicates", 100, 1, 1000000, TRUE);

sm.tree.string = sm.tree[terms.trees.newick_with_lengths];
sm.node_labels = {};

Expand All @@ -95,13 +88,8 @@ utility.ForEachPair (sm.partitions, "_regexp_", "_leaves_",
);


//console.log (T);
//console.log (sm.node_labels);

sm.mp = //trees.ParsimonyLabel ("T", sm.node_labels);
Max (T, {"labels": sm.node_labels});
//console.log (sm.mp);

sm.mp = Max (T, {"labels": sm.node_labels});
sm.score = sm.mp ["score"];

io.ReportProgressMessageMD('SM', 'result', 'Inferred **' + sm.score + '** migration events');
Expand Down Expand Up @@ -148,7 +136,6 @@ sm.dist.structured.cutoff = sm.dist.structured [sm.replicates * 90 $ 100];

sm.structured.p = +sm.dist.shuffled["_MATRIX_ELEMENT_VALUE_<= sm.dist.structured.cutoff"];


sm.sampled_stats = math.GatherDescriptiveStats (sm.resampled_distribution[-1][0]);
sm.sampled_stuctured_stats = math.GatherDescriptiveStats (sm.resampled_distribution[-1][1]);

Expand All @@ -167,6 +154,9 @@ io.ReportProgressMessageMD('SM', 'reshuffled', 'Based on **' + sm.replicates +
+ Format ( sm.structured.p /(sm.replicates+1), 6, 3));
io.ReportProgressMessageMD('SM', 'reshuffled', '\n> This p-value is derived by comparing the distribution of migration events from the panmictic reshuffle to the 90% percentile of the simulated distribution of expected migrations if leaf labels are permuted partially respecting subtree structure (block permutations), which results in **' + sm.dist.structured.cutoff + '** expected migrations');

sm.json_path = sm.tree[terms.data.file] + ".json";
io.ReportProgressMessageMD('SM', 'file', 'Saving detailed report as a JSON file to \`' + sm.json_path + '\`');

sm.json = {
'replicates' : sm.replicates,
'compartments' : sm.group_count,
Expand All @@ -178,7 +168,9 @@ sm.json = {
'simulations' : {
'panmictic' : sm.dist.shuffled,
'structured' : sm.dist.structured
}
},
"events" : sm.mp["substitutions"]
};

io.SpoolJSON (sm.json, sm.json_path);
return sm.json;
17 changes: 16 additions & 1 deletion res/TemplateBatchFiles/libv3/tasks/trees.bf
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ lfunction trees.GetTreeString(look_for_newick_tree) {
SetDialogPrompt("Please select a tree file for the data:");
fscanf(PROMPT_FOR_FILE, REWIND, "Raw", treeString);
fprintf(stdout, "\n");

look_for_newick_tree = utility.getGlobalValue ("LAST_FILE_PATH");

if (regexp.Find(treeString, "^#NEXUS")) {
ExecuteCommands(treeString);
Expand Down Expand Up @@ -196,7 +198,11 @@ lfunction trees.GetTreeString(look_for_newick_tree) {
}
}

return treeString;
return
{
utility.getGlobalValue("terms.data.file"): look_for_newick_tree,
utility.getGlobalValue("terms.data.tree"): treeString
};
}


Expand Down Expand Up @@ -379,6 +385,13 @@ lfunction trees.RootTree(tree_info, root_on) {
*/
lfunction trees.ExtractTreeInfo(tree_string) {

if (Type (tree_string) == "AssociativeList") {
file_name = tree_string[^"terms.data.file"];
tree_string = tree_string[^"terms.data.tree"];
} else {
file_name = None;
}

Topology T = tree_string;

branch_lengths = BranchLength(T, -1);
Expand Down Expand Up @@ -418,6 +431,8 @@ lfunction trees.ExtractTreeInfo(tree_string) {
^"terms.trees.model_list": Columns(modelMap),
^"terms.trees.rooted" : rooted,
^"terms.trees.meta" : T.__meta,
^"terms.data.file" : file_name

};
}

Expand Down
11 changes: 7 additions & 4 deletions src/core/batchlan.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,15 +263,15 @@ void MPISendString (_String const& theMessage, long destID, bool isErro
{

long messageLength = theMessage.length(),
transferCount = 0;
transferCount = 0L;

if (isError) {
messageLength = -messageLength;
}

ReportMPIError(MPI_Send(&messageLength, 1, MPI_LONG, destID, HYPHY_MPI_SIZE_TAG, MPI_COMM_WORLD),true);

if (messageLength == 0) {
if (messageLength == 0L) {
return;
}

Expand Down Expand Up @@ -300,8 +300,8 @@ void MPISendString (_String const& theMessage, long destID, bool isErro
//____________________________________________________________________________________
_String* MPIRecvString (long senderT, long& senderID) {
_String* theMessage = nil;
long messageLength = 0,
transferCount = 0;
long messageLength = 0L,
transferCount = 0L;

int actualReceived = 0;
bool isError = false;
Expand Down Expand Up @@ -329,6 +329,8 @@ _String* MPIRecvString (long senderT, long& senderID) {
isError = true;
messageLength = -messageLength;
}

//printf ("MPIRecvString size tag %ld (size chunk %ld) \n",messageLength, MPI_SEND_CHUNK);

if (!isError) {
//MPI_Get_count (&status,MPI_CHAR,&actualReceived);
Expand All @@ -352,6 +354,7 @@ _String* MPIRecvString (long senderT, long& senderID) {
}

if (messageLength-transferCount) {
//printf ("Clause 2 %d %d\n", messageLength-transferCount, theMessage->length());
ReportMPIError(MPI_Recv((void*)(theMessage->get_str()+transferCount), messageLength-transferCount, MPI_CHAR, senderT, HYPHY_MPI_STRING_TAG, MPI_COMM_WORLD,&status),false);
MPI_Get_count (&status,MPI_CHAR,&actualReceived);
if (actualReceived!=messageLength-transferCount) {
Expand Down
14 changes: 5 additions & 9 deletions src/core/batchlanruntime.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1969,21 +1969,17 @@ bool _ElementaryCommand::HandleMPIReceive (_ExecutionList& current_program)

#ifdef __HYPHYMPI__




receptacle = _ValidateStorageVariable (current_program, 1UL);
_Variable* node_index_storage = _ValidateStorageVariable (current_program, 2UL);

long target_node = _ProcessNumericArgumentWithExceptions(*GetIthParameter(0UL), current_program.nameSpacePrefix),
node_count = hy_env::EnvVariableGetDefaultNumber(hy_env::mpi_node_count);
node_count = hy_env::EnvVariableGetNumber(hy_env::mpi_node_count);

if (target_node < -1L || target_node >= node_count) {
throw (GetIthParameter(1UL)->Enquote () & " (=" & node_count & ") is not a valid MPI node index (or -1 to accept from any node");
throw (GetIthParameter(1UL)->Enquote () & " (=" & node_count & ") must be a valid MPI node index (or -1 to accept from any node");
}

long received_from;

receptacle->SetValue(new _FString (MPIRecvString (target_node,received_from)), false);
node_index_storage->SetValue (new _Constant (received_from), false);

Expand All @@ -2009,10 +2005,10 @@ bool _ElementaryCommand::HandleMPISend (_ExecutionList& current_program){

#ifdef __HYPHYMPI__
long target_node = _ProcessNumericArgumentWithExceptions(*GetIthParameter(0UL), current_program.nameSpacePrefix),
node_count = hy_env::EnvVariableGetDefaultNumber(hy_env::mpi_node_count);
node_count = hy_env::EnvVariableGetNumber(hy_env::mpi_node_count);

if (target_node < 0L || target_node >= node_count) {
throw (GetIthParameter(1UL)->Enquote () & " (=" & node_count & ") is not a valid MPI node index");
throw (GetIthParameter(1UL)->Enquote () & " (=" & node_count & ") is not a valid MPI node index; valud range is " & target_node & " to " & (node_count-1));
}

_StringBuffer message_to_send (1024UL);
Expand All @@ -2039,7 +2035,7 @@ bool _ElementaryCommand::HandleMPISend (_ExecutionList& current_program){
if (message_to_send.nonempty()) {
MPISendString(message_to_send, target_node);
} else {
throw ("An ivalid (empty) MPI message");
throw (_String ("An invalid (empty) MPI message"));
}
#else
throw ("Command not supported for non-MPI versions of HyPhy. HBL scripts need to check for MPI before calling MPI features");
Expand Down
9 changes: 9 additions & 0 deletions src/core/global_things.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@

using namespace hy_env;

#define __HYPHY_MPI_MESSAGE_LOGGING__

extern _SimpleList freeSlots;


Expand Down Expand Up @@ -356,6 +358,13 @@ namespace hy_global {
has_terminal_stdout = isatty (STDOUT_FILENO);
has_terminal_stderr = isatty (STDERR_FILENO);



#ifdef __HYPHYMPI__
hy_env :: EnvVariableSet (hy_env::mpi_node_id, new _Constant (hy_mpi_node_rank), false);
hy_env :: EnvVariableSet (hy_env::mpi_node_count, new _Constant (hy_mpi_node_count), false);
#endif

#if not defined (__HYPHY_MPI_MESSAGE_LOGGING__) && defined (__HYPHYMPI__)
if (hy_mpi_node_rank == 0L) {
#endif
Expand Down
2 changes: 1 addition & 1 deletion src/core/matrix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6067,7 +6067,7 @@ HBLObjectRef _Matrix::Random (HBLObjectRef kind) {
_String pdfkey ("PDF"),
* arg0 = (_String *)keys->GetItem(0L);
DeleteObject (keys);
if (arg0->Equal(&pdfkey)) {
if (arg0->Equal(pdfkey)) {
_String pdf ((_String *) (pdfArgs->GetByKey(pdfkey,STRING))->toStr()),
arg ("ARG0");

Expand Down
17 changes: 5 additions & 12 deletions src/mains/unix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -600,23 +600,16 @@ int main (int argc, char* argv[])
#endif

#ifdef __HYPHYMPI__
int rank,
size;

MPI_Init (&argc, &argv);
int rank,
size;

MPI_Comm_rank(MPI_COMM_WORLD, &rank);
MPI_Comm_size(MPI_COMM_WORLD, &size);

hy_env :: EnvVariableSet (hy_env::mpi_node_id, new _Constant (rank), false);
hy_env :: EnvVariableSet (hy_env::mpi_node_count, new _Constant (size), false);

hy_mpi_node_rank = rank;
hy_mpi_node_count = size;

if (rank == 0) {
mpiNodesThatCantSwitch.Populate (size,1,0);
}



/*
int i = 0;
char hostname[256];
Expand Down
6 changes: 2 additions & 4 deletions src/utils/hyphyunixutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ void mpiNormalLoop (int, int, _String &);
void mpiOptimizerLoop (int, int);

void mpiBgmLoop (int, int);
_SimpleList mpiNodesThatCantSwitch;
#endif

extern _List batchLanguageFunctionNames;
Expand Down Expand Up @@ -242,7 +241,7 @@ void mpiNormalLoop (int rank, int size, _String & baseDir)
ReportWarning ("[MPI] Returned from mpiOptimizer loop");
hyphyMPIOptimizerMode = _hyphyLFMPIModeNone;
PushFilePath(baseDir, false, false);
} else if ( theMessage->Equal (&mpiLoopSwitchToBGM) ) {
} else if ( *theMessage == mpiLoopSwitchToBGM) {
ReportWarning ("[MPI] Received signal to switch to mpiBgmLoop");
MPISendString (mpiLoopSwitchToBGM, senderID); // feedback to source to confirm receipt of message
mpiBgmLoop (rank, size);
Expand Down Expand Up @@ -291,8 +290,7 @@ void mpiNormalLoop (int rank, int size, _String & baseDir)
}

MPISendString(*resStr,senderID);



if (hy_env::EnvVariableTrue (preserveSlaveNodeState) == false) {
PurgeAll (true);
InitializeGlobals ();
Expand Down
10 changes: 5 additions & 5 deletions tests/hbltests/UnitTests/HBLCommands/Random.bf
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ function runTest () {
// *** set a breakpoint in malloc_error_break to debug

// The code below returns the errors
//mean1 = {{1,1,1}};
//cov1 = {{1,0}{0,1}};
//a1 = {"PDF":"Gaussian","ARG0":cov1};
//z = Random(mean1,a1);
//fprintf (stdout, 'z: ', z, '\n');
mean1 = {{1,1,1}};
cov1 = {{1,0}{0,1}};
a1 = {"PDF":"Gaussian","ARG0":cov1};
z = Random(mean1,a1);
fprintf (stdout, 'z: ', z, '\n');

//mean2 = {{1,1,1}};
//cov2 = {{1,0}{0,1}};
Expand Down
2 changes: 1 addition & 1 deletion tests/hbltests/libv3/BUSTED.wbf
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ LoadFunctionLibrary("SelectionAnalyses/BUSTED.bf", {
"0": "Universal",
"1": PATH_TO_CURRENT_BF + "data/CD2.nex",
"2": "GROUP3",
"3": "All"
"3": "No"
});

0 comments on commit 040e098

Please sign in to comment.