Commit Graph

1596 Commits (master)

Author SHA1 Message Date
Sébastien Villemot 086d65d98c
Remove unused enum values 2023-11-07 15:32:12 +01:00
Sébastien Villemot 53987fc039
Block: more symmetry between bytecode and non-bytecode write helpers 2023-11-07 15:32:12 +01:00
Sébastien Villemot 66dcb59d2b
🐛 Bytecode: fix FSTPG3_::get_lag()
It would return an incorrect result. This had no impact except for debugging
information.
2023-11-07 15:32:12 +01:00
Sébastien Villemot 3c7b02e87e
🐛 Bytecode+block+mfs>0: fix Jacobian computation in “evaluate” mode
When parsing the FSTPG{2,3} opcodes, the bytecode MEX internally constructs a
Jacobian with as many lines as feedback variables. But the preprocessor would
also output instructions for filling derivatives of equations corresponding to
recursive variables in the “evaluate” mode, thus leading to memory corruption
in the bytecode MEX.
2023-11-07 15:31:51 +01:00
Sébastien Villemot 1e159319d0
Static block derivatives: minor simplification 2023-11-03 11:26:59 +01:00
Sébastien Villemot 17ba27330a
Minor simplification 2023-10-25 14:38:43 +02:00
Sébastien Villemot 9b50a8a159
Rename ys0_ into oo_.initial_steady_state and ex0_ into oo_.initial_exo_steady_state 2023-10-23 17:33:49 +02:00
Sébastien Villemot 6235e69075
No longer forbid bytecode with k_order_solver
The two are now compatible, even though the bytecode representation will not be
used.
2023-10-19 14:09:05 -04:00
Sébastien Villemot e6f38e724c
Cosmetics: remove empty list of parameters for lambda functions 2023-10-19 09:55:59 -04:00
Sébastien Villemot f78c428d99
New option “relative_to_initval” to “mshocks” block 2023-10-18 16:16:41 -04:00
Sébastien Villemot f179ec4dac
Use __builtin_unreachable() to silent some GCC warnings
This is cleaner than using exit() or assert() for that purpose.
2023-10-18 14:28:59 -04:00
Sébastien Villemot 6af84b8cac
The “mshocks” block now accepts the “learnt_in=…” option 2023-10-17 15:59:10 -04:00
Sébastien Villemot 6ec7f580d5
New option “static_mfs” to “model” block (and “model_options” command)
Currently defaults to 0.
2023-10-16 11:50:26 -04:00
Sébastien Villemot 98c27fad59
StaticModel: add missing fields in copy constructor and assigment operators
This should have been in commit 0169240f76.
2023-10-16 11:49:33 -04:00
Sébastien Villemot 9ecc288f72
Bison grammar: small simplification w.r.t. “model” block options
Those options do not internally behave as the usual command options (which have
a “o_*” rule), so it makes more sense to treat them differently.
2023-10-16 11:49:33 -04:00
Sébastien Villemot 43fc59a2bc
The “mfs” option of the “model” block no longer affects the static model
This is a restoration of the behaviour that was present in 5.x.
2023-10-16 11:49:30 -04:00
Sébastien Villemot db3a6bc301
ModelTree::equationTypeDetermination(): remove “mfs” as an input argument
It is already available as a class member.
2023-10-13 17:02:36 -04:00
Sébastien Villemot 613a8578ee
InitvalFileStatement: call histval_initvalf.m directly instead of initvalf.m wrapper 2023-10-11 16:52:04 -04:00
Johannes Pfeifer 3c20b9862b
Add interface for nomodelsummary option 2023-10-11 09:31:22 -04:00
Johannes Pfeifer 16b063f666
Remove options_ as third input to set_state_space 2023-10-11 09:22:35 -04:00
Sébastien Villemot 084372a314
Add new option “from_initval_to_endval” to “homotopy_setup” block 2023-10-10 10:20:21 -04:00
Sébastien Villemot a4bc539364
Rename HomotopyStatement class to HomotopySetupStatement
For consistency with other such classes, since it represents the homotopy_setup
block.
2023-10-06 16:51:39 -04:00
Sébastien Villemot 3d225c8df6 Merge branch 'irf_matching_preprocessor' into 'master'
Options for Bayesian IRF Matching in method_of_moments command

See merge request Dynare/preprocessor!85
2023-09-29 08:56:01 +00:00
Sébastien Villemot 86b24dc9bf
Gracefully handle division by zero when attempting equation normalization
Instead of crashing the preprocessor (because DataTree::DivisionByZeroException
is not caught), just abort the normalization and mark it as failed.

