From 747894a8ca8d9e88bdf4dfc9a753e94e059dd81f Mon Sep 17 00:00:00 2001 From: Matt McKay Date: Tue, 7 May 2024 16:13:25 +1000 Subject: [PATCH] [overborrowing] MAINT: collect status messages (#178) * [overborrowing] MAINT: collect status messages and print at the end of iteration * fix syntax --- lectures/overborrowing.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lectures/overborrowing.md b/lectures/overborrowing.md index b8da1d43..576b3f25 100644 --- a/lectures/overborrowing.md +++ b/lectures/overborrowing.md @@ -634,15 +634,17 @@ def compute_equilibrium(parameters, sizes, arrays, H = generate_initial_H(parameters, sizes, arrays) error = tol + 1 i = 0 + msgs = [] while error > tol and i < max_iter: H_new, vfi_num_iter = update_H(parameters, sizes, arrays, H, α) - print(f"VFI terminated after {vfi_num_iter} iterations.") + msgs.append(f"VFI terminated after {vfi_num_iter} iterations.") error = jnp.max(jnp.abs(b_grid[H] - b_grid[H_new])) - print(f"Updated H at iteration {i} with error {error}.") + msgs.append(f"Updated H at iteration {i} with error {error}.") H = H_new i += 1 if i == max_iter: - print("Warning: Equilibrium search iteration hit upper bound.") + msgs.append("Warning: Equilibrium search iteration hit upper bound.") + print("\n".join(msgs)) return H ```