
Cheat sheet: Backends & solvers
Source:vignettes/articles/cheatsheet-solvers.Rmd
cheatsheet-solvers.RmdFrom a scenario to a solver and back: routes, solver_options presets, paths, run folders and logs
| `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.
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)
scen <- solve_model(mod, name = "BASE",
solver = solver_options$mm_highs)
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
lang are former names (mmcloud*): a solve with one stops and names the new preset.-
solver =of the call, else - the scenario's own (
scen@settings@solver), else -
get_default_solver()-- out of the boxglpk.
get_default_solver()$name
[1] "glpk"
old <- set_default_solver(
solver_options$julia_highs_barrier)
solver = where it matters.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"
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".get_exchange_format()
[1] "feather"
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 |
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)
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")
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.
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, …)compare_solve_settings(mod,
settings = list(default = list()),
solvers = list(
glpk = solver_options$glpk,
highs = solver_options$mm_highs))solve_model(object, name, solver, ondisk, fold, ...)solve_scenario(object, solver, force, variant, wait, invisible, log, round, …)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)
Rscript solve.R.write_model(object, solver.dir, solver, log, …)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
scenario_run_info(scen, run)$cmdline.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().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.
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
|
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)with_solver_log(
solver_options$julia_highs_barrier,
"highs.log")$name
[1] "julia_highs_barrier+log"
drop_solver_outputs(object, runs, dry_run, …)input/, logs, imported output/); a dry run by default.set_solver_path(backend, path)"gams", "glpk", "python", "julia": the folder holding the executable; NULL clears it.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")en_config_path(global)
An option is looked up as an R option (energyRt.gams_path), an environment variable (ENERGYRT_GAMS_PATH), the config file, the default.
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.
- 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.
en_check_dependencies(solver_pkgs, solve)en_check_solve(backends, timeout)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().
-
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/_crossoverrecover a vertex at the cost of an extra solve. - PDLP (
_pdlp, cuOpt): first-order, approximate duals; cuOpt returns primals only unless crossover runs. -
_hiponeeds Julia's HiGHS build: the R highs and highspy builds fall back tochoose. -
_bs3: for models in MW, MWh, EUR, where HiGHS warns of large bounds -- not for GW/GWh/MEUR. -
pyomo_highs_barrierhangs 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.