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

New warnings for METAD adn WALKERS_MPI #931

Merged
merged 15 commits into from
May 14, 2023

Conversation

Iximiel
Copy link
Member

@Iximiel Iximiel commented Apr 27, 2023

Description

This should resolve #926:

METAD now throws if the user ask for WALKERS_MPI without a MPI installation and also if the MPI routines are not set up.

I wanted the changes testable so:

  • I added a static variable to the Communicator to have the user access to the information "plumed is compiled with MPI" at runtime.
  • I created a small non standard reg test to test the error thrown without using external tools and that tests exactly the needed messages
  • I added the thrown exceptions with the messages set up to pass the new test

This is a draft because I wanted to show the solution that I have found, and I have not added the new test to the github workflow

Type of contribution
  • changes to code or doc authored by PLUMED developers, or additions of code in the core or within the default modules
  • changes to a module not authored by you
  • new module contribution or edit of a module authored by you
Copyright
  • I agree to transfer the copyright of the code I have written to the PLUMED developers or to the author of the code I am modifying.
  • the module I added or modified contains a COPYRIGHT file with the correct license information. Code should be released under an open source license. I also used the command cd src && ./header.sh mymodulename in order to make sure the headers of the module are correct.
Tests
  • I added a new regtest or modified an existing regtest to validate my changes.
  • I verified that all regtests are passed successfully on GitHub Actions.

@GiovanniBussi
Copy link
Member

Thanks @Iximiel ! A few comments:

  • You can directly access the macro __PLUMED_HAS_MPI. Notice that any code including Communicator.h is currently forced to define all the relevant macros or it will not work.

  • In general, I would avoid static member variables, since they can be modified by mistake with const_cast. I think using a function that returns a bool is more robust.

  • An alternative way is to use directly Communicator::initialized() which also check if MPI is initialized. I think this is even better since you want to make sure that this is true

  • Finally, in src we only keep source code and not tests. All tests are supposed to go in regtests, so that (a) they are executed on GitHub actions and (b) they are not installed

//If this Action is not compiled with MPI the user is informed and we exit gracefully
if(walkers_mpi_){
plumed_assert(Communicator::PlumedHasMPI) << "Invalid walkers configuration: WALKERS_MPI flag requires MPI compilation";
plumed_assert(Communicator::initialized()) << "Invalid walkers configuration: WALKERS_MPI needs the communicator correctly initialized.";
Copy link
Member

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!!

Copy link
Member Author

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

Copy link
Member

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

@Iximiel
Copy link
Member Author

Iximiel commented Apr 27, 2023

Thanks @Iximiel ! A few comments:

* You can directly access the macro __PLUMED_HAS_MPI. Notice that any code including `Communicator.h` is currently forced to define all the relevant macros or it will not work.

Yes, but I set up the test as a completely external code, so when I compile the test I'm not seeing the compile-time definitions of PLUMED, or at least, I do not know how to access to them.

* In general, I would avoid static member variables, since they can be modified by mistake with const_cast. I think using a function that returns a bool is more robust.

My bad, now Communicator::PlumedHasMPI() is a function

* An alternative way is to use directly Communicator::initialized() which also check if MPI is initialized. I think this is even better since you want to make sure that this is true

when Communicator::initialized() returns false I don't know if it is because PLUMED is compiled without MPI or the MPI communication is not initialized

* Finally, in src we only keep source code and not tests. All tests are supposed to go in regtests, so that (a) they are executed on GitHub actions and (b) they are not installed

the test is in not in src/, but in unittest. Since is very far from the standard you use in the regtest directory, I though it was a good idea to keep it separated before the full merge

@carlocamilloni
Copy link
Member

Hi @Iximiel, this is good with me! as a side note, the test that is failing now is a "style check" one. We enforce some basic styling in the code and you can get it fixed by running "make astyle" in src/ and commit again

@GiovanniBussi
Copy link
Member

@Iximiel regarding this point:

Yes, but I set up the test as a completely external code, so when I compile the test I'm not seeing the compile-time definitions of PLUMED, or at least, I do not know how to access to them.

You are right. However, since we use some of the compile-time definitions of PLUMED in header files (actually very few, but __PLUMED_HAS_MPI is currently one of those), in order to properly compile source files including those header files you need to use the proper compile-time definitions. This is an (unsolved) problem for anyone willing to use plumed as an external library. Indeed, I am not aware of general solutions to this problem. A partial solution is that all those macros are included in the installed file lib/pkgconfig/plumedInternals.pc, but this is only for packages using pkgconfig. I guess for packages using cmake it should be straightforward.

Given this, once you bring your test within the regtest library, this is designed to make the macros available when compiling regtests.

So, I think it's fine using these macros in regtests. But it's also ok (and I think better) to write a small function that makes the bool available for outside usage.

@GiovanniBussi
Copy link
Member

My bad, now Communicator::PlumedHasMPI() is a function

another stylistic convention that we have is: classes upper case, functions lower case. So perhaps it's more consistent to have Communicator::plumedHasMPI()

:-)

