Gateway to simple external solver that is run from the command line and stores quantity of interest and its jacobian (with respect to problem parameters in output text files.

shell_solver(
  cmd,
  nparams,
  qoi_file,
  jacobian_file = NULL,
  qoi_read_fn = function(file) scan(file, quiet = TRUE),
  jacobian_read_fn = if (!is.null(jacobian_file)) read_matrix(nparams),
  arg_combine_fn = function(x, ...) paste(x, collapse = " "),
  wd = NULL,
  ignore.stdout = TRUE,
  ignore.stderr = TRUE,
  required_args = NULL
)

Arguments

cmd

command to run the solver executable.

nparams

numeric, number of parameters, must be provided.

qoi_file

name of file containing the computed quantity of interest, may be absolute or relative to wd, cannot be NULL.

jacobian_file

name of file containing the computed Jacobian matrix of quantity of interest, can be absolute or relative to wd, NULL indicates that the solver does not provide gradient info.

qoi_read_fn

function reading the quantity of interest from file.

jacobian_read_fn

function reading the Jacobian matrix from file.

arg_combine_fn

function producing appropriate numeric scalar from point and precision for solver command line

wd

character, working directory, i.e. directory where actual solver exec has to be run, when NULL current working directory will be used

ignore.stdout

logical, should solver STDOUT be ignored?

ignore.stderr

logical, should solver STDERR be ignored?

required_args

character, mandatory args for run().

Value

An object of classes shell_solver and solver

Examples

rscript_path <- file.path(R.home(), "bin", "Rscript") solver_path <- file.path(find.package("solvergater"), "exec", "fake_simple.R") nparams <- 2 nqoi <- 5 solver_cmd <- paste(rscript_path, solver_path, nparams, nqoi) s <- shell_solver(solver_cmd, nparams = nparams, qoi_file = "output_qoi", jacobian_file = "output_jacobian", wd = tempdir()) run(s, c(20, 5))
#> Solver command: /Library/Frameworks/R.framework/Resources/bin/Rscript /Users/runner/work/_temp/Library/solvergater/exec/fake_simple.R 2 5 20 5
#> Entering /var/folders/24/8k48jl6d249_n_qfxwsl6xvm0000gn/T//Rtmp2pZMh5
#> Solver exited normally
#> $qoi #> [1] 25 425 8125 160625 3203125 #> #> $jacobian #> [,1] [,2] #> [1,] 1 1 #> [2,] 40 10 #> [3,] 1200 75 #> [4,] 32000 500 #> [5,] 800000 3125 #>