Reads the variables a solver wrote for one run and returns the scenario with
its @modOut populated. This is the import step: solve_scenario() leaves
the raw output on disk, and nothing else reads it.
Usage
read_solution(
object,
run = NULL,
dir = NULL,
wait = FALSE,
save = FALSE,
restore_solver = NULL,
promote = FALSE,
cleanup = FALSE,
...,
ondisk = !isInMemory(object)
)
# S4 method for class 'scenario'
read(
object,
run = NULL,
dir = NULL,
wait = FALSE,
save = FALSE,
restore_solver = NULL,
promote = FALSE,
cleanup = FALSE,
...,
ondisk = !isInMemory(object)
)Arguments
- object
scenario object.
- run
character, optional run to read:
"<solve>"for a base-problem run or"<variant>/<solve>"— seescenario_runs(). The scenario's active run switches to it. DefaultNULLreads the active run (or, for a freshly loaded scenario, the manifest'sdefault:run).- dir
deprecated: the former spelling of
solver.dir, still accepted with a message.- wait
FALSE(default) reads what is there now.TRUEblocks until the run'soutput/is complete, which is what a detached solve (wait = FALSEon the solve) needs; a number waits that many seconds and then gives up. Needsrunordir, to know what to wait for.- save
logical.
TRUEpersists the solution withsave_scenario(), so it survives the session – this is whatimport_solution()did. A read that produced no variables refuses to save rather than writing an empty store over a run whoseoutput/is the only copy.- restore_solver
logical. Copy the solver identity recorded in the run's
solver.csvonto the scenario.NULL(default) means "when saving", which is what makes an imported run reproducible.- promote
logical, make the read run the scenario's active solution (
promote_solution()). Requires the store on disk, so it impliessave.- cleanup
logical, drop the solver's raw
output/afterwards (drop_solver_outputs()). A clean-up failure warns and does not undo the import.- ...
optional
solver.dir: a run's working folder outside the scenario, read instead of resolving a recorded run – a solve that ran outside R, on a cluster or a rented GPU. It is the same argument as insolve_scenario()andwrite_model(); a recorded run is chosen withrun =instead.tmp.diris a deprecated alias.- ondisk
logical.
TRUEwrites each variable into the run'smodOut/store as it is read, instead of returning the whole solution in memory; the returned@modOutis then an on-disk object read lazily. Defaults to!isInMemory(obj). Needs a run folder, so an externalsolver.dirfalls back to memory. The saved scenario still has to be saved:save_scenario()records the store, and skips rewriting it.
Value
The function returns the scenario object with populated modOut slot from the solved model directory.
Details
Without run, it reads the active run — or, for a freshly loaded scenario,
the default: run named in scenario.yml. Naming a variant run switches
the whole in-memory problem, settings and parameters together, so
getData() stays consistent with the run you are looking at.
Reading alone does not persist anything: save_scenario() writes the
modOut/ store, and import_solution() does both in one call.
scenario_solutions() lists what each run holds before you choose.
Why the imported store, and not just output/
The two are different things, and modOut/ is not a compressed copy of
output/. The solver's dump is untyped text in the backend's own naming;
the import normalises the backend away (GDX, CSV, Arrow and Parquet all
land in one store), synthesises the set aliases no solver writes (src,
dst, regionp, yearp, acomm, commp, timeslicep), types every
dimension against its declared set members rather than the values that
happen to occur, keeps an empty typed skeleton for variables the solver
skipped so their columns stay known, and computes two variables no solver
ever wrote — vTechEmsFuel (emission factors against vTechInp) and
vUserCosts (each cost object against the variable it is defined on).
Re-deriving that on demand would also need @modInp, since the set members
come from the problem — and a variant swap may have replaced it.
The solver's output/ is never modified
Reading a solution only ever reads output/, whatever ondisk is. It is
the solver's raw dump and, until the solution has been imported, the only
copy of it — drop_solver_outputs() is the one verb that removes it, it
refuses while the run is not imported, and it is dry-run by default.
See also
save = TRUE keeps the solution (import_solution() is the
deprecated spelling of that);
scenario_solutions() to see what each run holds; solve_scenario(),
save_scenario().
Other solving:
mm_run(),
solve_by_region(),
solve_by_sample(),
solve_guided(),
solve_model(),
solve_recursive(),
with_solver_log(),
write_model()
