This project implements an MPI-parallel Monte Carlo simulation of the two-flavor Schwinger model using a Hybrid Monte Carlo (HMC) algorithm. The simulation uses Wilson fermions, pseudofermions, and iterative solvers for the fermion operator. For an OpenMP implementation, check the OpenMP branch.
Gauge configurations are written in binary format with records of the form:
Here
The mass_analysis directory contains Python helpers and a notebook for computing
- CMake
- A C++20 compiler
- An MPI implementation such as OpenMPI, MPICH, or Microsoft MPI
- Python 3 with Jupyter, NumPy, Matplotlib, and SciPy for the mass analysis
- Linux, Windows with a compatible toolchain, or another Unix-like environment
The shell scripts require Bash and common Unix utilities such as sed and mv. On Windows, run them from an MSYS2/MinGW environment or follow the manual CMake commands below.
From the repository root, configure and build the project:
cmake -S . -B build
cmake --build buildThe lattice dimensions are set in CMakeLists.txt:
set(NS "64")
set(NT "64")Change NS and NT before configuring if a different lattice is required. The build produces SM_${NS}x${NT} for the HMC simulation and mass_${NS}x${NT} for correlator computation. On Windows, the executables have an .exe suffix.
Twisted mass is also implemented in the code. To compile the twisted mass version build:
cmake -S . -B build -DTWISTED_MASS=ON
cmake --build buildFor the default lattice, run the HMC executable with MPI:
mpirun -n <number-of-ranks> ./build/SM_64x64The program will prompt for the simulation parameters. A typical example is:
----------------------------
| Two-flavor Schwinger model |
| Hybrid Monte Carlo simulation |
----------------------------
Nx NS Nt NT
ranks_x: number of processes on the x direction
ranks_t: number of processes on the t direction
m0: 0
Molecular dynamics steps: 10
Trajectory length: 1
beta: 2
Thermalization: 1000
Measurements: 1000
Step (sweeps between measurements): 10
Save configurations yes/no (1 or 0): 1
In case the program was compiled for the twisted mass operator, an extra parameter (the twisted mass) will be requested.
-
ranks_xandranks_t: number of MPI ranks in the$x$ and$t$ directions. The total number of processes isranks_x * ranks_t. - The lattice dimensions must be divisible by the corresponding rank count, so the workload is balanced across processes.
-
m0: bare mass parameter. -
Molecular dynamics steps: number of leapfrog integration steps. -
Trajectory length: integration length in lattice units. -
beta: inverse gauge coupling. -
Thermalization: number of configurations discarded before measurements begin. -
Measurements: number of configurations used for measurements. -
Step: number of sweeps discarded between saved measurements. -
Save configurations: set to1to write configurations to disk, or0to skip writing them.
The script run.sh edits the lattice dimensions, configures the build if needed, builds the HMC executable, supplies a sample parameter set, and runs it. Review its variables before use. It currently moves the executable into the repository root and writes output there.
The bare mass parameter must remain above the critical mass to avoid unphysical configurations. The following values are useful guides:
| 1 | 0.3204(7) |
| 2 | 0.1968(9) |
| 3 | 0.1351(2) |
| 4 | 0.1033(1) |
| 5 | 0.0840(1) |
| 6 | 0.0719(1) |
These values are from N. Christian, K. Jansen, K. Nagai and B. Pollakowski, “Scaling test of the fermion actions in the Schwinger Model”, Nucl. Phys. B 739 (2006).
When Save configurations is 1, the simulation writes binary .ctxt files and a summary file such as _SimData.txt.
readBinConf.cpp converts one binary configuration to text. Update NX, NT, and CONF_PATH in readBin.sh, then run it from the repository root:
./readBin.shThe converter writes records in the form:
x, t, mu, Re(U_mu), Im(U_mu)
From an MSYS2 shell with MinGW and an MPI implementation available on PATH:
cmake -S . -B build -G "MinGW Makefiles" \
-DCMAKE_CXX_COMPILER=C:/msys64/ucrt64/bin/g++.exe \
-DCMAKE_C_COMPILER=C:/msys64/ucrt64/bin/gcc.exe
cmake --build build --config Release
mpiexec -n 4 ./build/SM_64x64.exeThe exact compiler, MPI implementation, and generator flags may vary. The Bash helper scripts are not native PowerShell scripts.
Once the simulation is completed and the configurations are written to disk, the mass_NSxNT program determines the necessary correlators, which are later analyzed with Python (check mass_analysis.ipynb) to compute
--------------------------------------------
| Pion and PCAC correlators computation |
--------------------------------------------
Nx NS Nt NT
ranks_x: number of processes on the x direction
ranks_t: number of processes on the t direction
m0: same as the simulation
beta: same as the simulation (using for file naming)
File with list of confs (ls -1 *.ctxt > confFiles.txt): confFiles.txt
The last one corresponds to a list with the name of the configurations that will be considered for the analysis. This can be easily created in Linux by typing
ls -1 -v *.ctxt > confFiles.txtin the directory with the configurations. The output of the program are two .txt files with the correlators for the pion and PCAC. The corresponding names are 2D_U1_${NX}x${NT}"_b${BETA}_m${M0}_corr.txt and 2D_U1_${NX}x${NT}"_b${BETA}_m${M0}_corrPCAC.txt. This files are used in the Python program to calculate
If CMake or the runtime reports missing MPI libraries, verify that MPI is installed and that the compiler and MPI launcher are on PATH.
Use the same NS and NT values when building the simulation, building the mass executable, and converting configurations. Also keep readBinConf.cpp consistent with the configuration dimensions.
Reduce the trajectory length or increase the number of molecular-dynamics steps.
Set Save configurations to 1 and verify that the process can write to the working directory.
For background on the physics and algorithm, see HMC_doc.pdf and the scaling-test reference cited above.