Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .Rbuildignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@
^\.claude$
^cran-comments\.md$
^tests/testthat/\.fz$
^doc$
^Meta$
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,5 @@ __pycache__/
.Python
venv/
env/
/doc/
/Meta/
1 change: 1 addition & 0 deletions DESCRIPTION
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Description: Provides R bindings to the 'funz-fz' Python package using
algorithm-driven analyses by substituting variable placeholders in text
input files and collecting outputs into data frames. Calculators can run
locally (shell), over SSH, or on 'SLURM' clusters.
See <https://github.com/Funz/fz> for the underlying framework.
License: BSD_3_clause + file LICENSE
Encoding: UTF-8
Language: en-US
Expand Down
3 changes: 0 additions & 3 deletions LICENSE

This file was deleted.

30 changes: 15 additions & 15 deletions R/config.R
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' get_interpreter() # e.g. "python"
#' get_interpreter()
#' }
#' }
get_interpreter <- function() {
Expand All @@ -27,10 +27,10 @@ get_interpreter <- function() {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' set_interpreter("R") # evaluate formulas with R
#' set_interpreter("python") # evaluate formulas with Python (default)
#' set_interpreter("R")
#' set_interpreter("python")
#' }
#' }
set_interpreter <- function(interpreter) {
Expand All @@ -46,9 +46,9 @@ set_interpreter <- function(interpreter) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' as.character(get_log_level()) # e.g. "WARNING"
#' as.character(get_log_level())
#' }
#' }
get_log_level <- function() {
Expand All @@ -66,11 +66,11 @@ get_log_level <- function() {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' set_log_level("DEBUG") # maximum verbosity
#' set_log_level("WARNING") # default
#' set_log_level("ERROR") # errors only
#' set_log_level("DEBUG")
#' set_log_level("WARNING")
#' set_log_level("ERROR")
#' }
#' }
set_log_level <- function(level) {
Expand All @@ -88,7 +88,7 @@ set_log_level <- function(level) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' cfg <- get_config()
#' cfg$max_workers
Expand All @@ -108,7 +108,7 @@ get_config <- function() {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' print_config()
#' }
Expand All @@ -127,11 +127,11 @@ print_config <- function() {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' Sys.setenv(FZ_MAX_WORKERS = "8")
#' reload_config()
#' get_config()$max_workers # now 8
#' get_config()$max_workers
#' }
#' }
reload_config <- function() {
Expand Down
44 changes: 11 additions & 33 deletions R/core-functions.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,15 @@
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' # Write a template with two variables and their defaults
#' tf <- tempfile(fileext = ".txt")
#' writeLines(c("pressure = ${P~1.013}", "volume = ${V~22.4}"), tf)
#'
#' model <- list(varprefix = "$", delim = "{}", formulaprefix = "@",
#' commentline = "#")
#'
#' vars <- fzi(tf, model)
#' # vars$P == 1.013, vars$V == 22.4
#'
#' # Using an installed model alias instead of an inline dict:
#' # vars <- fzi(tf, "PerfectGas")
#' }
#' }
fzi <- function(input_path, model) {
Expand All @@ -46,7 +41,7 @@ fzi <- function(input_path, model) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' tf <- tempfile(fileext = ".txt")
#' writeLines(c("P = ${P~1.013}", "V = ${V~22.4}"), tf)
Expand All @@ -55,10 +50,7 @@ fzi <- function(input_path, model) {
#' commentline = "#")
#' out <- tempfile()
#'
#' # Single case: one compiled directory P=2,V=11.2
#' fzc(tf, list(P = 2.0, V = 11.2), model, out)
#'
#' # Grid: 2 x 2 = 4 compiled directories
#' fzc(tf, list(P = c(1.0, 2.0), V = c(11.2, 22.4)), model, out)
#' }
#' }
Expand All @@ -81,21 +73,18 @@ fzc <- function(input_path, input_variables, model, output_dir = "output") {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' # After running a simulation that wrote "result = 42" to output.txt:
#' out_dir <- "my_results/P=2,V=11.2"
#' out_dir <- file.path(tempdir(), "P=2,V=11.2")
#' dir.create(out_dir, recursive = TRUE)
#' writeLines("result = 42", file.path(out_dir, "output.txt"))
#'
#' model <- list(
#' varprefix = "$", delim = "{}", formulaprefix = "@", commentline = "#",
#' output = list(result = "grep 'result' output.txt | cut -d= -f2")
#' )
#'
#' values <- fzo(out_dir, model)
#' # values$result == "42"
#'
#' # Glob to read all cases at once:
#' # values <- fzo("my_results/*", model)
#' }
#' }
fzo <- function(output_path, model) {
Expand Down Expand Up @@ -128,9 +117,8 @@ fzo <- function(output_path, model) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' # Template: shell script that writes sum of x and y
#' tf <- tempfile(fileext = ".sh")
#' writeLines(c(
#' "#!/bin/sh",
Expand All @@ -142,13 +130,8 @@ fzo <- function(output_path, model) {
#' output = list(result = "grep result output.txt | cut -d= -f2")
#' )
#'
#' # Two values of x, one value of y -> 2 cases
#' results <- fzr(tf, list(x = c(1L, 2L), y = 3L), model,
#' calculators = "sh://bash input.sh")
#' # results is a data frame with columns x, y, result
#'
#' # Using an installed model alias:
#' # results <- fzr("input.txt", list(P = c(1, 2, 3)), "PerfectGas")
#' }
#' }
fzr <- function(input_path, input_variables, model,
Expand Down Expand Up @@ -180,17 +163,13 @@ fzr <- function(input_path, input_variables, model,
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' # List everything
#' info <- fzl()
#' names(info$models) # e.g. c("PerfectGas", "Moret")
#' names(info$calculators) # e.g. c("sh://")
#' names(info$models)
#' names(info$calculators)
#'
#' # Check only models whose name starts with "Perfect"
#' info <- fzl(models = "Perfect*")
#'
#' # Probe calculators to verify they are reachable
#' info <- fzl(check = TRUE)
#' }
#' }
Expand Down Expand Up @@ -225,7 +204,7 @@ fzl <- function(models = "*", calculators = "*", check = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' tf <- tempfile(fileext = ".txt")
#' writeLines(c("x = ${x~0}", "y = ${y~0}"), tf)
Expand All @@ -235,7 +214,6 @@ fzl <- function(models = "*", calculators = "*", check = FALSE) {
#' output = list(z = "grep z output.txt | cut -d= -f2")
#' )
#'
#' # Run 30 Monte Carlo samples over x in [0,1] and y in [-5,5]
#' result <- fzd(
#' tf,
#' list(x = "[0;1]", y = "[-5;5]"),
Expand Down
22 changes: 11 additions & 11 deletions R/install.R
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fz_install <- function(method = "auto", conda = "auto", pip = TRUE, ...) {
#' @importFrom reticulate py_module_available
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' message("fz is available!")
#' } else {
Expand Down Expand Up @@ -65,7 +65,7 @@ fz_available <- function() {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' install_model("Funz/Model-PerfectGas")
#' }
Expand All @@ -90,7 +90,7 @@ install_model <- function(source, global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' install_algorithm("Funz/Algorithm-MonteCarlo")
#' }
Expand All @@ -111,7 +111,7 @@ install_algorithm <- function(source, global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' uninstall_model("PerfectGas")
#' }
Expand All @@ -132,7 +132,7 @@ uninstall_model <- function(model_name, global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' uninstall_algorithm("MonteCarlo")
#' }
Expand All @@ -152,10 +152,10 @@ uninstall_algorithm <- function(algorithm_name, global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' models <- list_installed_models()
#' names(models) # e.g. c("PerfectGas")
#' names(models)
#' }
#' }
list_installed_models <- function(global = FALSE) {
Expand All @@ -173,7 +173,7 @@ list_installed_models <- function(global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' algos <- list_installed_algorithms()
#' names(algos)
Expand All @@ -193,7 +193,7 @@ list_installed_algorithms <- function(global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' names(list_models())
#' }
Expand All @@ -212,7 +212,7 @@ list_models <- function(global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' install("Funz/Model-PerfectGas")
#' }
Expand All @@ -232,7 +232,7 @@ install <- function(source, global = FALSE) {
#' @export
#'
#' @examples
#' \dontrun{
#' \donttest{
#' if (fz_available()) {
#' uninstall("PerfectGas")
#' }
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -139,4 +139,4 @@ Contributions are welcome. Please open a Pull Request or file an issue at

## License

MIT — see [LICENSE](LICENSE).
BSD 3-Clause — see [LICENSE](LICENSE.md).
Loading
Loading