Commit Graph

1596 Commits (master)

Author SHA1 Message Date
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
Sébastien Villemot 7acf278370
Performance improvement of chain rule derivation
Commit 23b0c12d8e introduced caching in chain
rule derivation (used by block decomposition), which increased speed for mfs >
0, but actually decreased it for mfs=0.

This patch introduces the pre-computation of derivatives which are known to be
zero using symbolic a priori (similarly to what is done in the non-chain rule
context). The algorithms are now identical between the two contexts (both
symbolic a priori + caching), the difference being that in the chain rule
context, the symbolic a priori and the cache are not stored within the ExprNode
class, since they depend on the list of recursive variables.

This patch brings a significant performant improvement for all values of the
“mfs” option (the improvement is greater for small values of “mfs”).
2023-03-02 17:52:36 +01:00
Sébastien Villemot f8edce01ec
Minor simplification 2023-03-02 17:28:03 +01:00
Sébastien Villemot bf8ca27a47
Make ExprNode::prepareForDerivation() a protected member (was public) 2023-03-02 16:08:55 +01:00
Sébastien Villemot fe83933b1d
Bugfix: undefined behaviour in AbstractExternalFunctionNode::prepareForDerivation()
Input and output ranges should not overlap when calling std::set_union(),
otherwise the behaviour is undefined.

It seems that in this precise case the computation would still be
correct (though inefficient), because of the properties of std::set or because
of the specific implementation in libstdc++. But it’s better to be on the safe
side.
2023-03-02 15:55:51 +01:00
Sébastien Villemot 41052ccb74
Optimization for derivation of STEADY_STATE(…) operator in a dynamic context
In a dynamic context, the only potentially non-null derivatives of
STEADY_STATE(…) are the parameters. We know that the derivatives w.r.t. other
variables are zero, so store that information in non_null_derivatives.
2023-03-02 15:11:49 +01:00
Sébastien Villemot d64317a64f
Minor simplification 2023-03-02 15:11:47 +01:00
Sébastien Villemot ae83974e0e
Minor simplification using if with initialization 2023-02-28 16:27:31 +01:00
Sébastien Villemot 62c455ff56
Misc simplifications using STL algorithms 2023-02-28 16:27:29 +01:00
Sébastien Villemot 008a80910e
Bytecode: move CodeLoad class out of the preprocessor 2023-02-21 16:01:27 -05:00
Sébastien Villemot a88b921991
Bytecode: improve deserialization routines for FCALL and FBEGINBLOCK 2023-02-17 16:20:40 -05:00
Sébastien Villemot cf3ab36ac8
Bytecode: simplify specialized serialization methods 2023-02-17 15:31:22 -05:00
Sébastien Villemot 114d8eadfb
New “homotopy_alt_starting_point” option to “perfect_foresight_solver” command 2023-02-07 14:44:59 -05:00
Sébastien Villemot 389a2647d3
Block decomposition: make mfs=1 the default
NB: mfs=3 is nevertheless used when “block” option has not been used, and the
model is purely backward/forward or static, for solve_algo={12,14}.
2023-01-25 18:38:58 +01:00
Sébastien Villemot dc966014a3
Remove some incorrect normalization rules for the case mfs=3
More precisely, incorrect equation normalization could occur in the presence of
cos, sin, tan, cosh and x^n (where n is an even integer).

