Skip to content
/ smac Public

Code I have written for course: Statistical Mechanics and Computations

Notifications You must be signed in to change notification settings

weka511/smac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Statistical Mechanics and Computations

Code from the course: Statistical Mechanics and Computations. It includes exercises from the textbook Statistical Mechanics: Algorithms and Computations by Werner Krauth.

From the Course

# Folder File Description
1 Monte Carlo Algorithms: Direct Sampling & Markov Chain sampling
  Lecture direct_pi.py Algorithm 1.1 - compute pi using direct sampling
    direct_pi_multirun.py Compute pi using multiple runs of direct sampling
    markov_pi.py Calculate pi using Markov Chain Monte Carlo
    markov_pi_multirun.py Calculate pi using multiple runs of Markov Chain Monte Carlo
    pebble_basic.py Demonstrate neighbour table for MCMC-Algorithm 1.6
    pebble_basic_inhomogeneous.py Demonstrate neighbour table for MCMC-Algorithm 1.6 with inhomogeneous probabilities
  Tutorial pebble_basic.py Move pebble using neighbour Table 1.3
    pebble_basic_movie.py Move pebble using neighbour Table 1.3
    pebble_basic_multirun.py Move pebble using neighbour Table 1.3
    pebble_dual_eigen.py Two games: Illustrate conversion of reducible matrix to irreducible+aperiodic to make motion ergodic
    pebble_dual_movie.py '''Two games: Illustrate conversion of reducible matrix to irreducible+aperiodic to make motion ergodic'''
    pebble_multirun_all_histogram.py Show probability for reaching other cells after 0, 1, 2, ... moves
    pebble_multirun_histogram.py Show probability for reaching other cells after 0, 1, 2, ... moves
    pebble_recurrent_eigen.py Dual pebble: make aperiodic
    pebble_recurrent_movie.py Dual pebble: make aperiodic
    pebble_transfer.py Model Monte Carlo simulation as a transfer matrix, illustrating speed of convergence
    pebble_transfer_eigen.py Eigenvalues and eigenvectors of transfer matrix, illustrating speed of convergence
    pebble_transfer_sub.py Model Monte Carlo simulation as a transfer matrix; subtract equilibrium value to show speed of convergence
  Homework exerciseB.py Shows that the error of markov_pi follows the law: const / sqrt(N_trials)for large N_trials. The constant is larger (sometimes much larger) than 1.642 and it depends on the stepsize delta.
    exerciseC.py Bunching method: compute the error in markov_pi.py from a single run and without knowing the mathematical value of pi.
    exerciseC1.py Bunching method: compute the error in markov_pi.py from a single run and without knowing the mathematical value of pi
    exerciseC3.py Bunching method: compute the error in markov_pi.py from a single run and without knowing the mathematical value of pi
2 Hard Disks: from classical mechanics to statistical mechancs
  Lecture direct_disks_box.py Direct sampling of disks in box, tabula rasa
    direct_disks_box_a1.py Direct sampling of disks in box, tabula rasa: investigate success rate
    direct_disks_box_movie.py Direct sampling of disks in box, tabula rasa, plotted as movie
    direct_disks_box_multirun.py Direct sampling of disks in box, tabula rasa, multiple runs
    direct_disks_box_multirun_b1.py Generate histogram of x positions by direct sampling of disks in box, tabula rasa
    event_disks_box.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box
    event_disks_box_a3.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box. Repeat
    event_disks_box_b3.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box. Repeat and generate histogram
    event_disks_box_movie.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box. Repeat. Plotted as movie
    markov_disks_box.py Algorithm 2.2: generating a hard disk configuration from another one using a Markov chain
    markov_disks_box_a2.py Algorithm 2.2: generating a hard disk configuration from another one using a Markov chain
    markov_disks_box_movie.py Algorithm 2.2: generating a hard disk configuration from another one using a Markov chain
    markov_disks_box_multirun_b2.py Algorithm 2.2: generating a hard disk configuration from another one using a Markov chain
  Tutorial direct_discrete.py Create configuration of rods using tabula rasa to give equiprobable distribution
    direct_disks_any.py Compute acceptance probability for hard disks as a function of density
    direct_disks_box.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box
    direct_disks_box_slow.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box. Build full set of disks, including invalid, then cull.
    direct_disks_multirun.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box with periodic boundary conditions: multiple runs to collects stats
    direct_disks_multirun_movie.py Algorithm 2.1: event-driven molecular dynamics for hard disks in a box with periodic boundary conditions: multiple runs to collects stats
    random_sequential_discrete.py Create configuration of rods without tabula rasa: does not give equiprobable distribution
    random_sequential_discrete_movie.py Create configuration of rods without tabula rasa: does not give equiprobable distribution
