Fine-mapping · Python + RustLucaJiang/prusie
On this page

Convergence and refinement

Because IBSS optimizes the SuSiE variational objective sequentially across single-effect components, a fit can either stop at max_iter before reaching tolerance or satisfy its stopping criterion at a local mode of the evidence lower bound (ELBO). prusie provides built-in tools to diagnose stopping behavior (assess_convergence), extend an unfinished fit from its saved posterior (continue_fit), and search alternative initializations for a higher-ELBO solution (refine_fit).

Both continue_fit and refine_fit operate on retained input snapshots. After running either procedure, compare the resulting PIPs and credible sets against the baseline fit to evaluate how the updated optimization trajectory affects your fine-mapping conclusions.

Start with a tracked fit

Passing track_fit="compact" (or track_fit=True) to a fitting function records per-sweep convergence metrics in fit.trace and automatically retains the validated inputs needed for continuation and refinement. Here we demonstrate this workflow on the susieR FinemappingConvergence dataset:

import prusie
from prusie.viz import plot_convergence, plot_refinement

example = prusie.load_convergence_example()
fit = prusie.susie_suff_stat(
    **example["inputs"],
    **example["parameters"],
    track_fit="compact",
)
print("Stop:", fit.convergence["stop_reason"], "Iterations:", fit.niter)
convergence_view = plot_convergence(fit, layout="compact")

Expected output:

Stop: criterion_satisfied Iterations: 10

In plot_convergence, layout="compact" displays the ELBO trajectory, the per-sweep signed change ΔELBO\Delta\mathrm{ELBO}, and the maximum absolute changes in component inclusion probabilities (alpha) and marginal PIPs. Choosing layout="variance" plots the component prior variances V and residual variance sigma2, while layout="full" combines both views.

Assess the last few sweeps

When a fit terminates—especially at max_iter—it is useful to know both why it stopped and whether the posterior inclusion probabilities were still changing. prusie.assess_convergence inspects the recorded per-sweep trace (on either a SusieResult or a summarize dictionary) without refitting:

assessment = prusie.assess_convergence(fit)
print(assessment["status"])
print(assessment["message"])

The returned assessment["status"] classifies the trajectory into one of the following states:

  • converged: the configured stopping criterion was satisfied.
  • slow_monotone: the ELBO is still increasing monotonically with diminishing increments. Running additional sweeps via continue_fit usually achieves convergence; assessment["elbo_tail"]["estimated_extra_sweeps"] estimates the required sweep budget from the recent decay rate.
  • oscillating: the posterior alternates among a recurring cycle of states. Additional IBSS sweeps rarely resolve an oscillation; inspect the cycling components listed in moving_components.
  • elbo_decreasing: the ELBO decreased across recent sweeps, which in summary-statistic fits typically points to LD mismatch or allele misalignment. Run diagnose_ld to investigate.
  • numerical_failure, unclassified, or not_assessable (when track_fit was not enabled during fitting).

In addition, assessment["inference_stability"] evaluates whether the fine-mapping results have stabilized over the final tail sweeps (default 5). If every active component maintained the same lead variant and no marginal PIP changed by pip_stability (default 0.001) or more over that window, the credible sets are unlikely to change with further sweeps even if the formal ELBO tolerance has not yet been reached.

Continue first, then consider refinement

If a fit stops at iteration_limit (max_iter), run continue_fit first to give the solver additional IBSS sweeps from the saved posterior:

fit_for_search = fit
if fit.convergence["stop_reason"] == "iteration_limit":
    fit_for_search = prusie.continue_fit(fit, max_iter=100, track_fit="compact")
print("IBSS converged:", fit_for_search.ibss_converged)

In continue_fit, max_iter specifies the number of additional sweeps to run, and the returned niter counts those newly executed sweeps. By default, continue_fit inherits the baseline's convergence criterion and tolerance (tol), though either can be overridden via tol= or convergence=prusie.ConvergenceConfig(...). (In the example above, fit had already converged, so continuation is skipped.)

