feat: enable discrete swaps #58
Open
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.
Summary
This PR enables users to setup DiscreteSwap moves in their input toml file.
This move is a bit different than the others, as it requires knowledge of the number of particles of each species in the system. Its instantiation can therefore only be done after the system has been setup.
If in the future some moves that change the number of particles of each species are implemented (something like grand canonical moves for instance), then the current implementation of DiscreteSwap will produce spurious results (but won't raise an error).
Alternative implementation
I kept the existing implementation of the DiscreteSwap struct intact, and only added a new constructor.
Alternatively, the number of particle per species could be a parameter (the vector passed to the actions) rather than a field of the class.
It's a bit unclear to me why some things are fields, and others are parameters. I think parameters are in a sense controlled by the simulation rather than the action (for things like policy guided MC).
If that is indeed the case, it could make sense to refactor the DiscreteSwap struct, to have the number of particles per species as a parameter, as it's "system dependent" and not so much "action dependent".
Test plan
The validation test for binary mixtures of LJ has been updated to include swap moves, and still recovers published results. So the action works as intended.
Also, I manually checked that the acceptance rate is > 0 (so moves do happen), and that in the final configurations, the species of some particles changed. I also checked with a system with 3 species that allowing 1<->2 swaps doesn't change any of the 3s.