-
Notifications
You must be signed in to change notification settings - Fork 189
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
Refactor integrator framework to reduce coupling #3390
Conversation
Split Integrator class in multiple classes managed by an IntegratorHandle class. Cleanup integrator documentation.
Remove code duplication by having all the integrator logic in a single class SteepestDescent. The MinimizeEnergy class is now a wrapper to setup and run the steepest descent integrator. API change: it is now necessary to restore the original integrator after energy minimization using `system.minimize_energy.disable()`.
Give steepest descent the same core interface as other integrators. Remove the code logic in `steepest_descent()` that saved then restored the previous value of the `integ_switch` flag (this is now achieved by the `MinimizeEnergy` Python class, thus making `Integrator` Python classes free of side effects).
Check out this pull request on You'll be able to see Jupyter notebook diff and discuss changes. Powered by ReviewNB. |
Codecov Report
@@ Coverage Diff @@
## python #3390 +/- ##
========================================
Coverage ? 86%
========================================
Files ? 538
Lines ? 25299
Branches ? 0
========================================
Hits ? 21818
Misses ? 3481
Partials ? 0 Continue to review full report at Codecov.
|
Feel free to comment on this WIP. Possible talking points:
|
I'll have a read today and will give you some feedback. |
int integrate_set_steepest_descent(const double f_max, const double gamma, | ||
const int max_steps, | ||
const double max_displacement) { | ||
if (f_max < 0.0) { |
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.
f_max == 0
should be allowed.
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.
it is allowed
Generally I don't think the |
If the goal is to keep the current syntax for the integrators ( I think the logical next step from here would be to put the core integrators into classes, akin to the |
Makes things much more clear on the Python side. I think, the legacy Minimizeenergy interface can be removed. The 4.2 release will break the interface non-silently in a few places anyway. On a different note, integrate_vv() is no longer responsible for Velocity-Verlet alone, so the _vv should probably be removed. Is there a reason to manually allocate the memory for the steepest descent struct? |
As I was saying, this should be kept as a free function. That is a common think, and I can easily picture how forgetting to switch back the integrator after energy minimization can be a common error mode. @RudolfWeeber I don't think that core refactoring is in scope for this PR, let's tackle this in the next step. |
Although I initially planned to remove completely the This strategy doesn't seem satisfactory from an abstraction perspective: minimization algorithms like steepest descent, simulated annealing or genetic algorithms don't have a well-defined notion of time (i.e. at each "integration" step, the time step is different for every particle in the system) and can't really be considered as integrators. It's unfortunate the steepest descent algorithm was initially developed as a pseudo-integrator, but until we find a need to decouple the integration loop (e.g. to support other minimization algorithms), we would probably be better off by removing the Designing the
Yes, that's the main goal. In the future, we could think of a new syntax like
Not really. The bug mentioned in the issue was already shipped in 4.1.1, and the side-effects mentioned in the commit messages are only relevant to this refactoring.
Good idea.
Probably not, I'll have a look.
The changes proposed by Rudolf seems small enough to me. |
There are a few, e.g. the |
29566ae
to
062549b
Compare
062549b
to
95549a9
Compare
The integration function does more than just velocity Verlet.
@jngrad yes, this looks good to me. Any other opinions on this? With this the high level logic of |
If we are keeping steepest descent as a free function (which I'd personally not do as per Pep8 reommendation to have peferrabley only one way to do a thing), the function should
|
I agree with the goal to split system state from stuff that modifies the system. Probably, the core needs to be done first, though. |
It seems to me that having two ways to do it for now is just the price of not changing the whole API at once. I don't have strong opinions on the name, and returning available information to the user is always a good idea. |
This requires introducing a new global variable to store the state of the steepest descent, because steepest descent does not increment the simulation time and there is no simulation step counter. |
@jngrad why can't you just return the number of steps that were executed from the function? |
@fweik this would require Also, we should make sure the return value of espresso/src/core/io/writer/h5md_core.cpp Line 385 in 467581d
|
You could always return the number of steps that are integrated. This also does not need communication, because this information is available on the head node, no? |
Remove documentation of inexistent REQ_* MPI tags and update instructions to add new callbacks. Clean up documentation of functions used in callbacks. Remove references to the Tcl setmd command.
Implement Communication::Result::Ignore and add a new operation Communication::Result::MasterRank to read from the head node only.
In boost::mpi version 1.69 (default on CentOS/Fedora), reduction functions taking a user-defined operation expect a struct with an operator() method. Lambda functions are no longer allowed and generate a compilation error: "error: use of deleted function '<lambda(const int&, const int&)>::<lambda>()'".
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.
LGTM except for one small issue.
Fixes #3271
Description of changes:
IntegratorHandle
Python class to store the currently active integratorsteepest_descent()
that reverted theinteg_switch
value after integrationespressomd.minimize_energy.MinimizeEnergy
toespressomd.integrate.SteepestDescent
espressomd.minimize_energy.MinimizeEnergy
as a wrapper for backward compatibilityespressomd.minimize_energy.MinimizeEnergy
: now a stateless free function that takes an espresso system as argument, renamed tosteepest_descent