Skip to content

Commit

Permalink
Merge pull request #127 from orichters/master
Browse files Browse the repository at this point in the history
add orange 'no mif', don't fail on run folder with blanks
  • Loading branch information
orichters authored Feb 13, 2025
2 parents bcdba10 + c5e9c42 commit 2b5323d
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 22 deletions.
2 changes: 1 addition & 1 deletion .buildlibrary
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
4 changes: 2 additions & 2 deletions CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions DESCRIPTION
Original file line number Diff line number Diff line change
@@ -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")
Expand Down
20 changes: 10 additions & 10 deletions R/getRunStatus.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand Down Expand Up @@ -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"
}
Expand All @@ -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)))) {
Expand Down Expand Up @@ -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 ||
Expand Down
9 changes: 6 additions & 3 deletions R/loopRuns.R
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
@@ -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)

Expand Down Expand Up @@ -47,17 +47,17 @@ In case of questions / problems please contact Anastasis Giannousakis <giannou@p

To cite package **modelstats** in publications use:

Giannousakis A, Richters O (2025). "modelstats: Run Analysis Tools." Version: 0.22.6, <https://github.com/pik-piam/modelstats>.
Giannousakis A, Richters O (2025). "modelstats: Run Analysis Tools." Version: 0.22.7, <https://github.com/pik-piam/modelstats>.

A BibTeX entry for LaTeX users is

```latex
@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},
}
```

0 comments on commit 2b5323d

Please sign in to comment.