-
Notifications
You must be signed in to change notification settings - Fork 289
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
New warnings for METAD adn WALKERS_MPI #931
Merged
Merged
Changes from all commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
398b63b
Test with and without MPI
Iximiel 4d6859c
WALKERS_MPI now throws without MPI initializated
Iximiel c7a97fb
test and error message now are more clear
Iximiel ba30aa1
clearer comments in the tests
Iximiel a39d918
added the last newline to the new files
Iximiel bd4d611
PlumedHasMPI is now a function
Iximiel 2f6ebaf
camelCased plumedHasMPI
Iximiel 2c3fd41
style aligned
Iximiel 1067974
moved files
Iximiel 49aae4c
created compiledtest type
Iximiel 0a18446
compiled tests now support align with the other tests
Iximiel b881e98
Moved the new test in the basic directory
Iximiel 556cb4e
now the new test is completely aligned with the old ones
Iximiel 9a556af
removed compiled test
Iximiel 3f992bf
updated the reference
Iximiel File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
include ../../scripts/test.make |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
type=make | ||
# this is needed because we are explicitly checking some exception message | ||
export PLUMED_STACK_TRACE=no |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
METAD WALKER_MPI : Exception thrown, correct message |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#include <fstream> | ||
|
||
#include "plumed/wrapper/Plumed.h" | ||
#include "plumed/tools/Communicator.h" | ||
|
||
constexpr unsigned nat=10; | ||
//it is a struct because we don't need getter/setters (for now) | ||
struct plumedThrowChecker{ | ||
unsigned natoms=nat; | ||
std::vector<double> positions=[](unsigned natoms){ | ||
std::vector<double> toret(natoms*3,0.0); | ||
for(unsigned i=0; i<3*natoms; i++) toret[i]=i; | ||
return toret; | ||
}(nat); | ||
std::vector<double> masses{nat,1.0}; | ||
std::vector<double> forces{3*nat,0.0}; | ||
std::vector<double> box{9,0.0}; | ||
std::vector<double> virial{9,0.0}; | ||
///This initializes a new plumed to test each throw in the cleanliest way possible | ||
int checkThrow (std::ostream& out,std::string name, std::string cmd, std::string expectedMessage){ | ||
//GIVEN an initialized Plumed interface | ||
PLMD::Plumed plumed; | ||
|
||
plumed.cmd("setNatoms",&natoms); | ||
int step=0; | ||
plumed.cmd("setLogFile","test.log"); | ||
plumed.cmd("init"); | ||
plumed.cmd("setStep",&step); | ||
plumed.cmd("setPositions",positions.data()); | ||
plumed.cmd("setBox",box.data()); | ||
plumed.cmd("setForces",forces.data()); | ||
plumed.cmd("setVirial",virial.data()); | ||
plumed.cmd("setMasses",masses.data()); | ||
|
||
plumed.cmd("readInputLine","d: DISTANCE ATOMS=1,2"); | ||
plumed.cmd("readInputLine","d1: DISTANCE ATOMS={1 2}"); | ||
///TODO: expand with a "readInputLines" to give the possibility to test in more situations | ||
try { | ||
//WHEN the user ask for the given input | ||
plumed.cmd("readInputLine",cmd.c_str()); | ||
//THEN plumed should gracefully exit with a clear error message | ||
} catch(PLMD::Plumed::ExceptionError &e) { //correct throw, we are happy | ||
std::string exceptionText{e.what()}; | ||
out << name << " : "; | ||
if (exceptionText.find(expectedMessage) != std::string::npos) { | ||
out << "Exception thrown, correct message\n"; | ||
return 0; | ||
} | ||
|
||
out << "Exception thrown, wrong message: " | ||
<< e.what() ; | ||
out << "\tExpected message should contain: \"" | ||
<< expectedMessage << "\"\n"; | ||
return 1; | ||
} | ||
out << "Exception not thrown\n"; | ||
return 1; | ||
} | ||
}; | ||
|
||
int main(int, char**) { | ||
std::ofstream out("output"); | ||
plumedThrowChecker ptc; | ||
//When the user aks for a WALKERS_MPI in the METAD action, | ||
//if MPI is not installed then the user must be informed | ||
//if MPI is installed then the comunications must be already set up | ||
//WHEN PLUMED is not compiled with MPI or the MPI routines are not initialized | ||
std::string expectedMessage="WALKERS_MPI flag requires MPI compilation"; | ||
if (PLMD::Communicator::plumedHasMPI()) { | ||
expectedMessage="WALKERS_MPI needs the communicator correctly initialized"; | ||
} | ||
ptc.checkThrow(out,"METAD WALKER_MPI", | ||
"METAD ARG=d,d1 SIGMA=0.1,0.2 HEIGHT=0.1 PACE=2 RESTART=YES WALKERS_MPI", | ||
expectedMessage); | ||
|
||
//add other throw messages checks | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here I think you could just remove the first test.
Beside this, the way to raise the warnings is correct!!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In my first draft i had a single error message with "MPI is not initialized or plumed is not compiled with MPI", but I think is more clear for the user to have two more specialized messages, and easier to test for the developers
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you are right