Once a baseline fit has converged (or if continuation cannot resolve a local mode), refine_fit searches for a higher-ELBO solution under the same model by iteratively excluding retained credible sets and re-optimizing:

search_config = prusie.RefinementConfig(
    max_rounds=10,
    absolute_tol=1e-3,
    relative_tol=None,
    max_iter=100,
    inner_tol=1e-3,
    candidate_budget=20,
)
refined = prusie.refine_fit(fit_for_search, search_config, track_fit="compact")
search = refined.refinement
print("Search:", search["status"])
print(
    "Accepted attempts:", sum(row["accepted"] for row in search["history"]),
    "of", len(search["history"]),
)

In each round of refinement, every retained credible set in the current incumbent fit generates a two-stage candidate:

  1. Stage A (exclusion fit): Prior weights for the members of one credible set are zeroed out (subject to standard log⁡(πj+ϵ)\log(\pi_j + \sqrt{\epsilon}) smoothing) and a cold-start fit is run.
  2. Stage B (re-optimization): The original prior weights are restored, and a warm-start fit is initialized from Stage A's posterior (alpha, mu, mu2) with V and sigma2 reset to the model's initial values.

Candidates are ranked by their final pre-trimming Stage B ELBO under the original prior. If the best valid candidate in a round improves the ELBO by more than absolute_tol, it replaces the incumbent and triggers another round, up to max_rounds or candidate_budget exclusion attempts (each attempt performs two inner fits).

Refinement compared with susieR

Passing refine=True directly to susie_rss (or calling refine_fit(fit) without a custom RefinementConfig) matches the default refinement procedure in susieR 0.16.6 (commit 8e56a8e038e989856d106d9ca5175cc664fea9d2; for non-retained routes, see Refinement, continuation and warm starts):

