Commit Graph

488 Commits (17ba27330a844dcc195d86867584944b89b5d6e5)

Author SHA1 Message Date
Sébastien Villemot 5b400b69f0
Use std::filesystem::path::string() when writing paths to std::cout/std::cerr
Otherwise they will be quoted, which is not desirable, especially under
Windows (backslashes will be duplicated).
2022-10-11 11:31:15 +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 49a530a775
use_dll: allow more flexible output directory in interface of ModelTree::compileMEX() 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 08a86b67cb
Drop logic for selecting whether to compute derivatives w.r.t. exogenous
We now always compute those derivatives, so no need for an alternate codepath.
2022-10-07 18:04:17 +02:00
Sébastien Villemot 5c33051990
Use std::string_view in a few places where it makes sense 2022-10-04 16:47:16 +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 18037fd29a
Drop code for supporting temporary terms corresponding to model-local variables
Since model-local variables are now substituted out of the model at an early
stage (see cfb41d291c), such temporary terms are
no longer generated.
2022-09-26 17:34:20 +02:00
Sébastien Villemot 5b12354dc3
Minor performance improvement in copy constructors/assignments of ModelTree and DynamicModel 2022-09-21 17:37:02 +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 1aead92cd5
Fix bug in block derivatives w.r.t. exogenous deterministic 2022-09-12 17:38:47 +02:00
Johannes Pfeifer da5b36704d Add missing whitespace in output of BGP warning 2022-08-03 10:52:08 +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 50d5b916e2
Remove constructor and accessors for AuxVarInfo
Rather make all data members public and const, and use aggregate-initialization.
2022-07-20 14:48:30 +02:00
Sébastien Villemot ae150d2b1f
Bytecode: refactor routines for creating .cod file in non-block mode 2022-07-13 18:51:01 +02:00
Sébastien Villemot 89debf429a
Factorize code for writing JSON output 2022-07-12 18:04:05 +02:00
Sébastien Villemot 6da24fc763
Fix bug in JSON output for dynamic derivatives w.r.t. parameters
Variable and parameter indices were wrong (offset by 1).
2022-07-12 17:45:00 +02:00
Sébastien Villemot 9e6c01f132
Streamline some function names 2022-07-12 17:04:41 +02:00
Sébastien Villemot a541d23055
Minor simplification 2022-07-12 16:39:17 +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 2013056a2c
Fix bug in JSON output for derivatives w.r.t. parameters
Confusion between a symbol ID and a derivation ID, which could lead to invalid
output or crash.
2022-07-12 16:23:44 +02:00
Sébastien Villemot 7fd78606ae
Fix bug in MATLAB/Octave output introduced in 3e1f9dbb82 2022-07-12 16:23:32 +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 8da663a110
Further factorization in methods for writing static and dynamic files 2022-07-12 16:05:15 +02:00
MichelJuillard 3e1f9dbb82 use @inbounds blocks instead of @inbounds for each line 2022-07-12 13:07:33 +02:00
MichelJuillard a4556896db Julia functions Float64 -> <: Real 2022-07-12 11:15:51 +02:00
Sébastien Villemot 5174c3b52c
Minor simplification 2022-07-11 22:30:50 +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 c8b046ec86
Simplification using non-default std::ofstream constructor 2022-07-11 22:17:36 +02:00
Sébastien Villemot 6d2d73a5d7
Bytecode: refactor output methods around an enum class similar to ExprNodeOutputType
By the way, add assertions to ensure that assignment LHS output type is only
used on VariableNode(s) and AbstractExternalFunctionNode(s).
2022-07-06 16:46:40 +02:00
Sébastien Villemot 3b99ac5df0
Remove unused parameters to various methods 2022-06-24 17:11:38 +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 13dc0a1144
Use operator""s to replace some calls to std::string constructor
By the way, remove other unnecessary calls to that constructor.
2022-06-22 12:47:11 +02:00
Sébastien Villemot 83693e4427
Bytecode: stop using unsigned integers where signed ones avoid unnecessary casts 2022-06-20 17:49:31 +02:00
Sébastien Villemot 5cd5676c8e
Bytecode: directly use several enums inside instruction classes 2022-06-20 15:19:08 +02:00
Sébastien Villemot 82751d21fe
Remove useless debugging code 2022-06-17 12:46:32 +02:00
Sébastien Villemot a85730313c
Split CodeInterpreter.hh into two headers
– a generic one: CommonEnums.hh
– and a bytecode-specific one: Bytecode.hh

