Skip to content

Updated LKJ notebook to PyMC 6#875

Open
fonnesbeck wants to merge 1 commit into
pymc-devs:mainfrom
fonnesbeck:LKJ_v6
Open

Updated LKJ notebook to PyMC 6#875
fonnesbeck wants to merge 1 commit into
pymc-devs:mainfrom
fonnesbeck:LKJ_v6

Conversation

@fonnesbeck
Copy link
Copy Markdown
Member

Pretty straightforward update:

  • uses an xr.Dataset
  • plot_trace -> plot_dist

Helpful links

@review-notebook-app
Copy link
Copy Markdown

Check out this pull request on  ReviewNB

See visual diffs & provide feedback on Jupyter Notebooks.


Powered by ReviewNB

@review-notebook-app
Copy link
Copy Markdown

review-notebook-app Bot commented May 11, 2026

View / edit / reply to this conversation on ReviewNB

aloctavodia commented on 2026-05-11T06:41:18Z
----------------------------------------------------------------

This should also work:

az.add_lines(pc, Rho_actual[0, 1]);


aloctavodia pushed a commit that referenced this pull request May 26, 2026
* update variational_api_quickstart for PyMC 6

Part of #862.

Five distinct breakages addressed with minimal source changes; full
Restart & Run All produced fresh outputs and execution metadata.

- Cells 9, 21, 50, 53: Approximation.sample(...) now requires an active
  model context in PyMC 6. Wrapped each call in 'with <model>:'.
- Cell 21: az.plot_posterior was removed in ArviZ 1.0. Replaced with
  az.plot_dist(idata, var_names=[...]), matching the migration pattern
  used in #875.
- Cells 28, 40, 84: pm.callbacks was removed; Tracker and
  CheckParametersConvergence now live in pm.variational.callbacks.
- Cell 100: passing total_size=data.shape (tuple) to a multi-dim
  observed RV triggers an IndexError in get_scaling under
  symbolic_normalizing_constant. Changed to total_size=data.shape[0]
  (int), which is simpler and the intended API regardless.

Verified under pymc 6.0.1, pytensor 3.0.3, arviz 1.1.0. All 105 cells
execute cleanly under Restart & Run All; pre-commit passes.

* address review: migrate to ArviZ 1 plot API

Per @aloctavodia's review:

- Drop %matplotlib inline; apply az.style.use("arviz-variat") (cell 1).
- Install ipywidgets locally; progress-bar warnings cleared from outputs
  (cell 5 thread).
- Replace sns.kdeplot model comparisons with az.plot_dist dict form
  (cells 10, 50, 53).
- az.plot_trace -> az.plot_trace_dist (cell 16). Kept plot_trace_dist
  over plot_rank_dist to stay consistent with the surrounding
  "Above are traces for x^2 and sin(x)" narrative.
- Update markdown around repeated sample_node.eval(): in modern
  PyTensor the random graph is compiled, so repeated .eval() returns
  the cached value. Note this and point to sample_node(size=N) for
  fresh samples (cell 60).
- Replace sns.kdeplot of raw numpy with az.convert_to_dataset +
  az.plot_dist; the first plot also switches to sample_node(size=N)
  so it reflects independent samples (cells 61, 64).

* address 2nd-round review: legends + visual cleanup

Per @aloctavodia's followup:

- Cell 10: add legend via pc.add_legend("model") and disable
  credible_interval/point_estimate visuals to keep only the KDE.
- Cell 34: add trailing semicolon to advi.approx to suppress the
  bare-repr output.

Applied the same legend + visuals pattern to the other two
multi-model plot_dist calls (cells 50 and 53) for consistency.

* strip trailing newline from cell sources (pre-commit fixup)

CI's black-jupyter wanted the trailing newline removed from the last
line of three code cells; local hooks now match.

* fix narrative: sample_node().eval() returns the same draw because
PyTensor's compiled function reads the shared RNG state without
advancing it, not because the value is "cached" — the previous
phrasing was inaccurate. Verified by inspecting RNG state across
.eval() calls (state identical) and by compiling an explicit
function with updates={rng_shared: next_rng}, which does advance
and produces fresh samples.

---------

Co-authored-by: Yicheng Yang <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant