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.
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.
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).
By the way, this probably fixes a bug in the presence of external
functions (so-called TEF terms were not properly repeated in each per-block
static file).
Also remove debugging output in the M-file.
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).
This is for consistency with other graph algorithms. Previously it would return
an index from vertex_index1.
See also 1d92adacf4 (which this commit basically
reverts).
Also do some cosmetic changes in calling graph code.
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).
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.
— 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.
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