Commit Graph

201 Commits (master)

Author SHA1 Message Date
Sébastien Villemot f55019c41e
Bytecode: rename several classes and class members, for consistency and clarity 2023-12-14 16:17:22 +01:00
Sébastien Villemot 22709f8225
Move bytecode stuff into a dedicated namespace, for better code separation 2023-12-14 15:48:22 +01:00
Sébastien Villemot 22675728aa
No longer call std::move on trivially-copyable types
Automatically detected by clang-tidy with performance-move-const-arg check.

Do not make the modification for Tokenizer::location type, since we have no
guarantee that the type will remain trivially-copyable in the future.
2023-12-13 15:37:07 +01:00
Sébastien Villemot bffd68e0bf
Add a clang-tidy configuration file
Also add some annotations to remove some false positives.

There remain some boost-related false positives, it’s unclear how to suppress
them.
2023-12-04 16:37:00 +01:00
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 5af38c8ced
ModelTree.hh: fix misplaced #endif for include guard 2023-12-01 15:35:40 +01:00
Sébastien Villemot 7e6abc97c4
Add [[nodiscard]] attribute to various functions
Automatically detected using clang-tidy with modernize-use-nodiscard check.
2023-12-01 14:14:44 +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 1ad7dd9672
Refactor parsing of equation tags in a more functional way
Incidentally, makes tag names case-insensitive in “model_replace” and
“model_remove”, which is consistent with tag declarations.
2023-11-14 15:55:30 +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 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 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
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
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 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
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 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 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 b9bfcaad5d
Block+bytecode: minor simplification 2023-04-03 18:29:57 +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 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 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 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 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 bae04fa899
ModelTree::findGccOnMacOS() now returns a std::filesystem::path 2023-01-10 11:48:33 +01:00
Sébastien Villemot 253fbbe7d6
Use std::filesystem::path in more places 2023-01-05 17:21:28 +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 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 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 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
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 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
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 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 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 723fc4139b
Implement new sparse model representation in Julia
Ref. dynare#1859
2022-11-02 15:49:56 +01:00