Commit Graph

198 Commits (bffd68e0bf5b7976a911bbc98d37d09a855b327d)

Author SHA1 Message Date
Sébastien Villemot af9bd8f109
Remove the unfinished decomposition in linear and nonlinear blocks
Also remove the det_cond_forecast interface, that was related to it.

Ref. dynare!1626
Closes: #39
2021-01-25 18:03:37 +01:00
Sébastien Villemot db8c5439f7
use_dll: higher order derivatives are now returned as sparse matrices by static/dynamic files
Previously they were returned as 3-column matrices. But this was inconsistent
with the M-file mode.
2020-06-23 17:50:50 +02:00
Sébastien Villemot ad5e196d30
Block decomposition now compatible with 'use_dll' option 2020-06-23 15:13:04 +02:00
Sébastien Villemot b402e35683
In the driver file, provide mapping between model local variables and indices in the temporary terms vector
The structures are M_.model_local_variables_{dynamic,static}_tt_idxs.

Ref. dynare#1722
2020-06-05 17:12:15 +02:00
Sébastien Villemot 90b9b6a1e4
JSON output: write model local variables in parsed model (modfile.json)
Ref. dynare#1723
2020-06-05 16:10:38 +02:00
Sébastien Villemot 7b11898689
use_dll: merge the two generated C source files into a single one
Also, do various other cosmetic/simplification changes.
2020-05-29 16:12:01 +02:00
Sébastien Villemot a6d9ba6e55
Rename EquationType::evaluate_s to evaluateRenormalized, for clarity 2020-05-20 11:49:32 +02:00
Sébastien Villemot c579a45b08
Remove helper now unused because of 1d838e96ff 2020-05-20 11:35:44 +02:00
Sébastien Villemot 4b28f1fe9c
Bytecode: remove unused data structure 2020-05-20 10:31:31 +02:00
Sébastien Villemot 2944484442
Bytecode: rename output methods for better consistency 2020-05-19 17:45:33 +02:00
Sébastien Villemot a2bea00fee
Block decomposition: another fix related to temporary terms refactoring
Temporary terms need to be computed per equation (as was done previously), and
not simply per block.

It’s necessary to track temporary terms per equation, because some equations
are evaluated instead of solved, and an equation E1 may depend on the value of
an endogenous Y computed by a previously evaluated equation E2; in this case,
if some temporary term TT of equation E2 contains Y, then TT needs to be
computed after E1, but before E2.
2020-05-13 16:58:19 +02:00
Sébastien Villemot 2e6bc7ecaa
Bytecode: fix handling of temporary terms
They were broken by 49036f166d
2020-05-13 12:53:47 +02:00
Sébastien Villemot 49036f166d
Block decomposition: refactor code for computing temporary terms
In particular, in dynamic models, temporary terms are now computed for
derivatives w.r.t. exogenous, and also w.r.t. endogenous variables that do not
belong to the block.
2020-05-12 18:39:13 +02:00
Sébastien Villemot 928aa977b6
Block decomposition: replace expr_t by BinaryOpNode * in a couple of places 2020-05-07 15:24:35 +02:00
Sébastien Villemot c699d57308
Block decomposition: no longer compute static Jacobian, it’s not used
Also remove a message about elements below the cutoff that was no longer
correct (elements below the cutoff have no impact on the incidence matrix
outside of normalization).
2020-05-06 18:11:11 +02:00
Sébastien Villemot 4f453320d1
Block decomposition: remove unneeded code for exogenous 2020-05-05 16:17:22 +02:00
Sébastien Villemot cb61ee8506
Block decomposition: make structures storing derivatives w.r.t. other endo/exo symmetric with those for endos belonging to the block 2020-04-30 18:24:24 +02:00
Sébastien Villemot a8c2defe26
Block decomposition: compute simulation types into separate function; prologue and epilogue are no longer class members
By the way, remove the BlockType stuff which was purely informative (and it’s
not worth carrying over prologue and epilogue information just for that).
2020-04-30 12:48:16 +02:00
Sébastien Villemot 26fc71ffa7
Block decomposition: store max lead/lag of all variables in the “blocks” structure
By the way, regroup all code that computes the dynamic structure of a block
into a single function.
2020-04-30 12:03:14 +02:00
Sébastien Villemot 7f57821401
Now compute blocks[].first_equation from ModelTree::computeBlockDecompositionAndFeedbackVariablesForEachBlock
Also include various cosmetic changes.
2020-04-29 18:48:42 +02:00
Sébastien Villemot 4948adf2cd
Block decomposition: remove unused data structure 2020-04-29 17:47:48 +02:00
Sébastien Villemot f39c687d85
Block decomposition: store mapping between endos/eqs and their block
Previously this computation was done at several places.
2020-04-29 17:42:46 +02:00
Sébastien Villemot 39407083be
Block decomposition: ensure that the cutoff option only impacts normalization
Previously, the cutoff option would also impact the block decomposition itself,
since it would had an influence on the incidence matrix used for computing the
blocks and their derivatives.

The problem is that, in the general case, it’s quite possible that an element
of the numerical Jacobian be zero at the evaluation point, while being quite
different from zero along the simulation path. A typical example is an
expression of the type x*y, where y is an endogenous and x is an exogenous not
present in the initval block (and hence initialized to zero).
2020-04-29 12:41:39 +02:00
Sébastien Villemot 470cb5fcb0
Block decomposition: remove mostly unused structure ModelTree::derivative_endo
It has been superseded by ModelTree::blocks_derivatives.

By the way, fix the initial number of non-zero elements in sparse Jacobian.

Also avoid computing suboptimal temporary terms.
2020-04-28 14:12:29 +02:00
Sébastien Villemot 2e136cae56
Block decomposition: simplify computation of block derivatives
— use a std::map for storing block derivatives
— remove redundant ModelTree::first_chain_rule_derivatives structure
— remove unused codepaths in StaticModel
— DynamicModel: simplify code that determines the type of derivatives in a
  block. We now use a slightly different categorization.
— by the way, fix the max lead/lag information for blocks that are obtained via
  merging. A workaround was previously implemented in
  DynamicModel::get_Derivative(), but it is no longer needed with this fix.
2020-04-28 12:26:51 +02:00
Sébastien Villemot 5ee45f5bd4
Block decomposition: remove helpers that are no longer needed since data structure are cleaner
Add a new helper for getting the number of recursive variables in a block.
2020-04-23 16:31:57 +02:00
Sébastien Villemot 118ceab85b
Block decomposition: reorganize data structures storing block information 2020-04-21 18:25:33 +02:00
Sébastien Villemot 8eafd9ab4f
Block decomposition: various refactorings 2020-04-17 19:23:52 +02:00
Sébastien Villemot a741799f90
Block decomposition: factorize various helper functions
Should have been done in 76c2e87c3b.
2020-04-17 16:04:19 +02:00
Sébastien Villemot 7327fb9f17
Block decomposition: give more explicit names to ModelTree::{inv_,}{equation,variable}_reordered 2020-04-17 15:09:22 +02:00
Sébastien Villemot 4e819f09b2
Block decomposition: various refactorings 2020-04-15 17:56:28 +02:00
Sébastien Villemot 4d30f17e0b
Block decomposition: move collectFirstOrderDerivativesEndogenous in ModelTree
By the way, use camel case for the function name.
2020-03-30 14:51:53 +02:00
Sébastien Villemot 9263a02a9b
Skip constant equations replacement only when there is an “mcp” tag
Since bef537d40a, constant equations were not
simplified as soon as they had a tag attached.

But this is too wide a restriction. In particular, this breaks the trend
component models which have a target that is set to a constant.

So we now only skip the replacement in the case where there is an “mcp” tag.

Ref. dynare#1697
2020-03-27 18:17:04 +01:00
Sébastien Villemot 50776a766a
Remove the unsignedness of many integer variables and function arguments
This was only adding unneeded complexity, for no clear reason (we’re very far
from reaching 2³¹ equations, and if we wanted to support models that large, it
would be better to use long integers to avoid being limited to 2³²).
2020-03-24 18:28:03 +01:00
Sébastien Villemot 78ff24ea14
Block decomposition: misc style and doc improvements 2020-03-24 16:57:45 +01:00
Sébastien Villemot 5d6e6338f4
Block decomposition: remove unused codepaths in computation of normalization 2020-03-20 18:49:31 +01:00
Sébastien Villemot 097bdfde03
Misc simplifications and cosmetics 2020-03-20 18:42:59 +01:00
Sébastien Villemot ce1cbb3e52
Block decomposition: turn EquationType into an enum class 2020-03-20 18:00:56 +01:00
Sébastien Villemot 8b4d046f9f
Block decomposition: turn BlockSimulationType into an enum class 2020-03-20 17:31:14 +01:00
Sébastien Villemot f1061e8df1
Block decomposition: turn BlockType into an enum class 2020-03-20 16:38:43 +01:00
Sébastien Villemot fcef9cf8b9
Block decomposition: further streamlining of function prototypes 2020-03-20 15:23:23 +01:00
Sébastien Villemot bd6eee93df
Block decomposition: refactor the prototypes of various functions
— return output arguments on the left-hand side
— do not pass class members as input/output arguments

By the way, fix a (benign) vector allocation bug in
{Static,Dynamic}Model::computeChainRuleJacobian().
2020-03-19 17:47:12 +01:00
Sébastien Villemot 76c2e87c3b
Block decomposition: factorize data structures between StaticModel and DynamicModel 2020-03-17 18:58:34 +01:00
Houtan Bastani 7371558321
rework equation tags
Create new EquationTags class to simplify use of equation tags throughout the code and avoid repeated code

issue #38
2020-02-21 17:49:38 +01:00
Sébastien Villemot bef537d40a
Do not simplify constant equations which have a tag attached
In particular, in the case of an 'mcp' tag, this could lead to a convergence
failure.

Ref. dynare#1697
2020-01-27 16:09:05 +01:00
Sébastien Villemot 23a08a3662
Ensure that dynamic model files contains all the derivatives that have been computed
Previously, there could be a discrepancy if the order mandated by
“identification” was less that the one mandated by “stoch_simul”.

Ref. #40
2020-01-20 17:22:32 +01:00
Sébastien Villemot 4e2538a2a2
Ensure original tags and line numbers are preserved with ramsey_model
In particular, introduce a method for clearing all equations, so that tags and
line numbers are also cleared.

Ref. dynare#1685
2020-01-06 18:26:35 +01:00
Sébastien Villemot e2d5a83592
Global reindentation 2019-12-20 16:59:30 +01:00
Sébastien Villemot 031c0cff5f
Various code simplifications and modernizations 2019-12-16 19:42:59 +01:00
Sébastien Villemot 2af26ee2c2
Ramsey: use information from transformed model for filling M_.nonzero_hessian_eqs
Since commit 9c9e8f816f, it’s the information
from the original model which was in this field, which is not what is expected.

By the way, do not output this field (and the related M_.hessian_eq_zero) when
the Hessian is not computed by the preprocessor (i.e. in practice for perfect
foresight), since they would otherwise contain incorrect information.

Ref. dynare#1681
2019-12-13 18:02:35 +01:00
Houtan Bastani 02cb4cc973
add compiler statement
Allows the user to set the compiler, flags, and libs to be used with `use_dll`

Issue #35
2019-12-04 16:57:20 +01:00
Sébastien Villemot 23ff36a0dd
Systematically compute recursive ordering of auxiliary equations
Auxiliary equations appearing in set_auxiliary_variables.m and
dynamic_set_auxiliary_series.m need to appear in recursive ordering, since
those files are used for sequential evaluation.

Previously, the recursive ordering was guaranteed by a set of ad hoc rules and
workarounds, but that would not cover certain edge cases.

With this commit, the recursive ordering is systematically computed, using a
topological sort on the directed acyclic graph whose vertices are auxiliary
equations and whose edges are dependency relationships.

Closes: #22
2019-12-03 14:26:13 +01:00
Houtan Bastani e3a3979eba
remove unnecessary line included in 0ff7a9d 2019-11-26 16:37:01 +01:00
Houtan Bastani 0ff7a9d2ab
introduce command line options: `exclude_eqs` and `include_eqs`
Allows for the inclusion/exclusion of a set of equations, specified either on the command line or in a text file.

If the equation has a single endogenous variable on the LHS, then the equation is moved. If not, if the equation has an `endogenous` tag then that variable is removed along with this equation. If not, then an error is thrown.

As a command line argument, `exclude_eqs` can take the form (same syntax for `include_eqs`):
* `exclude_eqs=eq1 to remove all equations declared as `[name=eq1]`
* `exclude_eqs=[eq 1, eq 2]` to remove all equations declared as `[name=eq 1]` or `[name=eq 2]`
* `exclude_eqs=[tagname=X]` to remove all equations declared as `[tagname=X]`
* `exclude_eqs=[tagname=(X, Y)]` to remove all equations declared as `[tagname=X]` or `[tagname=Y]`

When declared in a file, the file should be of the form:
```
eq 1
eq 2
```
to remove all equations declared as `[name=eq 1]` or `[name=eq 2]`.

It should be of the form:
```
tagname=
X
Y
```
to remove all equations declared as `[tagname=X]` or `[tagname=Y]`.
2019-11-26 14:16:00 +01:00
Houtan Bastani fa9c9435ff
add xref for equation tags 2019-10-29 14:05:55 +01:00
Sébastien Villemot ecdca502aa
Modernization: stop using make_pair() and make_tuple()
In many cases, they can be replaced by the curly braces syntax.

Otherwise, we can now use the pair() and tuple() constructors, without the need
to specify template parameters, thanks to class template argument
deduction (new in C++17).
2019-10-24 10:49:13 +02:00
Houtan Bastani 8211edc4e8
fix typo 2019-10-10 15:31:03 +02:00
Sébastien Villemot 0c755460b1
Use std::filesystem instead of boost::filesystem
Note that there is no equivalent of boost::filesystem::unique_path(), so I
implemented ModFile::unique_path() which does something similar.
2019-09-11 14:47:48 +02:00
Sébastien Villemot 0988a1f755
Generated LaTeX files are now under <basename>/latex/ 2019-07-11 17:33:53 +02:00
Sébastien Villemot 176732ee2c
ModelTree: pass argument by const-reference rather than by value in some methods 2019-07-05 18:41:13 +02:00
Houtan Bastani 21fe0f4bdc
avoid cast warnings when compiling boost headers 2019-04-23 14:57:03 +02:00
Sébastien Villemot 43906691d3
JSON: simplification of method for writing temporary terms 2019-04-18 17:10:39 +02:00
Sébastien Villemot b73d554ad2
Use Unicode copyright symbol (in UTF-8 encoding) 2019-04-16 11:35:31 +02:00
Houtan Bastani 02ae0af3e5
change map type for readability 2019-01-29 17:43:17 +01:00
Houtan Bastani f5df7e7567
when an equation is of the form `X` = `constant`, replace all occurrences of `X` in other equations with `constant` 2019-01-28 15:32:12 +01:00
Sébastien Villemot 571b5d0816
Computation of temporary terms generalized to any derivation order 2018-11-30 12:22:13 +01:00
Sébastien Villemot d733f3fb5a
Various simplifications and modernizations of the block/bytecode part 2018-11-23 17:19:59 +01:00
Sébastien Villemot e3a3992c1c
Derivation engine w.r.t. parameters generalized to any order
Also, no longer compute two times symmetric elements in derivation w.r.t.
parameters at order 2, for consistency with derivation w.r.t. endogenous.
It is therefore now necessary to duplicate them in the output to keep behavior
unchanged.
2018-11-22 17:13:55 +01:00
Sébastien Villemot 6fa115aedd
Derivation engine w.r.t. endogenous generalized to any order 2018-11-22 17:13:55 +01:00
Sébastien Villemot b524e19cde
Remove duplicate storage of temp terms for params derivs in ModelTree 2018-11-16 18:26:36 +01:00
Sébastien Villemot e9b5f239df
Properly deal with model local variables in params derivatives file
Closes #13
2018-11-16 18:26:11 +01:00
Sébastien Villemot 3d2125287a
Temporary terms: various simplifications and added comments 2018-11-16 17:11:06 +01:00
Sébastien Villemot e89dd9cb8b
Make storage of derivatives ready for k-order
This is the first step towards computing k-order derivatives.

Ref Dynare/dynare#217, #10
2018-11-15 17:48:46 +01:00
Sébastien Villemot 4a974bb428
The preprocessor now compiles the MEX when use_dll is specified
New options "mexext" and "matlabroot" are introduced, so that the preprocessor
knows where to find MATLAB and which architecture to compile for.

Only recent gcc is now supported. A set of optimization flags is used so that
compilation goes reasonably fast on large models.

Consequently, options "msvc", "mingw" and "cygwin" have been removed.
2018-10-26 18:09:13 +02:00
Sébastien Villemot ac94ad906e Various fixes for silencing errors and warnings under Clang 6 2018-10-11 11:21:58 +02:00
Sébastien Villemot f2cf86b734 Add copy constructors / assignment operators for the DataTree class hierarchy
In particular, it is necessary to turn back DataTree::AddVariable() into a
non-virtual method, because it is called from DataTree's constructor. Enforcing
the absence of leads/lags is now done using a new boolean DataTree::is_static.

Take advantage of the new copy constructor for handling
PlannerObjectiveStatement more elegantly.

Unfortunately it is not possible to implement *move* constructor / assigment
operators, because the reference ExprNode::datatree is not mutable.
2018-10-10 12:53:55 +02:00
Sébastien Villemot 7bb5382428 Always use brace-initializer in constructors
The syntax makes clearer the distinction between a function call and an
initialization. Also, it prevents bugs due to implicit type conversions.
2018-10-04 17:19:18 +02:00
Ferhat Mihoubi 139e3efa82 Adds a new model option "linear_decomposition" that creates a block composed of the non-linear equations o the model 2018-09-28 14:54:52 +02:00
Sébastien Villemot c6cb9aa1b8 Fix bug in option notmpterms with model local variables
Since model local variables are now treated as temporary terms, they must be
marked as such even when option notmpterms is present.
2018-09-25 15:57:56 +02:00
Houtan Bastani 85dbb649b7 move trend_component_table and var_model_table to DynamicModel as they are only used there 2018-09-14 17:04:06 +02:00
Houtan Bastani 539fddc9f6 introduce var model table 2018-08-22 12:15:02 +02:00
Houtan Bastani afe0e475b1 trend_component_model statement 2018-08-17 16:52:48 +02:00
Sébastien Villemot b9ee0bb204 aux_equations may diverge from those in the main model
aux_equations only contain the definition of auxiliary variables, and
may diverge from those in the main model (equations), if other model
transformations applied subsequently. This is not a problem, since
aux_equations is only used for regenerating the values of auxiliaries
given the others.

For example, such a divergence appears when there is an expectation
operator in a ramsey model, see
tests/optimal_policy/nk_ramsey_expectation.mod */
2018-07-27 14:20:36 +02:00
Sébastien Villemot 762f25abe9 Remove useless separate list for diff auxiliary variables
This table serves no useful purpose. It is better to append auxiliary equations
at the time they are created, to avoid messing with the recursive ordering.
2018-07-26 17:41:58 +02:00
Sébastien Villemot b91ed6f78c Move the location of static and dynamic files on the filesystem
- M and MEX files are now under +${MODELNAME}/
- bytecode and C source now under ${MODELNAME}/model/
2018-06-27 15:30:25 +02:00
Sébastien Villemot 130004ef47 Simplify types for storing derivatives using std::tuple 2018-06-05 15:34:34 +02:00
Sébastien Villemot 608c43450c Replace most calls to make_pair by braced-initializer lists or emplace()/emplace_back() 2018-06-04 16:36:46 +02:00
Sébastien Villemot 7d9cd718fc Replace more typedefs by using
Those were not automatically replaced by clang-tidy, I don’t know why…
2018-06-04 15:03:31 +02:00
Sébastien Villemot 182c53273e Remove useless spaces in type qualifiers
In C++11, it is no longer necessary to put a space between two consecutive ">".
2018-06-04 15:03:31 +02:00
Sébastien Villemot f8cc3ae355 Port to C++11 using keyword
Performed using modernize-use-using from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-using.html
2018-06-04 15:03:31 +02:00
Sébastien Villemot e73ebc7033 Port to C++11 noexcept keyword
Performed using modernize-use-noexcept from clang-tidy.

https://clang.llvm.org/extra/clang-tidy/checks/modernize-use-noexcept.html
2018-06-04 15:03:31 +02:00
Sébastien Villemot 3f874cfced Remove obsolete function 2018-05-28 16:39:28 +02:00
Sébastien Villemot ea3573180a Fix ordering of model local variables 2018-05-28 15:50:29 +02:00
Sébastien Villemot dd6799187c Fix derivs w.r.t. parameters with temporary terms array 2018-05-28 15:23:15 +02:00
Sébastien Villemot 164a6f303b Fix bug in temporary terms array in the presence of model local variables
In the presence of MLVs, the temporary terms indexing was corrupted. The code
was using the implicit assumption that the ExprNodeLess ordering was giving the
same ordering as the temporary terms indexes ordering. But MLVs can be higher
in ExprNodeLess ordering than some other temporary terms, while they have the
lowest temporary terms index, hence the bug.

Fix this by no longer relying on the ExprNodeLess ordering, and rather use a
full map<ExprNode *, int> for ModelTree::temporary_terms_idxs. By the way,
simplify the code by removing a few useless data structures (e.g.
ModelTree::temporary_terms_idxs_*).
2018-05-24 19:35:21 +02:00
Houtan Bastani ec215e2a44 separate temporary terms: WIP 2018-03-28 16:41:48 +02:00
Houtan Bastani feb5b93eea create function to calculate aux vars as dseries 2018-03-02 17:50:35 +01:00
Houtan Bastani b504f160ca move files to src directory 2018-02-15 11:48:04 +01:00