Also add some comments explaining why some other rules are (hopefully) correct.
2023-01-25 17:14:01 +01:00
Sébastien Villemot 0ddcf81ac0
Fix typo 2023-01-25 16:50:56 +01:00
Sébastien Villemot 1c813a1cf9
Run detrending engine if trend variables are present, even if unused in a var(deflator=…) statement
Closes: #113
2023-01-24 14:14:40 +01:00
Sébastien Villemot 74e5bbf537
Drop dynamic_g1_nz.m generated file
No longer needed since perfect_foresight_problem MEX has moved to the sparse
representation.
2023-01-23 16:20:12 +01:00
Sébastien Villemot 4f9241442c
Fix size of dynamic derivatives (legacy representation) when there are unused exogenous and “nostrict” option is given 2023-01-19 11:00:32 +01:00
Sébastien Villemot c47d91c20b
Block decomposition: another fix for sparse indices of static Jacobian when mfs > 0 2023-01-19 10:03:37 +01:00
Sébastien Villemot 7db02b23e9
Block decomposition: fix sparse indices of static Jacobian when mfs > 0 2023-01-17 19:04:21 +01:00
Sébastien Villemot 9013a5cb1b
No longer create +<basename>/+block/ folder (now empty) 2023-01-17 18:42:40 +01:00
Sébastien Villemot f45a99fc68
Correctly propagate “mfs” and “cutoff” to the static model
Those two settings were previously always at their default value for the static
model, independently of what the user would set in the .mod file.
2023-01-17 16:38:03 +01:00
Sébastien Villemot fe503d3eab
Remove confusing comment 2023-01-17 16:37:24 +01:00
Sébastien Villemot 4bba274f39
Block decomposition: drop unused max lead/lag fields
Note that DynamicModel::determineBlockDerivativesType(), it’s legitimate to
replace max_{lead,lag} by max_endo_{lead,lag}, because for exogenous
lag=lead=0, and we no longer compute derivatives w.r.t. to endogenous that do
not belong to the block (so-called “other” endogenous).
2023-01-17 14:42:29 +01:00
Sébastien Villemot 2e09df90e7
Bytecode w/ block decomposition: no longer output derivatives w.r.t. exogenous and endogenous outside the block 2023-01-17 14:23:40 +01:00
Sébastien Villemot 1e377f061a
Block decomposition: drop unused structure fields 2023-01-17 14:18:41 +01:00
Sébastien Villemot bbdbd0807b
Sparse representation: Octave compatibility fix
Octave does not support “private” subdir inside plus folders (“+namespace”).

See https://savannah.gnu.org/bugs/?45444
2023-01-16 17:12:10 +01:00
Sébastien Villemot 8ebd9a9496
Drop the “Sigma_e” statement 2023-01-16 15:08:23 +01:00
Sébastien Villemot a7b0a324c9
Drop the “periods” statement 2023-01-16 15:02:50 +01:00
Sébastien Villemot 93b9ed6957
Drop the legacy representation of the block-decomposed model
As a consequence, and as a temporary measure, always output the
non-block-decomposed legacy representation.

Also drop the block kalman filter output, and drop now useless variables in
M_.block_structure.
2023-01-13 16:57:06 +01:00
Sébastien Villemot 35ac73fad8
Sparse representation: fix various bugs in the non-block MATLAB/Octave output 2023-01-10 15:58:45 +01:00
Sébastien Villemot e18ecc3fa5
ModFile::remove_directory_with_matlab_lock(): minor performance improvement
Use std::filesystem::file_status and cached directory entries information to
avoid extra filesystem operations.
2023-01-10 11:49:39 +01:00
Sébastien Villemot bae04fa899
ModelTree::findGccOnMacOS() now returns a std::filesystem::path 2023-01-10 11:48:33 +01:00
Sébastien Villemot a4f299c0b7
Bytecode: change interface of function called from bytecode MEX 2023-01-09 14:09:09 +01:00
Sébastien Villemot ec3ce156b4
Bytecode: always produce block and non-block versions
The block decomposed version is now under <BASENAME>/bytecode/block/.
2023-01-09 13:35:49 +01:00
Stéphane Adjemian (Guts) 4348f4d57f
Provisions for conditional likelihhod estimation. 2023-01-06 12:17:02 +01:00
Sébastien Villemot 0bc1539f45
Drop clang workaround 2023-01-05 18:11:33 +01:00
Sébastien Villemot cf493ef6a6
Add two missing checks for file opening failures 2023-01-05 17:21:30 +01:00
Sébastien Villemot 253fbbe7d6
Use std::filesystem::path in more places 2023-01-05 17:21:28 +01:00
Sébastien Villemot d36eb82b7c
Macro processor: removed unused “basename” variable 2023-01-05 15:49:36 +01:00
Sébastien Villemot 1f3ff760e1
EquationTags: drop useless method 2023-01-04 19:27:01 +01:00
Sébastien Villemot 3927862d23
EquationTags: misc implementation improvements 2023-01-04 17:15:51 +01:00
Sébastien Villemot 9658d82cc6
EquationTags::getEqnByTag() now returns an optional<int> instead of throwing 2023-01-04 16:45:12 +01:00
Sébastien Villemot e2c72a1b75
Drop ModelTree::getEquationTags(), and replace it by calls to better interfaces 2023-01-04 16:20:50 +01:00
Sébastien Villemot bdb5d37dec
EquationTags::getTagValueByEqnAndKey() now return an optional<string>
By the way, optimize the implementation.
2023-01-04 16:03:49 +01:00
Sébastien Villemot 422cbf5736
EquationTags: remove unused function 2023-01-04 16:03:45 +01:00
Sébastien Villemot df3a153356
Simplify residuals output (MATLAB/Octave and C) by dropping lhs/rhs temporary variables 2023-01-04 14:49:07 +01:00
Sébastien Villemot 9f5ea9467d Merge branch 'dynamic_model_info' into 'master'
Add dynamic option to model_info