By the way, rename global constant “near_zero” into “power_deriv_near_zero”,
for clarity.
2022-06-16 17:53:23 +02:00
Sébastien Villemot 9b04c5436e
Block decomposition: fix crash when a variable appears in an equation but has zero symbolic derivative 2022-06-13 16:32:58 +02:00
Sébastien Villemot ee8ee7c27f
Optimization: use move semantics in a few more places 2022-06-13 14:27:19 +02:00
Sébastien Villemot c94dfb848c
C++20 modernization: use initialization within range-based for loop
In particular, use this feature in many loops which feature a special treatment
for the first iteration, using a boolean variable (replacing iterator
manipulation). By the way, also use std::exchange() to simultaneously test the
value of this variable and update it.
2022-06-07 14:35:59 +02:00
Sébastien Villemot 9ace2dc413
C++17 modernization: take advantage of class template argument deduction 2022-06-07 14:35:26 +02:00
Sébastien Villemot 0b5c88109f
Various simplifications 2022-06-07 14:34:30 +02:00
Sébastien Villemot 8b5e33b87a
Avoid name clash between function parameter and class member 2022-06-03 20:38:07 +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 3e94250582
C++17 modernization: use std::optional in ExprNode::getPacOptimizingShareAndExprNodes() 2022-05-16 19:10:16 +02:00
Sébastien Villemot 0eb11d3323
C++17 modernization: use std::optional in expression matching functions 2022-05-16 19:10:16 +02:00
Sébastien Villemot 3496d77eb4
C++17 modernization: use std::optional to store orig diff vars in VAR and TCM
By the way, remove the unused TrendComponentModelTable::getOrigDiffVar() method.
2022-05-16 19:10:16 +02:00
Sébastien Villemot 06d05e9a8d
C++17 modernization: use std::optional for SymbolTable::getEquationNumberForMultiplier() 2022-05-16 19:10:16 +02:00
Sébastien Villemot fa7a926143
C++17 modernization: use std::optional for the storage of orig_symb_id and orig_lead_lag in SymbolTable
For the diff and unaryOp auxvar types, these value may be set or unset
depending on the complexity of the expression represented by the auxvar.
2022-05-16 19:10:15 +02:00
Sébastien Villemot fc037a4352
Simplify printing of booleans using std::boolalpha 2022-05-16 19:10:15 +02:00
Sébastien Villemot 92d3b8166a
C++17 modernization: use std::optional for equation line numbers 2022-05-16 19:10:15 +02:00
Sébastien Villemot 0b51294994
C++17 modernization: use std::optional for trend variables in TCM 2022-05-16 19:10:15 +02:00
Sébastien Villemot b42ee40b55
C++20 modernization: use contains() method on containers 2022-05-04 17:37:57 +02:00
Sébastien Villemot 54ca5d9cc0
Improve messages during model normalization
– Indicate whether we are trying to normalize the static or dynamic model
– If failed to normalize the static model, suggest to use the “no_static”
  option
– Remove a superfluous error message
2022-04-19 17:11:13 +02:00
Sébastien Villemot bfdcc546ec
Julia: adapt DynamicSetAuxiliarySeries.jl for TimeDataFrame objects 2022-04-01 17:34:37 +02:00
Sébastien Villemot 71edfd05e4
Add new “log” option to “var” statement
When an endogenous is declared with “var(log)”, say “y”:
– creates an auxiliary named “LOG_y”
– replaces “y(±l)” everywhere by “exp(LOG_y(±l))”
– adds a new auxiliary equation “y=exp(LOG_y)”
– adds a new definition “LOG_y=log(y)” in set_auxiliary_variables.m and
  dynamic_set_auxiliary_series.m files

