qlat.selected_points_types — Typed Selected-Points Classes¶
Source: qlat/qlat/selected_points_types.pyx.in
Note: Update this document when updating the source file.
Outline¶
Overview¶
selected_points_types is a template module (.pyx.in) that generates concrete
SelectedPoints{Type} subclasses of SelectedPointsBase for every lattice data
type. Each generated class stores data at a discrete set of lattice points
identified by a PointsSelection.
Unlike SelectedField (which stores data at sites in a contiguous block
according to a FieldSelection), SelectedPoints stores data at arbitrary
lattice coordinates. This makes them suitable for correlator measurements,
point-source operators, and data exchange via shuffle plans.
All selected-points classes are registered in selected_points_type_dict.
Generated Types¶
The template generates SelectedPoints variants for all 16 element types:
Category |
Classes |
|---|---|
Complex matrices |
|
Complex scalars |
|
Real scalars |
|
Integer types |
|
Construction¶
sp = SelectedPointsRealD() # empty
sp = SelectedPointsRealD(n_points, multiplicity, points_dist_type) # from sizes
sp = SelectedPointsRealD(None) # empty
sp = SelectedPointsRealD(psel) # with points selection
sp = SelectedPointsRealD(psel, multiplicity) # with multiplicity
sp = SelectedPointsRealD(sp_src, ssp) # via shuffle plan
sp = SelectedPointsRealD(sf, ssp) # from SelectedField via shuffle
Parameters:
psel— aPointsSelectionspecifying which points to store.points_dist_type— distribution type:"g"(global),"l"(local),"r"(round-robin),"f","o".ssp— aSelectedShufflePlanfor data redistribution.
Properties¶
Property |
Type |
Description |
|---|---|---|
|
|
Number of selected points |
|
|
Number of elements per point |
|
|
Size of one element in bytes |
|
|
Distribution type: |
|
|
Geometry from |
The points_dist_type property is read/write.
Assignment and Copying¶
The @= operator assigns data. It does not change self.psel.
sp1 @= sp2 # SelectedPoints ← SelectedPoints (psel may differ)
sp @= sf # SelectedPoints ← SelectedField (gather available points)
sp @= f # SelectedPoints ← Field (gather at selected points)
Method |
Description |
|---|---|
|
Deep copy with same |
|
Set all elements to zero |
|
Swap contents with another |
|
Swap raw bytes with a |
Mutation Operations¶
sp.set_zero()
sp.set_rand(rng, upper=1.0, lower=0.0) # uniform random
sp.set_rand_g(rng, center=0.0, sigma=1.0) # Gaussian random
Method |
Description |
|---|---|
|
Global squared norm (scalar float) |
|
Per-point squared norm → |
Arithmetic Operations¶
In-place arithmetic is supported:
sp1 += sp2 # element-wise addition
sp1 -= sp2 # element-wise subtraction
sp *= 2.0 # scalar multiplication
sp *= (1.0+0.5j) # complex scalar multiplication
I/O and Serialization¶
sp.save(path, is_sync_node=True)
sp.load(path, is_sync_node=True)
sp.save_str(is_sync_node=True) # serialize to bytes (node root only)
sp.load_str(content, is_sync_node=True) # deserialize from bytes (node 0 only)
LatData Conversion¶
Types with double-precision, single-precision, long, or int elements support
conversion to and from LatData:
ld = sp.to_lat_data() # → LatData / LatDataRealF / LatDataLong / LatDataInt
sp.from_lat_data(ld) # ← LatData
The concrete LatData type depends on the element type:
Element types |
LatData type |
|---|---|
|
|
|
|
|
|
|
|
Broadcasting¶
sp.bcast(root=0)
Broadcast data from root to all nodes. Also broadcasts self.psel.
Sets self.psel to None if psel.n_points == 0.
NumPy Buffer Protocol¶
All selected-points types support zero-copy NumPy access:
arr = np.asarray(sp) # shape: (n_points, multiplicity, *element_shape)
Selected-Points Type Dictionary¶
from qlat.field_type_dict import selected_points_type_dict
SelectedPointsRealD = selected_points_type_dict[ElemTypeRealD]
Examples¶
import qlat as q
import numpy as np
q.begin_with_mpi([[1, 1, 1, 4]])
geo = q.Geometry(q.Coordinate([4, 4, 4, 8]))
# Create a PointsSelection with a few global coordinates
total_site = q.Coordinate([4, 4, 4, 8])
psel = q.PointsSelection(total_site, [[0, 0, 0, 0], [1, 1, 1, 1]])
# Construct SelectedPoints with multiplicity 1
sp = q.SelectedPointsRealD(psel, 1)
sp.set_zero()
print(f"n_points: {sp.n_points}")
# Set uniform random values
rng = q.RngState("seed-1")
sp.set_rand(rng)
# Access as NumPy array
arr = np.asarray(sp)
print(f"Shape: {arr.shape}")
# Arithmetic
sp += sp
sp *= 0.5
# Norm
norm = sp.qnorm()
print(f"qnorm: {norm}")
# LatData round-trip
ld = sp.to_lat_data()
sp2 = q.SelectedPointsRealD(psel, 1)
sp2.from_lat_data(ld)
# Save/load
sp.save("sp_data")
sp3 = q.SelectedPointsRealD()
sp3.load("sp_data")
q.end_with_mpi()