From c5e9c42b4c77af299136d1bd14c48503575893a7 Mon Sep 17 00:00:00 2001 From: orichters Date: Thu, 13 Feb 2025 12:11:10 +0100 Subject: [PATCH] add orange 'no mif', don't fail on run folder with blanks --- .buildlibrary | 2 +- CITATION.cff | 4 ++-- DESCRIPTION | 4 ++-- R/getRunStatus.R | 20 ++++++++++---------- R/loopRuns.R | 9 ++++++--- README.md | 8 ++++---- 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/.buildlibrary b/.buildlibrary index 80b0dd5..e313de6 100644 --- a/.buildlibrary +++ b/.buildlibrary @@ -1,4 +1,4 @@ -ValidationKey: '4548250' +ValidationKey: '4569964' AcceptedWarnings: - 'Warning: package ''.*'' was built under R version' - 'Warning: namespace ''.*'' is not available and has been replaced' diff --git a/CITATION.cff b/CITATION.cff index 034fe22..476469f 100644 --- a/CITATION.cff +++ b/CITATION.cff @@ -2,8 +2,8 @@ cff-version: 1.2.0 message: If you use this software, please cite it using the metadata from this file. type: software title: 'modelstats: Run Analysis Tools' -version: 0.22.6 -date-released: '2025-02-06' +version: 0.22.7 +date-released: '2025-02-13' abstract: A collection of tools to analyze model runs. authors: - family-names: Giannousakis diff --git a/DESCRIPTION b/DESCRIPTION index 789ff72..32f970c 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,8 +1,8 @@ Package: modelstats Type: Package Title: Run Analysis Tools -Version: 0.22.6 -Date: 2025-02-06 +Version: 0.22.7 +Date: 2025-02-13 Authors@R: c( person("Anastasis", "Giannousakis", email = "giannou@pik-potsdam.de", role = c("aut","cre")), person("Oliver", "Richters", role = "aut") diff --git a/R/getRunStatus.R b/R/getRunStatus.R index c4cb31e..c64a000 100644 --- a/R/getRunStatus.R +++ b/R/getRunStatus.R @@ -149,17 +149,17 @@ getRunStatus <- function(mydir = dir(), sort = "nf", user = NULL) { cm_iteration_max <- cfg$gms$cm_iteration_max if (isTRUE(cfg$gms$cm_nash_autoconverge > 0) && grepl("nash", out[i, "RunType"])) { if (file.exists(fullgms)) { - cm_iteration_max <- suppressWarnings(system(paste0("tac ", fullgms, "| grep -m 1 'cm_iteration_max = [1-9].*.;[ ]*$'"), intern = TRUE)) + cm_iteration_max <- suppressWarnings(system(paste0("tac '", fullgms, "' | grep -m 1 'cm_iteration_max = [1-9].*.;[ ]*$'"), intern = TRUE)) cm_iteration_max <- sub(";[ ]*", "", sub("^.*.= ", "", cm_iteration_max)) } } out[i, "Iter"] <- "NA" out[i, "RunStatus"] <- "NA" if (file.exists(fulllog)) { - suppressWarnings(try(loop <- sub("^.*.= ", "", system(paste0("grep 'LOOPS' ", fulllog, " | tail -1"), intern = TRUE)), silent = TRUE)) + suppressWarnings(try(loop <- sub("^.*.= ", "", system(paste0("grep 'LOOPS' '", fulllog, "' | tail -1"), intern = TRUE)), silent = TRUE)) if (length(loop) > 0) out[i, "Iter"] <- loop if (length(cm_iteration_max) > 0) out[i, "Iter"] <- paste0(out[i, "Iter"], "/", cm_iteration_max) - suppressWarnings(try(out[i, "RunStatus"] <- substr(sub("\\(s\\)", "", sub("\\*\\*\\* Status: ", "", system(paste0("grep '*** Status: ' ", fulllog), intern = TRUE))), start = 1, stop = 17), silent = TRUE)) + suppressWarnings(try(out[i, "RunStatus"] <- substr(sub("\\(s\\)", "", sub("\\*\\*\\* Status: ", "", system(paste0("grep '*** Status: ' '", fulllog, "'"), intern = TRUE))), start = 1, stop = 17), silent = TRUE)) if (onCluster && out[i, "RunStatus"] == "NA") { if (out[i, "jobInSLURM"] == "no" || grepl("pending$", out[i, "jobInSLURM"])) { if (file.exists(logtxt)) { @@ -193,8 +193,8 @@ getRunStatus <- function(mydir = dir(), sort = "nf", user = NULL) { if (out[i, "RunStatus"] == "NA") out[i, "RunStatus"] <- "Run interrupted" } if (out[i, "RunStatus"] == "Normal completion" && file.exists(logtxt) && out[i, "jobInSLURM"] != "no") { - startrep <- suppressWarnings(system(paste0("tac ", logtxt, " | grep -m 1 'Starting output generation for'"), intern = TRUE)) - endrep <- suppressWarnings(system(paste0("tac ", logtxt, " | grep -m 1 'Finished output generation for'"), intern = TRUE)) + startrep <- suppressWarnings(system(paste0("tac '", logtxt, "' | grep -m 1 'Starting output generation for'"), intern = TRUE)) + endrep <- suppressWarnings(system(paste0("tac '", logtxt, "' | grep -m 1 'Finished output generation for'"), intern = TRUE)) if (length(startrep) > length(endrep) && out[i, "jobInSLURM"] != "no") { out[i, "RunStatus"] <- "Running reporting" } @@ -212,16 +212,16 @@ getRunStatus <- function(mydir = dir(), sort = "nf", user = NULL) { } } if (file.exists(logmagtxt) && out[i, "jobInSLURM"] != "no" && (out[i, "RunStatus"] == "Normal completion" || grepl("log-mag.txt", logmagtxt))) { - startmag <- suppressWarnings(system(paste0("tac ", logmagtxt, " | grep -m 1 'Preparing MAgPIE'"), intern = TRUE)) - endmag <- suppressWarnings(system(paste0("tac ", logmagtxt, " | grep -m 1 'MAgPIE output was stored'"), intern = TRUE)) + startmag <- suppressWarnings(system(paste0("tac '", logmagtxt, "' | grep -m 1 'Preparing MAgPIE'"), intern = TRUE)) + endmag <- suppressWarnings(system(paste0("tac '", logmagtxt, "' | grep -m 1 'MAgPIE output was stored'"), intern = TRUE)) if (length(startmag) > length(endmag)) { fulllogmag <- gsub("-rem-", "-mag-", gsub("output", file.path("magpie", "output"), fulllog)) if (! file.exists(fulllogmag)) fulllogmag <- gsub("-rem-", "-mag-", gsub("output", file.path("..", "magpie", "output"), fulllog)) loopmag <- NULL if (file.exists(fulllogmag)) { - suppressWarnings(try(loopmag <- sub("^.*.= ", "", system(paste0("grep 'LOOPS' ", fulllogmag, " | tail -1"), intern = TRUE)), silent = TRUE)) + suppressWarnings(try(loopmag <- sub("^.*.= ", "", system(paste0("grep 'LOOPS' '", fulllogmag, "' | tail -1"), intern = TRUE)), silent = TRUE)) } - if (length(suppressWarnings(system(paste0("tac ", logmagtxt, " | grep -m 1 'Start getReport'"), intern = TRUE)) > 0)) loopmag <- "report" + if (length(suppressWarnings(system(paste0("tac '", logmagtxt, "' | grep -m 1 'Start getReport'"), intern = TRUE)) > 0)) loopmag <- "report" out[i, "RunStatus"] <- paste("Run MAgPIE", loopmag) } if (isTRUE(grepl("try to acquire model lock", try(system(paste("tail -1", logmagtxt), intern = TRUE), silent = TRUE)))) { @@ -257,7 +257,7 @@ getRunStatus <- function(mydir = dir(), sort = "nf", user = NULL) { # Calib Iter if ((isTRUE(grepl("Calib", out[i, "RunType"])) || isTRUE(cfg$gms$CES_parameters == "calibrate")) && file.exists(logtxt)) { - calibiter <- tail(suppressWarnings(system(paste0("grep 'CES calibration iteration' ", logtxt, " | grep -Eo '[0-9]{1,2}'"), intern = TRUE)), n = 1) + calibiter <- tail(suppressWarnings(system(paste0("grep 'CES calibration iteration' '", logtxt, "' | grep -Eo '[0-9]{1,2}'"), intern = TRUE)), n = 1) if (isTRUE(as.numeric(calibiter) > 0)) out[i, "Iter"] <- paste0(out[i, "Iter"], " ", "Clb: ", calibiter) if (isTRUE(out[i, "Conv"] %in% c("converged", "converged (had INFES)")) && (length(system(paste0("find ", ii, " -name 'fulldata_*.gdx'"), intern = TRUE)) > 10 || diff --git a/R/loopRuns.R b/R/loopRuns.R index 8495c01..f1d92fd 100644 --- a/R/loopRuns.R +++ b/R/loopRuns.R @@ -24,9 +24,10 @@ loopRuns <- function(mydir, user = NULL, colors = TRUE, sortbytime = TRUE) { if (mydir[[1]] == "exit") return(NULL) red <- make_style("orangered") + orange <- make_style("orange") if (colors) { cat("# Color code: ", yellow("pending"), "/", yellow("startup"), ", ", cyan("running"), ", ", - underline(green("converged")), ", ", blue("converged (had INFES)"), ", ", + underline(green("converged")), ", ", blue("converged (had INFES)"), ", ", orange("no mif"), ", ", green("finished"), ", ", magenta("conopt stalled?"), ", ", red("error"), ".\n\n", sep = "") } a <- file.info(mydir) @@ -109,14 +110,16 @@ loopRuns <- function(mydir, user = NULL, colors = TRUE, sortbytime = TRUE) { cat(magenta(out)) } else if (! status[["jobInSLURM"]] == "no") { cat(cyan(out)) - } else if (status[["Conv"]] == "converged (had INFES)") { + } else if (status[["Conv"]] == "converged (had INFES)" && ! status[["Mif"]] == "no") { cat(blue(out)) } else if (grepl("not_converged|Execution erro|Compilation er|interrupted|Intermed Infes", status[["RunStatus"]])) { cat(red(out)) - } else if (status[["Conv"]] %in% c("converged", "Clb_converged")) { + } else if (status[["Conv"]] %in% c("converged", "Clb_converged") && ! status[["Mif"]] == "no") { cat(underline(green(out))) } else if (grepl("2: Locally Optimal", status[["modelstat"]]) && ! grepl("nash", status[["RunType"]])) { cat(green(out)) + } else if (status[["Mif"]] == "no" && status[["Conv"]] %in% c("converged", "Clb_converged", "converged (had INFES)")) { + cat(orange(out)) } else if (status[["jobInSLURM"]] == "no") { cat(red(out)) } else { diff --git a/README.md b/README.md index d336c15..b883d8b 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Run Analysis Tools -R package **modelstats**, version **0.22.6** +R package **modelstats**, version **0.22.7** [![CRAN status](https://www.r-pkg.org/badges/version/modelstats)](https://cran.r-project.org/package=modelstats) [![R build status](https://github.com/pik-piam/modelstats/workflows/check/badge.svg)](https://github.com/pik-piam/modelstats/actions) [![codecov](https://codecov.io/gh/pik-piam/modelstats/branch/master/graph/badge.svg)](https://app.codecov.io/gh/pik-piam/modelstats) [![r-universe](https://pik-piam.r-universe.dev/badges/modelstats)](https://pik-piam.r-universe.dev/builds) @@ -47,7 +47,7 @@ In case of questions / problems please contact Anastasis Giannousakis . +Giannousakis A, Richters O (2025). "modelstats: Run Analysis Tools." Version: 0.22.7, . A BibTeX entry for LaTeX users is @@ -55,9 +55,9 @@ A BibTeX entry for LaTeX users is @Misc{, title = {modelstats: Run Analysis Tools}, author = {Anastasis Giannousakis and Oliver Richters}, - date = {2025-02-06}, + date = {2025-02-13}, year = {2025}, url = {https://github.com/pik-piam/modelstats}, - note = {Version: 0.22.6}, + note = {Version: 0.22.7}, } ```