See merge request Dynare/preprocessor!74
2023-01-04 09:57:18 +00:00
Johannes Pfeifer 2fd0681151 Add block_dynamic option to model_info
Also renames the old static option
2023-01-03 16:06:25 +01:00
Sébastien Villemot 21fcfa7758
use_dll: fixes to parallel compilation
— No longer call std::exit() from threads when compilation fails, that function
  is marked as not thread-safe under GNU/Linux; and it leads to deadlocks under
  Windows. Rather store the list of failed objects, and exit with a message and
  an error code from the main thread when that list is not empty at the end of
  preprocessing.
– Fix the condition used for waiting until all compilation threads finish;
  checking that the queue is empty is not enough, since a compilation may be
  ongoing. So also track objects whose compilation is ongoing.
2022-12-20 16:52:47 +01:00
Sébastien Villemot f349e22f4c
Macro processor: fix error message when @#include is used with nonexistent file 2022-12-14 15:22:20 +01:00
Sébastien Villemot 50a2737e41
Macro processor: fix tracking of line numbers after @#define, @#include and @#includepath directives
Closes: #108
2022-12-14 15:22:07 +01:00
Sébastien Villemot 8734bc5ca6
Allow LOG_* auxiliary variables in various commands
Closes: #107
2022-12-14 12:42:55 +01:00
Sébastien Villemot a234176d3c
Julia: do not rewrite derivatives w.r.t. parameters files when unmodified
Closes: #105
2022-12-14 12:35:50 +01:00
Sébastien Villemot a5eac0260a
JSON: fix output of date options
They were not enclosed within quotes.

Ref. dynare#1875
2022-12-14 12:16:04 +01:00
Sébastien Villemot 2758f46c83
Fix indexing in M_.endo_trends
It would use 0-based indexing, instead of 1-based.

Ref. dynare#1648

Closes: #109
2022-12-14 12:05:12 +01:00
Sébastien Villemot 8cb3437d2d
Minor simplification in static block decomposition driver output 2022-12-12 14:57:50 +01:00
Sébastien Villemot 4aa1ff1f73
Sparse representation: fix bug in output of indices in driver and JSON files
Jacobian column numbers were incorrect (it would return internal derivation
IDs).

Ref. dynare#1859
2022-12-12 14:57:49 +01:00
Sébastien Villemot 4f7794a8f9
Sparse representation: compatibility fix with MATLAB < R2020a
For those older MATLABs, the “sparse” function does not accept vectors of
integer data type as indices.

Ref. dynare#1875
2022-12-08 14:35:23 +01:00
Sébastien Villemot 83bfc792af
Sparse representation: fix bug in output of indices in driver and JSON files
It would previously forget to write the indices for the highest derivation
order (e.g. if order=3, then it would only write sparce indices up to 2nd
order).

Ref. dynare#1859
2022-12-07 16:10:03 +01:00
Johannes Pfeifer 9b015a6a10 Add new mh_init_scale_factor-option 2022-12-01 15:23:37 +01:00
Sébastien Villemot c48248fc0d
Implement time-recursive block decomposition tuned for purely backward/forward/static models
Such a decomposition has to be simulated with periods as the outer loop and
blocks as the inner loop.

It is enabled by default for purely backward/forward/static models, as long as
the “block” option is not given. In that case, “mfs” is also set to 3 by
default (until that value becomes the global default).

