13 Solving the model
13.1 Overview
ems_solve() runs the teems solver on a deployed model and, by default, parses the results into structured R objects with ems_compose(). A teems Docker image must be available. After the run, the solve is checked for singularity, accuracy and errors, and the findings are written to model_diagnostics.txt in the run directory. On Linux the solver container runs as the calling user, so the files it writes to the run directory belong to you.
ems_solve() chooses nothing on your behalf: the run is exactly the arguments given, so it can be reproduced from its record. A bare ems_solve(cmf_path) solves with Gragg 2-4-6 (as GEMPACK) and LU on one task and one thread, which is accurate and correct for every model but slow for large ones. ems_probe() suggests what to use instead.
ems_solve(
cmf_path,
solution_method = c("Gragg", "Johansen", "Euler", "Midpoint", "RK2",
"Heun", "RK4", "BoSha32", "DoPri54"),
matrix_method = c("LU", "DBBD", "SBBD", "NDBBD"),
n_subintervals = 1L,
steps = NULL,
n_tasks = 1L,
n_threads = 1L,
precision = c("single", "double"),
verbosity = 1L,
suppress_outputs = FALSE,
terminal_run = FALSE,
accuracy_vars = NULL,
...
)13.2 Basic usage
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "Gragg",
matrix_method = "LU"
)13.3 Arguments
| Argument | Default | Description |
|---|---|---|
cmf_path |
Path to the CMF file generated by ems_deploy() |
|
solution_method |
"Gragg" |
How the shock is applied (see Solution methods) |
matrix_method |
"LU" |
How each linear system is solved (see Matrix methods) |
n_subintervals |
1L |
Splits the shock into this many parts, each solved in turn. Helps with large shocks |
steps |
c(2L, 4L, 6L) |
Step counts. For "Gragg", "Midpoint" and "Euler", two or three strictly increasing counts are extrapolated, and a single count is one multi-step run without extrapolation (see Single-pass runs); a single count for the Runge-Kutta methods |
n_tasks |
1L |
Parallel tasks. Must be 1L with "LU" |
n_threads |
1L |
Threads per task |
precision |
"single" |
"double" uses the double-precision solver: about twice the memory, for runs with many steps or a near-singular system |
verbosity |
1L |
Log detail: 0 errors, warnings and the accuracy summary; 1 adds progress and timings; 2 adds per-rank detail and a one-line tally of what was written (coefficients, sets, variables) |
suppress_outputs |
FALSE |
When TRUE, outputs are not parsed; the CMF path is returned invisibly for a later ems_compose() |
terminal_run |
FALSE |
When TRUE, prepares the run without starting it, so it can be launched from a terminal |
... | | Named extras: the Runge-Kutta controls (adaptive, eps_tolerance, max_retries, retry_adjust; see Runge-Kutta controls), the MA48 workspace guesses (laA, laD, laDi) and expert solver flags (e.g. condest, inmemory, postsim). Unknown names are an error |The severities of TAB Assertion failures and declared-range violations are package options (assertions, range_test_initial, range_test_updated).
13.4 Solution methods
| Method | Use it for |
|---|---|
"Gragg" |
The default and the standard accurate method: several multi-step solutions combined by extrapolation (see the GEMPACK manual) |
"Johansen" |
A quick one-step linear approximation. Good for checking that a model and closure run; not accurate for nonlinear results or large shocks |
"Euler" |
Like "Gragg" but converges more slowly. With adaptive "DoPri54" or "BoSha32", the choice for severe shocks, such as a variable driven close to -100%, where "Gragg" and "Midpoint" can become unstable (GEMPACK manual 30.2; Schiffmann 2022) |
"Midpoint" |
Gragg’s method without its final smoothing pass. It never carries the shocks past their end point, so it takes a shock of exactly -100%, which "Gragg" refuses |
"RK2", "Heun", "RK4" |
Runge-Kutta methods with a single step count and no extrapolation. "RK4" with a few steps is an inexpensive way to get three to four correct digits on large shocks |
"BoSha32", "DoPri54" |
Runge-Kutta methods that estimate their own error and can control their step size (adaptive = "yes") |
"Gragg" suits most work; "Johansen" is a quicker way to check that a new setup runs, and adaptive "DoPri54" is an alternative for large shocks. A shock that is too large for the step schedule shows up as a singularity abort preceded by warnings that updated coefficients crossed their declared bounds; ems_solve() then names the remedies below rather than the closure. On large shocks, use more than one subinterval with "Gragg":
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "Gragg",
n_subintervals = 4,
steps = c(2, 4, 8)
)With matrix_method = "DBBD", a run split into subintervals can occasionally abort with a singularity partway through the shock although the closure is sound; the solver names the elements involved. Change n_subintervals (1 is the simplest) or use matrix_method = "LU" for that run.
Adaptive "DoPri54" reaches about the same accuracy with roughly half the work. It controls its own step size, so n_subintervals does not apply, and it returns a per-element error_estimate column. Treat the estimate as a pointer to the least settled results, not as a bound on the error.
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "DoPri54",
steps = 4,
adaptive = "yes",
eps_tolerance = 0.01
)
outputs$dat$qgdp$error_estimateTo check that a result has converged, repeat the run with a tighter eps_tolerance or more steps and compare. The finer Runge-Kutta controls are described below.
13.4.1 Step counts and single-pass runs
"Gragg", "Midpoint" and "Euler" normally solve three times with increasing step counts and extrapolate from the three results, which also gives the accuracy summary. The summary covers every endogenous result unless accuracy_vars names the variables it should cover, for example accuracy_vars = c("qgdp", "pm"). The "Gragg" and "Midpoint" counts must be all even or all odd (c(2, 4, 6) or c(3, 5, 7)); even counts are recommended. Two counts (c(2, 4)) extrapolate from two results, with no accuracy summary. The package option converge = TRUE applies GEMPACK’s treatment of results that do not converge cleanly: their extrapolation is replaced by the result with the most steps, or by the average when the three results are nearly equal.
A single count gives one multi-step run without extrapolation:
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "Euler",
steps = 16
)Use it for models whose updated data must follow the steps themselves, such as a step counter or an iterative (RAS-style) balancing update, which extrapolation would distort. No accuracy summary is available for a single-pass run.
13.4.2 Runge-Kutta controls
ems_RK(
cmf_path,
solution_method = c("DoPri54", "BoSha32", "RK4", "Heun", "RK2"),
steps = 4L,
eps_tolerance = 0.01,
adaptive = NULL,
matrix_method = c("LU", "DBBD", "SBBD", "NDBBD"),
n_tasks = 1L,
n_threads = 1L,
precision = c("single", "double"),
n_subintervals = 1L,
verbosity = 1L,
suppress_outputs = FALSE,
terminal_run = FALSE,
accuracy_vars = NULL,
max_retries = 3L,
retry_adjust = 0.5,
chart = c("log", "percent"),
error_norm = c("max", "rms"),
controller = c("std", "pi"),
scope = c("pct", "all"),
h_init = NULL,
guard = NULL,
...
)ems_RK() is ems_solve() for the Runge-Kutta methods. It defaults to adaptive "DoPri54" and adds the step-size controls; the remaining arguments are those of ems_solve(), with the same defaults. When most retries come from step checks (a variable approaching -100%, a range test) rather than from eps_tolerance, the cheaper steps of "BoSha32" can make it faster than "DoPri54" (Schiffmann 2022).
# adaptive DoPri54
outputs <- ems_RK(cmf_path)
# fixed-step RK4
outputs <- ems_RK(cmf_path, solution_method = "RK4", steps = 8L)| Argument | Default | Description |
|---|---|---|
solution_method |
"DoPri54" |
"DoPri54", "BoSha32", "RK4", "Heun" or "RK2" |
steps |
4L |
Number of steps; under adaptive control, the starting number |
adaptive |
"yes" for "DoPri54"/"BoSha32", otherwise "no" |
"yes" retries steps that miss eps_tolerance or fail a step check (a variable crossing -100%, a range test or an assertion, as in GEMPACK) and adjusts the step size; "accuracy-only" ignores the step checks |
eps_tolerance |
0.01 |
Accuracy target per step. GEMPACK suggests 0.1 for most simulations; on large shocks the default 0.01 reaches four correct digits on most elements, and 0.001 gains the last digits at about 1.6 times the cost |
max_retries, retry_adjust |
3L, 0.5 |
How often, and by how much, a step is shortened when it fails a step check |
chart |
"log" |
"log" keeps every level positive; "percent" combines stages in percentage changes |
error_norm |
"max" |
Whether the worst element ("max") or the root mean square ("rms") decides if a step is accepted |
controller |
"std" |
"pi" rejects fewer steps on rough solution paths |
scope |
"pct" |
Which variables steer the step size: percentage-change variables ("pct") or all variables ("all") |
h_init, guard |
NULL |
First step length, at most 1/steps (a longer one is refused); and the level ratio at which a stage is rejected under chart = "log" |
The defaults suit most runs.
13.5 Matrix methods
| Method | Models | Description |
|---|---|---|
"LU" |
all | Sequential LU factorization. The most robust; one task only |
"DBBD" |
static | Splits the system into blocks (usually by region) solved in parallel, treating regions as separable economies (Kompas and Van Ha 2019) |
"SBBD" |
intertemporal | Splits the system by time period, solved in parallel (Van Ha and Kompas 2016; Van Ha et al. 2017) |
"NDBBD" |
intertemporal | A nested split for intertemporal models too large for "SBBD" in the available memory |
13.5.1 Choosing a method and resources
ems_probe(
cmf_path,
components = TRUE,
cores = NULL,
memory = NULL,
...
)Run ems_probe() once per deployment, before the first solve. It runs the solver up to the point where the equation system is assembled, without solving, and from that system it checks that the closure is sound, measures the structure the matrix methods exploit, reads the cores and memory available to the solver’s container, and prints the call to use. A probe takes seconds on a condensed GTAP model; on an uncondensed system its cost grows faster than the size, to minutes at a few million equations.
probe <- ems_probe(cmf_path)
#> ℹ Probing 'GTAPv7.cmf'; solver log at 'out/probe/solver_out_probe.txt'
#> ℹ Probe finished in 20.9 s
probe
#> ── Structural probe ─────────────────────────────────── 110,849 equations ──
#> ✔ Closure valid: every variable is determined and no equation is redundant,
#> structurally and at base data
#> → Recommended for this container (8 cores, 12.0 GB): "LU", 1 task × 8
#> threads
#> `ems_solve(cmf_path, matrix_method = "LU", n_threads = 8)`
#> ℹ `summary(x)` for the full reportPass cores and memory (in GB) to get the recommendation for another machine, for example a server you will solve on later.
ems_probe() is experimental. Its rules come from a limited set of measured models and machines, so treat the recommendation as a starting point: a different method, task count or thread count may well be faster for your model and machine. Try other settings with ems_solve(), and if a suggestion is off, please open an issue.
13.5.1.1 Reading the printed summary
While it runs, the two progress lines name the deployment, the solver log and the time taken; any Warning: lines the solver wrote to that log are repeated afterwards. Both are silent under ems_option_set(verbose = FALSE). The short form printed above has four parts:
- The header gives the number of equations in the system the solver will factorize. For a condensed model (the vetted static models) this is the system after backsolving, which is much smaller than the model.
- The closure verdict.
Closure validmeans that every endogenous variable is pinned down by some equation and no equation duplicates another, both in the model’s structure and with the base data in place. A model that fails this test cannot be solved, however it is configured; the alternative lines are described under Singular systems. - A memory warning, only when the estimated peak of the recommended run comes close to the container’s memory.
- The recommendation: the matrix method, the number of parallel tasks and the threads per task, for the machine named in brackets, followed by the
ems_solve()call to paste. “This container” means the cores and memory were read from the Docker container the solver runs in (on Docker Desktop, the limits under Settings > Resources); “the machine given” means you passedcoresandmemory.
When no sound recommendation can be made, the probe says so instead of guessing: the closure is singular (fix the model first), the container’s cores could not be read (pass cores and memory), or no method fits in the memory available (the message gives the smallest estimate and the remedies: more memory for the container, a coarser aggregation, or condensation).
13.5.1.2 The full report
summary(probe) prints the evidence behind the verdict and the recommendation:
summary(probe)
#> ── Structural probe: full report ────────────────────────────────────────────
#> • System: 110,849 equations after condensation (68 backsolved variables;
#> 3,667,721 uncondensed)
#> ✔ Structural rank: 110,849 of 110,849
#> ✔ Rank at base data: 110,849 of 110,849
#> • Structure: no time chain; block partition by "reg" (66 blocks, 497 border
#> variables)
#> • Simultaneous components: 1,947 of 58,290 components have more than
#> one element; the largest has 50,548 rows
#> • Largest component by equation: e_peb ×6,172, e_qes1 ×5,280, e_qo ×2,640,
#> e_po ×2,640, e_qc ×2,640, e_qpa ×2,640, and 40 more
#> • Statements: 178 equation statements, 1,150 statement-variable incidences
#> ── Heaviest statement-variable incidences ───────────────────────────────────
#> # A tibble: 10 × 4
#> eq var weight rows
#> <chr> <chr> <int> <int>
#> 1 e_qms tfm 8764800 2640
#> 2 e_qds tfd 8764800 2640
#> ...
#> ── Condensation ─────────────────────────────────────────────────────────────
#> • 68 backsolved variables remove 97% of the uncondensed system (3,667,721 to
#> 110,849 equations)
#> ✔ "reg" partitions the condensed system into 66 blocks, but below 120,000
#> condensed equations threaded "LU" beats "DBBD"
#> ── Recommendation ───────────────────────────────────────────────────────────
#> ✔ "LU", 1 task × 8 threads for this container (8 cores, 12.0 GB)
#> • Evidence: 110,849 equations (condensed), no time chain, partition reg (66
#> blocks, border 20.5% of the system), assessed at 2 tasks
#> • Rationale: one rank; threads for the condensed factorization
#> • Memory: about 4.0 GB at 1 task, 33% of 12.0 GB (fits)
#> → `ems_solve(cmf_path, matrix_method = "LU", n_threads = 8)`
#> ℹ Files: report '/path/to/run/out/probe/sol.probe.json', solver log
#> '/path/to/run/out/probe/solver_out_probe.txt'Section by section:
- System. The size of the system the solver factorizes and, for a condensed model, how many variables were backsolved out and how large the model is before condensation.
- Structural rank and Rank at base data. Two tests of the closure. The first looks only at which variables each equation mentions; the second also discards entries whose base-data value is zero (for example a trade flow that is zero in the database), which can leave a variable with nothing to determine it even though the model’s structure is fine. Both should read “N of N”; a smaller rank is a singular system (see below).
- Structure. What the parallel methods have to work with. A time chain is the period-by-period structure of an intertemporal model, which
"SBBD"splits into blocks; a block partition is a set (usually the regions) along which"DBBD"splits a static system. The border variables are the ones that link the blocks; the fewer, the better the split. - Simultaneous components. How much of the system must be solved at once. Most equations in a CGE model can be solved one after another once a few central ones are known; a component is a group that cannot, and the largest component shows how much of the system is genuinely simultaneous.
plot(probe, type = "components")draws them. - Statements and Heaviest incidences. The model’s equations as statements, and the pairs of equation statement and variable that put the most entries into the system.
plot(probe, type = "incidence")draws the whole pattern. These lines are for understanding the model; they do not affect the recommendation. - Condensation. What backsolving likely does to this deployment (see when backsolving pays); the verdict is kept in
probe$condense$verdict."faster": a condensed system without a block partition is likely bound to"LU", where condensation tends to speed the solve."lu_fine": a condensed system with a partition below about 120 thousand condensed equations, where threaded"LU"was the fastest measured on a laptop."slower": above that size, or with a time chain, the partition belongs to a parallel method and substitution works against it, so the report suggests trying a redeploy withoutbacksolve."candidate": an uncondensed"LU"-bound system of a million equations or more, which may gain frombacksolveinems_model(). - Recommendation. The method, tasks and threads, then the evidence (the size, the time chain and the partition it was judged on, at the task count it was judged for), the rationale (the measured rule that produced it), and the memory estimate of the run against the container’s memory. Further lines appear when they matter:
"DBBD"would have been faster but does not fit;"NDBBD"replaces"SBBD"for the same reason;"LU"is excluded because its workspace would exceed the 32-bit limit; the"DBBD"refinement step is off. Withsolution_method = "Johansen"the method can differ, and a line says which it would be.
13.5.1.3 Singular systems
A structurally singular system prints differently:
#> ── Structural probe ──────────────────────────────────── 10,530 equations ──
#> ✖ Structurally singular: rank 10,527 of 10,530 (3 unmatched equations, 3
#> unmatched variables)
#> Undetermined: dprobeb ×3
#> Over-constrained: e_dprobe2 ×3
#> ℹ Locate it with `plot(x, type = "dm")`
#> ✖ No solve recommendation: the closure is structurally singular; fix it firstUndetermined names the variables (with the number of elements) that no equation pins down: the closure leaves them endogenous but nothing determines them, so one of them should be exogenous, or an equation is missing. Over-constrained names the equations that compete for the same variables: too many equations for the variables they involve, so one of them should be dropped or one of its variables made endogenous. The two lists are two sides of the same defect, and swapping a variable between them is usually the fix. Singular at base data instead of Structurally singular means the structure is sound but zero flows in the data leave elements undetermined; the remedy is in the data or the aggregation, not the closure. summary(probe) lists every defective element, probe$defects holds them as a tibble, and plot(probe, type = "dm") draws where in the system they sit.
13.5.1.4 Files the probe leaves
The probe writes into out/probe/ under the run directory, and overwrites it on every call: sol.probe.json (the report the object is built from), sol.stats.json (the measured structure) and solver_out_probe.txt, the solver’s own log of the run. probe$paths has the paths. A probe never touches a solution already in the run directory.
The log is worth a look when the verdict surprises you. After the solver’s banner and the setup timings, its probe: lines hold the whole diagnosis in order: the time chain found (intertemporal models), the partition candidates, one line per set with its block count, border size and whether it is usable, the set selected and its border, the Jacobian assembly, the structural and base-data ranks with the verdict in words, the simultaneous components and the largest one, the report path, and the total time. Lines starting with Warning: are the solver’s warnings about the model file and are repeated on the console.
13.5.1.5 The rules behind the recommendation
Measured on a 12 GB laptop profile with 4 and 8 cores and on a 32-core server, they come down to the following; other models and machines may behave differently:
- Intertemporal models:
"SBBD", with up to 8 tasks and the remaining cores as threads."NDBBD"only when"SBBD"would not fit in memory. - Static models:
"DBBD"at two tasks for an uncondensed system with a usable partition, more where cores and memory allow. Condensed systems, including the vetted GTAP models, suit"LU"with threads up to about 120 thousand condensed equations; above that the probe suggests trying a redeploy without backsolve for a parallel method. Uncondensed"LU"runs on one thread, since threads do not help it. - Small systems: below 300 thousand equations (counting the backsolved ones), the smallest size measured, every method finishes in seconds and
"LU"is recommended. - Tasks before threads: more tasks usually beat more threads on the same cores, with little gain beyond 8 tasks.
For example, a 16-period GTAP-RE at 23 regions and 5 sectors on an 8-core laptop:
probe <- ems_probe(cmf_path, cores = 8, memory = 12)
#> ── Structural probe ─────────────────────────────────── 616,509 equations ──
#> ✔ Closure valid: every variable is determined and no equation is redundant,
#> structurally and at base data
#> → Recommended for the machine given (8 cores, 12.0 GB): "SBBD", 8 tasks × 1
#> thread
#> `ems_solve(cmf_path, matrix_method = "SBBD", n_tasks = 8)`
#> ℹ `summary(x)` for the full report
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "Gragg",
matrix_method = "SBBD",
n_tasks = 8
)13.6 Memory
Before a run starts, teems-R estimates its peak memory and compares it with the memory available to the container (on Docker Desktop, the limit under Settings > Resources). A run that clearly will not fit is refused before it starts, and the message names the remedies:
- a coarser aggregation or a condensed model,
- fewer tasks (each
"DBBD"task holds its own copy of the data), "NDBBD"for an intertemporal model,- more memory for Docker, or a larger machine.
A run close to the limit gets a warning instead. With "DBBD", each linear solve also gets one refinement step, which holds the system matrix through the solve; the memory estimate includes it (see the refine package option). During the solve, the log reports memory after each phase, and the peaks are recorded in model_diagnostics.txt.
The solver sizes its factorization workspace automatically and grows it when needed, so laA, laD and laDi are normally left unset. If the log shows the workspace growing, passing the size recorded as la_used in sol.stats.json skips that search on the next run. A single "LU" factorization cannot exceed the 32-bit workspace limit; a system that needs more must be condensed, aggregated more coarsely, or solved with a parallel method.
13.7 Checking solve quality
If a model solves but the results look implausible, the system may be numerically near-singular, typically because the closure depends on base-data flows close to zero. condest = TRUE measures how sensitive each linear solve is to the data:
outputs <- ems_solve(
cmf_path = cmf_path,
solution_method = "Gragg",
matrix_method = "LU",
condest = TRUE
)Values of kappa_w2 around 1e8 are normal for CGE models; values approaching 1e15 trigger a warning that the solution is unreliable. Look for near-zero flows the closure depends on, or rerun with precision = "double". The check does not change results, costs a few percent of solve time, and applies to "LU" only.
jacdump = TRUE writes the linearized system at the base data, every equation element against every variable element, to sol.jac beside the solution, with the equation map in sol.jac.json. It is taken before the first step and does not change results.
13.8 Reproducibility
The same deployment solved with the same image gives byte-identical results with "LU", "SBBD" and "NDBBD", at any thread count and on any machine the image supports. Three cases agree only to rounding:
"DBBD"with more than one thread, where a multi-step solve of a poorly conditioned model can amplify the rounding on its least determined results; usen_threads = 1Lwhen byte-for-byte results matter,- runs with more than one task, compared across machines,
- different image variants (for example
amd64andarm64).
Each run records the solver version and numerical kernels it used in model_diagnostics.txt.
13.9 Solver version
Before every solve, teems-R checks that the image’s solver version matches the package. A missing, old or mismatched solver stops the solve and names the pull or rebuild step. If the image still does not accept a solver option or input file that teems sends, the solve stops and names it rather than running without it; use the image released with your version of teems.
13.10 Concurrent runs
Several runs can solve at the same time, one deploy directory each. The directory is set by the tempdir option, so give every run its own before deploying it:
library(parallel)
outputs <- mclapply(c("Johansen", "Gragg"), function(method) {
ems_option_set(tempdir = file.path("~/runs", method))
dat <- ems_data(dat_input, par_input, set_input,
REG = "big3", ACTS = "macro_sector")
cmf <- ems_deploy(dat, model, shock)
ems_solve(cmf, solution_method = method)
}, mc.cores = 2)mclapply() forks the R session, so each run sets its own tempdir; forking is not available on Windows, where parLapply() serves instead.
A second solve in a deploy directory that is already solving is refused. If an interrupted run leaves its claim behind, the message names the .solve_lock directory to remove.
13.11 Terminal mode
For long-running models, terminal_run = TRUE prepares the run and exits, so you can close R and launch the solve from a terminal:
ems_solve(
cmf_path = cmf_path,
solution_method = "Gragg",
terminal_run = TRUE
)13.12 Solving in-situ
solve_in_situ() calls the teems-solver directly with user-supplied input files, bypassing the ems_data() / ems_model() / ems_deploy() pipeline. The model file is parsed, but input files must be provided in their final form: no checks or modifications are applied to them. This suits pre-prepared input files, or re-solving the files written to disk by ems_deploy().
solve_in_situ(
...,
model_dir,
model_file,
closure_file,
shock_file,
ignore_condense = FALSE,
solution_method = c("Gragg", "Johansen", "Euler", "Midpoint", "RK2",
"Heun", "RK4", "BoSha32", "DoPri54"),
matrix_method = c("LU", "DBBD", "SBBD", "NDBBD"),
n_subintervals = 1L,
steps = NULL,
n_tasks = 1L,
n_threads = 1L,
precision = c("single", "double"),
verbosity = 1L,
suppress_outputs = FALSE,
terminal_run = FALSE,
accuracy_vars = NULL,
solver_args = NULL
)13.12.1 Arguments
| Argument | Default | Description |
|---|---|---|
... |
Input files, named after the model’s File statements |
|
model_dir |
Directory the run uses; input files not already there are copied in, and outputs are written there | |
model_file |
Path to the model Tablo (.tab) file | |
closure_file |
Path to the closure (.cls) file | |
shock_file |
Path to the shock (.shf) file | |
ignore_condense |
FALSE |
Set to TRUE when the closure and shock files come from a model loaded with ems_model(..., ignore_condense = TRUE) |
suppress_outputs |
FALSE |
When TRUE, returns the CMF file path instead of parsed outputs |
solver_args |
NULL |
Named list of everything ems_solve() takes through ..., the Runge-Kutta controls included, e.g. list(condest = TRUE) or list(adaptive = "yes") |
The solve arguments (solution_method, matrix_method, n_subintervals, steps, n_tasks, n_threads, precision, accuracy_vars and the rest) work as in ems_solve().
13.12.2 Input files
Each name passed through ... must match a File statement in the model Tablo file. For GTAP-RE, the Tablo file declares:
File GTAPDATA # base data file;
File GTAPINT # intertemporal data file;
File GTAPPARM # parameter file;
File GTAPSETS # set file;
These names are then used as the named arguments:
solve_in_situ(
GTAPDATA = file.path(write_dir, "teems", "GTAPDATA.txt"),
GTAPINT = file.path(write_dir, "teems", "GTAPINT.txt"),
GTAPPARM = file.path(write_dir, "teems", "GTAPPARM.txt"),
GTAPSETS = file.path(write_dir, "teems", "GTAPSETS.txt"),
model_dir = "~/in_situ_run/",
model_file = "GTAP-RE.tab",
closure_file = "GTAP-RE.cls",
shock_file = "a_shock_file.shf",
solution_method = "Gragg",
matrix_method = "SBBD",
n_tasks = 4L
)The model file is processed exactly as ems_model() processes it, so in-TAB Substitute and Backsolve statements apply.
By default, solve_in_situ() returns the model’s variables and coefficients; with suppress_outputs = TRUE it returns the CMF path, which can be passed to ems_compose().