Commit Graph

95 Commits (master)

Author SHA1 Message Date
Sébastien Villemot b2e9ec205e
No longer use reserved identifiers for include guards
Automatically detected using clang-tidy with bugprone-reserved-identifier
check.

By the way, homogeneize the define identifiers in relation to camel case
convention.
2023-12-01 15:39:01 +01:00
Sébastien Villemot d463607e90
Reformat C++ source code using clang-format 15 2023-11-30 15:58:32 +01: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 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 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 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
Sébastien Villemot 1ef5feec15
Factorize methods for writing set auxiliary variables/series files 2023-03-28 16:37:05 +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 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 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 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 9013a5cb1b
No longer create +<basename>/+block/ folder (now empty) 2023-01-17 18:42:40 +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 a234176d3c
Julia: do not rewrite derivatives w.r.t. parameters files when unmodified
Closes: #105
2022-12-14 12:35:50 +01:00
MichelJuillard cf4e2194b7 Julia: remove module for derivatives w.r.t. parameters 2022-11-22 10:18:11 +00: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 4ab3e937ea
Implement new sparse model representation in MATLAB/Octave
Ref. dynare#1859
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
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 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 3dd40c6c42
use_dll: split generated C file into smaller files that will be compiled in parallel
By the way, factorize the code between the dynamic and static versions.

Ref. #41
2022-10-07 18:04:18 +02:00
Sébastien Villemot dd66459e5f
use_dll: parallelize compilation of multiple object files within single MEX file
In particular, it implements dependency tracking in the thread scheduler, so
that multiple MEX files can share object files.

Ref. #41
2022-10-07 18:04:17 +02:00
Sébastien Villemot d9bda244d4
use_dll: refactor MEX compilation so that it happens inside “write” methods 2022-10-07 18:04:17 +02:00
Sébastien Villemot 4c58451d83
Factorize computing pass for block decomposition
Also add “block_decomposed” data member for tracking whether the block
decomposition has been successful.
2022-10-04 16:00:30 +02:00
Sébastien Villemot 36fcbf6cfe
Functions that write C files now return the paths to the generated files
This avoids computing those paths two times (the second time when compiling them).
2022-10-04 16:00:30 +02:00
Sébastien Villemot 3d9ac26aa6
Remove all instances of the “map.find(key)->second” pattern
This is unsafe since the find() method can return a past-the-end iterator,
which should be tested for.

Replace most instances by calls to the std::map::at() method (which throws if
the key is unknown), and which is incidentally more readable.
2022-09-27 12:56:16 +02:00
Sébastien Villemot b403cef871
Put driver output of static block decomposition in a separate function
For symmetry with the dynamic case, and for avoiding a call to “return” in the
middle of StaticModel::writeDriverOutput().
2022-09-21 18:48:35 +02:00
Sébastien Villemot 1088cc4242
Improve informative messages about derivatives and block decomposition
When computing the derivatives or block decomposition of the planner objective,
the epilogue or the original Ramsey model, the preprocessor would talk about
dynamic/static model, which was confusing. It now uses the right terminology.
2022-09-14 17:51:36 +02:00
Sébastien Villemot d67f569035
Always compute block decomposition, even if “block” option was not passed
If block decomposition fails, error out if “block” option was passed, but not
otherwise.

This commit does not modify the generated files.

This is a preliminary step for dynare#1859.
2022-09-13 16:16:00 +02:00
Sébastien Villemot ad40f1365c
Block decomposition: code factorization 2022-07-21 18:20:35 +02:00
Sébastien Villemot d4c453c422
Block decomposition: (likely) performance improvement in static file in relation to temp terms
Compute temporary terms for derivatives of “evaluate” mode, even though those
derivatives are not computed. This is because the temporary terms may be useful
for subsequent blocks.

By the way, add an explanatory comment for the equivalent code in dynamic file.
2022-07-21 17:31:48 +02:00
Sébastien Villemot a58109d094
Bytecode: refactor methods for writing .cod and .bin files in the block decomposition case 2022-07-20 16:02:24 +02:00
Sébastien Villemot 89debf429a
Factorize code for writing JSON output 2022-07-12 18:04:05 +02:00
Sébastien Villemot 9e6c01f132
Streamline some function names 2022-07-12 17:04:41 +02:00
Sébastien Villemot 157c67e04b
New helpers to simplify common operations with derivation IDs 2022-07-12 16:30:45 +02:00
Sébastien Villemot 1d71386f01
Further templating of helpers for writing output files
So that more stuff is computed at compile-time (using constexpr features).
2022-07-12 16:23:28 +02:00
Sébastien Villemot 9c3eeb7c8d
Refactor code for writing derivatives w.r.t. parameters 2022-07-12 16:18:16 +02:00
Sébastien Villemot f38c8278ae
Refactor methods for writing static and dynamic files
– factorize common code between the static and the dynamic version
– reorganise language-specific code into dedicated functions
– use a function template in the main helper to do some computations
  at compile-time (using constexpr features)
2022-07-11 22:29:28 +02:00
Sébastien Villemot e0c9a287c5
Remove unused StaticModel::copyHelper() 2022-06-24 15:28:42 +02:00
Sébastien Villemot 9bd2973034
Refactor bytecode output around a new BytecodeWriter class and operator<< overloads 2022-06-24 13:10:04 +02:00
Sébastien Villemot 171cd65566
Fix bytecode compilation of external function nodes 2022-05-20 11:43:02 +02:00
Sébastien Villemot 591b5e5f9e
Always create bytecode output
And, symmetrically, when the “bytecode” option is requested by the user, always
create the .m static/dynamic files.

The “bytecode” option therefore no longer modifies the preprocessor output.
2022-05-19 14:49:46 +02:00
Sébastien Villemot 0284b249f5
Remove unused “bytecode” argument in {Static,Dynamic}Model::computingPass() 2022-05-19 14:10:22 +02:00
Sébastien Villemot 2795207802
No longer delete move constructor/assignment operator
We follow the advice given by Josuttis in his book about move semantics.

Deleting those member fuctions can be a bug if we want to allow copy semantics,
because overload resolution will no longer fallback to the copy
constructor/assignment operator when given an rvalue.

In particular, this explain why it was not possible to delete the move
assignment operator of the StaticModel class.
2022-05-18 16:33:48 +02:00
Sébastien Villemot 0db05a886a
Move “using namespace std” statement after inclusion of standard headers
Otherwise clang emits this warning:
 using directive refers to implicitly-defined namespace 'std'
2022-01-06 14:54:57 +01:00