Ref. #92
2023-09-28 15:32:38 +02:00
Willi Mutschler 960c1563a0
Reorder IRF matching options alphabetically 2023-09-28 12:40:46 +02:00
Willi Mutschler 37ac40352a
Add options and checks for Bayesian IRF matching 2023-09-28 12:40:03 +02:00
Willi Mutschler a2a6342865
Save options_mom_ to results.mat 2023-09-28 12:38:08 +02:00
Willi Mutschler d714b2cb15
Remove unused option zero_moments_tolerance 2023-09-28 12:38:08 +02:00
Sébastien Villemot dec60b25e6
Do not write bytecode for discretionary optimal policy models
Those models do not have as many variables as equations, and this case is not
supported by bytecode.

The present commit is an improvement over commit
a8ea57dd63, which had already removed bytecode
for the planner objective model.
2023-09-27 14:49:06 +02:00
Sébastien Villemot ef57a28b5f
Use same default variable cleaning rule under Octave as under MATLAB ⩾ 8.6
“clearvars” has been implemented in Octave since version 5.
2023-09-27 12:24:45 +02:00
Sébastien Villemot a8ea57dd63
Fix illegal memory access when doing Ramsey
The preprocessor would try to write bytecode for the planner objective. But
bytecode only works when there are as many endogenous as equations, which is
not the case for the PlannerObjective object derived from StaticModel.
2023-09-27 11:23:18 +02:00
Johannes Pfeifer 0abb0077d5 Remove unused lik_algo-option 2023-09-25 11:59:13 +02:00
Johannes Pfeifer 35e324fa23 occbin.solver: do not pass and return full oo_ structure 2023-09-25 11:59:12 +02:00
Sébastien Villemot 3804222667
Ignore -Wold-style-cast in Flex-generated files 2023-09-22 14:29:22 +02:00
Sébastien Villemot 5b7299766f
Remove warning about unused parameter (-Wunused-parameter) under Windows 2023-09-22 14:16:23 +02:00
Sébastien Villemot 5104759bd5
Drop autoconf/automake build system 2023-09-20 15:26:32 +02:00
Johannes Pfeifer f08d02ea66 StaticModel: remove transformation of complex residuals for Julia as well 2023-09-19 12:54:06 +02:00
Johannes Pfeifer 5313286db5 StaticModel: remove transformation of complex residuals 2023-09-19 12:54:06 +02:00
Johannes Pfeifer 2672d9911f estimation: allow additional_optimizer_steps option 2023-09-14 14:56:03 +02:00
Johannes Pfeifer 27a3a559e4
Move BVAR to +bvar folder 2023-09-14 11:59:06 +02:00
Johannes Pfeifer 5a2b3e052f OSR: allow analytic_derivation option 2023-09-12 09:02:40 +02:00
Sébastien Villemot bd0ba65a61
Merge branch 'osr_global' of git.dynare.org:JohannesPfeifer/preprocessor
Ref. !81
2023-09-11 16:45:20 +02:00
Johannes Pfeifer 320ccf46a0 display_static_residuals: remove globals 2023-09-08 14:56:38 +02:00
Johannes Pfeifer 4fc61eec53 Remove globals from OSR 2023-09-08 14:08:34 +02:00
Sébastien Villemot 3a18707685
Bytecode: make destructors of base classes protected
This prevents destruction through a base pointer, which would a memory leak
since the destructor is not virtual (and we cannot make it virtual because it
would break our crude serialization strategy).
2023-09-01 13:50:57 +02:00
Sébastien Villemot c8cd182e98
Build system / Meson: hack for static linking under Windows
[skip ci]
2023-07-28 14:21:09 +02:00
Sébastien Villemot dcb8b50cf8
Build system: split Meson file, for integration with build system for whole of Dynare
[skip ci]
2023-07-28 12:13:46 +02:00
Willi Mutschler 958b0a3800
macOS: use clang if GCC is not available for use_dll
Related to Dynare/dynare#1893 and Dynare/dynare#1894
2023-07-19 10:14:42 +02:00
Sébastien Villemot e1e1a753d0
Do not use C++20 aggregate initialization with parentheses
Initialization with initalizer list is nicer. And, more importantly,
initialization with parentheses is not supported by Clang < 16.
2023-07-07 14:32:16 +02:00
Johannes Pfeifer 508f2ff01e Add interface for brooks_gelman_plotrows option 2023-07-05 13:42:46 -04:00
Johannes Pfeifer 0990492e2f Remove unused exo_names_orig_ord 2023-06-23 08:36:37 -04:00
Johannes Pfeifer 43a7d231d0 Rename resid command
Related to dynare#1888
2023-06-22 14:12:39 -04:00
Sébastien Villemot fa5c4c5191
New homotopy options for perfect_foresight_{setup,solver} and perfect_foresight_with_expectation_errors_solver
Also remove homotopy_alt_starting_point option, and some options from
perfect_foresight_with_expectation_errors_setup.
2023-06-21 15:57:43 +02:00
Sébastien Villemot a1b8602760
Drop terminal_steady_state_as_guess_value option to pfwee_solver 2023-06-15 15:23:36 +02:00
Sébastien Villemot 1947e6de58
Use different filenames for Bison-generated location files 2023-06-07 11:57:12 +02:00
Sébastien Villemot 0de27e8dab
macOS: bump to GCC 13 (for compilation and for use_dll) 2023-06-07 10:48:37 +02:00
Sébastien Villemot 3cc531315b
C++20 modernization: use new standard mathematical constants 2023-05-25 19:06:48 +02:00
Sébastien Villemot 150547b560
🐛 Bytecode + block decomposition: temporary terms were not correctly output
Temporary terms computed in previous blocks were not used in the bytecode
output of a given block. This was inefficient (because this means that
expressions already computed and store in the temporary terms vector would be
recomputed), and incidentally it would break the external functions
output (because it would trigger a lookup in the “TEF terms”, which would thus
fail).

