Skip to content

Conversation

@pujaltes
Copy link

@pujaltes pujaltes commented Nov 24, 2025

Description

This PR adds the option for deterministic_swap_order to ReplicaExchangeSampler for deterministic even/odd (DEO) swap alternation when swapping between pairs of neigbours (swap-neighbors). When enabled, the swap offset alternates deterministically between even and odd swaps which has been shown both empirically and theoretically to improve sampling efficiency across a variety of systems [1, 2]. Notably, DEO appears to be the default in the GROMACS/PLUMED replica-exchange implementation.

Note that I define a new private _deo_odd_offset attribute to track the even/odd swap order since tracking via _iteration could cause issues since this is not updated during the equilibration phase.

Todos

  • Implement feature / fix bug
  • Add tests
  • Update documentation as needed
  • Update changelog to summarize changes in behavior, enhancements, and bugfixes implemented in this PR

Status

  • Ready to go

Changelog message

Add ``deterministic_swap_order`` parameter to ``ReplicaExchangeSampler`` for deterministic even/odd swap ordering (DEO).

@mikemhenry
Copy link
Contributor

Thanks for this! I think all that is missing is some testing. Is there an analytical way we can test this?

@codecov
Copy link

codecov bot commented Nov 25, 2025

Codecov Report

❌ Patch coverage is 78.94737% with 4 lines in your changes missing coverage. Please review.
✅ Project coverage is 85.26%. Comparing base (7b6e86c) to head (0e582c2).

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@pujaltes pujaltes force-pushed the deo branch 2 times, most recently from f343b30 to 8fcd21c Compare November 25, 2025 10:55
@pujaltes
Copy link
Author

Hi Mike,

Thanks for reviewing the proposed code.

I drew inspiration from noegroup/reform and added some tests to empirically validate the deterministic (DEO) and random swapping schemes (SEO).

For DEO we just check that it alternates between even and odd pairs and for SEO we check that: (1) it isn't DEO; i.e. doesn't just alternate between even and odd swaps and (2) that it proposes swaps between even and odd states; i.e. doesn't exclusively propose even or odd swaps.

The SEO checks have ~0 probability of false failures (0.5^100), but I can remove them if you prefer and keep only the deterministic DEO tests.

I also ran yapf on test_sampling.py but it reformatted the entire file, so I excluded those changes to keep the diff focused. Let me know if you want me to run formatting before merging this.

Best,
Sebastian

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.

2 participants