You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Update AdvancedMH.jl wrapper for Monte Carlo sampling. (#325)
1. AdvancedMH or one of its dependencies may have updated a keyword from "initial_config" to "initial_params".
This caused NQCD to not deliver initial positions to the sampling chain correctly, leading to weird results for systems not centred around 0.
2. Updated new keywords `movement_ratio` and `stop_ratio`, where `movement_ratio=1-stop_ratio` as the old `move_ratio` was confusing. Warning for deprecated kwargs was added and documentation updated with information about new keywords
* Drop compat for AdvancedMH.jl<0.8 for #320,#321
* Version bump for #325
Copy file name to clipboardexpand all lines: docs/src/initialconditions/metropolishastings.md
+47-31
Original file line number
Diff line number
Diff line change
@@ -14,7 +14,17 @@ random walk starting from an initial configuration.
14
14
These are accepted or rejected based upon the Metropolis-Hastings criteria.
15
15
The result is a Markov chain that samples the canonical distribution.
16
16
17
-
## Example
17
+
!!! Legacy version
18
+
19
+
Prior to the use of [`AdvancedMH.jl`](https://github.com/TuringLang/AdvancedMH.jl),
20
+
an alternative version of the algorithm was implemented that works for both classical
21
+
and ring polymer systems: `MetropolisHastings.run_monte_carlo_sampling(sim, R0, Δ, passes)`
22
+
23
+
This is currently still included in the code but should be regarded as deprecated and
24
+
will likely be removed/combined with the [`AdvancedMH.jl`](https://github.com/TuringLang/AdvancedMH.jl)
25
+
version.
26
+
27
+
## Example 1
18
28
19
29
We can perform the sampling by setting up a classical simulation in the usual way and
20
30
providing an appropriate initial configuration.
@@ -33,14 +43,30 @@ steps = 1e4
33
43
step_size = Dict(:H=>1)
34
44
```
35
45
36
-
Now we can run the sampling. The extra keyword argument `move_ratio` is used to specify
46
+
Now we can run the sampling. The extra keyword argument `movement_ratio` is used to specify
37
47
the fraction of the system moved during each Monte Carlo step.
38
48
If we attempt to move the entire system at once, we can expect a very low acceptance ratio,
39
49
whereas is we move only a single atom, the sampling will take much longer.
40
50
You will likely have to experiment with this parameter to achieve optimal sampling.
51
+
52
+
!!! note
53
+
54
+
Keyword arguments relating to how much of the system to sample were recently changed. The existing `move_ratio` and `internal_ratio` arguments are no longer used.
55
+
56
+
Instead, there are now two options to specify how much of the system to move:
57
+
58
+
`movement_ratio`: Defines which fraction of the system to move. 1 moves the entire system.
59
+
60
+
`stop_ratio`: Defines which fraction of the system *not* to move. 1 stops the entire system.
61
+
62
+
`movement_ratio_internal`: Defines which proportion of ring polymer normal modes to perturb. 1 moves the entire system.
63
+
64
+
`stop_ratio_internal`: Defines which proportion of ring polymer normal modes not to perturb. 1 stops the entire system.
65
+
66
+
41
67
```@example mh
42
68
using NQCDynamics.InitialConditions: ThermalMonteCarlo
Prior to the use of [`AdvancedMH.jl`](https://github.com/TuringLang/AdvancedMH.jl),
59
-
an alternative version of the algorithm was implemented that works for both classical
60
-
and ring polymer systems.
61
-
This is currently still included in the code but should be regarded as deprecated and
62
-
will likely be removed/combined with the [`AdvancedMH.jl`](https://github.com/TuringLang/AdvancedMH.jl)
63
-
version.
64
-
65
-
Here, we use the legacy version to obtain a thermal distribution in a simple
66
-
model system.
83
+
## Example 2
84
+
Here, we obtain a thermal distribution in a simple model system with some additional tweaks to
85
+
try and sample a larger configuration space.
67
86
68
87
```@setup monte
69
88
using NQCDynamics
@@ -83,40 +102,37 @@ nothing # hide
83
102
```
84
103
85
104
Then we have to specify the parameters for the Monte Carlo simulation and perform the sampling.
86
-
`Δ` contains the step sizes for each of the species, `R0` the initial geometry and `passes` the
87
-
number of monte carlo passes we perform (`passes*n_atoms` steps total).
105
+
`Δ` contains the step sizes for each of the species, `R0` the initial geometry and `samples` the
106
+
number of configurations we want to obtain.
107
+
108
+
*AdvancedMH.jl* provides some additional options to control the sampling process. To (hopefully) include
109
+
a larger configuration space in the final results, we set a `thinning` of 10, meaning that we only keep
110
+
every 10th proposed configuration. In addition, we discard the first 100 samples, since our initial configuration might not
111
+
lie in the equilibrium. This is set with `discard_initial`.
112
+
Further explanations of the keyword arguments can be found in the *AbstractMCMC.jl*[documentation](https://turinglang.org/AbstractMCMC.jl/dev/api/#Common-keyword-arguments).
Sample the configuration space for the simulation `sim` starting from `r`.
33
33
34
34
Total number of steps is given by `steps` and `σ` is the dictionary of
35
35
step sizes for each species.
36
36
37
-
`move_ratio` defaults to `0.0` and denotes the fraction of system moved each step.
38
-
If `move_ratio = 0`, every degree of freedom is moved at each step.
39
-
If `move_ratio = 1`, then nothing will happen. Experiment with this parameter to achieve
40
-
optimal sampling.
37
+
`movement_ratio` denotes the fraction of system moved each step.
38
+
`internal_ratio` works as for `movement_ratio` but for the internal modes of the ring polymer.
39
+
For `movement_ratio = 0`, every degree of freedom is moved at each step, if `movement_ratio = 1`, then nothing will happen.
41
40
42
-
`internal_ratio` works as for `move_ratio` but for the internal modes of the ring polymer.
41
+
If neither arguments are defined, default behaviour is to move one atom (and one ring polymer normal mode) per step on average.
42
+
43
+
Further kwargs are passed to `AdvancedMH.sample` to allow for [extra functionality](https://turinglang.org/AbstractMCMC.jl/dev/api/#Common-keyword-arguments).
43
44
"""
44
45
functionrun_advancedmh_sampling(
45
46
sim::AbstractSimulation,
46
47
r,
47
48
steps::Real,
48
49
σ::Dict{Symbol,<:Real};
49
-
move_ratio=0.0,
50
-
internal_ratio=0.0
50
+
movement_ratio=nothing,
51
+
stop_ratio=nothing,
52
+
movement_ratio_internal=nothing,
53
+
stop_ratio_internal=nothing,
54
+
move_ratio=nothing, # deprecated
55
+
internal_ratio=nothing, # deprecated
56
+
kwargs...
51
57
)
52
58
59
+
# Give a warning if move_ratio or internal_ratio are used
60
+
if move_ratio !==nothing|| internal_ratio !==nothing
61
+
@warn"move_ratio and internal_ratio kwargs are deprecated and may be removed in future. More information: https://nqcd.github.io/NQCDynamics.jl/stable/initialconditions/metropolishastings/"
0 commit comments