Closes: #115
2023-05-12 17:24:31 +02:00
Johannes Pfeifer 868e3b6417 parallel_use_psexec: use correct field 2023-05-11 13:14:50 -04:00
Sébastien Villemot 2d3e3eff6f
Block decomposition: add specialized normalization algorithm for purely backward models
If the model is purely backward, determine whether all original equations have
a single contemporaneous endogenous on the LHS. If this is the case, then first
try a normalization by enforcing that each original equation is matched with
the endogenous on the LHS.

This helps with the simulation of purely backward models, where equations are
renormalized with mfs=3, since it produces a simpler system to be recursively
evaluated/solved.
2023-04-24 17:49:54 +02:00
Sébastien Villemot d246f9f99a
ModelTree::computeNormalization(): throw an exception in case of normalization failure
It would previously return a boolean. The exception is more convenient for
producing a different error message in the case of the specialized algorithm
introduced in the next commit.
2023-04-24 17:47:29 +02:00
Sébastien Villemot e761da71bd
ModelTree::compute{,NonSingular}Normalization(): minor improvements 2023-04-24 16:52:10 +02:00
Sébastien Villemot a53426fc1f
Use ModelTree::addAuxEquation() method instead of directly manipulating ModelTree::aux_equations 2023-04-24 16:52:10 +02:00
Sébastien Villemot 34edd4e143
Bytecode: remove useless FBEGINBLOCK_::endo_nbr data member 2023-04-18 16:54:35 +02:00
Sébastien Villemot faa1291055
use_dll: turn getPowerDeriv() and sign() into inline functions
This allows the compiler to better optimize by inlining those call when worth
it.
2023-04-11 15:58:49 +02:00
Sébastien Villemot 1b7b70ec93
Build system: enable the dangling else warning (-Wdangling-else)
Adapt the code accordingly.
2023-04-11 14:22:32 +02:00
Sébastien Villemot 6caf8c6c59
use_dll: simplify definition of getPowerDeriv() function using C99 2023-04-07 16:38:25 +02:00
Sébastien Villemot b1e4884237
🐛 sign(0) was returning 1 instead of 0 with use_dll
The C99 copysign() function was used in the generated C output, but that
function does not correctly handle zero. Replace it by a custom sign()
function.
2023-04-07 16:38:23 +02:00
Sébastien Villemot 5a4297088d
Optimization: use std::unordered_map instead of std::map when computing temporary terms
Improve performance on very large models (⩾ 5000 equations).

Note that std::unordered_set cannot be used for the temporary_terms_t type,
because ordering is needed there (for writing the output files).
2023-04-05 19:49:16 +02:00
Sébastien Villemot e22d9049ee
Optimization: use std::unordered_map instead of std::map for caching chain rule derivation
Improves performance on very very large models (tens of thousands of equations).
2023-04-05 19:49:16 +02:00
Sébastien Villemot b9bfcaad5d
Block+bytecode: minor simplification 2023-04-03 18:29:57 +02:00
Sébastien Villemot a87f536799
ramsey_policy: implement fully at the preprocessor level
The implementation no longer relies on ramsey_policy.m at the MATLAB/Octave
level.

