Skip to contents

From a scenario to a solver and back: routes, solver_options presets, paths, run folders and logs

PDF, A4, 2 pages · energyRt 0.91.5.9015 (dev) · 2026-11-29
Routes and what each needs
`lang` needs installed presets
GLPK glpsol: the glpsol R package, Rtools on Windows, or a system GLPK glpk
GAMS GAMS with a licence; for GDX exchange the R package gamstransfer gams_*
JuMP Julia + JuMP, Arrow, ProgressMeter and the solver's package: HiGHS, Cbc, GLPK, CPLEX; cuOpt (Linux only) julia_*
PYOMO Python + pyomo, pandas, pyarrow; highspy for HiGHS; the cbc / glpsol executables; CPLEX pyomo_*
mm the multimod package (writes the MPS matrix) + the R highs package; Julia with HiGHS.jl for mm_julia_*; cuOpt in WSL on an NVIDIA GPU for mm_cuopt_wsl* mm_*
NEOS the R packages httr2, xml2 and an email; a GAMS text job needs no local GAMS neos_*
cloud the mmcloud package and a token for the service: the matrix is built locally, solved by cuOpt on a rented GPU *_cuopt_cloud*

One formulation, maintained in each language. A preset is data only: choosing it does not check the toolchain -- en_check_dependencies() does.

The round trip
scen <- interpolate_model(mod,
  name = "BASE")
scen <- write_model(scen,
  solver = solver_options$glpk)
scen <- solve_scenario(scen)
scen <- read_solution(scen)
scen <- save_scenario(scen)
Write, run, read: each stage can be stopped, inspected or moved to another machine.
scen <- solve_model(mod, name = "BASE",
  solver = solver_options$mm_highs)
All of it in one call.
What a preset name encodes

route _ solver _ method _ place: julia_highs_barrier, gams_gdx_cplex, mm_cuopt_wsl_crossover. Routes: glpk, pyomo_, julia_, gams_, mm_, neos_; solvers: cbc, glpk, cplex, highs, cuopt.

_barrier interior point, crossover off
_simplex simplex
_parallel multi-threaded settings
_hipo, _ipx a HiGHS interior-point code by name
_pdlp, _hipdlp first-order (PDLP)
_concurrent cuOpt: PDLP, barrier and dual simplex race
_crossover recover a vertex solution; _xover too
_bs3 bounds scaled by 2^-3 inside HiGHS
_wsl cuOpt on a local GPU through WSL
_cloud cuOpt on a rented GPU
_py cuOpt through its Python interface
_mps write the matrix, do not solve
csv, gdx GAMS exchange: text or GDX
_sqlite, _rdata legacy exchange containers
lang <- sapply(solver_options,
               `[[`, "lang")
table(unlist(lang))
 GAMS  GLPK  JuMP    mm PYOMO 
   12     1    22    10    13 
62 entries; the four without a lang are former names (mmcloud*): a solve with one stops and names the new preset.
Which solver a solve uses
  • solver = of the call, else
  • the scenario's own (scen@settings@solver), else
  • get_default_solver() -- out of the box glpk.
get_default_solver()$name
[1] "glpk"
old <- set_default_solver(
  solver_options$julia_highs_barrier)
The setter returns the previous default. A session default is invisible in a saved script: pass solver = where it matters.
The families
glpk GLPK, MathProg
pyomo_* cbc, glpk, cplex[_barrier], highs[_barrier], mps, cbc_sqlite
julia_* highs + _simplex, _parallel, _barrier[_bs3], _hipo[_xover|_bs3], _ipx, _pdlp, _hipdlp, _rdata; cuopt + _concurrent, _pdlp, _crossover; cbc, glpk, cplex[_barrier], mps
gams_* csv_ or gdx_ + cplex, cbc; gdx_cplex_barrier, gdx_cplex_parallel
mm_* highs[_barrier[_bs3]], julia_highs_barrier[_bs3], cuopt_wsl[_crossover], cuopt_wsl_py, cuopt_cloud[_crossover]
*_cuopt_cloud pyomo_cuopt_cloud[_crossover], julia_cuopt_cloud: a matrix written by Pyomo or JuMP, solved on a rented GPU
neos_* pyomo_cplex[_barrier], pyomo_cbc, gams_[gdx_]cplex[_barrier], gams_[gdx_]cbc
grep("hipo", names(solver_options),
     value = TRUE)