3 Entropic Interactions and Phase Transitions
  Lecture direct_pins.py Algorithm 6.1: direct sampling
    direct_pins_improved.py Algorithm 6.1: direct sampling
    direct_pins_movie.py Algorithm 6.1: direct sampling
    direct_pins_noreject.py Algorithm 6.2: rejection free sampling
    direct_pins_noreject_movie.py Algorithm 6.2: rejection free sampling
  Tutorial direct_pins.py Algorithm 6.1: direct sampling
    direct_pins_density.py
    direct_pins_movie.py
    direct_pins_noreject.py
    direct_pins_noreject_movie.py
    direct_pins_noreject_periodic.py
    direct_pins_noreject_periodic_pair.py
  Homework my_markov_disks.py
    preparation1.py
    preparation2.py
4 Sampling and Integration
  Lecture direct_sphere_3d.py
    direct_sphere_3d_movie.py
    direct_surface.py
    direct_surface_3d.py
    direct_surface_3d_movie.py
    gauss_2d.py
    gauss_2d_movie.py
    gauss_3d.py
    gauss_3d_movie.py
    gauss_test.py
    gauss_test_movie.py
    naive_gauss.py
    naive_gauss_movie.py
  Tutorial basic_use_random.py
    gamma_transform.py
    gauss_transform.py
    markov_gauss.py
    markov_gauss_movie.py
    markov_inv_sqrt.py
    markov_inv_sqrt_movie.py
    naive_ran.py
    reject_direct_gauss_cut.py
    reject_inv_sqrt_cut.py
    tower_discrete.py
    walker_test.py
  Homework data-bunch.py
    markov_hypersphere.py
    markov_hypersphere_C2.py
    markov_sphere_3D.py
    markov_sphere_4D.py
5 Quantum Statistical Mechancs 1/3: Density Matrices and Path Integrals
  Lecture harmonic_wavefunction.py
    harmonic_wavefunction_check.py
    harmonic_wavefunction_check_movie.py
    harmonic_wavefunction_movie.py
    matrix_square_harmonic.py
    matrix_square_harmonic_movie.py
    naive_harmonic_path.py
    naive_harmonic_path_movie.py
  Tutorial free_periodic_complex_exp.py
    free_periodic_complex_exp_movie.py
    free_periodic_sine_cosine.py
    free_periodic_sine_cosine_movie.py
    harmonic_trotter_movie.py
    quantum_time_evolution.py
  Homework a2.py
    markov_gauss_a1.py
    markov_gauss_movie_a1.py
    matrix_square_anharmonic_c1.py
    matrix_square_anharmonic_c3.py
    matrix_square_harmonic_b1.py
    path_Integral_b2.py
    path_Integral_c2.py