By the way, drop ModFileStructure::ramsey_model_present, which is now
redundant.
2023-03-29 16:14:59 +02:00
Sébastien Villemot e9babf0242
🐛 ramsey_policy: lift restriction that order must be ⩽ 2
This restriction no longer exists, and is actually not applied to stoch_simul
when following ramsey_model.
2023-03-29 16:05:38 +02:00
Sébastien Villemot 419c684929
🐛 Extend incompatibility with deterministic exogenous to ramsey_model command
The check was only done with ramsey_policy.
2023-03-29 15:33:15 +02:00
Sébastien Villemot d0bc8128c7
ramsey_model: remove useless checks
Options “order”, “partial_information” and “k_order_solver” are not accepted by
the command (this code is probably a remnant of the deprecated “ramsey_policy”
command).
2023-03-29 15:27:57 +02:00
Sébastien Villemot 4282c98527
New field: M_.discretionary_orig_eq_nbr
It indicates the number of equations written in the model block by the user in
the discretionary policy case.
2023-03-28 18:47:02 +02:00
Sébastien Villemot cecc9aad69
New fields: M_.ramsey_orig_{eq,endo}_nbr
– M_.ramsey_orig_endo_nbr is the number of endogenous variables in the model
  present just before adding the Lagrange multipliers and computing the Ramsey
  FOC; it is by construction equal to the number of equations that will be added
  by the process of computing the FOCs
– M_.ramsey_orig_eq_nbr is the number of equations in the model present just
  before adding the Lagrange multipliers and computing the Ramsey FOC; it is by
  construction equal to the number of Lagrange multipliers that will be added by
  the process of computing the FOCs

Note that both may be greater than the number of endogenous/equations written
by the user, because some auxiliary variables may have already been added.

Also note that the number of policy instruments in M_.ramsey_orig_endo_nbr −
M_.ramsey_orig_eq_nbr

As a consequence, drop M_.ramsey_eq_nbr (which was actually equal to
M_.ramsey_orig_endo_nbr) and M_.orig_eq_nbr (which was actually equal to
M_.ramsey_orig_eq_nbr, but would also be set in the non-Ramsey case). The new
names are clearer.
2023-03-28 18:46:42 +02:00
Sébastien Villemot 70192aec71
Always set options_.{ramsey,discretionary}_policy at the preprocessor level
And set them before any computation is done.

These fields should rather be in M_.
2023-03-28 18:29:42 +02:00
Sébastien Villemot 2f353a3c62
Remove useless casts 2023-03-28 16:39:13 +02:00
Sébastien Villemot 1ef5feec15
Factorize methods for writing set auxiliary variables/series files 2023-03-28 16:37:05 +02:00
Sébastien Villemot 0d41e0ce3d
Make ModFileStructure a struct 2023-03-28 15:07:45 +02:00
Sébastien Villemot 0169240f76
Ramsey: write derivatives of static model w.r.t. Lagrange multipliers in a new file
The computing of the Ramsey steady state relies on the fact that Lagrange
multipliers appear linearly in the system to be solved. Instead of directly
solving for the Lagrange multipliers along with the other variables,
dyn_ramsey_static.m reduces the size of the problem by always computing the
value of the multipliers that minimizes the residuals, given the other
variables (using a minimum norm solution, easy to compute because of the
linearity property). That function thus needs the derivatives of the optimality
FOCs with respect to the multipliers. The problem is that, when multipliers
appear in an auxiliary variable related to a lead/lag, then those derivatives
need to be retrieved by a chain rule derivation, which cannot be easily done
with the regular static file.

This commit implements the creation of a new file,
ramsey_multipliers_static_g1.{m,mex}, that provides exactly the needed
derivatives w.r.t. Lagrange multipliers through chain rule derivation.

Ref. dynare#633, dynare#1119, dynare#1133
2023-03-28 14:27:51 +02:00
Sébastien Villemot fe3f18947e
No longer replace all auxiliary variables by their definition in the static model
This is effectively a revert of commits 1b4f68f934,
32fb90d5f3 and f6f4ea70fb.

This transformation had been introduced in order to fix the computation of the
Ramsey steady state in the case where Lagrange multipliers appeared with a lead
or lag ⩾ 2 (and where thus part of the definition of an auxiliary variable).

But this transformation had introduced bugs in the handling of external
functions which were difficult to tackle.

Moreover, it seems preferable to keep the strict correspondence between the
dynamic and static model, in order to make reasoning about the preprocessor
internals easier (in particular, for this reason this transformation was not
implemented in ModFile::transformPass() but in ModFile::computingPass(), which
was a bit confusing).

