1.6. Solving
solve is the gateway between a parsed model and everything else.
You pass it a model object and a handful of options; you get back a
solved model and a return code. This chapter is the reference for
the option surface, the return-code discipline, and the diagnostic
protocol when a solve fails.
1.6.1. The signature
[m, retcode] = solve(m, name = value, name = value, ...);
The first input is a model object. Subsequent arguments are
name-value pairs validated by an arguments block on solve.
The first output is the model object with the solution attached;
downstream methods (irf, simulate, estimate, filter,
…) consume it. The second output is the retcode – always
capture it and always check it.
1.6.2. The retcode pattern
The retcode is the single source of truth about whether the solve succeeded:
[m, retcode] = solve(m);
assert(retcode == 0, decipher(retcode));
retcode == 0– the model is solved.retcode > 0– the solve failed in a specific, named way.decipher(retcode)returns the human-readable explanation.
Never read the model object’s solution fields without first
checking retcode. A non-zero retcode can leave the solution
empty or partially populated; downstream methods will then return
empty results or raise unrelated errors.
A complete list of return codes appears at the end of this chapter.
1.6.3. Picking a solver
The solver option selects the underlying algorithm. For
constant-parameter models RISE picks a sensible default. For
switching models it defaults to mfi (functional iteration). You
may force a specific solver by prefixing the name with +:
m = solve(m, solver = '+mn'); % force Newton, no auto-pick
With the solver option left empty, RISE makes the choice at every solve,
from the system it solves: rise_1 when every regime has the same
first-order system (outside discretion), mfi otherwise. The solver used is
recorded with the solution, in m.model_data.state_space{1}.solver, and
print_solution names it. m.model_data.options.solver{1} keeps what you
set, so a model re-solved at other parameters chooses again.
The available solvers:
Name |
Family |
Notes |
|---|---|---|
|
Functional iteration (switching default) |
Cheapest per iteration. Can miss solutions where the operator is not a contraction; see the diagnostic protocol below. |
|
Multisecant-accelerated functional iteration |
Iterates the same map as |
|
Newton (switching), no Kronecker |
Robust to non-contraction. Use when |
|
Newton (switching), with Kronecker |
Same robustness as |
|
Full (non-sparse) variants |
Use when sparsity exploitation in the standard variants causes numerical issues. |
|
Farmer-Waggoner-Zha Newton |
Their algorithm; sometimes finds solutions the others miss, sometimes the reverse. |
|
Groebner-basis all-solutions |
Finds every solution. Can be very slow (minutes to never) on non-trivial models. Do not include in a default diagnostic sweep. |
|
Undetermined coefficients |
For switching models. |
|
Schur decomposition |
Only with the Maih-Waggoner perturbation strategy. |
|
Constant-parameter default |
Generalized Schur / QZ decomposition. |
|
Klein’s method |
Constant-parameter; classical reference algorithm. |
|
Cyclic reduction |
Constant-parameter. |
|
AIM solver |
Constant-parameter. |
A user-defined solver – a function handle with a specific
signature – is also accepted; see the solve doc-comment for the
required inputs and outputs.
1.6.4. Bound arguments for a user solver
A callback may be named by a character vector or a function handle. To bind payloads, put the callback and its arguments in an inner cell, then pair that cell with the solver options:
specification={{@my_solver,configuration,weights},struct('MaxIter',10)};
[m,retcode]=solve(m,'solver',specification);
The callback receives the standard six inputs
Gplus01,A0,Aminus,B,Q,steady_state, followed by configuration,weights
in that order, unchanged. The outer options struct is distinct from these
bound arguments; it is not automatically appended to the callback inputs.
If a callback needs options, bind the required value explicitly. A character
name can replace @my_solver with the same payload contract. See the
bounded example in WorkingWithAModel/user_solver_arguments.
1.6.5. Solver options
solver may be a plain string or a two-element cell
{name, opts} where opts is a struct that RISE passes through
to the inner iterator. The fields use MATLAB-standard option names:
opts = struct( ...
MaxIter = 1e6, ...
TolFun = 1e-10, ...
Display = 'iter', ...
ObjectiveLimit = 1e+12);
[m, retcode] = solve(m, solver = {'mn', opts});
Field |
Default |
Role |
|---|---|---|
|
|
Maximum number of iterations. |
|
|
Convergence tolerance on the residual. |
|
|
Set to |
|
|
Treat the iteration as divergent if the residual exceeds this. |
Note
The legacy toolbox accepted the same options under the names
fix_point_maxiter, fix_point_TolFun,
fix_point_verbose, fix_point_explosion_limit. The modern
convention is the MATLAB-standard names above; the legacy names
have been retired as user-facing options and passing them now
errors as an unknown option.
1.6.6. Order of approximation
solve_order controls the order of the perturbation expansion:
m = solve(m, solve_order = 3);
Supported orders are 1 through 5. With the default symbolic
derivatives (solve_derivatives_type = 'symbolic'), the derivatives
are computed when the model is parsed, up to max_deriv_order
(default 1), so an order above 1 requires that the model was
parsed with at least the matching max_deriv_order:
m = dsge_model('mymodel.rs', max_deriv_order = 3);
m = solve(m, solve_order = 3);
Asking for a higher order than was parsed stops with an error that
says so. Re-parse the model, or use derivatives that are computed when
the model is solved, for whatever order is asked: 'automatic',
'numerical' or 'matlab' need no re-parsing:
m=solve(m,solve_order=3,solve_derivatives_type='automatic');
See Higher-order perturbation.
The derivatives of order \(k\) are held as sparse matrices with
\(n_v^k\) columns, \(n_v\) being the number of variables the
equations are differentiated with respect to (the leads, the current values,
the lags and the shocks). A sparse matrix in MATLAB keeps one pointer for each
column, however few of its entries are not zero: eight bytes per column, for
each matrix and each pair of regimes. With 53 variables that is 63 MB at order
4 and 3.3 GB at order 5; with 300 variables, 216 MB at order 3 and 65 GB at
order 4. Pick solve_order with the number of variables in mind: the
orders above 3 are for models of a few tens of variables.
At order \(\geq 2\) a simulated path can diverge. Simulation
pruning is an explicit opt-in for keeping such paths bounded, off by
default and enabled through the simul_pruned option; see
Forecasting and simulation.
1.6.7. Reducing the size of the system
solve_prune_hank_constants removes variables whose equations pin
their first-order deviations at exactly zero at the evaluated steady
state – saturated interpolation weights, slack multipliers, pinned
policies, fixed aggregates – solves the smaller system, and re-inflates
the solution with exact zeros. The answer is identical with the option
on or off; only the cost of the solve changes. It is binary,
parameter-free, off by default, and applies at first order. Its habitat
is heterogeneous-agent models, where the expansion manufactures such
constants in bulk; see Heterogeneous agents (HANK).
Note
Three distinct things in RISE are called “pruning”; they do not overlap.
solve_prune_hank_constantsdrops variables that are constant in the linearized model. First-order solving. Exact – the solution is unchanged.simul_pruneddrops explosive higher-order cross-terms when simulating an already-solved model. Coefficients untouched.Distribution/state reduction (Reiter, Bayer–Lütticke) replaces the histogram by a low-dimensional parameterization. An approximation, available through the option
solve_reduction(see Model reduction).
1.6.8. Optimal policy
Two orthogonal options control optimal-policy solutions:
Option |
Values |
Default |
|---|---|---|
|
|
|
|
|
|
solve_policy_type controls commitment versus discretion:
'ramsey'– full commitment; the planner re-optimizes only att = 0.'discretion'– time-consistent / Markov-perfect policy; the planner re-optimizes every period.
solve_policy_equilibrium controls the equilibrium concept in
multi-player games:
'OLE'(open-loop equilibrium) – the classical Lagrangian formulation in which each player takes the opponent’s path as given.'MPE'(Markov-perfect equilibrium) – each player takes the opponent’s policy function as given.
All four combinations are supported. Both options are passed to
solve – they are not declared in the model file. Loose
commitment and stochastic replanning are also available through a
small extension of this surface; see Optimal policy in the
Modeling chapter for the model-side syntax.
1.6.9. Occasionally-binding constraints
The piecewise-linear (OccBin) solve of an occasionally-binding
constraint is provided by the occbin.paradigm solve paradigm,
activated through the solve_paradigm option:
C = { {'R>=1','ocb'} }; % constraint R >= 1 on the 'ocb' chain
m = set(m,'solve_paradigm',{@occbin.paradigm,'ref',1,'constraints',C});
m = solve(m);
The model-side construction (the binding chain and the convex-combination equation) is covered in Occasionally-binding constraints, and the paradigm interface – the constraint-cell grammar and its options – in Extending RISE through paradigms.
1.6.10. Perturbation strategy
solve_perturbation_type selects how a switching model is expanded
when its parameters, and possibly its steady state, switch across
regimes. The types, their syntax, what to expect from each and the
guidance on choosing one are on their own page,
Perturbation types for regime-switching models; in short:
Value |
Strategy |
|---|---|
|
Self-consistent expansion points of the shock-free switching economy, with curvature higher orders. |
|
Joint fixed point over the expansion points and all orders. |
|
Former plain M: isolated regime steady states with the existing |
|
Maih and Waggoner (2018): the transition probabilities of all chains perturbed along with the shocks. |
|
As above but only the chains in |
|
Foerster, Rubio-Ramirez, Waggoner and Zha (2016): unique steady state at the ergodic mean of the parameters, perturbing all switching parameters (their naive form). |
|
As above but only the parameters in |
|
Barthelemy and Marx (2016): the P-weighted steady state of their Assumption 2, then the standard perturbation engine. |
mkv_list and part_list may also be {'*none'},
{'*all'}, {'*all_but'}, or {'*all_but', 'v1', 'v2', ...}.
The M variant comes second and settings follow it as name-value pairs,
for example {'m','joint','Continuation',false}; no options object is
used. The curvature variant is the default. The isolated variant takes no
setting. Unknown, duplicate, inactive, and invalid settings are rejected.
Continuation applies only to the joint variant.
The former keys ExpansionPoint and HigherOrders raise a migration
error in new calls that names the positional form. Former separate-method
spellings, cell payloads, and constructor objects also raise migration
errors. Older saved models translate on loading. See Perturbation types for regime-switching models for all
settings, defaults, saved-model migration, and the unchanged algorithms.
When steady states or growth rates switch, the restrictions described in
When the steady state or the growth rate switches, change the type apply to the explicit
regime-steady-state configuration. They do not describe the new default.
Evaluate the model’s residuals with
rise.engine.dsge_tools.accuracy.perturbation_report. The report uses
the stored type, including its inline settings, unless types is
supplied explicitly. Report timings include the public solve call.
1.6.11. Other options worth knowing
Option |
Role |
|---|---|
|
|
|
|
|
|
|
|
|
Function handle for the automatic differentiator engine (default: |
|
Struct describing non-Gaussian shock distributions. See the |
|
Eigenvalue cutoff for constant-parameter QZ-based solvers (default: |
|
|
1.6.12. The diagnostic protocol when solve fails
When solve returns a non-zero retcode, work down this list in
order; each step is cheap and rules out a class of causes:
Read the retcode.
decipher(retcode)gives the human-readable reason. If the message is specific (e.g. “Complex solution”, “Cannot take a log-expansion of a variable whose steady state is close to 0”), fix the model, not the solver settings.If retcode is 21 (“Maximum Number of iterations reached or multiple solutions”), raise the iteration cap first. It is the cheapest test and rules out simple truncation:
opts = struct(MaxIter = 1e8); [m, retcode] = solve(m, solver = {'mfi', opts});
If
retcode == 0, you were just being truncated.If retcode is still 21, switch to a Newton solver.
mfi’s functional iteration is not a contraction on every model; Newton solvers are robust to that and find fixed pointsmficannot reach:[m, retcode] = solve(m, solver = '+mn'); % or [m, retcode] = solve(m, solver = '+mnk');
If Newton returns retcode 25 (“System unstable”), the solution it found is not mean-square stable. That does not prove that this parameterization has no stable solution: the equations the solver solves have several solutions in general, even in a constant-parameter model, and Newton from another start can reach the stable one. Search from random starts with
rise.engine.dsge_tools.stability.find_stable_solution(see Failure diagnosis: diagnose(m) and friends). If no start returns a mean-square-stable solution, investigate the calibration – vary the parameters and recheck where a stable solution is found.If retcode is 28 (“transition matrix must be diagonal”), an OBC chain has non-zero off-diagonal transition probabilities. Set them to zero – OBC switching is endogenous, not stochastic.
If retcode is in the evaluation range (1-11), the failure is upstream of the solver. Read the message; it points at the steady-state file, the Jacobian, the transition matrix construction, or the parameter restrictions. Fix that before touching
solve.
1.6.13. Return-code reference
The canonical table lives in utils.error.registry; this is the
human-readable summary, in three groups.
Evaluation (pre-solve)
Code |
Meaning |
|---|---|
|
Steady state could not solve |
|
Complex or nan steady-state residuals |
|
NaNs in Jacobian |
|
Problem in transition matrix |
|
Parameter restrictions violated |
|
Definitions are NaN, Inf, or imaginary |
|
NaNs or Infs in planner objective |
|
Bounds or restriction violation |
|
The measurement-error covariance built from the |
Solving
Code |
Meaning |
|---|---|
|
Maximum number of iterations reached or multiple solutions |
|
Discretionary outer loop: max iterations reached |
|
NaNs in solution or no solution |
|
Complex solution |
|
Explosion limit reached |
|
Discretionary outer loop: explosion limit reached |
|
Explosive solution |
|
System unstable |
|
DSGE-VAR solution: system unstable |
|
VAR approximation to the DSGE failed |
|
DSGE prior is not proper |
|
DSGE-VAR solution: covariance matrix not positive definite |
|
SVAR solution: matrix not invertible |
|
Cannot take a log-expansion of a variable whose steady state is close to 0 |
|
For this solver the transition matrix must be diagonal |
Filtering and likelihood (downstream of solve, listed for completeness)
Code |
Meaning |
|---|---|
|
Max iterations reached in Lyapunov solution |
|
NaNs in Lyapunov solution |
|
Explosion limit reached in Lyapunov solution |
|
Failure of covariance in sigma-points determination |
|
Covariance of forecast errors not positive definite |
|
Unlikely parameter vector |
|
NaN/Inf/complex in log prior |
|
Inconsistent ergodic probabilities |
|
Error in user-defined endogenous priors |
|
NaNs or Inf in initial conditions for the state vector |
|
NaNs or Inf in initial covariance matrix |
|
NaN/Inf/complex likelihood |
|
Forecast covariance positive definite but determinant = 0 |
1.6.14. Deferred higher-order fallback storage
After an iterative higher-order solve fails, the HOPS Sylvester path may try a second solver. If its state-transition blocks are deferred function handles, their sparsity is unknown until those handles are evaluated. The fallback now checks the total possible storage of all those square blocks before evaluating any handle. Above 1 GiB at eight bytes per possible entry, it skips that fallback and preserves the iterative solver’s failed iterate and nonzero return code. This is the same allowance used for all-solutions candidate storage.
This is a conservative admission check: a large block that would turn out to be sparse can also be refused. Already materialized blocks follow the existing fallback path. The threshold is separate from the reduced operator’s nonzero limit; neither is a bound on total process memory, intermediate allocations, or factorization workspaces. A nonzero return code remains a failed solve.
1.6.15. The retcode-aware pattern
The pattern is the same for every solve in a script:
[m, retcode] = solve(m, solver = '+mn');
if retcode ~= 0
warning('solve failed: %s -- trying mfi with raised MaxIter', ...
decipher(retcode));
opts = struct(MaxIter = 1e8);
[m, retcode] = solve(m, solver = {'mfi', opts});
end
assert(retcode == 0, decipher(retcode));
print_solution(m);
Always capture the retcode; always decipher on failure; do not
read the solution fields until retcode == 0. See Teaser
Example for the canonical worked solve on the standard
documentation model.