This option also works in conjunction with “deflator=…”, such as “var(log,
deflator=…)” (the “log” must appear befor “deflator”). There are no provisions
for combining “log” with “log_deflator”, because that would not make much sense
from an economic point of view (amounts to taking the log two times).

Ref. dynare#349
2022-03-30 17:46:07 +02:00
Sébastien Villemot b78ac1d31f
Bytecode: fix temporary terms for dynamic derivatives in “evaluate” mode
The temporary terms for dynamic derivatives were only computed in the
“simulate” mode.
2022-02-18 12:38:06 +01:00
Sébastien Villemot 01bea3f5e7
TCM: remove useless 3rd dimension of A0 and A0star (supposedly for lags) 2022-01-28 16:38:50 +01:00
Sébastien Villemot 1e77f7c5a7
SymbolTable::getOrigSymbIdForAuxVar() now also works on unaryOp and diffForward auxvars
This is a more natural semantics.

Incidentally, this fixes a bug in the variable mapping (M_.mapping) where some
endogenous, appearing in a log() in a VAR or TCM, would not be mentioned (e.g.
in the var-expectations/7/example1.mod test, and many others).
2022-01-28 16:30:11 +01:00
Sébastien Villemot 289b4773d7
Fix matching of diff leads/lags in TCM and PAC models
The logic was flawed in several ways. In particular, the test files
pac/trend-component-{3,10,11}/example1.mod would return A0 and A0star matrices
where the (2,2) element was incorrectly zero.
2022-01-28 15:53:41 +01:00
Sébastien Villemot b709da7f17
Fix SymbolTable’s getOrigSymbIdForAuxVar() and getUltimateOrigSymbID() so that they never return -1
The case of a diff aux var corresponding to a complex expression was not
correctly handled, and could lead to a value -1 being returned by these
methods.
2022-01-28 15:53:39 +01:00
Sébastien Villemot 5e8b478ccf
Add check to ensure that column indices in derivative matrices do not overflow
Closes: #89
2022-01-21 14:31:29 +01:00
Sébastien Villemot 6c7c2bc321
Simplification using std::set range constructor 2022-01-21 11:05:17 +01:00
Sébastien Villemot aa0e06bc7d
Refactor handling of var_expectation_model statements
Creates a VarExpectationModelTable analogous to PacModelTable.
2022-01-20 16:26:15 +01:00
Sébastien Villemot e1e5118373
Refactor the code that substitutes unary ops in model equations
In particular, make it more visible that the substitution also occurs in PAC
equations (and not only in VAR and TCM equations).
2022-01-19 15:56:44 +01:00
Sébastien Villemot d149d3a76c
PAC: substitute unary ops in “growth” expressions (in “pac_model” and “pac_target_info”)
Ref. dynare#1837
2022-01-18 12:40:15 +01:00
Sébastien Villemot 5572e478f1
Indentation fix 2022-01-06 14:46:38 +01:00
Sébastien Villemot a8fce06dc4
PAC: new options “auxname” and “kind” to “pac_model” 2021-12-16 15:40:47 +01:00
Sébastien Villemot ea6fb40db7
PAC: new “pac_target_info” block and “pac_target_nonstationary” operator
Ref. Madysson/estimation-codes#5
2021-12-16 15:40:47 +01:00
Sébastien Villemot 1f004584e9
New model_remove statement and model_replace block
Factorize the implementation with the existing code for the include_eqs and
exclude_eqs options (which has been refactored by the way).