A better solution for the Ramsey steady state issue will is implemented in the
descendent of the present commit.

Ref. dynare#633, dynare#1119, dynare#1133
2023-03-28 14:10:13 +02:00
Sébastien Villemot f48a698458
🐛 Suboptimal temporary terms for external functions
If a given external function was called two times with different arguments,
then the second call would always be computed in the same temporary terms
chunk (derivation order or block) as the first call, even if this was not
necessary (technically, the second call would be promoted in the temporary
terms computation in the same category as the first call).

This could possibly lead to an inefficiency.
2023-03-28 14:00:06 +02:00
Sébastien Villemot 712b11a045
🐛 Incorrect stochastic transformation with endo lead ⩾ 2 or exo lead ⩾ 1 in external functions
If an endogenous with a lead ⩾ 2 or an exogenous with a lead ⩾ 1 appeared in
the argument(s) of a call to an external function, the auxiliary variable
transformation was incorrect (the variable was replaced inside the function
call, while it is the whole function call that has to be replaced).

This could lead to incorrect results in stochastic contexts, when the external
function is nonlinear.
2023-03-28 13:56:13 +02:00
Sébastien Villemot 3b20f835db
ModelTree: fix call to ExprNode::computeTemporaryTerms()
The first argument to ExprNode::computeTemporaryTerms() is supposed to be a
pair (endo derivation order, param derivation order). The two elements were
interverted in the call. This would not affect the result, because parameter
derivatives are not computed there and what matters is the lexical ordering
which remains the same. But fixing the order is better, for consistency with
the method description.
2023-03-28 13:54:10 +02:00
Sébastien Villemot 34c37cfd01
🐛 Crash when writing the (static) set_auxiliary_variables file in the presence of external functions 2023-03-28 13:49:34 +02:00
Sébastien Villemot acdfc1ad62
🐛 Julia: auxiliary variables of static model were incorrect in set_auxiliary_variables!
The output was in MATLAB syntax instead of Julia syntax.
2023-03-28 13:47:18 +02:00
Sébastien Villemot a8fc8e7afc
🐛 Incorrect cost table used when computing temporary terms in static model with “use_dll”
It was erroneously using MATLAB costs, leading to possible
inefficiencies (though those cost tables are probably not very accurate and
should be revised).
2023-03-28 13:43:31 +02:00
Sébastien Villemot 42ea2aac34
Fix typo 2023-03-24 19:02:33 +01:00
Sébastien Villemot 89a1a4d27f
Remove unused function 2023-03-24 19:02:33 +01:00
Sébastien Villemot 5ff503a964
Use map::try_emplace() instead of map::emplace() to simplify some calls
By the way, remove a redundant Cluster{} constructor call.
2023-03-23 16:10:42 +01:00
Sébastien Villemot 7c6402cc34
DataTree: optimize the filling of node maps
Use map::{try,}emplace() instead of operator[], which should in theory be
slightly faster.
2023-03-23 16:10:40 +01:00
Sébastien Villemot 69a394a115
ExprNode: factorization of code that recurisively applies a transformation on a node 2023-03-23 12:39:35 +01:00
Sébastien Villemot 661f116af1
Rename the argument to ExprNode::clone() for clarity
The argument had the same name as the data member “datatree”, so this could
lead to confusion (though there was no bug, since the argument was masking
the data member).
2023-03-23 12:39:35 +01:00
Sébastien Villemot 2f111f5055
ExprNode: simplification of external function nodes clone() and toStatic() methods 2023-03-23 12:39:11 +01:00
Sébastien Villemot bff80c0eaf
use_dll: under Windows, append MinGW location to the PATH variable only once
Previously, the MinGW location was appended multiple times to the PATH
variable, which in some cases would make the variable too long and thus
dysfunctional.

The variable is now initialized once when the worker threads are created.

By the way, move the macOS+Octave environment variable initializations to the
same place, for consistency.
2023-03-20 18:27:33 +01:00
Sébastien Villemot a219c68543
Macroprocessor: drop useless Expression::clone() method 2023-03-16 11:36:41 +01:00
Sébastien Villemot 96e7a764b2
Macroprocessor: make method Expression::eval() const 2023-03-16 11:32:50 +01:00
Sébastien Villemot 715ec9e4bc
Fix bytecode for block+mfs>0 in static model
Variable indices would be incorrect in the evaluated Jacobian if recursive
variables were present. This would lead to incorrect results and/or crashes in
bytecode MEX. This bug has been exposed by commit
f45a99fc68, which actually enabled mfs>0 for
static models.
2023-03-03 17:45:08 +01:00