6 Quantum Statistical Mechancs 2/3: Lévy Quantum Paths
  Lecture continuous_random_walk.py Construct path using a simple random walk (endpoint is not held fixed)
    levy_free_path.py Simple simplementation of Levy Free Path Algorithm
    levy_harmonic_path.py
    levy_harmonic_path_3D.py Lévy flight in 3D
    levy_harmonic_path_movie.py
    naive_harmonic_path.py Construct path using direct sanpling (inefficient)
    naive_path_slice.py
    naive_path_slice_movie.py
    trivial_free_path.py Generate a random walk, then pull back as described in Lecture 6, 20:12. Compare result with Lévy free path
  Tutorial naive_boson_trap.py Enumerate energies in a simple harmonic trap
    naive_single_particle.py Enumerate states for Bosons, i.e. indistinguisgable particles
  Homework a1.py
    a2.py
    a3.py
    b1.py
    b2.py
    b3.py
    c1.py
    c2.py
7 Quantum Statistical Mechancs 3/3: Bose-Einstein Condensation
  Lecture markov_harmonic_bosons.py
    markov_harmonic_bosons_movie.py
    permutation_sample.py
  Tutorial canonic_harmonic_recursion.py
    canonic_harmonic_recursion_movie.py
    direct_harmonic_bosons.py
    markov_harmonic_bosons.py
    permutation_sample.py
    permutation_sample_cycle.py
  Homework a1.py
    a2.py
    a2a.py
    a3.py
    b1.py
    b2.py
    c1.py
8 Ising Model: Enumerations and Monte-Carlo Algorithms
  Lecture cluster_ising.py
    cluster_ising_movie.py
    energy_ising.py
    enumerate_ising.py
    enumerate_ising_mod.py
    enumerate_ising_movie.py
    gray.py
    markov_ising.py
    markov_ising_movie.py
    thermo_ising.py
    thermo_ising_movie.py
  Tutorial heatbath_ising.py
    heatbath_ising_random_map.py
    heatbath_ising_random_map_movie.py
  Homework A1.py
    A2.py
    B1.py
    B2.py
    C1.py
    C2.py
9 Dynamic Monte Carlo, Simulated Annealing
  Lecture dynamic_ising.py
    dynamic_ising_patch.py
    fast_spin_dynamics.py
    fast_throw.py
    naive_spin_dynamics.py
    naive_spin_dynamics_movie.py
    naive_throw.py
  Tutorial direct_sphere_disks.py
    direct_sphere_disks_any.py
    direct_sphere_disks_any_movie.py
    direct_sphere_disks_movie.py
    example_pylab_visualization.py
    markov_sphere_disks.py
    resize_disks.py
    simulated_annealing.py
    simulated_annealing_movie.py
  Homework A1.py
    A2.py
    B1.py
    C1.py
    C2.py
10 The Alpha and Omega of Monte Carlo
  Lecture direct_gamma.py Integral of x**gamma, illustrating need for importance sampling
    direct_gamma_average.py Integral of x**gamma, illustrating need for importance sampling
    direct_gamma_average_movie.py Histogram of Integral of x**gamma, illustrating need for importance sampling
    direct_gamma_average_rescaled.py
    direct_gamma_average_rescaled_movie.py Integral of x**gamma: rescale, plot histograms, and compare with Lévy distribution
    direct_gamma_running.py
    direct_gamma_running_movie.py
    direct_needle.py Buffon's experiment (with cheat)
    direct_needle_patch.py Buffon's experiment

From the Book