Ref. #19
2021-12-15 12:11:25 +01:00
Sébastien Villemot b356b8d5fa
Substitute out adl() operators in equations marked [static] 2021-12-06 17:17:38 +01:00
Sébastien Villemot dc99d81c45
Explain why expectation() operators need not be substituted in equations marked [static]
By the way, also perform a small code simplification.
2021-12-06 17:17:38 +01:00
Sébastien Villemot 214f0db4db
Add comment about predetermined variables and equations marked [static]
By the way, also perform a small code simplification.
2021-12-06 17:17:38 +01:00
Sébastien Villemot 5fe94ed606
Simplify constant equations also in equations marked [static]
The simplifyEquations() methods had to be moved to DynamicModel, in order to
access the static_only_equations member.
2021-12-06 17:17:37 +01:00
Sébastien Villemot fe974c4c31
When looking for unused endos/exos, also search in equations marked [static] 2021-12-06 17:17:37 +01:00
Sébastien Villemot 8d4cab6fe3
Substitute model-local variables in equations marked [static] 2021-12-06 17:17:27 +01:00
Sébastien Villemot 7b8fc8edb7
Symbolic detrending engine: correctly handle equations marked [static]
Incidentally, this also fixes a detrending bug in the Occbin engine (since the
latter internally generates a [static] equation).

Ref. dynare#1827

By the way, perform a small code simplification.
2021-12-06 12:59:21 +01:00
Sébastien Villemot a210a8fd59
Add several types of auxiliary variables to M_.mapping
In practice, only those auxiliary variables which do not have an orig_symb_id
will be listed (in addition to unary ops, due to an implementation bug).
2021-11-24 11:27:17 +01:00
Sébastien Villemot 2282d4773c
PAC: new auxiliary variable type for pac_expectation operator
Also add the new equation to auxiliary equations in the backward case (but not
in the MCE case, since that equation is recursive).
2021-11-23 14:31:03 +01:00
Sébastien Villemot ae242770f9
PAC: in the backward case, unify h0 and h1 parameters vector into a single vector
There is no reason to keep this distinction.

Additionally, since the data structure is now symmetric with the MCE case,
unify this “h” parameter vector with the “α” parameter vector.
2021-11-23 14:31:03 +01:00
Sébastien Villemot 0f89569f7e
PAC: in the backward case, create an aux. var. for the pac_expectation expression
By the way, refactor the MCE case by merging two routines related to the Z₁ aux. var.
This restores the symmetry with the backward case, now that the latter also has
an aux. var. for the pac_expectation operator. Also store the aux. var. IDs in a
structure common to the backward and MCE cases.
2021-11-23 14:31:03 +01:00
Sébastien Villemot 0e62206203
PAC: drop support for multiple PAC equations associated to a given PAC model 2021-11-23 14:31:02 +01:00
Sébastien Villemot 1041f205ea
PAC: trap a few more cases when an auxiliary param conflicts with a declared one 2021-11-09 15:48:59 +01:00
Sébastien Villemot 37a6ed6261
PAC: rethink the relation between PacModelTable and DynamicModel classes 2021-10-29 14:11:30 +02:00
Sébastien Villemot 127361971f
PAC: refactor with new PacModelTable that replaces PacModelStatement(s)
Incidentally, the auxiliary endogenous variable representing Z₁ and created for
PAC MCE models no longer necessarily appear as the first auxiliary variable (so
this is effectively a revert of 64f55e4a5e).
2021-10-29 14:11:30 +02:00
Sébastien Villemot 5bef185370
PAC: add growth correction term for definition of Z₁ in the MCE case 2021-10-25 17:28:01 +02:00
MichelJuillard 561bee0790 add NNZderivatives to JSON + use AbstractVector for Julia functions 2021-10-06 17:45:11 +02:00
Sébastien Villemot 78e295115a
PAC: better error message in case of name conflict for the growth neutrality correction parameter 2021-10-06 16:41:09 +02:00
Sébastien Villemot 784dd4122a
PAC: generate the “growth_neutrality_param_index” MATLAB field for MCE models
Previously it was only generated in the case of backward PAC models.
2021-08-31 17:54:20 +02:00
Sébastien Villemot e1f7d8c735
VAR models: add a parameter representing the constant in the development of the pac_expectation operator 2021-07-21 17:53:55 +02:00
Sébastien Villemot a6add6127b
VAR models: output vector of constants in varmatrices.m 2021-07-21 17:53:54 +02:00
Sébastien Villemot 1cf03a5f07
Cosmetic improvement 2021-07-21 17:53:54 +02:00
Sébastien Villemot ebd9954d33
Occbin: new syntax for constructing multi-regime equations
Ref. #68
2021-07-20 18:18:24 +02:00