Diffusion models for SU(N) degrees of freedom.
Project description
sun_diffusion
Diffusion models for ${\rm SU}(N)$ degrees of freedom.
What this package does:
- Implements diffusion processes on the ${\rm SU}(N)$ Lie group manifold with
- different noise schedules
- customizable parameters
- Includes utilities for manipulating matrices (and their spectra) on ${\rm SU}(N)$ and $\mathfrak{su}(N)$, including
- diagonalization
- canonicalization
- eigendecomposition
- algebra-to-group projections (and vice versa)
- irreducible representations
- Provides heat kernel evaluations, sampling routines, and score functions
Installation
CPU only (default)
pip install sun_diffusion
GPU (CUDA) Users
Before installing, make sure to install a CUDA-enabled PyTorch compatible with your GPU. For example, for CUDA 12.4:
pip install torch --index-url https://download.pytorch.org/whl/cu124
pip install sun_diffusion[gpu]
If PyTorch cannot detect a GPU, your code will fall back to CPU, or set_device('cuda') will raise an error. You can verify CUDA availability with a small example:
from sun_diffusion.devices import set_device, summary, HAS_CUDA
# Check CUDA availability
print('CUDA available:', HAS_CUDA)
if HAS_CUDA:
set_device('cuda', 0)
else:
set_device('cpu')
print(summary())
>>> CUDA available: True
>>> Using device: cuda:0 (NVIDIA GH200 120GB) with dtype: torch.float32
Further utilities for handling devices and dtypes can be found in the sun_diffusion.devices module.
Quickstart / Examples
Note: More in-depth examples can be found in the notebooks of this repository.
Physics Actions
This package allows one to define actions and evaluate them on batches of ${\rm SU}(N)$ configurations:
from sun_diffusion.action import SUNToyAction
from sun_diffusion.sun import random_sun_element
# Create a toy action
action = SUNToyAction(beta=1.0)
# Random batch of SU(3) matrices
batch_size = 4
U = random_sun_element(batch_size, Nc=3)
# Evaluate the action
S = action(U)
print(S)
>>> tensor([-0.0338, -0.0705, -0.5711, -0.7625])
See the sun_diffusion.action module for more details.
Diffusion Processes
This package also enables users to define diffusion processes on Euclidean space:
import torch
from sun_diffusion.diffusion import VarianceExpandingDiffusion
batch_size = 512
x_0 = 0.1 * torch.randn((batch_size, 3))
# Diffuse x_0 -> x_1 on R^3
diffuser = VarianceExpandingDiffusion(kappa=1.1)
x_1 = diffuser(x_0, t=torch.ones(batch_size))
print('x_0 std =', x_0.std().item())
print('x_1 std =', x_1.std().item())
>>> x_0 std = 0.10194464772939682
>>> x_1 std = 1.0630394220352173
as well as on the ${\rm SU}(N)$ manifold:
from sun_diffusion.diffusion import PowerDiffusionSUN
batch_size = 512
U_0 = random_sun_element(batch_size, Nc=2, scale=0.1)
# Diffuse U_0 -> U_1 on SU(2)
diffuser = PowerDiffusionSUN(kappa=3.0, alpha=1.0)
U_1, xs, V = diffuser(U_0, torch.ones(batch_size))
See sun_diffusion.diffusion for more diffusion processes and implementation details.
Heat Kernel and Group Algebra
Sampling from the ${\rm SU}(N)$ heat kernel over the diagonal subalgebra of eigenangles is also simple, and can easily be combined with this package's matrix algebra utilities to produce group elements:
from sun_diffusion.heat import sample_sun_hk
from sun_diffusion.linalg import adjoint
from sun_diffusion.sun import random_un_haar_element, embed_diag, matrix_exp
# Batch of HK eigenangles
batch_size = 2
Nc = 2
xs = sample_sun_hk(batch_size, Nc=Nc, width=torch.rand(batch_size), n_iter=10)
# Promote to Algebra -> project to SU(N)
X = embed_diag(torch.tensor(xs))
V = random_un_haar_element(batch_size, Nc=Nc)
U = V @ matrix_exp(X) @ adjoint(V)
print(U)
>>> tensor([[[ 0.8995-0.3124j, 0.0070+0.3055j],
[-0.0070+0.3055j, 0.8995+0.3124j]],
[[ 0.9748+0.1920j, 0.0399+0.1061j],
[-0.0399+0.1061j, 0.9748-0.1920j]]])
See the sun_diffusion.heat, sun_diffusion.linalg and sun_diffusion.sun modules for more.
Conventions
Some notes on mathematical conventions and notation:
Exponential Map
In physics, the exponential map $\exp: \mathfrak{su}(N) \to {\rm SU}(N)$ is defined conventionally through
$$U = \exp(A) := e^{iA}$$
where $A = A^\dagger$ is a Hermitian matrix. In the math literature, one absorbs the factor of $i$ into the matrix so that $A$ is anti-Hermitian. We adopt the physicist's convention, so our functions that map between group and algebra, namely sun.matrix_exp() and sun.matrix_log(), expect a Hermitian matrix as input/output, respectively.
Heat Equation
In mathematics, the Heat equation is often written simply as
$$\partial_t p_t(U) = \Delta p_t(U)$$
where $\Delta$ is the Laplace-Beltrami operator on the manifold $\mathcal{M} \ni U$. But to define more expressive diffusion processes, one introduces a time-dependent diffusion-coefficient, denoted $g_t$, such that
$$\partial_t p(U) = \frac{g_t^2}{2}\Delta p_t(U).$$
The factor of 1/2 originates from not inserting a factor of $\sqrt{2}$ in the SDE that defines the diffusion process, which we adopt as well.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file sun_diffusion-0.1.0.tar.gz.
File metadata
- Download URL: sun_diffusion-0.1.0.tar.gz
- Upload date:
- Size: 27.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
404cb2d1da57cc0793f7081196114a40f2b8151eab651b5e6ab40fa79186fc2b
|
|
| MD5 |
d7fa67764884f7c8bffe6cb6e308030b
|
|
| BLAKE2b-256 |
998efe359db0a961b916174e798fba5294ff1d63dba45a574b8e69545d17aafb
|
File details
Details for the file sun_diffusion-0.1.0-py3-none-any.whl.
File metadata
- Download URL: sun_diffusion-0.1.0-py3-none-any.whl
- Upload date:
- Size: 29.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.10.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ed90cebbbd16a56652cb1a32e62cbc9e3a8f8a3e1ac11826b0914ddb5bdc60ba
|
|
| MD5 |
deda22746cac15984f246af15bfa51e6
|
|
| BLAKE2b-256 |
30b1ff7207bf79cfd3b845177bd12e0c27bf6b5816677a0c0d148090da9f98b0
|