auto_contractor.distillation_mat_op — Distillation Matrix Operations¶
Source: qlat/auto_contractor/distillation_mat_op.py
Note: Update this document when updating the source file.
Outline¶
Overview¶
distillation_mat_op provides NumPy-based matrix operations for the
distillation framework, where propagators are stored as dense NumPy arrays
indexed by (spin, noise_vector) rather than as compact WilsonMatrix objects.
All operations use np.einsum with cached contraction paths for performance.
The module distinguishes three matrix types by their index structure:
Abbreviation |
Type |
Index Convention |
|---|---|---|
|
Wilson matrix |
|
|
Spin matrix |
|
|
Colour/noise matrix |
|
Einsum Cache Path¶
einsum_cache_path(subscripts, *operands, optimize=None)¶
Wrapper around np.einsum that supports cached contraction paths. When
optimize is an empty list [], the optimal path is computed via
np.einsum_path with optimize="optimal", stored into the list, and printed.
Subsequent calls reuse the cached path.
Gamma Matrix¶
get_gamma_matrix(mu)¶
Return the gamma matrix for direction mu (0–3 for spatial, 5 for γ₅) as a
NumPy array. Results are cached via @functools.lru_cache.
wilson_matrix_g5_herm(x)¶
Compute γ₅ · x† · γ₅ for a Wilson matrix x. Used to obtain the
G-parity-conjugate propagator.
load_prop(x)¶
Load a propagator, applying g5_herm conjugation if x is a tuple
("g5_herm", prop_data). Uses q.ama_apply1 for AMA support.
Wilson Matrix Operations¶
All Wilson matrix trace/multiply functions use 4-index Einstein summation.
Function |
Einsum |
Description |
|---|---|---|
|
|
Trace of a Wilson matrix |
|
|
Trace of product of two Wilson matrices |
|
|
Product of two Wilson matrices |
Spin Matrix Operations¶
Function |
Einsum |
Description |
|---|---|---|
|
|
Trace of a spin matrix |
|
|
Trace of product of two spin matrices |
|
|
Product of two spin matrices |
Colour Matrix Operations¶
Function |
Einsum |
Description |
|---|---|---|
|
|
Trace of a colour matrix |
|
|
Trace of product of two colour matrices |
|
|
Product of two colour matrices |
Cross-Type Trace Operations¶
These trace functions combine operators of different index types.
Function |
Einsum |
Description |
|---|---|---|
|
|
tr(WilsonMatrix · SpinMatrix) |
|
— |
tr(SpinMatrix · WilsonMatrix), delegates to |
|
|
tr(WilsonMatrix · ColorMatrix) |
|
— |
tr(ColorMatrix · WilsonMatrix), delegates to |
Cross-Type Multiplication Operations¶
Function |
Einsum |
Description |
|---|---|---|
|
|
WilsonMatrix × SpinMatrix |
|
|
SpinMatrix × WilsonMatrix |
|
|
WilsonMatrix × ColorMatrix |
|
|
ColorMatrix × WilsonMatrix |
Each cross-type function has a corresponding einsum_optimize_* list that
caches the contraction path on first use.
Examples¶
import qlat as q
import numpy as np
q.begin_with_mpi([[1, 1, 1, 4]])
from auto_contractor.distillation_mat_op import (
get_gamma_matrix,
mat_mul_wm_wm,
mat_tr_wm,
einsum_cache_path,
)
# Create random 4-index Wilson matrices (spin=4, noise=10)
rng = np.random.default_rng(42)
ns, nc = 4, 10
wm1 = rng.standard_normal((ns, nc, ns, nc)) + 1j * rng.standard_normal((ns, nc, ns, nc))
wm2 = rng.standard_normal((ns, nc, ns, nc)) + 1j * rng.standard_normal((ns, nc, ns, nc))
# Multiply and trace
wm3 = mat_mul_wm_wm(wm1, wm2)
tr = mat_tr_wm(wm3)
print(f"tr(S1 * S2) = {tr}")
# Gamma matrix
g5 = get_gamma_matrix(5)
print(f"gamma_5 shape: {g5.shape}")
q.end_with_mpi()