Skip to content

Commit 4a1ca74

Browse files
committed
Merge branch 'fix_run_lpjml_inside_jobs' into 'master'
Fix run_lpjml call for jobs; change default to new HPC system. See merge request lpjml/lpjmlkit!110
2 parents 9c24888 + 2a48534 commit 4a1ca74

File tree

7 files changed

+68
-23
lines changed

7 files changed

+68
-23
lines changed

.buildlibrary

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
ValidationKey: '3612220'
1+
ValidationKey: '34827570'
22
AutocreateReadme: yes
33
AcceptedWarnings:
44
- 'Warning: package ''.*'' was built under R version'

.github/workflows/check.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,13 @@ on:
44
push:
55
branches: [main, master]
66
pull_request:
7+
types: [opened, synchronize, reopened, ready_for_review]
78
branches: [main, master]
89

910
jobs:
1011
check:
1112
runs-on: ubuntu-latest
13+
if: github.event.pull_request.draft == false
1214

1315
steps:
1416
- uses: actions/checkout@v4
@@ -58,9 +60,31 @@ jobs:
5860
lucode2::check(runLinter = FALSE)
5961
6062
- name: Test coverage
63+
if: ${{ github.event_name != 'pull_request' }}
6164
shell: Rscript {0}
6265
run: |
6366
nonDummyTests <- setdiff(list.files("./tests/testthat/"), c("test-dummy.R", "_snaps"))
64-
if(length(nonDummyTests) > 0 && !lucode2:::loadBuildLibraryConfig()[["skipCoverage"]]) covr::codecov(quiet = FALSE)
67+
if(length(nonDummyTests) > 0 && !lucode2:::loadBuildLibraryConfig()[["skipCoverage"]]) {
68+
coverage <- covr::package_coverage(quiet = FALSE)
69+
# The following function might be unnecessary if r-lib/covr#616 gets merged
70+
to_simple_codecov <- function(coverage) {
71+
fullLineCoverage <- covr:::per_line(coverage)
72+
data <- Map(function(fileCoverage) {
73+
resultCoverage <- lapply(fileCoverage$coverage, jsonlite::unbox)
74+
names(resultCoverage) <- seq_along(resultCoverage)
75+
return(resultCoverage)
76+
}, fullLineCoverage)
77+
return(jsonlite::toJSON(list("coverage" = data), na = "null"))
78+
}
79+
writeLines(to_simple_codecov(coverage), "simple-codecov.json")
80+
}
6581
env:
6682
NOT_CRAN: "true"
83+
84+
- uses: codecov/codecov-action@v4
85+
if: ${{ github.event_name != 'pull_request' }}
86+
with:
87+
file: ./simple-codecov.json
88+
plugin: noop
89+
disable_search: true
90+
token: ${{ secrets.CODECOV_TOKEN }}

CITATION.cff

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ cff-version: 1.2.0
22
message: If you use this software, please cite it using the metadata from this file.
33
type: software
44
title: 'lpjmlkit: Toolkit for Basic LPJmL Handling'
5-
version: 1.7.9
6-
date-released: '2025-04-02'
5+
version: 1.7.10
6+
date-released: '2025-10-06'
77
abstract: A collection of basic functions to facilitate the work with the Dynamic
88
Global Vegetation Model (DGVM) Lund-Potsdam-Jena managed Land (LPJmL) hosted at
99
the Potsdam Institute for Climate Impact Research (PIK). It provides functions for

