Homework 5
Due 2023 November 3
Report instructions
Please upload one PDF file to Gradescope (Entry code:
K326P6).
For this homework you will implement code (on PrairieLearn) for a
Monte Carlo simulation code to calculate the transition temperature of
argon (as you did in homework 3, using molecular dynamics). You will be
able to re-use many pieces of your code from earlier homeworks, so
if you are concerned that they do not fully work, please make sure
you get those working (by posting on Canvas and/or by attending office
hours)!
When reusing the old MD code, set box length to =4.0.
Introduction
Potential Energy
We will start by writing a Metropolis Monte Carlo code. Remember, in
classical Metropolis Monte Carlo you will be sampling configurations
with probability ,
where is the potential energy of
the configuration and
is the inverse temperature. These probabilities should be familiar to
you as the Boltzmann distribution for a canonical ensemble at
thermodynamic equilibrium.
First, we should verify that we can evaluate the potential energy on
a single particle in your system. You should already have code that
helps you do this from your molecular dynamics simulation. Adapt it for
this homework.
Moves
Metropolis Monte Carlo works by proposing particle moves at random,
and probabilistically accepting or rejecting these moves according to
the Metropolis criterion. We need to implement a function that updates
the position of a single particle. You will update a particle position
by choosing the new position
where is chosen from a Gaussian
distribution of mean 0 and variance , i.e., the probability of
proposing a move to position
such that is
To study
as the probability of drawing the displacement from a Gaussian distribution
centered on x with variance , we write: Note that
since . For many more sophisticated moves, this is not
the case.
Metropolis Acceptance
Criterion
Now, let’s calculate the acceptance probability. Remember, in
Metropolis Monte Carlo, the probability of accepting a move from
position to is where is the potential energy of the
system in configuration , and
is the
probability of proposing a move from to .
Metropolis Monte Carlo
Algorithm
Remember the steps of a basic Metropolis Monte Carlo:
- Choose a particle to move (this can be done by selecting
particles at random, but it is also acceptable and easier to implement a
loop over all particles that moves each particle in succession).
- Evaluate the energy on this particle.
- Move this particle with a function
UpdatePosition()
.
- Evaluate the energy again, getting the difference from the old energy (before the
move).
- Accept the move with probability ; otherwise reject
(remember if you are rejecting to return the particle to its old
position).
Monitoring Acceptance
and Setting up Runs
Before we set up some runs to generate data, we want to add
functionality to our code that calculates acceptance ratios (i.e.,
measure the total number of accepted moves divided by the total number
of attempted moves). Knowing the acceptance ratio of your MC simulation
is particularly important to judge whether you are sampling
configuration space efficiently. You can tune your simulation by
adjusting the value of ,
which sets the length scale for your attempted moves and thus determines
the acceptance ratio of these moves.
For all runs here, unless explicitly noted otherwise, use the
following simulation parameters:
L = 4.0 # box length
rho = 1.0 # number density
N = 64 # particle number
M = 48.0 # mass
T = 2.0 # Temperature; beta = 0.5; for canonical ensemble.
Standard
Metropolis Monte Carlo Acceptance Criterion
Take the statement of detailed balance, which
says that the flux of particles from point to is equal to the flux in the
reverse direction, i.e., the net flux is zero. Here, is the probability of the system
being in configuration , is the probability
of proposing a move from to , and is the probability
of accepting the proposed move.
Force-Bias Type Move (Smart
MC)
Above, we implemented a Gaussian displacement move that proposed a
displacement drawn from a Gaussian distribution with mean 0 and
specified variance . In
this case the forward and reverse sampling probabilities canceled out,
i.e. which you derived. Often
it is non-trivial to find the reverse sampling probability, , given a sampling
probability .
We will study one case here.
The motivation of a “force-bias type” move is to propose a
displacement that is not random, but rather is biased in the direction
of the force acting on the particle to be moved. To implement this idea,
we will make the same Gaussian displacement described above, but we will
shift the center of our Gaussian in the direction of the force. The
center of the Gaussian will be shifted by Thus the new move will choose a new position
where is chosen from a
Gaussian distribution with probability
This is called “smart Monte Carlo,” and has an asymmetry in the
transition probability which must be reflected in the Metropolis
acceptance criterion.
Your report
- Show that the standard Metropolis Monte Carlo acceptance criterion
below satisfies the detailed balance equation. Note this should only take a couple lines of
algebra, but it is very important to understand where this equation
comes from. Note also that this expression for is not unique, but
it is commonly used because it maximizes acceptance of proposed
moves.
- By running your code, find a value of that gives you an acceptance ratio
between 0.2 and 0.5. An acceptance ratio in this broad range is likely
to give you optimal efficiency. Quote your acceptance ratio and your
choice of . Using this value,
perform a run of 100 passes. The term “passes” means one attempted move
on each particle, so 100 passes is equivalent to 6400 single-particle
moves for a system of 64 particles. Produce a plot of the potential
energy as a function of MC step, and a plot of the pair correlation
function for this run.
- Now, find a value of
that gives an acceptance ratio below 0.01; state the value of you are using. Run your simulation
again for 100 passes and produce plots of the energy and pair
correlation function. Find a value of that gives an acceptance ratio
greater than 0.95; state the value of you are using. Run your simulation
again for 100 passes and produce plots of the energy and pair
correlation function. Comparing data from your three runs, discuss what
happens to your simulation if your acceptance ratio is either
effectively 0 or effectively 1. State specifically how this leads to an
inefficient simulation in each case.
- Now, using your choice of in the optimal range of 20% to 50%
acceptance, perform some longer runs. Run the above simulation
conditions for a minimum of 2000 passes.Plot of the energy as a function
of Monte Carlo simulation steps made. State the total number of Monte
Carlo steps, the average energy, and the standard error for your
simulation. Plot the pair correlation function and structure
factor.
- Now do two simulations, one at temperature =1.0 and one at a temperature below
=0.5. Produce plots of the energy,
structure factor, and pair correlation function at each temperature.
Compare these results with your data from the MD simulations in HW
3.
- For the “smart MC” move, write an expression for . Write an
expression for the reverse probability . Combine these
terms to write the acceptance criterion .
- Finally, modify (but save your old code) your code to switch over to
using this move. Again, measure the energy of your system using the same
number of steps as you did before. Submit a trace plot, number of steps,
energy and standard error of your simulation. Compare the standard error
you get using this move with the standard error you get using the more
naive move. Also, compare the total number of minutes it took to run.
Which move is better? Why?
- This is optional for everyone with 3 Credit Hours:
Now we would like you to design your own move that you think would be
more efficient than the conventional Gaussian displacement move we used
above. The only requirement is that your move obey detailed balance,
which you will demonstrate. Describe your move in detail and explain why
you think it will be more efficient. For this new move, write an
expression for the sampling probability . Write the reverse
probability .
Write an expression for the acceptance probability .
- This is optional for everyone: Finally, let’s look
at a situation where such a move should be particularly effective,
looking at a vacancy. To do this, you should take the following
steps
- Figure out how to initialize your system with a vacancy in it
(i.e. create a new position array that has one less particle and copy
all but one of the particles in it).
- Add an observable that measures where your vacancy is. One effective
method to do this is to define a number of lattice sites and say your
vacancy is the lattice site further from any of the particles.
- Alternately using both moves, measure the approximate number of
steps it takes for the vacancy to move from one site to another.