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

Reaction methods bug fixes #4589

Merged
merged 4 commits into from
Oct 14, 2022
Merged

Conversation

jngrad
Copy link
Member

@jngrad jngrad commented Oct 7, 2022

Description of changes:

@jngrad jngrad added this to the Espresso 4.3.0 milestone Oct 7, 2022
@jngrad jngrad requested a review from davidbbeyer October 7, 2022 16:25
@jngrad jngrad force-pushed the reaction_bugfixes branch from aaabe63 to 8400107 Compare October 7, 2022 16:54
@jngrad jngrad added the Testcase label Oct 7, 2022
@jngrad jngrad marked this pull request as draft October 7, 2022 18:19
jngrad added 3 commits October 7, 2022 21:30
Restore original velocities when a displacement move is rejected.
When one move in the sequence is rejected, skip the remaining move
attempts. Fix infinite loop when not enough particles are available.
When no user-defined type is available, explicitly assign type 0.
This is necessary for tracking particles ids in reaction methods.
@jngrad jngrad force-pushed the reaction_bugfixes branch from 8400107 to 292bf32 Compare October 7, 2022 19:30
@jngrad jngrad marked this pull request as ready for review October 7, 2022 22:00
@jngrad jngrad requested a review from pm-blanco October 11, 2022 13:02
@pm-blanco
Copy link
Contributor

pm-blanco commented Oct 12, 2022

Thanks for involving me in this PR! There are some things that I am not convinced about the MC displacement move method:

  • I think that the input variable n_part is ambiguous: one could propose a new configuration moving n_part (as in the current implentation) or one could choose n_part particles and perform an MC trial move with each. For consistency with the rest of MC methods, I propose that instead we use steps as input variable, standing for the number of MC steps that the method would do. Then each MC step one particle is randomly chosen and moved, and the move is accepted or rejected according the probability given by the canonical ensemble.
  • Instead of having a method for moving only particles of one specific type, I think that the method should by default try to move any particle. Then, one could provide an optional argument (something like list_particle_types_to_move) which could be used to restrict which particles are selected.

@davidbbeyer do you think that such an implementation would still be compatible for your project? If yes and all of you agree with this alternative implementation I volunteer to change the code accordingly

@jngrad
Copy link
Member Author

jngrad commented Oct 13, 2022

Offline discussion with @pm-blanco: the Monte Carlo displacement move method in its current state could benefit from a few improvements, but that work might take a couple of weeks to complete. There is also a newly discovered bug when combining constant-pH with Widom insertion, which may be relevant for Monte Carlo displacement moves too, since displacement moves can be carried out from any reaction method class instance.

Since this PR fixes important bugs and is blocking the parallel Monte Carlo project, we agreed that this PR should be merged now. The other points can be taken care of in an upcoming PR that will be orthogonal to the parallel MC project.

pm-blanco
pm-blanco previously approved these changes Oct 13, 2022
Copy link
Contributor

@pm-blanco pm-blanco left a comment

Choose a reason for hiding this comment

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

As discussed with @jngrad we accept this PR as it is for now to allow the developing of the parallelization of the MC and we will continue improving it in a future PR

@jngrad jngrad requested a review from reinaual October 13, 2022 11:52
Comment on lines 593 to 599
m_tried_configurational_MC_moves += 1;
particle_inside_exclusion_range_touched = false;

auto const particle_number_of_type = number_of_particles_with_type(type);
if (particle_number_of_type == 0 or
particle_number_of_type_to_be_changed == 0) {
if (n_part == 0) {
// reject
return false;
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this really intentional that we increase the counter of m_tried_configurational_MC_moves when n_part is zero? Did one really try a configurational move if one doesn't change anything?

Copy link
Member Author

Choose a reason for hiding this comment

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

That's an oversight. Calling this method with 0 particles doesn't make sense, and it isn't meaningful to return true or false because no move was actually attempted. It's even worse if n_part is a negative number... I'll fix that.

Comment on lines 596 to 604
if (n_part <= 0) {
throw std::domain_error(
"Parameter 'particle_number_to_be_changed' must be >= 1");
}
auto const n_particles_of_type = number_of_particles_with_type(type);
if (n_part > n_particles_of_type) {
throw std::domain_error(
"Parameter 'particle_number_to_be_changed' must be less or equal to "
"the number of particles in the system");
}
Copy link
Contributor

@reinaual reinaual Oct 13, 2022

Choose a reason for hiding this comment

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

We should spend a second thought on this change, because it will probably break old espresso scripts.
What I was thinking of is a reactive system (e.g. GCMC) where you have initially setup a species that will react with time. At some point it might happen that this species has completely reacted, but one might have used displacement moves in the script to change the configuration. In such a case one would have just rejected the move in the old implementation, but now an error is thrown. An additional, explicit check before the displacement moves would be necessary to prevent this error.
The very same happens when providing zero, which might happen when using the current particle number as the number of displacement moves.

Disclaimer: I'm not claiming any of this is good practice, but it used to work and I have written scripts where this change would also break my code.

@jngrad jngrad force-pushed the reaction_bugfixes branch from cb58c0e to 7893235 Compare October 13, 2022 21:10
@jngrad jngrad added the automerge Merge with kodiak label Oct 14, 2022
@kodiakhq kodiakhq bot merged commit 99b4b4e into espressomd:python Oct 14, 2022
@jngrad jngrad deleted the reaction_bugfixes branch October 14, 2022 11:51
@jngrad jngrad removed this from the Espresso 4.3.0 milestone Nov 21, 2022
@jngrad jngrad added this to the Espresso 4.2.1 milestone Nov 21, 2022
jngrad pushed a commit to jngrad/espresso that referenced this pull request Nov 30, 2022
Description of changes:
- track particles with default-constructed type 0 (fixes espressomd#4588)
- restore the original particle velocity when a Monte Carlo displacement move is rejected (fixes espressomd#4587)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Particles without user-defined type are not tracked by reactions Monte Carlo displacement move is broken
3 participants