mirror of
https://git.gfz-potsdam.de/naaice/poet.git
synced 2025-12-13 03:18:23 +01:00
Added qs2 as new default format
This commit is contained in:
parent
b29be5fd6d
commit
9f89edd492
@ -109,69 +109,6 @@ msgm <- function(...) {
|
||||
}
|
||||
|
||||
|
||||
## Function called by master R process to store on disk all relevant
|
||||
## parameters for the simulation
|
||||
StoreSetup <- function(setup, filesim, out_dir) {
|
||||
to_store <- vector(mode = "list", length = 4)
|
||||
## names(to_store) <- c("Sim", "Flow", "Transport", "Chemistry", "DHT")
|
||||
names(to_store) <- c("Sim", "Transport", "DHT", "Cmdline")
|
||||
|
||||
## read the setup R file, which is sourced in kin.cpp
|
||||
tmpbuff <- file(filesim, "r")
|
||||
setupfile <- readLines(tmpbuff)
|
||||
close.connection(tmpbuff)
|
||||
|
||||
to_store$Sim <- setupfile
|
||||
|
||||
## to_store$Flow <- list(
|
||||
## snapshots = setup$snapshots,
|
||||
## gridfile = setup$gridfile,
|
||||
## phase = setup$phase,
|
||||
## density = setup$density,
|
||||
## dt_differ = setup$dt_differ,
|
||||
## prolong = setup$prolong,
|
||||
## maxiter = setup$maxiter,
|
||||
## saved_iter = setup$iter_output,
|
||||
## out_save = setup$out_save )
|
||||
|
||||
to_store$Transport <- setup$diffusion
|
||||
|
||||
## to_store$Chemistry <- list(
|
||||
## nprocs = n_procs,
|
||||
## wp_size = work_package_size,
|
||||
## base = setup$base,
|
||||
## first = setup$first,
|
||||
## init = setup$initsim,
|
||||
## db = db,
|
||||
## kin = setup$kin,
|
||||
## ann = setup$ann)
|
||||
|
||||
if (dht_enabled) {
|
||||
to_store$DHT <- list(
|
||||
enabled = dht_enabled,
|
||||
log = dht_log
|
||||
## signif = dht_final_signif,
|
||||
## proptype = dht_final_proptype
|
||||
)
|
||||
} else {
|
||||
to_store$DHT <- FALSE
|
||||
}
|
||||
|
||||
if (dht_enabled) {
|
||||
to_store$DHT <- list(
|
||||
enabled = dht_enabled,
|
||||
log = dht_log
|
||||
# signif = dht_final_signif,
|
||||
# proptype = dht_final_proptype
|
||||
)
|
||||
} else {
|
||||
to_store$DHT <- FALSE
|
||||
}
|
||||
|
||||
saveRDS(to_store, file = paste0(fileout, "/setup.rds"))
|
||||
msgm("initialization stored in ", paste0(fileout, "/setup.rds"))
|
||||
}
|
||||
|
||||
GetWorkPackageSizesVector <- function(n_packages, package_size, len) {
|
||||
ids <- rep(1:n_packages, times = package_size, each = 1)[1:len]
|
||||
return(as.integer(table(ids)))
|
||||
@ -179,7 +116,7 @@ GetWorkPackageSizesVector <- function(n_packages, package_size, len) {
|
||||
|
||||
|
||||
## Handler to read R objs from binary files using either builtin
|
||||
## readRDS() or qs::qread() based on file extension
|
||||
## readRDS(), qs::qread() or qs2::qs_read() based on file extension
|
||||
ReadRObj <- function(path) {
|
||||
## code borrowed from tools::file_ext()
|
||||
pos <- regexpr("\\.([[:alnum:]]+)$", path)
|
||||
@ -187,7 +124,8 @@ ReadRObj <- function(path) {
|
||||
|
||||
switch(extension,
|
||||
rds = readRDS(path),
|
||||
qs = qs::qread(path)
|
||||
qs = qs::qread(path),
|
||||
qs2 = qs2::qs_read(path)
|
||||
)
|
||||
}
|
||||
|
||||
@ -201,6 +139,73 @@ SaveRObj <- function(x, path) {
|
||||
|
||||
switch(extension,
|
||||
rds = saveRDS(object = x, file = path),
|
||||
qs = qs::qsave(x = x, file = path)
|
||||
qs = qs::qsave(x = x, file = path),
|
||||
qs2 = qs2::qs_save(object = x, file = path)
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
######## Old relic code
|
||||
|
||||
## ## Function called by master R process to store on disk all relevant
|
||||
## ## parameters for the simulation
|
||||
## StoreSetup <- function(setup, filesim, out_dir) {
|
||||
## to_store <- vector(mode = "list", length = 4)
|
||||
## ## names(to_store) <- c("Sim", "Flow", "Transport", "Chemistry", "DHT")
|
||||
## names(to_store) <- c("Sim", "Transport", "DHT", "Cmdline")
|
||||
|
||||
## ## read the setup R file, which is sourced in kin.cpp
|
||||
## tmpbuff <- file(filesim, "r")
|
||||
## setupfile <- readLines(tmpbuff)
|
||||
## close.connection(tmpbuff)
|
||||
|
||||
## to_store$Sim <- setupfile
|
||||
|
||||
## ## to_store$Flow <- list(
|
||||
## ## snapshots = setup$snapshots,
|
||||
## ## gridfile = setup$gridfile,
|
||||
## ## phase = setup$phase,
|
||||
## ## density = setup$density,
|
||||
## ## dt_differ = setup$dt_differ,
|
||||
## ## prolong = setup$prolong,
|
||||
## ## maxiter = setup$maxiter,
|
||||
## ## saved_iter = setup$iter_output,
|
||||
## ## out_save = setup$out_save )
|
||||
|
||||
## to_store$Transport <- setup$diffusion
|
||||
|
||||
## ## to_store$Chemistry <- list(
|
||||
## ## nprocs = n_procs,
|
||||
## ## wp_size = work_package_size,
|
||||
## ## base = setup$base,
|
||||
## ## first = setup$first,
|
||||
## ## init = setup$initsim,
|
||||
## ## db = db,
|
||||
## ## kin = setup$kin,
|
||||
## ## ann = setup$ann)
|
||||
|
||||
## if (dht_enabled) {
|
||||
## to_store$DHT <- list(
|
||||
## enabled = dht_enabled,
|
||||
## log = dht_log
|
||||
## ## signif = dht_final_signif,
|
||||
## ## proptype = dht_final_proptype
|
||||
## )
|
||||
## } else {
|
||||
## to_store$DHT <- FALSE
|
||||
## }
|
||||
|
||||
## if (dht_enabled) {
|
||||
## to_store$DHT <- list(
|
||||
## enabled = dht_enabled,
|
||||
## log = dht_log
|
||||
## # signif = dht_final_signif,
|
||||
## # proptype = dht_final_proptype
|
||||
## )
|
||||
## } else {
|
||||
## to_store$DHT <- FALSE
|
||||
## }
|
||||
|
||||
## saveRDS(to_store, file = paste0(fileout, "/setup.rds"))
|
||||
## msgm("initialization stored in ", paste0(fileout, "/setup.rds"))
|
||||
## }
|
||||
|
||||
@ -7,7 +7,7 @@ function(ADD_BENCH_TARGET TARGET POET_BENCH_LIST RT_FILES OUT_PATH)
|
||||
foreach(BENCH_FILE ${${POET_BENCH_LIST}})
|
||||
get_filename_component(BENCH_NAME ${BENCH_FILE} NAME_WE)
|
||||
set(OUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/${BENCH_NAME})
|
||||
set(OUT_FILE_EXT ${OUT_FILE}.qs)
|
||||
set(OUT_FILE_EXT ${OUT_FILE}.qs2)
|
||||
|
||||
add_custom_command(
|
||||
OUTPUT ${OUT_FILE_EXT}
|
||||
|
||||
@ -35,7 +35,11 @@ int main(int argc, char **argv) {
|
||||
->default_val(false);
|
||||
|
||||
bool asRDS;
|
||||
app.add_flag("-r, --rds", asRDS, "Save output as .rds file instead of .qs")
|
||||
app.add_flag("-r, --rds", asRDS, "Save output as .rds")
|
||||
->default_val(false);
|
||||
|
||||
bool asQS;
|
||||
app.add_flag("-q, --qs", asQS, "Save output as .qs")
|
||||
->default_val(false);
|
||||
|
||||
CLI11_PARSE(app, argc, argv);
|
||||
@ -69,8 +73,14 @@ int main(int argc, char **argv) {
|
||||
}
|
||||
|
||||
// append the correct file extension
|
||||
output_file += asRDS ? ".rds" : ".qs";
|
||||
|
||||
if (asRDS) {
|
||||
output_file += ".rds";
|
||||
} else if (asQS) {
|
||||
output_file += ".qs";
|
||||
} else {
|
||||
output_file += ".qs2";
|
||||
}
|
||||
|
||||
// set working directory to the directory of the input script
|
||||
if (setwd) {
|
||||
const std::string dir_path = Rcpp::as<std::string>(
|
||||
|
||||
13
src/poet.cpp
13
src/poet.cpp
@ -57,7 +57,7 @@ static std::unique_ptr<Rcpp::List> global_rt_setup;
|
||||
// before the R runtime is initialized
|
||||
static poet::DEFunc master_init_R;
|
||||
static poet::DEFunc master_iteration_end_R;
|
||||
static poet::DEFunc store_setup_R;
|
||||
// MDL: unused -> static poet::DEFunc store_setup_R;
|
||||
static poet::DEFunc ReadRObj_R;
|
||||
static poet::DEFunc SaveRObj_R;
|
||||
static poet::DEFunc source_R;
|
||||
@ -66,7 +66,7 @@ static void init_global_functions(RInside &R) {
|
||||
R.parseEval(kin_r_library);
|
||||
master_init_R = DEFunc("master_init");
|
||||
master_iteration_end_R = DEFunc("master_iteration_end");
|
||||
store_setup_R = DEFunc("StoreSetup");
|
||||
// MDL: unused -> store_setup_R = DEFunc("StoreSetup");
|
||||
source_R = DEFunc("source");
|
||||
ReadRObj_R = DEFunc("ReadRObj");
|
||||
SaveRObj_R = DEFunc("SaveRObj");
|
||||
@ -146,8 +146,11 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms) {
|
||||
"Enable AI surrogate for chemistry module");
|
||||
|
||||
app.add_flag("--rds", params.as_rds,
|
||||
"Save output as .rds file instead of .qs");
|
||||
"Save output as .rds file instead of default .qs2");
|
||||
|
||||
app.add_flag("--qs", params.as_qs,
|
||||
"Save output as .qs file instead of default .qs2");
|
||||
|
||||
std::string init_file;
|
||||
std::string runtime_file;
|
||||
|
||||
@ -174,7 +177,9 @@ int parseInitValues(int argc, char **argv, RuntimeParameters ¶ms) {
|
||||
}
|
||||
|
||||
// set the output extension
|
||||
params.out_ext = params.as_rds ? "rds" : "qs";
|
||||
params.out_ext = "qs2";
|
||||
if (params.as_rds) params.out_ext = "rds";
|
||||
if (params.as_qs) params.out_ext = "qs";
|
||||
|
||||
if (MY_RANK == 0) {
|
||||
// MSG("Complete results storage is " + BOOL_PRINT(simparams.store_result));
|
||||
|
||||
@ -45,8 +45,10 @@ struct RuntimeParameters {
|
||||
|
||||
Rcpp::List init_params;
|
||||
|
||||
// MDL added to accomodate for qs::qsave/qread
|
||||
bool as_rds = false;
|
||||
std::string out_ext; // MDL added to accomodate for qs::qsave/qread
|
||||
bool as_qs = false;
|
||||
std::string out_ext;
|
||||
|
||||
bool print_progress = false;
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user