[1] "julia_highs_hipo"      
[2] "julia_highs_hipo_xover"
[3] "julia_highs_hipo_bs3"  
Presets by name token.
Exchange files

JuMP and Pyomo read the data from input/ and write the solution to output/ in the format of an option; a preset's export_format / import_format override it.

set_exchange_format(format)
"feather" (Arrow IPC), "parquet" (Pyomo only: Julia's Arrow.jl reads IPC), "csv".
set_exchange_compression(codec)
"zstd", "lz4", "uncompressed".
get_exchange_format()
[1] "feather"
Fields of a preset
p <- solver_options$mm_highs_barrier
data.frame(value = unlist(p))
                                       value
name                        mm_highs_barrier
lang                                      mm
solver                                 HiGHS
backend                                   mm
mm_solver                              highs
where                                  local
highs_options.presolve                    on
highs_options.solver                     ipm
highs_options.run_crossover              off
name preset id; the default run label
lang GLPK, GAMS, JuMP, PYOMO, mm
solver the solver inside the route
backend "mm": solve through a matrix; "neos": submit to NEOS
*_format export_format, import_format: "GDX" for GAMS; legacy "SQLite", "RData", "csv"; unset: the exchange_format option
inc1…inc5 code pasted at five fixed points of the generated model; options go in inc3 (JuMP, GAMS) or inc4 (Pyomo)
inc_solver the solver-selection code itself; not together with solver
cmdline the command that runs the model; filled by the writer when empty
wait default of wait =; likewise invisible, log
mm_solver "highs", "julia_highs", "cuopt"
where "local", "wsl", "remote"
highs_options named list handed to HiGHS as is
keep_mps TRUE keeps the matrix after decoding
gpu_* cuOpt: gpu_method, gpu_time_limit, gpu_solver_options, gpu_api, …
cloud_* rented GPU: cloud_flavor, cloud_timeout, …
neos_* neos_solver, neos_category
files named list: extra files written into the run folder, name = file name, value = its lines
A custom solver

Copy a preset, change the copy, give it a name of its own: the run folder is named after it.

my <- solver_options$mm_highs_barrier
my$name <- "highs_ipm_nopresolve"
my$highs_options$presolve <- "off"
unlist(my$highs_options)
     presolve        solver run_crossover 
        "off"         "ipm"         "off" 
jl <- solver_options$julia_highs
jl$name <- "julia_highs_1h"
jl$inc3 <- c(jl$inc3, paste0(
  'set_attribute(model, ',
  '"time_limit", 3600.0)'))
noquote(jl$inc3)
[1] set_attribute(model, "time_limit", 3600.0)
JuMP options: Julia lines in inc3. Pyomo: Python lines in inc4 (opt.options[...]).
g <- solver_options$gams_gdx_cplex
g$name <- "gams_cplex_ipm"
g$inc3 <- paste("energyRt.OptFile = 1;",
  "$onecho > cplex.opt", "lpmethod 4",
  "solutiontype 2", "$offecho",
  sep = "\n")
GAMS: statements in inc3, here a CPLEX option file (barrier, no crossover).

Pass the copy as any preset (solver = my). A field no writer reads is ignored without a message; the former hf_* names are refused on the matrix route.

Cross-check a backend

A small case on GLPK and on the new backend: status and objective within a stated tolerance, then capacity, activity, imports, storage. Keep both runs and logs.

compare_solve_settings(object, settings, solvers, …)
Objective, time, status and disagreement across solvers or settings.
compare_solve_settings(mod,
  settings = list(default = list()),
  solvers = list(
    glpk = solver_options$glpk,
    highs = solver_options$mm_highs))
Solve
solve_model(object, name, solver, ondisk, fold, ...)
Interpolate a model and solve it; a scenario already interpolated is solved as it is.
solve_scenario(object, solver, force, variant, wait, invisible, log, round, …)
Solve an interpolated scenario into a run folder.
scen <- solve_scenario(scen,
  solver = solver_options$glpk,
  run = "glpk-tight", force = TRUE,
  run.conflict = "suffix",
  verbose = FALSE)
run = labels the run (default: the preset name); run.conflict: "overwrite", "suffix" or "error"; verbose = FALSE silences progress and the solver console.
wait = FALSE launch detached and return; the run stays running
invisible = FALSE the solver gets a console of its own
round = TRUE snap values below round_tol to 0 on the way out
solver.dir = an external folder, no run record
transient = TRUE a throwaway folder, deleted after
scen <- solve_scenario(scen,
  run = "bg", wait = FALSE)
scen <- read_solution(scen, run = "bg",
  wait = TRUE, save = TRUE)
Detached: GLPK, GAMS, Pyomo, JuMP; a matrix run is started as Rscript solve.R.
Outside R
write_model(object, solver.dir, solver, log, …)
Write the model and its data, do not solve; the run is recorded written, and solve_scenario() runs it later without writing again.
glpsol -m energyRt.mod -d energyRt.dat
gams energyRt.gms
julia energyRt.jl
python energyRt.py
Rscript --vanilla solve.R     # mm
GLPK, GAMS, JuMP, Pyomo, matrix: run in the run folder; the exact command is scenario_run_info(scen, run)$cmdline.
mm_run(dir, verbose, stream)
Solve a written matrix from its solve.yml, in a process of its own.
scen <- read_solution(scen, run = "glpk",
  save = TRUE)
scen <- read_solution(scen,
  solver.dir = "path/to/copied/run")
run = a recorded run; solver.dir = a folder solved elsewhere (a cluster, a rented GPU). write_script() is the deprecated name of write_model().
What a run folder holds
scenario_runs(scen)[,
  c("run", "status", "lang")]
# A tibble: 3 × 3
  run         status  lang 
  <chr>       <chr>   <chr>
1 glpk        written GLPK 
2 julia_highs written JuMP 
3 mm_highs    written mm   
run <- function(r) list.files(
  file.path(scen@path, "runs", r))
run("glpk")
 [1] "energyRt.dat" "energyRt.mod"
 [3] "inc1"         "inc2"        
 [5] "inc3"         "inc4"        
 [7] "inc5"         "output"      
 [9] "run.yml"      "solver.csv"  
run("julia_highs")
 [1] "data.jl"           
 [2] "energyRt.jl"       
 [3] "inc_constraints.jl"
 [4] "inc_costs.jl"      
 [5] "inc_solver.jl"     
 [6] "inc1.jl"           
 [7] "inc2.jl"           
 [8] "inc3.jl"           
…
run("mm_highs")
 [1] "model.mps"               
 [2] "model_codes.csv"         
 [3] "model_col_index.parquet" 
 [4] "model_dim_names.csv"     
 [5] "model_eliminated.parquet"
 [6] "model_objective.csv"     
 [7] "model_row_index.parquet" 
 [8] "model_subst"             
 [9] "model_symbols.csv"       
[10] "output"                  
…

run.yml: solver, command, start and end, status, objective, host; solver.csv: the solver identity; input/: exchange tables (JuMP, Pyomo); output/: the raw dump; modOut/: the imported solution store.

Run status
written files written, not solved
running the solver is (or was last seen) at work
solved optimal, with an objective
finished ran, solution not read back
not-optimal no usable solution; also failed, interrupted
abandoned released by clear_run()
unknown optimal without an objective, or no readable run.yml
scenario_runs(object)
Every run: status, solver, time, peak memory, objective, active, stale.
scenario_run_info(object, run)
One run's full run.yml.
clear_run(object, run, …)
Release a run left running by a dead process.
Logs and clean-up

Every backend is asked to log natively: log = TRUE (default) writes solver.log beside run.yml, a string names the file, FALSE turns it off.

with_solver_log(opts, file)
JuMP/HiGHS: a followable iteration log; other routes are returned unchanged, with a warning.
with_solver_log(
  solver_options$julia_highs_barrier,
  "highs.log")$name
[1] "julia_highs_barrier+log"
drop_solver_outputs(object, runs, dry_run, …)
Delete the regenerable files of runs (sources, input/, logs, imported output/); a dry run by default.
drop_scenario_run(object, run, force)
Delete a whole run.
Paths to the toolchains
set_solver_path(backend, path)
"gams", "glpk", "python", "julia": the folder holding the executable; NULL clears it.
get_solver_path(backend)
Set or get the path to a solver toolchain
set_glpk_path() get_glpk_path()
set_gams_path() get_gams_path()
set_julia_path() get_julia_path()
set_python_path() get_python_path()
set_gdxlib_path() deprecated: GDX goes through gamstransfer, nothing reads it

Unset, GLPK looks for the glpsol package, then PATH and known places (Rtools); GAMS, Julia and Python are called by bare name on PATH. A path is needed only to override that, e.g. to pick one of several GAMS versions.

set_julia_path("~/.juliaup/bin/")
set_python_path("~/.conda/envs/energyRt")
Keep the settings
en_config_path(global)
The config file: user-wide under tools::R_user_dir(), or ./.energyRt.yml with global = FALSE.
en_config_write(config, global, …)
Write every option that differs from its default.
en_config_show()
What is in effect, and where each value came from.

An option is looked up as an R option (energyRt.gams_path), an environment variable (ENERGYRT_GAMS_PATH), the config file, the default.

When a solve fails

Check in order: the process exit status, the solver's termination status, whether a primal solution was decoded. Executable not found, infeasible and optimal but unreadable output are different failures with different fixes.

NEOS
set_neos_email(email)
Required for submission; also exported as NEOS_EMAIL for the Pyomo route.
get_neos_email()
NEOS submission email
neos_ping(timeout)
Is the server up?
neos_list_solvers(category, …)
"lp", "milp", ...: solver:inputMethod strings.
  • Free for academic and non-commercial use; jobs are public and stored -- no confidential data. About 3 GB RAM, 8 h per job.
  • neos_gams_* inline the data as text: small models only; neos_gams_gdx_* send it as compressed GDX (gamstransfer here).
  • neos_pyomo_* build the Pyomo model here and send the solve.
Is it installed?
en_check_dependencies(solver_pkgs, solve)
A status table per backend: found, version, path, next step. Read-only.
en_check_solve(backends, timeout)
Solves a tiny model (objective 8) on each configured backend; GAMS only when named.

One backend each, a one-row table: en_check_glpk(), en_check_gams(), en_check_julia(), en_check_julia_pkgs(), en_check_python(), en_check_pyomo().

en_setup(ref)
OS, Linux system libraries, both check tables.
en_install_deps(julia, python, r, recheck)
The Julia, Python and R libraries for the runtimes found.
Speed and accuracy
  • solve_model(fold = TRUE), interpolate_model(fold =, sparse =, prune =): a smaller problem, the same answer by construction.
  • _barrier: interior point without crossover -- no vertex solution; duals are interior-point duals. _xover / _crossover recover a vertex at the cost of an extra solve.
  • PDLP (_pdlp, cuOpt): first-order, approximate duals; cuOpt returns primals only unless crossover runs.
  • _hipo needs Julia's HiGHS build: the R highs and highspy builds fall back to choose.
  • _bs3: for models in MW, MWh, EUR, where HiGHS warns of large bounds -- not for GW/GWh/MEUR.
  • pyomo_highs_barrier hangs on HiGHS 1.7.2: use a current highspy.
  • Barrier and first-order runs may differ from simplex in the last digits; alternative optima share an objective with different activities.