
Cheat sheet: Workflow & scenarios
Source:vignettes/articles/cheatsheet-workflow.Rmd
cheatsheet-workflow.RmdFrom a model to results: the solve pipeline, runs, projects, and reading back
PDF, A4, 2 pages · energyRt 0.91.5.9015 (dev) · 2026-11-29One call, or stage by stage
open_project("~/models/demo") # once per session
scen <- solve_model(mod, name = "BASE",
solver = solver_options$glpk)
scen <- interpolate_model(mod, name = "BASE")
scen <- write_model(scen,
solver = solver_options$glpk)
scen <- solve_scenario(scen,
solver = solver_options$glpk)
scen <- read_solution(scen)
scen <- save_scenario(scen)
One step per line, each result assigned: a stage can be inspected, re-run, or handed to a solver outside R.
| model | bricks, regions, calendar, horizon |
↓ interpolate_model()
|
parameters on the horizon |
| scenario |
@modInp: the problem |
↓ write_model()
|
solver files in a run folder |
↓ solve_scenario()
|
the solver runs (or wait = FALSE) |
↓ read_solution()
|
@modOut: the solution |
↓ save_scenario()
|
to the project folder |
The scenario folder
scenarios/<name-model-calendar-horizon>/
scenario.yml # manifest; default: run
scen.rds # thin S4 shell
modInp/ # the interpolated problem
modOut/ # the promoted solution
runs/
glpk/ # one folder per run
run.yml # solver, time, status
input/ # tables for the solver
output/ # raw solver dump
modOut/ # the parsed solution
- A run owns its artifacts: a second solver writes beside the first, never over it.
- One solution is active in memory; switching is
read_solution(scen, run = ), not a re-solve. - A run's place is derived, so a moved folder keeps its runs.
Solvers
names(solver_options)
set_default_solver(solver_options$julia_highs)
scen <- solve_model(mod) # default solver
logged <- with_solver_log(
solver_options$julia_highs, "highs.log")
scen <- solve_scenario(scen, solver = logged,
run = "highs-logged", wait = TRUE)
set_default_solver(solver)
Project
open_project("~/models/demo",
ondisk = "auto")
options(energyRt.ondisk_ram = 0.5)
ondisk: keep tables in Arrow files, not memory -- TRUE, FALSE, or "auto" by size.Interpolate
interpolate_model(object, name, ..., base, ondisk, overwrite, horizon_segment)Extra bricks in
... are added for this scenario only.CO2TAX <- newTax("CO2TAX", comm = "CO2",
tax = data.frame(bal = 50))
co2 <- interpolate_model(mod, CO2TAX,
name = "CO2TAX", base = scen)
base =: reuse the unchanged tables of a solved scenario.by <- interpolate_model(mod,
name = "BY",
horizon_segment = "base_year")
by <- solve_scenario(by,
solver = solver_options$glpk)
prj <- interpolate_model(mod,
name = "BASE",
base_year_scenario = "BY")
Calibrate the base year first, then project from it.
Runs
solve_scenario(object, solver, force, variant, wait, …)run = names the run; variant = solves an own-problem variant.drop_scenario_run(object, run, force)
Save, load, share
save_scenario(object, path, embed_model, …)Identical content is a no-op; changed content updates in place.
load_scenario(path, name, …)
list_versions(x, type, …)
The registry
reg <- load_registry()
find_in_registry(reg,
type = "run", parent = "BASE")
getData(c("BASE", "CO2TAX"),
name = "vObjective",
merge = TRUE)
Scenarios are found by name:
getData() takes names, not objects.Read results
getData(scen, name, ..., merge = FALSE, run = NULL)Tidy tables;
... filters by set: tech =, comm =, region =, year =.getData(scen, name = "vTechOut",
comm = "ELC", merge = TRUE)
getData(scen, name = "vTechCap",
variants = TRUE, merge = TRUE)
getData(scen, name = "vTechOut",
run = c("glpk", "highs"),
merge = TRUE)
get_variable(object, name, …)
vEmsFuelTot |
Total emissions from fuels combustion (technologies) | cryt |
vBalance |
Net commodity balance (all sources) | cryt |
vTotalCost |
Regional annual total costs | ry |
vObjective |
Objective costs | |
vTechNewCap |
New capacity | ry |
vTechCap |
Total capacity of the technology | ry |
vTechOut |
Technology output | cryt |
vDummyImport |
Slack import, for debugging | cryt |
vStorageOut |
Storage output | cryt |
vTradeIr |
Trade flows between regions | crryt |
Plot
autoplot(scen, type = "capacity",
comm = "ELC")
autoplot(scen, type = "generation",
comm = "ELC", by = "cluster")
type: generation, capacity, new_capacity, fuel, storage.Compare and check
Beyond one solve
solve_recursive(object, name, horizon, step, …)Milestone by milestone (myopic), carrying capacity forward.
Scenario, variant, or run?
| what changed | it is a | lives at |
| solver, tolerance, method | run | runs/<label>/ |
| the scope: sampled calendar, region subset, horizon window | variant (own problem) | runs/<variant>/ |
| assumptions: a price, a cap, a cost |
scenario (base = a reference) |
its own folder |
Runs of one problem agree on every number going in. Not to be confused with vintage and cluster variants of a process (getVariants()).
When it does not solve
-
check_feasibility(mod)orinterpolate_model(check = TRUE): contradictions in the declarations. -
validate_scenario_parameters(),process_operability(): on the interpolated scenario. - Infeasible: switch on the balance slack, solve, read
vDummyImport/vDummyExport-- they name the commodity, region, year and slice that cannot close. - Optimal but suspect:
verify_solution(), then a second solver. - Numerical trouble:
audit_coefficients().
mod <- newModel("demo", repo = repo,
region = "R1", calendar = cal,
horizon = newHorizon(2030),
debug = data.frame(comm = NA,
region = NA, year = NA,
timeslice = NA,
dummyImport = 1e3,
dummyExport = 1e3))
A slack price well above every real cost; it does not relax
newConstraint() rows.Reports
report(scen, format = "html")
levcost(scen, name = "EGAS")
summary(scen)