3rd order pullback improvements - #300
Conversation
…ete unused test file for third order solution gradient
There was a problem hiding this comment.
Pull request overview
This PR focuses on improving performance and memory behavior in 3rd-order pullback routines by introducing more sparsity-aware adjoint kernels and by adding a sparse cotangent overload for compressed_kron³_pullback!. It also expands diagnostic output in Sylvester/Lyapunov solvers.
Changes:
- Reworked the mixed-sparsity
mul_fill_kron_adjoint!(A sparse, B dense) to use row-compressed representations and avoid large intermediate allocations /try...catch. - Added a sparse-
∂Yoverload forcompressed_kron³_pullback!and refactoredmul_compressed_kron³_pullback!to avoid materializingM1*M2. - Extended verbose solver logging (Sylvester/Lyapunov) with matrix types/sizes; minor edits in
choose_matrix_format.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| src/rrules.jl | New/rewritten 3rd-order pullback kernels and sparse-aware compressed_kron³_pullback!; integrates choose_matrix_format for cotangent formatting. |
| src/MacroModelling.jl | Adds commented-out alternative sparse conversion path in choose_matrix_format (currently dead code). |
| src/algorithms/sylvester.jl | Verbose logging now includes operand sizes/types. |
| src/algorithms/lyapunov.jl | Verbose logging now includes operand types (and more context in Schur deflation messages). |
| tol::Real = 0.0, | ||
| block::AbstractMatrix{R} = Matrix{R}(undef, size(M1, 1), 0), | ||
| ) where {R <: Real, TA <: Real, TB <: Real, Ti <: Integer} |
| tol_T = T(tol) | ||
|
|
||
| row_values = SparseArrays.rowvals(∂Y) | ||
| non_zero_values = nonzeros(∂Y) | ||
|
|
| j2 = col_second[col] | ||
| k2 = col_third[col] | ||
|
|
||
| for stored_index in SparseArrays.nzrange(∂Y, col) | ||
| row = Int(row_values[stored_index]) |
| ℒ.mul!(∂B_from_sylv, 𝐒₃_stable', ∂𝐗₃) | ||
| # ∂B_from_sylv = sparse(𝐒₃_stable' * ∂𝐗₃) | ||
|
|
||
| ∂B_from_sylv = choose_matrix_format(∂B_from_sylv) |
| # a = sparse(A) | ||
| # droptol!(a, tol) |
Benchmark Results
Benchmark PlotsA plot of the benchmark results have been uploaded as an artifact to the workflow run for this PR. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #300 +/- ##
==========================================
+ Coverage 88.05% 88.32% +0.27%
==========================================
Files 35 35
Lines 30243 30510 +267
==========================================
+ Hits 26629 26948 +319
+ Misses 3614 3562 -52 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
dd784a5 to
e1add5d
Compare
…rement_nested_initial_state_rdata! Co-authored-by: thorek1 <13523097+thorek1@users.noreply.github.com>
…thorek1/MacroModelling.jl into 3rd_order_pullback_improvements
The state_update in parse_algorithm_to_state_update was zeroing out the constant column of S₁: [S₁[:,1:nPast] zeros(nVars) S₁[:,nPast+1:end]]. Since the augmented state includes 1 as the constant, this dropped the constant contribution from the first-order term, breaking the SSS fixed-point property (no-shock IRF would not stay at SSS).
This reverts commit 0e0d2dd.
…thorek1/MacroModelling.jl into 3rd_order_pullback_improvements
…ut_to_index - Move normalize_superscript from StatsPlotsExt.jl to core module - Sort shock_idx by normalized name inside parse_shocks_input_to_index - Import normalize_superscript explicitly in StatsPlotsExt.jl - All downstream callers (get_irf, plot_irf, plot_irf!, girf) now get consistently sorted shock order
No description provided.