File IO

QAR

list_qar(string path_qar)

qar_create_info(string path_qar, ...)

qar_extract_info(string path_qar, ...)

get_qar_multi_vol_max_size()

Parameter controls the size of a single qar file in number of bytes.

qcat(string path)

Return contents of file as str

qcat_bytes(string path)

Return contents of file as bytes

qcopy_file_info(string path_src, string path_dst)

does_file_exist(string path)

does_file_exist_qar(string path)

does_regular_file_exist_qar(string path)

Pickle

save_pickle_obj(obj, path, *[, is_sync_node])

only save from node 0 when is_sync_node mk_file_dirs_info(path)

load_pickle_obj(path[, default_value, ...])

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

pickle_cache_call(func, path, *[, is_sync_node])

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.

LatData

LatData.info(self[, dim])

by default, return list can be used as the input argument for ld.set_info or mk_lat_data

LatData.set_info(self, list info_list, *, ...)

info_list format.

LatData.to_numpy(self)

LatData.from_numpy(self, ndarray val, ...)

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

LatData.load(self, string path)

LatData.save(self, string path)

mk_lat_data(list info_list, *, ...)

info_list format.

load_lat_data(string path)

Load lat_data from file path.

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

GaugeField(Geometry geo=None[, multiplicity])

GaugeField.save(self, path)

Save with the standard NERSC format

GaugeField.load(self, path)

Load with the standard NERSC format

Gauge Transform

GaugeTransform(Geometry geo=None[, multiplicity])

GaugeTransform.save(self, path)

Save as double precision with the generic Field format save_double

GaugeTransform.load(self, path)

Load as double precision with the generic Field format load_double

GaugeTransform.save_cps(self, path)

Save with the format used in CPS

GaugeTransform.load_cps(self, path)

Load with the format used in CPS

FieldBase

Support np.asarray(f).

Field(type ctype, Geometry geo=None, ...)

FieldBase

FieldBase.save_direct(self, path, *args, ...)

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)

FieldBase.load_direct(self, path, *args, ...)

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)

FieldBase.save_64(self, path, *args, **kwargs)

Generic save for 64-bit size element Field object save 64-bit Field (do conversion of endianness)

FieldBase.load_64(self, path, *args, **kwargs)

Generic load for 64-bit size element Field object load 64-bit Field (do conversion of endianness)

FieldBase.save_double(self, path, *args, ...)

Generic save for double element Field object save double Field as double (do conversion of endianness)

FieldBase.load_double(self, path, *args, ...)

Generic load for double Field object load double Field (do conversion of endianness)

FieldBase.save_float_from_double(self, path, ...)

Generic save for double element Field object save double Field as float (do conversion of endianness and precision)

FieldBase.load_double_from_float(self, path, ...)

Generic load for double Field object load double Field from float(do conversion of endianness or precision)

FieldBase.float_from_double(self, FieldBase f)

self needs to be FieldRealF

FieldBase.double_from_float(self, FieldRealF ff)

self can be any FieldBase subtype but need to be actually contains double precision numbers

FieldBase.to_from_endianness(self, tag)

Convert between the native endianness and the endianness specified by tag tag can be "big_32", "big_64", "little_32", "little_64"

FieldBase.as_field(self[, ctype])

return new Field(ctype) with the same content

FieldBase.from_field(self, f)

assign from f with the same content but possibly different type

FieldSelection

FieldSelection(*args)

FieldSelection.save(self, string path)

FieldSelection.load(self, string path)

FieldSelection.to_psel(self)

FieldSelection.to_psel_local(self)

SelectedFieldBase

Support np.asarray(sf).

SelectedField(type ctype, ...)

SelectedFieldBase

SelectedFieldBase.save_direct(self, path, ...)

Generic save for SelectedField object possible way to call: f.save_direct(path) # has some limitations f.save_direct(sfw, fn)

SelectedFieldBase.load_direct(self, path, ...)

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)

SelectedFieldBase.save_64(self, path, *args, ...)

Generic save for SelectedField object with conversion

SelectedFieldBase.load_64(self, path, *args, ...)

Generic load for SelectedField object with conversion

SelectedFieldBase.save_double(self, path, ...)

Generic save for SelectedField object with conversion

SelectedFieldBase.load_double(self, path, ...)

Generic load for SelectedField object with conversion

SelectedFieldBase.save_float_from_double(...)

Generic save for SelectedField object with conversion

SelectedFieldBase.load_double_from_float(...)

Generic load for SelectedField object with conversion

SelectedFieldBase.float_from_double(self, ...)

SelectedFieldBase.double_from_float(self, ...)

SelectedFieldBase.to_from_endianness(self, tag)

PointsSelection

Support np.asarray(psel).

PointsSelection(*args)

PointsSelection.save(self, string path)

PointsSelection.load(self, string path, ...)

PointsSelection.xg_arr

return xg for all selected points shape = (psel.n_points, 4,)

SelectedPointsBase

Support np.asarray(sp).

SelectedPoints(type ctype, ...)

SelectedPointsBase

SelectedPointsBase.save_str(self)

SelectedPointsBase.load_str(self, string content)

SelectedPointsBase.to_numpy(self)

SelectedPointsBase.from_numpy(self, arr)

need to be already initialized with ctype and psel arr.shape[0] == n_points

SelectedPointsRealD.save(self, string path)

SelectedPointsRealD.load(self, string path)

SelectedPointsRealD.to_lat_data(self)

SelectedPointsRealD.from_lat_data(self, ...)