# File Problem/Algorithm/Description
- template.py Template for python programs
1 smac.py Useful functions: BoxMuller, CircleThrowing, and SphereGenerator
1.1 direct-plot.py Implement Algorithm 1.1. Plot error and investigate relationship with N.
- markov-pi.py Implement Algorithm 1.2. Plot error and rejection rate.
- direct.py 1.3 Store state in file
- smacfiletoken.py
- markov-discrete-pebble.py 1.4 Use table
- large-markov.py
- transfer.m 1.8 Eigenvalues of transfer matrix
1.2 permutation.py 1.9 Sample permutations using Alg. 1.11 and verify that it generate all 120 permutations of 5 elements equally often
- permutation-histogram.py
- naivegauss.py 1.12 Gauss
- direct-surface.py Monte Carlo simulation of Exercise 2.11 of Chaosbook: in higher dimensions, any two vectors are nearly orthogonal
1.3 binomialconvolution.py 1.18 Binomial Convolution
1.4.2 direct-gamma.py 1.22 Importance sampling:Implement Algorithm 1.29, subtract mean value for each sample, and generate histograms of the average of N samples and the rescaled averages.
- direct-gamma-zeta.py
- markov-zeta.py Algorithm 1.31, use of Markov Chain to detect non-integrable singularity.
1.4.4 levy-convolution.py Algorithm 1.32
2.1.4 spheres2.py Exercise 2-4: Sinai's system of two large sphere in a box. Show histogram of positions.
2.2.1 pair-time.py Algorithm 2.2: Pair collision time for two particles
- md.py Algorithm 2.3 Pair collision
- md-viz.py Visualize data generated by md.py
- md-plot.py Visualize output from md.cpp. Plot distribution of distances from wall, and compare energy histogram with Bolzmann distribution.
- md Algorithm 2.3 Pair collision
- md Makefile Algorithm 2.3 Pair collision
- md configuration.cpp Manage a box full of particles
- md configuration.hpp Manage a box full of particles
- md md.cpp Algorithm 2.3 Pair collision
- md md.hpp Algorithm 2.3 Pair collision
- md particle.cpp Represents one single particle
- md particle.hpp Represents one single particle
- direct-disks.py Exercise 2.6: directly sample the positions of 4 disks in a square box without periodic boundary conditions, for different covering densities
- hist-plot.py Exercise 2.6: ...
- geometry.py Used to implement periodic and aperiodic boundary conditions in Exercises 2.6-2.8
2.2.2 directDisksAny.py
2.2.3 markov-disks.py Exercise 2.8 and Algorithm 2.9. Generating a hard disk configuration from an earlier valid configuration using MCMC.
3.1 harmonic_wavefunction.py Exercise 3.1: verify orthonormality of the solutions to Schroedinger's equation for Simple Harmonic Oscillator
- harmonic_density.py Exercise 3.2: determine density matrix
3.2 matrix-square.py Exercise 3.4: implement Alg 3.3, matrix-square
- matrix-square-check.py Exercise 3.4: check results of matrix squaring against exact solution.
- poeschl-teller.py Exercise 3.5: plot Poeschl-Teller potential and investigate density matrix and partition function
3.3 The Feynman path integral
3.4 Pair density matrices
3.5 Geometry of Paths
4 Bosons
5.1 gray.py Algorithm 5.2: Gray code for spins {1,...N}.
- enumerate-ising.py Algorithm 5.3: single flip enumeration for the Ising model.
- ising.py Algorithm 5.3: Single spin-slip enumeration for Ising model
- ising-stats.py Figure 6.6 - plot data from ising.py
- ising catch.hpp Support for Test harness for enumerate-ising.cpp
- ising enumerate-ising.cpp Algorithm 5.3: single flip enumeration for the Ising model.
- ising enumerate-ising.hpp Algorithm 5.3: single flip enumeration for the Ising model.
- ising gray.hpp Greycode for enumerate-ising.cpp, plus iterator for neighbours
- ising Makefile Makefile for enumerate-ising.cpp
- ising nbr.hpp Calculate neighbours for enumerate-ising.cpp
- ising test-gray.cpp Tests for gray.hpp
- ising test-nbr.cpp Tests for nbr.cpp
- ising tests.cpp Test harness for enumerate-ising.cpp
5.2 The Ising model - Monte-Carlo algorithm
5.3 Generalized Ising models
6 Entropic Forces
7 Dynamic Monte Carlo Methods

Exam

File Description
Q1.py
Q4-1.py
Q4-2.py
Q7.py
Q10.py
Q11.py

Miscellaneous

File Description
walker.py Used to create README.MD from file tree

About

Code I have written for course: Statistical Mechanics and Computations

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages