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¶
Return the current verbosity level as integer. |
|
|
Set the current verbosity level as integer. |
|
Print all the arguments and then print a newline. |
|
Same as |
Return the function name of the current function |
Timer¶
|
Timing functions. |
|
Timing functions. |
|
Timing functions with flops. |
|
Timing functions with flops. |
|
|
|
|
|
Return current time in seconds since epoch. |
Return start time in seconds since epoch. |
Random number¶
|
|
|
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¶
|
Return |
|
Return |
|
Return |
|
Return |
Return a list composed of the 4 components of the coordinate. |
|
Return a tuple composed of the 4 components of the coordinate. |
|
Return a np.ndarray composed of the 4 components of the coordinate. |
|
set value based on a list composed of the 4 components of the coordinate. |
|
Return the square sum of all the components as |
|
get spatial distance square as int |
|
get product of all components |
|
get product of all components |
|
|
|
|
|
Return a list composed of the 4 components of the coordinate. |
|
Return a tuple composed of the 4 components of the coordinate. |
|
Return a np.ndarray composed of the 4 components of the coordinate. |
|
set value based on a list composed of the 4 components of the coordinate. |
Cache system¶
|
|
|
make cache if it does not exist, otherwise return existing elements |
|
Remove values of cache, but keep all the structures |
|
|
|
remove cache if it exist |
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¶
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ElemType¶
Data analysis¶
|
Split |
Spatial distance list¶
|
|
|
Make a list of r values from 0 up to r_limit. |
|
Returns (x_idx_low, x_idx_high, coef_low, coef_high,) |
|
Return a list of tuples: |
Jackknife method¶
|
Perform initial Jackknife for the original data set. |
|
Perform (randomized) Super-Jackknife for the Jackknife data set. |
|
Create a jackknife sample with random numbers based on central value |
|
Return |
|
Return |
|
Return |
|
Return number of samples for the (randomized) Super-Jackknife data set. |
|
Return |
Example for the random Super-Jackknife method: examples-py/jackknife-random.py
#!/usr/bin/env python3
import qlat as q
import numpy as np
import functools
q.begin_with_mpi()
q.default_g_jk_kwargs["jk_type"] = "rjk"
q.default_g_jk_kwargs["n_rand_sample"] = 1024
q.default_g_jk_kwargs["rng_state"] = q.RngState("rejk")
q.default_g_jk_kwargs["jk_blocking_func"] = None
q.default_g_jk_kwargs["is_normalizing_rand_sample"] = True
@functools.lru_cache
def get_trajs(job_tag):
return list(range(25))
rs = q.RngState("seed")
job_tag = "test1"
trajs = get_trajs(job_tag)
data_arr = rs.g_rand_arr((len(trajs), 5,)) # can be list or np.array
jk_arr = q.g_jk(data_arr)
jk_idx_list = [ "avg", ] + [ (job_tag, traj) for traj in trajs ]
jk_arr = q.g_rejk(jk_arr, jk_idx_list)
avg, err = q.g_jk_avg_err(jk_arr)
q.displayln_info(f"CHECK: {avg}")
q.displayln_info(f"CHECK: {err}")
json_results = []
check_eps = 1e-10
for i in range(len(avg)):
json_results.append((f"avg[{i}]", avg[i],))
for i in range(len(avg)):
json_results.append((f"err[{i}]", err[i],))
q.check_log_json(__file__, json_results)
q.end_with_mpi()
q.displayln_info(f"CHECK: finished successfully.")
Example for the conventional Super-Jackknife method: examples-py/jackknife-super.py
#!/usr/bin/env python3
import qlat as q
import numpy as np
import functools
q.begin_with_mpi()
job_tags = [ 'test1', 'test2', ]
q.default_g_jk_kwargs["jk_type"] = "super"
@functools.lru_cache
def get_all_jk_idx():
jk_idx_list = [ 'avg', ]
for job_tag in job_tags:
trajs = get_trajs(job_tag)
for traj in trajs:
jk_idx_list.append((job_tag, traj,))
return jk_idx_list
q.default_g_jk_kwargs["get_all_jk_idx"] = get_all_jk_idx
@functools.lru_cache
def get_trajs(job_tag):
return list(range(25))
rs = q.RngState("seed")
job_tag = "test1"
trajs = get_trajs(job_tag)
data_arr = rs.g_rand_arr((len(trajs), 5,)) # can be list or np.array
jk_arr = q.g_jk(data_arr)
jk_idx_list = [ "avg", ] + [ (job_tag, traj) for traj in trajs ]
jk_arr = q.g_rejk(jk_arr, jk_idx_list)
avg, err = q.g_jk_avg_err(jk_arr)
q.displayln_info(f"CHECK: {avg}")
q.displayln_info(f"CHECK: {err}")
json_results = []
check_eps = 1e-10
for i in range(len(avg)):
json_results.append((f"avg[{i}]", avg[i],))
for i in range(len(avg)):
json_results.append((f"err[{i}]", err[i],))
q.check_log_json(__file__, json_results)
q.end_with_mpi()
q.displayln_info(f"CHECK: finished successfully.")
Plotting¶
|
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", ]. |
|
Example code to make a plot: examples-py/qplot.py
#!/usr/bin/env python3
import numpy as np
import qlat as q
q.begin_with_mpi()
q.qremove_all_info("results")
q.qmkdir_info("results")
q.qplot.plot_save_display_width = 500
x = np.arange(31) * (6 / 30) - 3
y = np.cos(x)
yerr = 0.1 / (1 + x**2)
dts = {
"table.txt": q.azip(x, y, yerr),
}
if q.get_id_node() == 0:
q.plot_save(
fn = "results/plot.png",
dts = dts,
cmds = [
"set size 0.8, 1.0",
"set key tm",
"set xlabel '$x$'",
"set ylabel '$y$'",
],
lines = [
"plot [-3:3] [-1.5:1.5]",
"0 not",
"sin(x) w l t '$y = \\sin(x)$'",
"'table.txt' w yerrorb t '$y = \\cos(x)$'",
],
)
q.timer_display()
q.end_with_mpi()
q.displayln_info(f"CHECK: finished successfully.")