A pyCUDA based Metropolis Monte Carlo simulator for 2D-magnetism systems. This code uses NVIDIA CUDA architecture wrapped by a simple python wrapper to work.
To use, clone the repository using
git clone https://github.com/arkavo/CUDA-METRO.git
into a directory of choice. Creating a new python3 environment is recommended to run the code.
To setup the environment after creation, simply run
pip install -r requirements.pip
Some template codes have already been provided under folder /src
along with sample input files in /inputs
and running configurations in /configs
There are 4 seperate files to design your simulations. To run a simple simulation, use python main.py <input_file_name>
.
If one wants to create their own input file from scratch, just copy this json template at your convenience:
{
"Single_Mat_Flag" : 1 if single material 0 otherwise (int),
"Animation_Flags" : DEPRECATED,
"DMI_Flag" : 1 if simulation in DMI mode 0 otherwise (int),
"TC_Flag" : 1 if simulation is in Critical Temperature mode 0 otherwise (int),
"Static_T_Flag" : 1 if simulation has a single temperature 0 otherwise (int),
"FM_Flag" : 1 if starting state is FM 0 otherwise,
"Input_flag" : 1 if starting from a specified <input.npy> state 0 otherwise,
"Input_File" : String value(use quotes please) for starting state file name (if applicable),
"Temps" : Array form of temperatures used for simulation (only in Critical Temperature mode),
"Material" : Material name (omit the ".csv"),
"Multiple_Materials" : File name with multiple materials (omit the ".csv"),
"SIZE" : Lattice size (int),
"Box" : DEPRECATED,
"Blocks" : How much to parallelize (int),
"Threads" : 2 (dont change this),
"B" : external magnetic field (use quotes, double),
"stability_runs" : MC Phase 1 batch runs,
"calculation_runs" : MC Phase 2 batch runs,
"stability_wrap" : MC Phase 1 batch size,
"calculation_wrap" : MC Phase 2 batch size,
"Cmpl_Flag" : DEPRECATED,
"Prefix" : String value to appear in FRONT of output folder
}
NOTE 1: The simulator can work in either Critical Temperature or DMI mode, because of the different Hamiltonians, while it is easy to see its an OR condition, please do not attempt to use 1 on both.
NOTE 2: The total number of raw MC steps will be
Blocks x (MC Phase 1 runs x MC Phase 1 size + MC Phase 2 runs x MC Phase 2 size)
. We typically divide the phases to study the Critical temperature, since that typically gives the simulation time to settle down inPhase 1
and then find out the statistical properties inPhase 2
(which is our data collection phase). For any raw simulation, where the evolution of states are required from start to finish, one may keep any one phase and omit the other.
A template file is given as main.py
, import the requisite 2 libraries to work as construct
and montecarlo
.
MonteCarlo is a class object which is defined in construct.py
as the Main code with montecarlo.py
having all the Hamiltonian constructs as the GPU kernel (written in CUDA cpp).
construct.MonteCarlo
is the MonteCarlo class construct.
construct.MonteCarlo.mc_init()
initializes the simulation (but does not run it yet).
construct.MonteCarlo.display_material()
prints out the current material properties.
construct.MonteCarlo.grid_reset()
resets the grid to ALL FM_Flag=1
else randomizes all spins.
construct.MonteCarlo.generate_random_numbers(int size)
creates 4 GPU processed arrays of size size
using the pyCUDA XORWOW random number generator.
construct.MonteCarlo.generate_ising_numbers(int size)
creates 4 GPU processed arrays of size size
using the pyCUDA XORWOW random number generator but the spin vectors are either
construct.MonteCarlo.run_mc_dmi_66612(double T)
runs a single Phase 1
batch size run, with the output as a np.array(NxNx3)
individual spin directions as raw output. This can be saved using the np.save
command.
Other variations of run_mc_dmi_66612(T)
are run_mc_<tc/dmi>_<mode>(T)
tc
and dmi
mode both contain modes for 66612
,4448
,3636
,2424
and 2242
, which are the primary lattice types explored in this code. dmi
can only be invoked by the configs 66612,4448,3636
, for the rest, if you wish to open a running simulation, use tc
mode with single temperature.
The template file to run a visual analyzer is given in visualize.py
, this will compile images for all given state *.npy
files in a given folder.
construct.Analyze(<Folder name>, reverse=False)
to create the Analyzer instance with an option to start from the opposite end (in case you only want end results)
construct.Analyze.spin_view()
creates a subfolder in the main folder called "spins" with the spin vector images inside. They are split into components as
construct.Ananlyze.quiver_view()
creates a subfolder in the main folder called "quiver" with the spin vector images inside. They show only the planar(xy) part of the spins on a flat surface. This is useful for finding patterns in results.
We consider a lattice system with a periodic arrangement of atoms, where each atom is represented by a 3D spin vector. This atomistic spin model is founded on the spin Hamiltonian, which delineates the essential spin-dependent interactions at the atomic scale, excluding the influences of potential and kinetic energy and electron correlations. The spin Hamiltonian is conventionally articulated as
Where
First, we report the "meron" and "anti-meron", which are structures with topological numbers
Secondly, we simulate skyrmions in
In Fig 4 we demonstrate the skyrmion neucleation process for the material
In Fig 5, we further show a similar life cycle evolution for a giant skyrmion of diameter
Fig 1: Discrepancy between simulation and reference results at differing levels of parallelization. At
Fig 2: Presence of anti-merons and merons in
Fig 3: Presence of skyrmions in
Fig 4: Lifetime of a skyrmion in
Fig 5: Lifetime of a skyrmion in
All these results and more are explored more in the attached JOSS Paper.md
file, which forms the cover for the project.
If one does not wish to use this purely for observation of microstructures in material, they can alternatively make use of its other modes like
To run a vector analysis, simple execute python test_main.py <config file name>
(main config file is /configs/test_config.json
)
After execution, an output folder will be created with name <prefix>_<material>_<date>_<time>
with .npy
files in them containing spin data in 1D array form as [s1x s1y s1z s2x s2y.........sny snz] and an additional metadata.json
file containing the details of the run.
For casual viewing, it is advised to use the in-built viewer as python test_view.py <folder name>
to provide visuals of the spin magnitudes in 3 directions as well as a top-down vector map of the spins.
To run a Critical temperature analysis, execute python tc_sims.py
after configuring the appropriate config file in /configs/tc_config.json
.
After the run, a graph of temperature vs magnetization and temperature vs susceptibility will be auto generated. If the graph is not desired, please comment out everything from line 21.
Contributions to this project are always welcome and greatly appreciated. To find out how you can contribute to this project, please read our contribution guidelines
To read our code of conduct, please visit CUDA-METRO Code of Conduct.