M_.time_recursive_block_decomposition is set to “true” when that decomposition
has been performed, “false” otherwise for the traditional decomposition (the
latter has to be simulated with blocks as the outer loop and periods as the
inner loop).
2022-11-30 14:43:44 +01:00
Sébastien Villemot bb3475d548
Remove call to setup_solvers.m
It is no longer used in the new implementation of solve_algo={12,14}.

However, the M_.lhs field that was created by setup_solvers.m is used from
other places, so reimplement it at the preprocessor level.
2022-11-30 14:43:44 +01:00
Sébastien Villemot ff296023a9
Block decomposition: ModelTree::block_decomposed field was not properly set on copy/move 2022-11-29 15:27:12 +01:00
Sébastien Villemot 53add0b2fe
Block decomposition: when falling back to symbolic normalization, use contemporaneous symbolic Jacobian
Previously, it would use a symbolic Jacobian where leads and lags were also
taken into account.
2022-11-28 13:40:49 +01:00
Johannes Pfeifer 56c62197d0 DynareBison.yy: add nobs and heteroskedastic_filter options to calib_smoother 2022-11-23 13:46:53 +01:00
Sébastien Villemot e01c748c7e
Julia: fix prototype of function computing dynamic derivatives w.r.t. parameters 2022-11-22 11:19:58 +01:00
MichelJuillard cf4e2194b7 Julia: remove module for derivatives w.r.t. parameters 2022-11-22 10:18:11 +00:00
Sébastien Villemot 2e171e28de
New files for helping a user to debug their model
The files are created under <basename>/+debug/dynamic_resid.m and
<basename>/+debug/static_resid.m.

Their purpose is to evaluate separately the LHS and RHS of each equation.
2022-11-16 11:18:09 +01:00
Sébastien Villemot 4807a6c880
use_dll: fix race condition with compilation of power_deriv.{c,h} 2022-11-14 13:45:15 +01:00
Sébastien Villemot 23b0c12d8e
Performance improvement of chain rule derivation, using caching
Useful for mfs > 0 on large models.
2022-11-08 12:34:05 +01:00
Sébastien Villemot dbc2851606
Merge branch 'max_check_ahead_periods' of git.dynare.org:JohannesPfeifer/preprocessor
Ref. !69
2022-11-07 16:32:10 +01:00
Johannes Pfeifer ed95a2ca2d OccBin: add interface for max_check_ahead_periods option
Related to 2f23604824
2022-11-04 23:11:59 +01:00
Sébastien Villemot 1430ab9cc2
Implement new sparse model representation in C
Ref. dynare#1859
2022-11-04 14:23:29 +01:00
Sébastien Villemot 836351565d
Fix segfault of notmpterms option with block decomposition
By the way, ensure that temporary terms associated to external functions are
not removed, since they are not optional.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 4ab3e937ea
Implement new sparse model representation in MATLAB/Octave
Ref. dynare#1859
2022-11-04 14:23:29 +01:00
Sébastien Villemot 2a8e26310d
Block decomposition: fix computation of recursive variables with mfs>0
Within a block, if mfs>0, the recursive variables would not appear in recursive
order. This could lead to wrong results in case of dependency relationships
between recursive variables.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 47290087f6
Provisions for new sparse representation of block-decomposed dynamic/static files
The stochastic mode in currently unsupported.

This commit adds new fields in M_.

This is a preliminary step for dynare#1859.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 1ed72f6da2
Write block decomposition information in M_ independently of “block” option
This is now possible since the block decomposition is always computed. Of
course, the information is not printed if the decomposition failed.
2022-11-04 14:23:29 +01:00
Sébastien Villemot 00fd9dadb6
Julia: no longer write the main dynamic/static files in legacy representation 2022-11-02 15:51:26 +01:00
Sébastien Villemot 6aca84bfbb
Julia: move all generated files to the <basename>/model/julia/ subdirectory 2022-11-02 15:49:57 +01:00
MichelJuillard 6af8a57f9f
replace Julia modules by simple functions 2022-11-02 15:49:56 +01:00
Sébastien Villemot 762243c705
Julia: drop get_power_deriv function from module
The function is now provided separately by Dynare.jl.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 4ae6df494d
JSON: add dynamic_tmp_nbr and static_tmp_nbr
As a consequence, remove the “tmp_nbr” variable from the Julia modules, since
it is now redundant.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 723fc4139b
Implement new sparse model representation in Julia
Ref. dynare#1859
2022-11-02 15:49:56 +01:00
Sébastien Villemot 0278c8577c
Provisions for new sparse representation of dynamic/static files
The new representation is only supported for MATLAB/Octave, C and Julia output
for the time being. Bytecode and JSON are unsupported.