DESCRIPTION

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
Package: lpjmlkit
22
Type: Package
33
Title: Toolkit for Basic LPJmL Handling
4-
Version: 1.7.9
4+
Version: 1.7.10
55
Authors@R: c(
66
person("Jannes", "Breier", , "jannesbr@pik-potsdam.de", role = c("aut", "cre"), comment = c(ORCID = "0000-0002-9055-6904")),
77
person("Sebastian","Ostberg", , "ostberg@pik-potsdam.de", role = "aut", comment = c(ORCID = "0000-0002-2368-7015")),
@@ -56,4 +56,4 @@ Suggests:
5656
R6
5757
Config/testthat/edition: 3
5858
VignetteBuilder: knitr
59-
Date: 2025-04-02
59+
Date: 2025-10-06

R/run_lpjml.R

Lines changed: 28 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@
3838
#' @param output_path Argument is deprecated as of version 1.0; use sim_path
3939
#' instead.
4040
#'
41+
#' @param debug Logical. If `TRUE`, only the command to run LPJmL is printed
42+
#' and parallelization is switched off.
43+
#'
4144
#' @return See `x`, extended by columns `"type"`, `"job_id"` and `"status"`.
4245
#'
4346
#' @details
@@ -164,17 +167,23 @@
164167
#'
165168
#' @md
166169
#' @export
167-
run_lpjml <- function(x,
170+
run_lpjml <- function(x, # nolint:cyclocomp_linter.
168171
model_path = ".",
169172
sim_path = NULL,
170-
run_cmd = "srun --propagate",
173+
run_cmd = "mpirun ",
171174
parallel_cores = 1,
172175
write_stdout = FALSE,
173176
raise_error = TRUE,
174-
output_path = NULL) {
177+
output_path = NULL,
178+
debug = FALSE) {
175179

176180
warn_runner_os("run_lpjml")
177181

182+
if (run_cmd != "" && !grepl(" $", run_cmd)) {
183+
run_cmd <- paste0(run_cmd, " ")
184+
message("Note: Added trailing space to run_cmd")
185+
}
186+
178187
# Check if model_path is set or unit test flag provided
179188
if (!dir.exists(model_path)) {
180189
stop("Folder of model_path \"", model_path, "\" does not exist.")
@@ -212,9 +221,10 @@ run_lpjml <- function(x,
212221
for (order in unique(sort(x$order))) {
213222
sim_names <- x$sim_name[which(x$order == order)]
214223

215-
if (parallel_cores == 1) {
224+
if (parallel_cores == 1 || debug) { # nolint:undesirable_function_linter.
216225
do_sequential(
217-
sim_names, model_path, sim_path, run_cmd, write_stdout, raise_error
226+
sim_names, model_path, sim_path, run_cmd, write_stdout, raise_error,
227+
debug = debug # nolint:undesirable_function_linter.
218228
)
219229
} else if (parallel_cores > 1 && Sys.getenv("SLURM_JOB_ID") != "") {
220230
do_parallel(
@@ -230,9 +240,10 @@ run_lpjml <- function(x,
230240
}
231241

232242
} else {
233-
if (parallel_cores == 1) {
243+
if (parallel_cores == 1 || debug) { # nolint:undesirable_function_linter.
234244
do_sequential(
235-
x$sim_name, model_path, sim_path, run_cmd, write_stdout, raise_error
245+
x$sim_name, model_path, sim_path, run_cmd, write_stdout, raise_error,
246+
debug = debug # nolint:undesirable_function_linter.
236247
)
237248
} else if (parallel_cores > 1 && Sys.getenv("SLURM_JOB_ID") != "") {
238249
do_parallel(
@@ -258,7 +269,8 @@ do_run <- function(sim_name,
258269
sim_path,
259270
run_cmd,
260271
write_stdout,
261-
raise_error) {
272+
raise_error,
273+
debug) {
262274

263275
config_file <- paste0("config_",
264276
sim_name,
@@ -279,6 +291,9 @@ do_run <- function(sim_name,
279291
sim_path,
280292
"/configurations/",
281293
config_file)
294+
if (debug) { # nolint:undesirable_function_linter.
295+
message("Debug mode is on, only printing command:\n", inner_command)
296+
}
282297

283298
stdout_file <- ifelse(write_stdout,
284299
paste0(sim_path,
@@ -328,7 +343,8 @@ do_sequential <- function(sim_names,
328343
sim_path,
329344
run_cmd,
330345
write_stdout,
331-
raise_error) {
346+
raise_error,
347+
debug) {
332348

333349
# tryCatch to unset and set MPI for function call outside of slurm job on
334350
# an HPC cluster even when function call is interrupted or has thrown
@@ -343,12 +359,13 @@ do_sequential <- function(sim_names,
343359
mpi_var <- NULL
344360
# If not specified by the user set number of processes to 1 to run lpjml
345361
# in interactive mode
346-
if (run_cmd == "mpirun") {
362+
if (run_cmd == "mpirun " && Sys.getenv("SLURM_JOB_ID") == "") {
347363
run_cmd <- paste0(run_cmd, " -np 1 ")
348364
}
349365
}
350366
for (sim_name in sim_names) {
351-
do_run(sim_name, model_path, sim_path, run_cmd, write_stdout, raise_error)
367+
do_run(sim_name, model_path, sim_path, run_cmd, write_stdout, raise_error,
368+
debug = debug) # nolint:undesirable_function_linter.
352369
}
353370
}, finally = {
354371
# Check if slurm is available

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# <a href=''><img src='inst/img/logo.png' align='right' alt='logo' height=139 /></a> Toolkit for Basic LPJmL Handling
22

3-
R package **lpjmlkit**, version **1.7.9**
3+
R package **lpjmlkit**, version **1.7.10**
44

55
[![CRAN status](https://www.r-pkg.org/badges/version/lpjmlkit)](https://cran.r-project.org/package=lpjmlkit) [![DOI](https://zenodo.org/badge/DOI/10.5281/zenodo.7773134.svg)](https://doi.org/10.5281/zenodo.7773134) [![R build status](https://github.com/PIK-LPJmL/lpjmlkit/workflows/check/badge.svg)](https://github.com/PIK-LPJmL/lpjmlkit/actions) [![codecov](https://codecov.io/gh/PIK-LPJmL/lpjmlkit/branch/master/graph/badge.svg)](https://app.codecov.io/gh/PIK-LPJmL/lpjmlkit) [![r-universe](https://pik-piam.r-universe.dev/badges/lpjmlkit)](https://pik-piam.r-universe.dev/builds)
66

@@ -76,7 +76,7 @@ In case of questions / problems please contact Jannes Breier <jannesbr@pik-potsd
7676

7777
To cite package **lpjmlkit** in publications use:
7878

79-
Breier J, Ostberg S, Wirth S, Minoli S, Stenzel F, Hötten D, Müller C (2025). "lpjmlkit: Toolkit for Basic LPJmL Handling." doi:10.5281/zenodo.7773134 <https://doi.org/10.5281/zenodo.7773134>, Version: 1.7.9, <https://github.com/PIK-LPJmL/lpjmlkit>.
79+
Breier J, Ostberg S, Wirth S, Minoli S, Stenzel F, Hötten D, Müller C (2025). "lpjmlkit: Toolkit for Basic LPJmL Handling." doi:10.5281/zenodo.7773134 <https://doi.org/10.5281/zenodo.7773134>, Version: 1.7.10, <https://github.com/PIK-LPJmL/lpjmlkit>.
8080

8181
A BibTeX entry for LaTeX users is
8282

@@ -85,9 +85,9 @@ A BibTeX entry for LaTeX users is
8585
title = {lpjmlkit: Toolkit for Basic LPJmL Handling},
8686
author = {Jannes Breier and Sebastian Ostberg and Stephen Björn Wirth and Sara Minoli and Fabian Stenzel and David Hötten and Christoph Müller},
8787
doi = {10.5281/zenodo.7773134},
88-
date = {2025-04-02},
88+
date = {2025-10-06},
8989
year = {2025},
9090
url = {https://github.com/PIK-LPJmL/lpjmlkit},
91-
note = {Version: 1.7.9},
91+
note = {Version: 1.7.10},
9292
}
9393
```

man/run_lpjml.Rd

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)