Step or control prusie default (refine=True) susieR 0.16.6
Stage A Cold start with target CS prior weights set to zero (smoothed by log⁡(π+ϵ)\log(\pi + \sqrt{\epsilon})) Identical
Stage B Restore original prior; warm-start from Stage A's alpha, mu, mu2; reset V and sigma2 Identical
Ranking objective Stage B's final pre-trimming ELBO under the original prior Identical (susie_get_objective)
Minimum absolute ELBO gain Strictly greater than the baseline fit's tol Identical
Relative-gain stopping rule Stop after acceptance if $\Delta\mathrm{ELBO} / \max(1, \mathrm{ELBO}_{\text{new}}
Inner IBSS convergence Not required for candidate acceptance; outer search status sets fit.converged Identical
Search budget Up to 100 rounds (RefinementConfig also supports candidate_budget) Up to 100 rounds
Error handling Rejects nonfinite ELBOs and catches per-candidate fitting errors while preserving the incumbent Errors in candidate fits propagate

Note that calling refine_fit(fit) with no RefinementConfig inherits the baseline fit's max_iter, tol, and relative-gain stopping rule (max_rounds=100), whereas instantiating RefinementConfig() uses its own defaults (max_rounds=10, absolute_tol=1e-3, inner_tol=1e-4, max_iter=100, and relative_tol=None). For source details, compare src/prusie/refinement.py with R/refinement.R and R/susie_get_functions.R in susieR, and see the Toy example and Numerical accuracy pages.

The relative stop in large samples

Following susieR, the default refinement search (refine=True) terminates after an accepted round if the relative ELBO gain falls below tol×max⁡(1,∣ELBO∣)\mathtt{tol} \times \max(1, |\mathrm{ELBO}|). Because the magnitude of the Gaussian ELBO is dominated by −n2log⁡(2πσ2)-\frac{n}{2}\log(2\pi\sigma^2) plus the expected residual sum of squares, ∣ELBO∣|\mathrm{ELBO}| scales linearly with sample size nn (∣ELBO∣≈1.42 n|\mathrm{ELBO}| \approx 1.42\,n for zz-score RSS with σ2=1\sigma^2 = 1). At n=500,000n = 500{,}000, this relative threshold reaches ∼70\sim 70 nats at tol=1e-4 and ∼700\sim 700 nats at tol=1e-3, whereas genuine refinement improvements typically gain tens of nats. Consequently, in large-sample GWAS datasets, the relative rule almost always halts refinement after the first accepted round.

When this occurs, refined.refinement["stop_reason"] is recorded as "relative_improvement_threshold", refined.refinement["relative_stop"] logs the achieved gain and threshold in nats, and the HTML report highlights the early stop. To allow refinement to continue until no candidate improves the absolute ELBO by more than tol, disable the relative threshold with relative_tol=None:

tol = fit.params["tol"]
no_relative = prusie.RefinementConfig(
    max_rounds=100,
    absolute_tol=tol,
    relative_tol=None,
    max_iter=fit.params["max_iter"],
    inner_tol=tol,
)
refined_further = prusie.refine_fit(fit, no_relative)

Compare before and after

You can visualize both the convergence trajectories and the refinement search history without re-running the search:

convergence_figure, _, _ = plot_convergence(
    fit_for_search, after=refined, layout="compact"
)
search_figure, _, _ = plot_refinement(fit_for_search, refined, layout="compact")
print("Same PIPs:", bool((fit_for_search.pip == refined.pip).all()))

In this example, Same PIPs: False confirms that refinement found a higher-ELBO solution with updated posterior inclusion probabilities. plot_refinement displays the before-and-after PIP comparison, the ELBO gain of each exclusion attempt relative to its round's incumbent, and the progression of accepted ELBO values (layout="full" adds credible-set membership tables).

refined.refinement["history"] archives every attempted candidate—including its extracted credible sets (candidate_cs), acceptance decision (accepted), and Stage A/B traces when track_fit is enabled on refine_fit. Furthermore, refined.refinement["competing_candidates"] lists any tried candidate whose final ELBO came close to the retained solution (gap_to_retained) along with whether it produced identical credible sets (same_cs_as_accepted). If a candidate with different credible sets lies within ∼1\sim 1 nat of the accepted solution, the data support two distinct fine-mapping configurations almost equally well, and write_report flags the ambiguity automatically. See the Toy example for an illustration.

Convergence diagnostics

fit.convergence records the requested and effective stopping rules, tolerances, and final sweep metrics (fit.convergence["last"]). Note that after refinement, fit.converged (and fit.ibss_converged) reflects the status of the outer refinement search (matching model$converged in susieR), whereas fit.convergence["inner_ibss_converged"] records whether the accepted fit's inner IBSS loop met its stopping tolerance (on unrefined fits, read fit.convergence["ibss_converged"]).

At each sweep t≥2t \ge 2, the solver tracks the maximum absolute posterior changes across components and variants:

Δα=max⁡ℓ,j∣αℓj(t)−αℓj(t−1)∣,ΔPIP=max⁡j∣PIPj(t)−PIPj(t−1)∣, \Delta_\alpha = \max_{\ell, j} \bigl|\alpha^{(t)}_{\ell j} - \alpha^{(t-1)}_{\ell j}\bigr|, \qquad \Delta_{\mathrm{PIP}} = \max_j \bigl|\mathrm{PIP}^{(t)}_j - \mathrm{PIP}^{(t-1)}_j\bigr|,

where Δα\Delta_\alpha includes any null column and ΔPIP\Delta_{\mathrm{PIP}} is computed over biological variants across active components (Vℓ>prior_tolV_\ell > \mathtt{prior\_tol}; see PIP and credible sets).

While the default stopping rule checks 0≤ΔELBO<tol0 \le \Delta\mathrm{ELBO} < \mathtt{tol}, you can configure posterior-based or joint stopping criteria via ConvergenceConfig:

rule = prusie.ConvergenceConfig(
    criterion="joint", alpha_tol=1e-6, pip_tol=1e-6
)

Passing convergence=rule to a fitting function, continue_fit, or refine_fit selects among "elbo", "alpha_pip" (requiring both Δα<alpha_tol\Delta_\alpha < \mathtt{alpha\_tol} and ΔPIP<pip_tol\Delta_{\mathrm{PIP}} < \mathtt{pip\_tol}, each defaulting to 1e-4), or "joint" (requiring both the ELBO and posterior conditions). Cycle detection monitors posterior states up to cycle_lag sweeps earlier (default 5) starting at min_iter (default 2):

  • Under "elbo", repeated states with a finite ELBO are logged diagnostically without halting the loop.
  • Under ConvergenceConfig with "alpha_pip" or "joint", a cycle at lag >1>1 stops the loop with stop_reason="cycle_detected" and converged=False unless the tolerance was already satisfied.
  • Under the susieR-compatible PIP stopping rule (convergence_method="pip"), a cycle of length 2≤k≤52 \le k \le 5 is accepted as converged and alpha is averaged over the kk cycle states.

In the native Gaussian solver, nonfinite ELBO values are handled according to the active criterion (for dynamic RSS routes, see Convergence outcomes):

Objective state Solver behavior
NaN ELBO in elbo mode At or after min_iter, switches to posterior checks (alpha_pip_nonfinite_fallback) using the PIP rule by default or explicit alpha_tol/pip_tol if configured
NaN ELBO in alpha_pip mode Evaluates the posterior stopping rule and records the nonfinite objective
NaN ELBO in joint mode Terminates immediately with stop_reason="numerical_failure" and converged=False
Infinite ELBO (or NaN posterior arrays) Raises ValueError

Technical details

Iteration phases and objective values

Per-sweep trace metrics are recorded at the end of each component pass, prior to any trailing residual-variance update, cycle averaging, or final component trimming. Consequently, if a fit exits at max_iter with estimate_residual_variance=True, the returned fit.sigma2 includes the post-sweep update, and fit.elbo / fit.XtXr reflect the state before final trimming of components with Vℓ<prior_tolV_\ell < \mathtt{prior\_tol} (logged in fit.convergence["finalization"]; see Iterations and finalization).

To evaluate the exact post-trimming ELBO without running additional IBSS sweeps, call prusie.evaluate_objective(fit), which recomputes the objective directly from the retained inputs and finalized posterior arrays.

Retained inputs and warm starts

For supported materialized Gaussian models, passing retain_data=True (or enabling track_fit, refine, or model_init) stores a read-only snapshot of the prepared inputs along with its SHA-256 data_signature. Both continue_fit and refine_fit operate on this private snapshot, insulating them from subsequent in-place changes to caller arrays.

When a fit is serialized with save_analysis, data_signature is recorded in analysis.json while the heavy input arrays are omitted. As a result, a reloaded fit cannot be passed directly to continue_fit, but it can warm-start a new fitting call when the original inputs are provided via model_init=restored (or s_init=restored). Warm starts verify that variant IDs, allele labels, scales, and null-column layout match the new inputs, and rebuild all component matrix products before the first sweep.

Tracking detail and search records

Compact tracking (track_fit=True or "compact") records exact scalar sweep metrics together with a sparse summary of alpha (retaining rows with max⁡jαℓj≥2/q\max_j \alpha_{\ell j} \ge 2/q and entries ≥1/q\ge 1/q, marked lossy=True), whereas track_fit="dense" archives full copies of alpha, mu, and mu2 at every sweep.

In refine_fit, candidate fits are untracked by default (track_fit=False) even if the baseline fit was tracked, and the entry-point shortcut susie_rss(..., refine=True, track_fit=True) tracks only the initial baseline fit. To record per-sweep trajectories for every Stage A and Stage B candidate fit in refinement["history"][i]["stages"][phase]["trace"], call refine_fit(..., track_fit="compact") explicitly (avoid "dense" during refinement on large regions, as storing full posterior arrays for every sweep of every candidate can consume substantial memory).

Next, see Sensitivity and LD diagnostics to evaluate robustness across modeling choices, or consult the quick-start report guide and plotting API.