File IO¶
QAR¶
|
|
|
|
|
|
Parameter controls the size of a single qar file in number of bytes. |
|
|
Return contents of file as str |
|
Return contents of file as bytes |
|
|
|
|
|
|
|
Pickle¶
|
only save from node 0 when is_sync_node mk_file_dirs_info(path) |
|
all the nodes read the same data if is_sync_node: one node read and broadcast to other nodes else: all nodes individually read the data |
|
all the nodes compute or load the same data if is_sync_node |
LatData¶
Multi-dimension array data structure for IO.
File format description¶
FILE-HEADER
BINARY-DATA
FILE-HEADER
example:
#!/usr/bin/env lat-io-glimpse
data_size
128
ndim: 3
"tsep"[4]: "0" "1" "2" "3"
"op"[2]: "0" "1"
"re-im"[2]: "re" "im"
crc32: 77A655DB
END_HEADER
BINARY-DATA
description:
Consist of the data stored in double precision (little endian) in sequential order as a standard C multidimensional array.
|
by default, return list can be used as the input argument for ld.set_info or mk_lat_data |
|
|
|
|
|
only set LatData shape if it is initially empty otherwise only set data and ignore shape completely dim_names should be a list of names for each dimension |
|
|
|
|
|
|
|
Load |
Example: examples-py/lat-io.py
#!/usr/bin/env python3
import qlat as q
import numpy as np
import os
q.begin_with_mpi()
q.qremove_all_info("results")
q.qmkdir_info("results")
rs = q.RngState("test")
info_list = [
[ "dim1", 4, ],
[ "dim2 name", 3, ],
[ "dim3", 2, [ "u", "d", ], ],
[ "dim4", 5, ],
]
ld = q.mk_lat_data(info_list)
q.displayln_info(ld.info())
rs.copy().g_rand_fill(np.asarray(ld).ravel())
arr = ld.to_numpy()
if q.get_id_node() == 0:
ld.save("results/ld.lat")
q.sync_node()
ld = q.LatData()
ld.load("results/ld.lat")
assert q.qnorm(np.asarray(ld) - arr) == 0
ld1 = q.load_lat_data("results/ld.lat")
assert q.qnorm(np.asarray(ld1) - arr) == 0
ld1 = q.mk_lat_data_real_f(info_list)
q.displayln_info(ld1.info())
ld1 @= ld
arr1 = ld1.to_numpy()
if q.get_id_node() == 0:
ld1.save("results/ld1.latf")
q.sync_node()
ld1 = q.LatDataRealF()
ld1.load("results/ld1.latf")
assert q.qnorm(np.asarray(ld1) - arr1) == 0
ld2 = q.mk_lat_data_long(info_list)
arr2 = ld2[:]
arr2.ravel()[:] = np.arange(len(arr2.ravel()))
if q.get_id_node() == 0:
ld2.save("results/ld2.latl")
q.sync_node()
ld2 = q.LatDataLong()
ld2.load("results/ld2.latl")
assert q.qnorm(ld2[:] - arr2) == 0
ld3 = q.mk_lat_data_int(info_list)
arr3 = ld3[:]
arr3.ravel()[:] = np.arange(len(arr3.ravel()))
if q.get_id_node() == 0:
ld3.save("results/ld3.latl")
q.sync_node()
ld3 = q.LatDataInt()
ld3.load("results/ld3.latl")
assert q.qnorm(ld3[:] - arr3) == 0
q.check_all_files_crc32_info("results")
q.timer_display()
q.end_with_mpi()
q.displayln_info(f"CHECK: finished successfully.")
C++ example: examples-cpp/latio/main.cpp
#include <qutils/lat-io.h>
namespace qlat
{ //
inline void demo_c()
{
const Long n_tsep = 4;
const Long n_op = 2;
LatData ld;
ld.info.push_back(lat_dim_number("tsep", 0, n_tsep - 1));
ld.info.push_back(lat_dim_number("op", 0, n_op - 1));
ld.info.push_back(lat_dim_string("type", make_array<std::string>("a", "b")));
ld.info.push_back(lat_dim_re_im());
lat_data_alloc(ld);
set_zero(ld);
for (int i = 0; i < n_tsep; ++i) {
for (int j = 0; j < n_op; ++j) {
Vector<ComplexD> v = lat_data_cget(ld, make_array<Long>(i, j));
v[0] = (ComplexD)i + ii * (ComplexD)j;
v[1] = (ComplexD)j + ii * (ComplexD)i;
}
}
ld.save("results-data-c.lat");
LatData ld1;
ld1.load("results-data-c.lat");
displayln_info(show(ld1));
}
inline void demo_r()
{
const Long n_tsep = 4;
const Long n_op = 2;
LatData ld;
ld.info.push_back(lat_dim_number("tsep", 0, n_tsep - 1));
ld.info.push_back(lat_dim_number("op", 0, n_op - 1));
ld.info.push_back(lat_dim_string("type", make_array<std::string>("a", "b")));
lat_data_alloc(ld);
set_zero(ld);
for (int i = 0; i < n_tsep; ++i) {
for (int j = 0; j < n_op; ++j) {
Vector<double> v = lat_data_get(ld, make_array<Long>(i, j));
v[0] = i;
v[1] = j;
}
}
ld.save("results-data-r.lat");
LatData ld1;
ld1.load("results-data-r.lat");
displayln_info(show(ld1));
}
} // namespace qlat
int main(int argc, char* argv[])
{
demo_c();
demo_r();
displayln_info("CHECK: finished successfully.");
return 0;
}
C++ code: qlat-utils/include/qlat-utils/lat-io.h
Gauge Field¶
|
|
|
Save with the standard NERSC format |
|
Load with the standard NERSC format |
Gauge Transform¶
|
|
|
Save as double precision with the generic Field format |
|
Load as double precision with the generic Field format |
|
Save with the format used in CPS |
|
Load with the format used in CPS |
FieldBase¶
Support np.asarray(f)
.
|
|
|
Generic save for Field object save Field directly (without any conversion of endianness or precision) possible way to call: f.save_direct(path) f.save_direct(sfw, fn) |
|
Generic load for Field object load Field directly (without any conversion of endianness or precision) Field geo and multiplicity will be determined during loading possible way to call: f.load_direct(path) f.load_direct(sfr, fn) |
|
Generic save for 64-bit size element Field object save 64-bit Field (do conversion of endianness) |
|
Generic load for 64-bit size element Field object load 64-bit Field (do conversion of endianness) |
|
Generic save for double element Field object save double Field as double (do conversion of endianness) |
|
Generic load for double Field object load double Field (do conversion of endianness) |
|
Generic save for double element Field object save double Field as float (do conversion of endianness and precision) |
|
Generic load for double Field object load double Field from float(do conversion of endianness or precision) |
|
self needs to be FieldRealF |
|
self can be any FieldBase subtype but need to be actually contains double precision numbers |
|
Convert between the native endianness and the endianness specified by |
|
return new Field(ctype) with the same content |
|
assign from f with the same content but possibly different type |
FieldSelection¶
|
|
|
|
|
|
|
|
SelectedFieldBase¶
Support np.asarray(sf)
.
|
|
|
Generic save for SelectedField object possible way to call: f.save_direct(path) # has some limitations f.save_direct(sfw, fn) |
|
Generic load for SelectedField object possible way to call: f.load_direct(path) # has some limitations f.load_direct(sfr, fn) if self.fsel is None, self.fsel will be set during f.load_direct(sfr, fn) |
|
Generic save for SelectedField object with conversion |
|
Generic load for SelectedField object with conversion |
|
Generic save for SelectedField object with conversion |
|
Generic load for SelectedField object with conversion |
Generic save for SelectedField object with conversion |
|
Generic load for SelectedField object with conversion |
|
|
|
|
|
|
PointsSelection¶
Support np.asarray(psel)
.
|
|
|
|
|
|
return xg for all selected points shape = (psel.n_points, 4,) |
SelectedPointsBase¶
Support np.asarray(sp)
.
|
|
|
|
|
need to be already initialized with ctype and psel arr.shape[0] == n_points |
|
|
|
|
|