This commit adds new fields in M_.

This is a preliminary step for dynare#1859.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 30853e7360
Block decomposition: improve debugging information for normalization
– print the information only for the final matching (and not the intermediary
  ones that may have failed);
– print the equation name next to its number.
2022-11-02 15:49:56 +01:00
Sébastien Villemot 627dd92c64
Block decomposition: bugfix with temporary terms when mfs=3
In an “evaluate” block, the LHS of a renormalized equation (such as “log(x)=…”)
could be associated to a temporary term that would then be incorrectly
computed: that temporary term would be evaluated *before* (and not after) the
evaluation of the associated variable (“x” in the example).
2022-10-26 17:33:26 +02:00
Johannes Pfeifer d5cf07fadd Occbin: implement simul_reset_check_ahead_period-option
Related to dynare@3765ef77 (dynare!2094)
2022-10-24 10:30:45 +02:00
Sébastien Villemot 219c8d2a47
Do not error out in stochastic mode if mfs > 0 but “block” option not passed
In that case, the block-DR routines will not be called.
2022-10-18 17:39:14 +02:00
Sébastien Villemot 5a6e276750
Fix comment 2022-10-18 17:39:14 +02:00
Sébastien Villemot 79c8fe61b1
Fix typo 2022-10-18 17:39:14 +02:00
Sébastien Villemot a31ef6069c
Correctly handle diff operator in equation renormalization
Should have no impact though, since diff nodes are already substituted out at
that point. But it’s better to implement it properly, in case we change the
substitution rules later.

By the way, make the computeSubExprContainingVariable method protected.
2022-10-18 17:39:14 +02:00
Sébastien Villemot 9f96db89ba
use_dll: ensure proper cleanup of thread workers threads in case of early exit (e.g. upon failure) 2022-10-17 14:03:27 +02:00
Sébastien Villemot 781e10c24b
Error out if “use_dll” is specified in Julia mode 2022-10-14 15:40:09 +02:00
Sébastien Villemot fd9902e87b
use_dll: rewrite the parallel compilation engine with a fixed number of threads
The previous system would spawn as many threads as there are object files to be
compiled (which could lead to hundreds of threads for large block-decomposed
models). This could pose a memory usage problem (even when not just waiting,
threads require memory for their own stack).
2022-10-14 15:33:52 +02:00
Sébastien Villemot e801f1a862
Fix typo
[skip ci]
2022-10-11 18:15:11 +02:00
Sébastien Villemot 39051aeb30
Make the hack for MATLAB+Windows directory lock work with any recursive directory structure
This simplifes the treatment of the new sparse representation, which creates
several subdirectories in the “+” package folder.
2022-10-11 17:26:47 +02:00
Sébastien Villemot 93054cf692
Various filesystem refactorings
– DataTree::packageDir() now takes a std::string_view, returns a
  std::filesystem::path, and no longer creates that directory
– DataTree::writeToFileIfModified() now takes a std::filesystem::path as
  argument
– Do not call DataTree::writeToFileIfModified() for generating MATLAB/Octave
  files, since it does not work (the directory inside which the file is written
  has been deleted by the preprocessor just before)
– Consistently use DataTree::packageDir() everywhere (for compatibility with
  planner_objective)
2022-10-11 16:28:17 +02:00
Sébastien Villemot 198ff70bce
Simplify strsplit() using std::string_view
By the way:
– improve the semantics by having a consistent treatment of empty substring
  components (previously, only the last one was ignored)
– move it to DataTree to make it more accessible from elsewhere (even though
  ideally it should be in a “utilities” namespace).
2022-10-11 16:23:11 +02:00