pretty_name: 4D phi4 diffusion models and Wolff FAHMC configurations
tags:
- lattice-field-theory
- phi4
- monte-carlo
- hmc
- wolff
- diffusion-models
license: mit
4D phi4 diffusion models and Wolff FAHMC configurations
This dataset contains 4D scalar phi4 lattice configurations generated with a Wolff + Fourier-Accelerated HMC sampler, together with the 4D score-model code, retained checkpoints, generated samples and analysis results.
Both JLD2 and NumPy variants are retained: JLD2 provides native Julia access, while NPZ is the published Python/Hugging Face format. For each lattice size, the two variants contain the same configurations and corresponding metadata values; the container formats and metadata key names differ.
Files
| File | Format | Lattice | Shape of cfgs |
dtype |
|---|---|---|---|---|
trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.jld2 |
JLD2 | 8^4 |
(8, 8, 8, 8, 5120) |
Float64 |
trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz |
NPZ | 8^4 |
(8, 8, 8, 8, 5120) |
float64 |
trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_16^4.jld2 |
JLD2 | 16^4 |
(16, 16, 16, 16, 5120) |
Float64 |
trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_16^4.npz |
NPZ | 16^4 |
(16, 16, 16, 16, 5120) |
float64 |
Repository layout
WolffFAHMC_ND.jl: shared dimension-independent sampler engine.WolffFAHMC_4D.jl: 4D wrappers and analysis functions. Importing it no longer starts a production run.trainingdata/: HMC training configurations in NPZ and JLD2 formats.train_phi4_4d.py,sample_phi4_4d.py: score-model training and reverse-SDE sampling entry points.diffusion_lightning.py,phi4_action.py: bundled diffusion and lattice action utilities; no DM parent-directory import is required.networks_nd.py: bundled 2D/3D reference implementation used by the 4D embedding test.julia/CorrelationUtils.jl: bundled dimension-generic propagator utilities.requirements.txt,Project.toml,Manifest.toml: Python requirements and a version-locked Julia environment.runs/: retained checkpoints, generated samples, metrics and propagators.scripts/run_production_4d.jl: explicit production example. Generated JLD2 files are kept beside their NPZ counterparts intrainingdata/.results/production/: complete production diagnostics (CSV and plots).results/scan_kappa_wolff_fahmc/: kappa-scan tables and plots.
Instantiate the declared Julia dependencies and run the production example from this repository root with:
julia --project=. -e 'using Pkg; Pkg.instantiate()'
julia --project=. scripts/run_production_4d.jl
Each .npz file contains:
cfgs: field configurations, with samples on the last axis.kappa: hopping parameter.lambda: quartic coupling.N: lattice size.n_samples: number of stored configurations.epsilon_final: final HMC step size.acc_rate: production HMC acceptance rate.
In Python, one configuration is cfgs[:, :, :, :, i], where i is the
zero-based sample index.
Download
Install the Hugging Face Hub client:
pip install -U huggingface_hub
Download the full self-contained snapshot:
hf download YangyangTan/4Dphi4 \
--repo-type dataset \
--local-dir 4Dphi4
Download one file:
hf download YangyangTan/4Dphi4 \
"trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz" \
--repo-type dataset \
--local-dir .
Load with NumPy
import numpy as np
path = "trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz"
data = np.load(path)
cfgs = data["cfgs"]
kappa = data["kappa"].item()
lam = data["lambda"].item()
N = data["N"].item()
phi0 = cfgs[:, :, :, :, 0]
print(cfgs.shape, cfgs.dtype)
print(kappa, lam, N)
You can also download directly from Python:
from huggingface_hub import hf_hub_download
import numpy as np
path = hf_hub_download(
repo_id="YangyangTan/4Dphi4",
filename="trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz",
repo_type="dataset",
)
data = np.load(path)
cfgs = data["cfgs"]
Train the score model
Run the scripts from the repository root on an NVIDIA GPU. The repository is self-contained and does not import source files from a parent DM directory.
The Python dependencies are PyTorch, PyTorch Lightning, torch-ema, NumPy,
PyYAML, tqdm and Matplotlib. Install them with:
python -m pip install -r requirements.txt
The current implementation uses CUDA and torch.compile. SciPy is included in
the requirements only for the optional RK45 probability-flow ODE sampler.
The NPZ layout must be (L, L, L, L, n_samples). The loader moves only the
final sample axis to the batch position and inserts the scalar-field channel,
producing network input (n_samples, 1, L, L, L, L).
The retained production configuration is:
# L=8
python train_phi4_4d.py \
--data_path trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz \
--sigma 305 --channels 36,64,128,256 \
--normalization minmax --final_bias --zero_mode_loss_weight 0 \
--lr 1e-3 --batch_size 64 --epochs 20000 \
--ema_start 0 --num_ckpts 100 --device cuda:0
# L=16
python train_phi4_4d.py \
--data_path trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_16^4.npz \
--sigma 1249 --channels 36,64,128,256 \
--normalization minmax --final_bias --zero_mode_loss_weight 0 \
--lr 1e-3 --batch_size 64 --epochs 20000 \
--ema_start 0 --num_ckpts 100 --device cuda:0
Omit --sigma to estimate it from the maximum pairwise distance in the
normalized training set. Checkpoints are saved on a logarithmic epoch schedule
under runs/<run-name>/models/; the exact configuration and CSV metrics are
stored in training_config.yaml and logs/version_*/metrics.csv.
Resume training
Use the same data, sigma, channels, normalization, bias, zero-mode weight and
output suffix as the original run. --epochs is the final total epoch, not the
number of additional epochs.
RUN=runs/phi4_4d_L8_k0.145_l0.9_ncsnpp_sigma305_ch36-64-128-256_minmax_bias_directscore_k0w0
python train_phi4_4d.py \
--data_path trainingdata/cfgs_wolff_fahmc_k=0.145_l=0.9_8^4.npz \
--sigma 305 --channels 36,64,128,256 \
--normalization minmax --final_bias --zero_mode_loss_weight 0 \
--lr 1e-3 --batch_size 64 --epochs 20000 \
--ema_start 0 --num_ckpts 100 --device cuda:0 \
--resume_from_checkpoint "$RUN/models/epoch=6021.ckpt"
Generate samples
Keep a checkpoint in its original run directory beside
training_config.yaml; the sampler reads that file to reconstruct the channel
widths and final-convolution bias. Sampling uses EMA weights by default.
RUN=runs/phi4_4d_L8_k0.145_l0.9_ncsnpp_sigma305_ch36-64-128-256_minmax_bias_directscore_k0w0
python sample_phi4_4d.py \
--checkpoint "$RUN/models/epoch=4929.ckpt" \
--num_samples 256 --num_steps 2000 --schedule linear --seed 0
The default output is
$RUN/data/samples_em_steps2000_linear_ep4929_seed0.npy, with shape
(L, L, L, L, n_samples). Use --no_ema for raw network weights,
--symmetrize_z2 for the Z2-symmetrized-score diagnostic, or
--output_dir DIR to choose another output directory.