@codecov-commenter
Copy link

codecov-commenter commented Apr 28, 2023

Codecov Report

Patch coverage: 100.00% and project coverage change: +0.09 🎉

Comparison is base (aadcb7e) 85.73% compared to head (1a83631) 85.82%.

❗ Current head 1a83631 differs from pull request most recent head 3f992bf. Consider uploading reports for the commit 3f992bf to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #931      +/-   ##
==========================================
+ Coverage   85.73%   85.82%   +0.09%     
==========================================
  Files         600      600              
  Lines       53472    54722    +1250     
==========================================
+ Hits        45843    46964    +1121     
- Misses       7629     7758     +129     
Impacted Files Coverage Δ
src/crystallization/EnvironmentSimilarity.cpp 94.06% <ø> (+0.02%) ⬆️
src/drr/DRR.h 100.00% <ø> (ø)
src/tools/Communicator.h 89.47% <ø> (ø)
src/tools/SwitchingFunction.cpp 95.95% <ø> (+0.14%) ⬆️
src/ves/TD_Multicanonical.cpp 96.53% <ø> (+0.10%) ⬆️
src/ves/TD_Uniform.cpp 98.11% <ø> (+0.11%) ⬆️
src/bias/MetaD.cpp 87.95% <100.00%> (+0.39%) ⬆️
src/drr/DRR.cpp 93.33% <100.00%> (+0.81%) ⬆️
src/drr/DynamicReferenceRestraining.cpp 90.55% <100.00%> (+0.29%) ⬆️
src/drr/drrtool.cpp 93.44% <100.00%> (-1.87%) ⬇️
... and 2 more

... and 262 files with indirect coverage changes

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@Iximiel
Copy link
Member Author

Iximiel commented Apr 28, 2023

I have moved the new test in the regtest folder and I did some addition to make it work via make check in the main directory and with make in the regtest directory with an environment ready to launch an installed plumed, moreover is compatible with make reset

I runned astyle on the src, I think this can exit the draft state

@Iximiel Iximiel marked this pull request as ready for review April 28, 2023 10:35
@carlocamilloni carlocamilloni merged commit ba817b6 into plumed:master May 14, 2023
19 checks passed
carlocamilloni pushed a commit that referenced this pull request May 14, 2023
* Test with and without MPI

* WALKERS_MPI now throws without MPI initializated

* test and error message now are more clear

* clearer comments in the tests

* added the last newline to the new files

* PlumedHasMPI is now a function

* camelCased plumedHasMPI

* style aligned

* moved files

* created compiledtest type

* compiled tests now support align with the other tests

* Moved the new test in the basic directory

* now the new test is completely aligned with the old ones

* removed compiled test

* updated the reference

---------

Co-authored-by: Daniele Rapetti <daniele.rapetti@sissa.it>
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.

Need an informative errore when a user uses METAD WALKERS_MPI but plumed was compiled without MPI
4 participants