qlat_utils

Qlattice utility package

Usage:

import qlat_utils as q

Will also be loaded by import qlat as q together with other qlat functions.

Message

get_verbose_level()

Return the current verbosity level as integer.

set_verbose_level([level])

Set the current verbosity level as integer.

displayln(level, *args)

Print all the arguments and then print a newline.

displayln_info(*args)

Same as displayln but only print if get_id_node() == 0.

get_fname()

Return the function name of the current function fname

Timer

timer([func])

Timing functions.

timer_verbose(func)

Timing functions.

timer_flops(func)

Timing functions with flops.

timer_verbose_flops(func)

Timing functions with flops.

timer_display(str tag=)

timer_display_stack()

timer_fork(...)

timer_merge()

get_time()

Return current time in seconds since epoch.

get_start_time()

Return start time in seconds since epoch.

Random number

RngState([x, y])

get_data_sig(x, RngState rs)

Return a signature (a floating point number, real or complex) of data viewed as a 1-D array of numbers.

Algorithm of the random number generator

The state of the generator is effectively composed of the history of the generator encoded as a string.

To generate random numbers, one computes the SHA-256 hash of the string. The hash result is viewed as a 8 32-bit unsigned integers.

The 8 32-bit unsigned integers are merged into 4 64-bit unsigned integers. These 4 numbers are treated as the random numbers generated by this random number generator.

Relevant source files: qlat-utils/include/qlat-utils/rng-state.h and qlat-utils/lib/rng-state.cpp

Coordinate

rel_mod(x, size)

Return x % size or x % size - size

rel_mod_sym(x, size)

Return x % size or x % size - size or 0

rel_mod_arr(x, size)

Return x % size or x % size - size where x and size are np.array of same shape

rel_mod_sym_arr(x, size)

Return x % size or x % size - size or 0 where x and size are np.array of same shape

Coordinate

Coordinate.to_list()

Return a list composed of the 4 components of the coordinate.

Coordinate.to_tuple()

Return a tuple composed of the 4 components of the coordinate.

Coordinate.to_numpy()

Return a np.ndarray composed of the 4 components of the coordinate.

Coordinate.from_list(x)

set value based on a list composed of the 4 components of the coordinate.

Coordinate.sqr()

Return the square sum of all the components as cc.Long.

Coordinate.r_sqr()

get spatial distance square as int

Coordinate.volume()

get product of all components

Coordinate.spatial_volume()

get product of all components

Coordinate.from_index(index, size)

Coordinate.to_index(size)

CoordinateD

CoordinateD.to_list()

Return a list composed of the 4 components of the coordinate.

CoordinateD.to_tuple()

Return a tuple composed of the 4 components of the coordinate.

Coordinate.to_numpy()

Return a np.ndarray composed of the 4 components of the coordinate.

Coordinate.from_list(x)

set value based on a list composed of the 4 components of the coordinate.

Cache system

Cache(*keys)

self.cache_keys

mk_cache(*keys[, ca])

make cache if it does not exist, otherwise return existing elements

clean_cache([ca])

Remove values of cache, but keep all the structures

list_cache([ca])

rm_cache(*keys[, ca])

remove cache if it exist

get_all_caches_info()

clear_all_caches()

Example code:

Usage:
cache_x = q.mk_cache("xx")
q.clean_cache(cache_x)
cache_x[key] = value
val = cache_x[key]
key in cache_x
val = cache_x.get(key)
val = cache_x.pop(key, None)

Matrix for QCD

WilsonMatrix

SpinMatrix

ColorMatrix

get_gamma_matrix(int mu)

wilson_matrix_g5_herm(WilsonMatrix x)

mat_tr_sm(SpinMatrix v)

mat_tr_cm(ColorMatrix v)

mat_tr_wm(WilsonMatrix v)

mat_tr_wm_wm(WilsonMatrix v1, WilsonMatrix v2)

mat_tr_wm_sm(WilsonMatrix v1, SpinMatrix v2)

mat_tr_sm_wm(SpinMatrix v1, WilsonMatrix v2)

mat_tr_sm_sm(SpinMatrix v1, SpinMatrix v2)

mat_tr_wm_cm(WilsonMatrix v1, ColorMatrix v2)

mat_tr_cm_wm(ColorMatrix v1, WilsonMatrix v2)

mat_tr_cm_cm(ColorMatrix v1, ColorMatrix v2)

mat_mul_wm_wm(WilsonMatrix v1, WilsonMatrix v2)

mat_mul_wm_sm(WilsonMatrix v1, SpinMatrix v2)

mat_mul_sm_wm(SpinMatrix v1, WilsonMatrix v2)

mat_mul_sm_sm(SpinMatrix v1, SpinMatrix v2)

mat_mul_wm_cm(WilsonMatrix v1, ColorMatrix v2)

mat_mul_cm_wm(ColorMatrix v1, WilsonMatrix v2)

mat_mul_cm_cm(ColorMatrix v1, ColorMatrix v2)

as_wilson_matrix(x)

as_wilson_matrix_g5_herm(x)

ElemType

ElemType

ElemTypeInt8t

ElemTypeInt32t

ElemTypeInt64t

ElemTypeChar

ElemTypeInt

ElemTypeLong

ElemTypeRealD

ElemTypeRealF

ElemTypeComplexD

ElemTypeComplexF

ElemTypeSpinMatrix

ElemTypeWilsonMatrix

ElemTypeColorMatrix

ElemTypeIsospinMatrix

ElemTypeNonRelWilsonMatrix

ElemTypeWilsonVector

Data analysis

get_chunk_list(total_list, *[, chunk_size, ...])

Split total_list into chunk_number chunks or chunks with chunk_size. One (and only one) of chunk_size and chunk_number should not be None. # Returns a list of chunks. Number of chunks is less or equal to chunk_number. Chunk sizes are less or equal to chunk_size. if rng_state is None: Do not randomly permute the list.

check_zero(x)

qnorm(x)

qnorm(2) == 4

Spatial distance list

mk_r_sq_list(r_sq_limit[, dimension])

mk_r_list(r_limit, *[, r_all_limit, ...])

Make a list of r values from 0 up to r_limit.

mk_interp_tuple(x, x0, x1, x_idx)

Returns (x_idx_low, x_idx_high, coef_low, coef_high,)

mk_r_sq_interp_idx_coef_list(r_list)

Return a list of tuples:

Interpolation

interp_i_arr(data_x_arr, x_arr)

return i_arr

interp(data_arr, i_arr[, axis])

return approximately data_arr[..., i_arr] if axis=-1.

interp_x(data_arr, data_x_arr, x_arr[, axis])

return interpolated_data_arr x_arr can be either an 1-D array-like object or a single number.

get_threshold_idx(arr, threshold)

return x

get_threshold_i_arr(data_arr, threshold_arr)

return i_arr

get_threshold_x_arr(data_arr, data_x_arr, ...)

return x_arr

Plotting

plot_save([fn, dts, cmds, lines, ...])

fn is full name of the plot or None dts is dict_datatable, e.g. { "table.txt" : [ [ 0, 1, ], [ 1, 2, ], ], } cmds is plot_cmds, e.g. [ "set key rm", "set size 1.0, 1.0 ", ] lines is plot_lines, e.g. [ "plot", "x", ].

plot_view([fn, dts, cmds, lines, ...])

Example code to make a plot: examples-py/qplot.py