CUDA-METRO · Reference

API

Two modules. construct holds the driver classes; montecarlo holds the CUDA kernels, compiled at runtime through pyCUDA's SourceModule.

Imports

import construct
import montecarlo

construct is the code you call. montecarlo carries the Hamiltonian implementations as GPU kernels written in CUDA C — you rarely touch it directly, but that is where the physics lives.

construct.MonteCarlo

MethodEffect
MonteCarlo(config_file, input_folder, output_folder) Base constructor. The folder arguments default to values that work when running sample.py from its own directory; set them to anything you like.
load_config()Reads the JSON config.
load_material()Reads a single material's parameters from the input file.
load_materials()Reads the multiple-materials file instead.
mc_init(tc_points: int) Initialises the simulation from the loaded parameters without running it. tc_points sets how many temperature points span the range; defaults to 11.
display_material()Prints the current material properties.
grid_reset() Resets the lattice. With FM_Flag = 1 every spin becomes (0,0,1); otherwise spins are randomised to a diamagnetic state.
generate_random_numbers(size: int) Allocates four GPU arrays of length size using pyCUDA's XORWOW generator.
generate_ising_numbers(size: int) As above, but spin vectors are constrained to (0,0,1) or (0,0,−1).

Run modes

Runners follow one shape:

run_mc_<mode>_<lattice>(T: double) -> numpy.ndarray

Each call executes one Phase 1 batch and returns an N × N × 3 array of raw spin directions, ready for np.save. <mode> is tc or dmi; <lattice> is one of the coordination codes.

LatticetcdmiExample
66612YesYesrun_mc_dmi_66612(T)
3636YesYesrun_mc_dmi_3636(T)
4448YesYesrun_mc_dmi_4448(T)
2424Yesrun_mc_tc_2424(T)
2242Yesrun_mc_tc_2242(T)
No DMI kernel?
For 2424 and 2242, run tc mode at a single temperature to get an open, evolving simulation.

construct.Analyze

The analyser walks a folder of saved .npy states and renders each one. It needs no config file — just a path. visualize.py is a ready-to-run template.

MethodEffect
Analyze(folder_path: str, reverse=False) Creates the analyser. reverse=True starts from the far end, for when you want the final state first.
spin_view() Writes a spins/ subfolder — spin vectors split into components as z = s(x,y).
quiver_view() Writes a quiver/ subfolder — the planar (xy) component only, on a flat surface. Best for spotting patterns.

From the command line:

python visualize.py <folder_path>

which covers most cases. For a custom job, pass your own script: python <visual_script> <folder_path>.