{"action":"created","issue":{"url":"https://api.github.com/repos/pandegroup/openmm/issues/938","labels_url":"https://api.github.com/repos/pandegroup/openmm/issues/938/labels{/name}","comments_url":"https://api.github.com/repos/pandegroup/openmm/issues/938/comments","events_url":"https://api.github.com/repos/pandegroup/openmm/issues/938/events","html_url":"https://github.com/pandegroup/openmm/issues/938","id":82534374,"number":938,"title":"Brainstorm for HMC context update feature or workaround","user":{"login":"kyleabeauchamp","id":1900459,"avatar_url":"https://avatars.githubusercontent.com/u/1900459?v=3","gravatar_id":"","url":"https://api.github.com/users/kyleabeauchamp","html_url":"https://github.com/kyleabeauchamp","followers_url":"https://api.github.com/users/kyleabeauchamp/followers","following_url":"https://api.github.com/users/kyleabeauchamp/following{/other_user}","gists_url":"https://api.github.com/users/kyleabeauchamp/gists{/gist_id}","starred_url":"https://api.github.com/users/kyleabeauchamp/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/kyleabeauchamp/subscriptions","organizations_url":"https://api.github.com/users/kyleabeauchamp/orgs","repos_url":"https://api.github.com/users/kyleabeauchamp/repos","events_url":"https://api.github.com/users/kyleabeauchamp/events{/privacy}","received_events_url":"https://api.github.com/users/kyleabeauchamp/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":28,"created_at":"2015-05-29T18:26:15Z","updated_at":"2015-05-29T22:52:22Z","closed_at":null,"body":"So I've now got (hopefully) working implementations of several hamiltonian monte carlo integrators, including all possible combinations of (HMC / GHMC) with RESPA and extra chance hamiltonian monte carlo (XCHMC) (https://github.com/kyleabeauchamp/openmmtools/blob/hmc/openmmtools/hmc_integrators.py).      (references: C. M. Campos, J. M. Sanz-Serna, J. Comp. Phys. 281, (2015)\r\n    J. Sohl-Dickstein, M. Mudigonda, M. DeWeese.  ICML (2014) )\r\n\r\nHowever, at this point I need to figure out a way to handle barostats and other forms of context updates.  The basic issue is that one of the algorithms (XCHMC) works like this (for one step of of the MC chain):\r\n\r\n-1.  Randomize velocities, completely (HMC) or partially (GHMC)\r\n0.  for k in range(n_extra_chances) {\r\n1.  Do L steps of hamiltonian dynamics\r\n2.  Accept or reject based on a modified metropolis criterion\r\n3.  If accept, break out of the for loop.  Otherwise, do another round of hamiltonian dynamics.\r\n4.  End for.  If still haven't accepted the proposal, reject and flip momement\r\n\r\nThe complexity of this algorithm is that the termination can take place after any of {1, 2, ..., n_extra_chances + 1} rounds of hamiltonian dynamics.  This logic is a bit challenging to implement with the tools in CustomIntegrator.  My current implementation lumps the steps (2, 3, 4) into a single call to `integrator.step()` and controls the outer for loop using a global variable `k`.  Then, to prevent the integrator from stopping at an intermediate stage (e.g. when the current positions are neither rejected nor accepted), I subclassed `integrator.step()` and wrapped it with a `while` loop to keep running dynamics until the current state is either accepted or rejected.  \r\n\r\nI've also considered an alternative implementation where one call to integrator.step actually does the entire sweep of steps (0, 1, 2, 3, 4).  However, this alternative implementation would require me to have some sort of `break` statement that allows me to jump to the next iteration of `step(1)` prematurely, without executing the remaining iterations of the for loop (0).  \r\n\r\nAnother way to handle the context updates would be to keep the implementation that I currently have, but allow some sort of \"conditional\" context update, where the context update is conditional on a global variable, similar to the `select()` function that we implemented recently. \r\n\r\nI'm curious if anyone has any cute ideas here for implementing this in the most straightforward manner."},"comment":{"url":"https://api.github.com/repos/pandegroup/openmm/issues/comments/106953972","html_url":"https://github.com/pandegroup/openmm/issues/938#issuecomment-106953972","issue_url":"https://api.github.com/repos/pandegroup/openmm/issues/938","id":106953972,"user":{"login":"jchodera","id":3656088,"avatar_url":"https://avatars.githubusercontent.com/u/3656088?v=3","gravatar_id":"","url":"https://api.github.com/users/jchodera","html_url":"https://github.com/jchodera","followers_url":"https://api.github.com/users/jchodera/followers","following_url":"https://api.github.com/users/jchodera/following{/other_user}","gists_url":"https://api.github.com/users/jchodera/gists{/gist_id}","starred_url":"https://api.github.com/users/jchodera/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jchodera/subscriptions","organizations_url":"https://api.github.com/users/jchodera/orgs","repos_url":"https://api.github.com/users/jchodera/repos","events_url":"https://api.github.com/users/jchodera/events{/privacy}","received_events_url":"https://api.github.com/users/jchodera/received_events","type":"User","site_admin":false},"created_at":"2015-05-29T22:52:22Z","updated_at":"2015-05-29T22:52:22Z","body":"Yep, I can confirm:\r\n\r\nWith initial line commented out and `Eold` cached at end of HMC step:\r\n```\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.624 s elapsed.\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.633 s elapsed.\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.644 s elapsed.\r\n```\r\nwith original HMC version and energies computed twice:\r\n```\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.864 s elapsed.\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.876 s elapsed.\r\n[chodera@gpu-2-17 openmmtools.jchodera]$ python benchmark-hmc.py\r\n0.848 s elapsed.\r\n```\r\n\r\nI am not using a barostat here, so the context update shouldn't be doing anything.\r\n"}}