Skip to content

Commit aa62b83

Browse files
authored
Merge branch 'copilot/improve-plotting-docs' into copilot/fix-13523097-571475096-fe70cbec-6382-49ab-b8a3-6ab2ac9742d1
2 parents ef22102 + ffd714e commit aa62b83

File tree

4 files changed

+37
-36
lines changed

4 files changed

+37
-36
lines changed

ext/StatsPlotsExt.jl

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -260,8 +260,8 @@ function plot_model_estimates(𝓂::ℳ,
260260

261261
shocks = shocks isa String_input ? shocks .|> Meta.parse .|> replace_indices : shocks
262262

263-
obs_idx = parse_variables_input_to_index(obs_symbols, 𝓂.timings) |> sort
264-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
263+
obs_idx = parse_variables_input_to_index(obs_symbols, 𝓂.timings) |> unique |> sort
264+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
265265
shock_idx = shocks == :none ? [] : parse_shocks_input_to_index(shocks, 𝓂.timings)
266266

267267
# Create display names and sort alphabetically
@@ -1212,8 +1212,8 @@ function plot_model_estimates!(𝓂::ℳ,
12121212

12131213
shocks = shocks isa String_input ? shocks .|> Meta.parse .|> replace_indices : shocks
12141214

1215-
obs_idx = parse_variables_input_to_index(obs_symbols, 𝓂.timings) |> sort
1216-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
1215+
obs_idx = parse_variables_input_to_index(obs_symbols, 𝓂.timings) |> unique |> sort
1216+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
12171217
shock_idx = parse_shocks_input_to_index(shocks, 𝓂.timings)
12181218

12191219
# Create display names and sort alphabetically
@@ -1482,7 +1482,7 @@ function plot_irf(𝓂::ℳ;
14821482

14831483
variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables
14841484

1485-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
1485+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
14861486

14871487
ignore_obc, occasionally_binding_constraints, obc_shocks_included = process_ignore_obc_flag(shocks, ignore_obc, 𝓂)
14881488

@@ -2166,7 +2166,7 @@ function plot_irf!(𝓂::ℳ;
21662166

21672167
variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables
21682168

2169-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
2169+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
21702170

21712171
ignore_obc, occasionally_binding_constraints, obc_shocks_included = process_ignore_obc_flag(shocks, ignore_obc, 𝓂)
21722172

@@ -3194,7 +3194,7 @@ function plot_conditional_variance_decomposition(𝓂::ℳ;
31943194

31953195
variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables
31963196

3197-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
3197+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
31983198

31993199
fevds = fevds isa KeyedArray ? axiskeys(fevds,1) isa Vector{String} ? rekey(fevds, 1 => axiskeys(fevds,1) .|> Meta.parse .|> replace_indices_special) : fevds : fevds
32003200

@@ -3488,7 +3488,7 @@ function plot_solution(𝓂::ℳ,
34883488

34893489
variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables
34903490

3491-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
3491+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
34923492

34933493
vars_to_plot = intersect(axiskeys(SS_and_std[:non_stochastic_steady_state])[1],𝓂.timings.var[var_idx])
34943494

@@ -3700,8 +3700,6 @@ function _plot_solution_from_container(;
37003700
model_names = unique(model_names)
37013701

37023702
for model in model_names
3703-
# println(grouped_by_model[model])
3704-
# println(typeof(grouped_by_model[model][:has_impact]))
37053703
if length(grouped_by_model[model]) > 1
37063704
diffdict_grouped = compare_args_and_kwargs(grouped_by_model[model])
37073705
diffdict = merge_by_runid(diffdict, diffdict_grouped)
@@ -4211,7 +4209,7 @@ function plot_solution!(𝓂::ℳ,
42114209

42124210
variables = variables isa String_input ? variables .|> Meta.parse .|> replace_indices : variables
42134211

4214-
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> sort
4212+
var_idx = parse_variables_input_to_index(variables, 𝓂.timings) |> unique |> sort
42154213

42164214
vars_to_plot = intersect(axiskeys(SS_and_std[:non_stochastic_steady_state])[1],𝓂.timings.var[var_idx])
42174215

src/MacroModelling.jl

Lines changed: 23 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -3317,11 +3317,11 @@ function write_block_solution!(𝓂,
33173317

33183318
prob = 𝒮.LinearProblem(chol_buff, ϵ, 𝒮.CholeskyFactorization())
33193319

3320-
chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization())
3320+
chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
33213321

33223322
prob = 𝒮.LinearProblem(buffer, ϵ, 𝒮.LUFactorization())
33233323

3324-
lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization())
3324+
lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
33253325

33263326
if lennz > nnz_parallel_threshold
33273327
parallel = Symbolics.ShardedForm(1500,4)
@@ -3382,11 +3382,11 @@ function write_block_solution!(𝓂,
33823382

33833383
prob = 𝒮.LinearProblem(ext_chol_buff, ϵᵉ, 𝒮.CholeskyFactorization())
33843384

3385-
ext_chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization())
3385+
ext_chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
33863386

33873387
prob = 𝒮.LinearProblem(ext_buffer, ϵᵉ, 𝒮.LUFactorization())
33883388

3389-
ext_lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization())
3389+
ext_lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
33903390

33913391
if lennz > nnz_parallel_threshold
33923392
parallel = Symbolics.ShardedForm(1500,4)
@@ -4731,11 +4731,11 @@ function solve_steady_state!(𝓂::ℳ;
47314731

47324732
prob = 𝒮.LinearProblem(chol_buff, ϵ, 𝒮.CholeskyFactorization())
47334733

4734-
chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization())
4734+
chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
47354735

47364736
prob = 𝒮.LinearProblem(buffer, ϵ, 𝒮.LUFactorization())
47374737

4738-
lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization())
4738+
lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
47394739

47404740
if lennz > nnz_parallel_threshold
47414741
parallel = Symbolics.ShardedForm(1500,4)
@@ -4796,11 +4796,11 @@ function solve_steady_state!(𝓂::ℳ;
47964796

47974797
prob = 𝒮.LinearProblem(ext_chol_buff, ϵᵉ, 𝒮.CholeskyFactorization())
47984798

4799-
ext_chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization())
4799+
ext_chol_buffer = 𝒮.init(prob, 𝒮.CholeskyFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
48004800

48014801
prob = 𝒮.LinearProblem(ext_buffer, ϵᵉ, 𝒮.LUFactorization())
48024802

4803-
ext_lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization())
4803+
ext_lu_buffer = 𝒮.init(prob, 𝒮.LUFactorization(), verbose = isdefined(𝒮, :LinearVerbosity) ? 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()) : false)
48044804

48054805
if lennz > nnz_parallel_threshold
48064806
parallel = Symbolics.ShardedForm(1500,4)
@@ -5352,22 +5352,25 @@ function block_solver(parameters_and_solved_vars::Vector{T},
53525352

53535353
if cold_start
53545354
guesses = any(guess .< 1e12) ? [guess, fill(1e12, length(guess))] : [guess] # if guess were provided, loop over them, and then the starting points only
5355+
start_vals = (fail_fast_solvers_only ? [false] : Any[false, 1.206, 1.5, 0.7688, 2.0, 0.897])
53555356

53565357
for g in guesses
53575358
for p in parameters
53585359
for ext in [true, false] # try first the system where values and parameters can vary, next try the system where only values can vary
5359-
if !isfinite(sol_minimum) || sol_minimum > tol.NSSS_acceptance_tol# || rel_sol_minimum > rtol
5360-
if solved_yet continue end
5361-
5362-
sol_values, total_iters, rel_sol_minimum, sol_minimum = solve_ss(SS_optimizer, SS_solve_block, parameters_and_solved_vars, closest_parameters_and_solved_vars, lbs, ubs, tol, total_iters, n_block, verbose,
5363-
# sol_values, total_iters, rel_sol_minimum, sol_minimum = solve_ss(SS_optimizer, ss_solve_blocks, parameters_and_solved_vars, closest_parameters_and_solved_vars, lbs, ubs, tol, total_iters, n_block, verbose,
5364-
g,
5365-
p,
5366-
ext,
5367-
false)
5368-
5369-
if isfinite(sol_minimum) && sol_minimum < tol.NSSS_acceptance_tol
5370-
solved_yet = true
5360+
for s in start_vals
5361+
if !isfinite(sol_minimum) || sol_minimum > tol.NSSS_acceptance_tol# || rel_sol_minimum > rtol
5362+
if solved_yet continue end
5363+
5364+
sol_values, total_iters, rel_sol_minimum, sol_minimum = solve_ss(SS_optimizer, SS_solve_block, parameters_and_solved_vars, closest_parameters_and_solved_vars, lbs, ubs, tol, total_iters, n_block, verbose,
5365+
# sol_values, total_iters, rel_sol_minimum, sol_minimum = solve_ss(SS_optimizer, ss_solve_blocks, parameters_and_solved_vars, closest_parameters_and_solved_vars, lbs, ubs, tol, total_iters, n_block, verbose,
5366+
g,
5367+
p,
5368+
ext,
5369+
s)
5370+
5371+
if isfinite(sol_minimum) && sol_minimum < tol.NSSS_acceptance_tol
5372+
solved_yet = true
5373+
end
53715374
end
53725375
end
53735376
end

src/algorithms/nonlinear_solver.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ function levenberg_marquardt(
177177
# sol_cache.A = X
178178
sol_cache.A = ∇̂
179179
sol_cache.b = guess_update
180-
𝒮.solve!(sol_cache, verbose = false)#, 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()))
180+
𝒮.solve!(sol_cache)
181181
copy!(guess_update, sol_cache.u)
182182

183183
if !isfinite(sum(guess_update))
@@ -477,7 +477,7 @@ function newton(
477477
ifisa SparseMatrixCSC
478478
sol_cache.A =
479479
sol_cache.b = new_residuals
480-
𝒮.solve!(sol_cache, verbose = false)#, 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()))
480+
𝒮.solve!(sol_cache)
481481
guess_update .= sol_cache.u
482482
new_residuals .= guess_update
483483
else
@@ -531,7 +531,7 @@ function newton(
531531
ifisa SparseMatrixCSC
532532
sol_cache.A =
533533
sol_cache.b = new_residuals
534-
𝒮.solve!(sol_cache, verbose = false)#, 𝒮.LinearVerbosity(𝒮.SciMLLogging.Minimal()))
534+
𝒮.solve!(sol_cache)
535535
guess_update .= sol_cache.u
536536
new_residuals .= guess_update
537537
else

src/filter/inversion.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3872,7 +3872,7 @@ function filter_data_with_model(𝓂::ℳ,
38723872
𝐒²ᵉ = nnz(𝐒²ᵉ) / length(𝐒²ᵉ) > .1 ? collect(𝐒²ᵉ) : 𝐒²ᵉ
38733873
𝐒⁻² = nnz(𝐒⁻²) / length(𝐒⁻²) > .1 ? collect(𝐒⁻²) : 𝐒⁻²
38743874

3875-
initial_state = copy(state)
3875+
initial_state = deepcopy(state)
38763876

38773877
state₁ = state[1][T.past_not_future_and_mixed_idx]
38783878
state₂ = state[2][T.past_not_future_and_mixed_idx]
@@ -4494,7 +4494,7 @@ function filter_data_with_model(𝓂::ℳ,
44944494
𝐒³ᵉ = nnz(𝐒³ᵉ) / length(𝐒³ᵉ) > .1 ? collect(𝐒³ᵉ) : 𝐒³ᵉ
44954495
𝐒⁻³ = nnz(𝐒⁻³) / length(𝐒⁻³) > .1 ? collect(𝐒⁻³) : 𝐒⁻³
44964496

4497-
initial_state = copy(state)
4497+
initial_state = deepcopy(state)
44984498

44994499
state₁ = state[1][T.past_not_future_and_mixed_idx]
45004500
state₂ = state[2][T.past_not_future_and_mixed_idx]

0 commit comments

Comments
 (0)