Skip to contents

From a model to results: the solve pipeline, runs, projects, and reading back

PDF, A4, 2 pages · energyRt 0.91.5.9015 (dev) · 2026-11-29
One 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_solver_path(backend, path)
Where a backend's executable lives.
with_solver_log(opts, file)
Keep the solver's log in the run folder.
mm_run(dir, …)
Run a model written through multimod, any of its backends.
en_setup(ref)
Install and check the solver toolchains.
Project
create_project(path, ondisk, …)
Folders and a registry, once.
open_project(path, ondisk, …)
Every session: scenarios, models and datasets are found from here.
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.
to_disk(object, …)
Move tables to the scenario folder, free memory; to_memory() back.
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.
scenario_runs(object)
Every run: solver, status, objective, which is active.
read_solution(object, run, …)
Activate a run's solution.
scenario_solutions(object, …)
Which attempts exist, to choose one to keep.
promote_solution(object, run, …)
Make a run the scenario's own solution.
import_solution(object, run, …)
Read a solve finished outside R.
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, …)
getScenario(name, …)
By name from the project, cached in the session.
save_model(object, …)
Models and repositories are stored and referenced, not copied.
seal_model(x, …)
Freeze the current content as a version; seal_scenario() alike.
list_versions(x, type, …)
list_dependents(x, type, …)
What references a model or scenario.
prepare_for_sharing(object, path, …)
A self-contained copy for somebody else.
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.
refresh_registry(root, file, write, lazy)
Rebuild the index from the manifests on disk.
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)
getMix(object, type, comm, region, year, …)
Generation or capacity mix, ready to plot.
get_variable(object, name, …)
findData(object, …)
Search names across sets, parameters and variables.
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.
gg_map(object, type, comm, year, …)
Results on the regions' map.
gg_heatmap(object, value, …)
A variable by timeslice and year.
gg_trade_network(object, value, year, …)
Flows between regions.
Compare and check
compare_scenarios(object, runs, base, …)
Solved results of several scenarios or runs.
compare_inputs(a, b, …)
Which interpolated inputs differ.
check_feasibility(object, years, …)
Cheap checks before a solve.
verify_solution(object, …)
Re-derive the model's identities from the results.
model_size(object, …)
Rows and columns by equation and variable.
Beyond one solve
solve_recursive(object, name, horizon, step, …)
Milestone by milestone (myopic), carrying capacity forward.
solve_by_sample(object, name, samples, …)
On sampled calendars, then the full one.
solve_by_region(object, name, regions, …)
Region by region, with boundary prices.
solve_guided(object, name, stages, …)
Coarse solve guides the fine one.
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
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(object, format, file, …)
A datasheet of a scenario, model or brick: "html", "pdf", "docx".
report(scen, format = "html")
levcost(scen, name = "EGAS")
summary(scen)