Skip to content

Improve integration with external samplers#2203

Merged
fehiepsi merged 19 commits into
pyro-ppl:masterfrom
juanitorduz:external-samplers
Jul 1, 2026
Merged

Improve integration with external samplers#2203
fehiepsi merged 19 commits into
pyro-ppl:masterfrom
juanitorduz:external-samplers

Conversation

@juanitorduz

@juanitorduz juanitorduz commented May 29, 2026

Copy link
Copy Markdown
Collaborator

Motivated by #2124 and specifically by #2124 (comment), we suggest a cleaner API to integrate with other samplers. This includes MCLMC from Blackjax. This is illustrated in the notebook.

(most from the code changes come from the notebook)

@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

@juanitorduz juanitorduz changed the title iImprove integration with external samplers Improve integration with external samplers May 29, 2026
@juanitorduz juanitorduz marked this pull request as draft May 29, 2026 10:45
Comment thread numpyro/infer/util.py Outdated
Comment thread numpyro/infer/util.py Outdated
Comment thread numpyro/infer/external.py Outdated
@juanitorduz juanitorduz marked this pull request as ready for review May 29, 2026 18:20
@juanitorduz juanitorduz requested a review from fehiepsi May 29, 2026 18:22
@juanitorduz

Copy link
Copy Markdown
Collaborator Author

Thank you for the feedback @fehiepsi . Let me know how this iteration looks. I am happy to keep iterating until we get the best level of abstraction :)

@reubenharry

Copy link
Copy Markdown

Would people be happy merging this? Certainly it looks good from my end

@juanitorduz

Copy link
Copy Markdown
Collaborator Author

I would 😄!

@fehiepsi

fehiepsi commented Jun 9, 2026

Copy link
Copy Markdown
Member

Let's wait a bit to rethink whether the design choices are reasonable. Looking like we are changing other internal codes due to the change. It indicates that we will likely break current user code. Let's see if we can come up with simpler solutions.

@juanitorduz

Copy link
Copy Markdown
Collaborator Author

Great! Always open for feedback 🤗

@juanitorduz

juanitorduz commented Jun 12, 2026

Copy link
Copy Markdown
Collaborator Author

@fehiepsi you were right, there was no need to add such a large change to the internal API 🙈 . In a463116, I simplified the approach and minimized the changes. Now this PR is way less invasive 🤗

fyi @reubenharry

@reubenharry

Copy link
Copy Markdown

Yeah, this seems pleasantly concise

@juanitorduz

Copy link
Copy Markdown
Collaborator Author

@fehiepsi, what do you think about the current status? Any additional feedback or concerns? :)

Comment thread numpyro/_typing.py Outdated
Comment thread numpyro/infer/util.py Outdated
juanitorduz and others added 2 commits June 30, 2026 23:38
Adopts master's ty-only type-checking toolchain (mypy removed, ty.toml
deleted, ty config consolidated in pyproject.toml). Resolved the lone
pyproject.toml conflict by keeping master's [tool.ty.*] config and adding
numpyro/infer/util.py to [tool.ty.src].include.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Per fehiepsi's review on PR pyro-ppl#2203, drop the get_log_density_fn helper, its
LogDensityInfo return type, and the PositionDict alias; build the log
density inline by negating model_info.potential_fn (initialize_model
already returns a single-position potential_fn/postprocess_fn).

- numpyro/infer/util.py: remove get_log_density_fn + LogDensityInfo; narrow
  w.message to Warning in find_valid_initial_params so util.py type-checks
  under ty (newly added to [tool.ty.src]).
- numpyro/_typing.py, numpyro/infer/__init__.py, docs/source/utilities.rst:
  drop the removed symbols.
- notebooks/source/other_samplers.ipynb: inline the pattern and re-execute.
- test/infer/test_external_helpers.py: inline the pattern; keep constrain_fn
  and end-to-end MCMCKernel coverage.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
juanitorduz and others added 4 commits June 30, 2026 23:46
Reword the markdown lead-in to the Pathfinder log-density cell to say we
build the log-density function by negating the potential energy, avoiding
the awkward doubled 'negated' phrasing.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Address fehiepsi review: remove get_log_density_fn, inline via initialize_model
@juanitorduz

juanitorduz commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator Author

Thanks @fehiepsi I simplified it as suggested and resolved the merge conflicts (sorry for the commit mess, but we will squash it anyway :) )

@juanitorduz juanitorduz requested a review from fehiepsi June 30, 2026 22:02
@fehiepsi

fehiepsi commented Jul 1, 2026

Copy link
Copy Markdown
Member

Looks great, thanks!

@fehiepsi fehiepsi merged commit 19a1fbb into pyro-ppl:master Jul 1, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request Tutorials/Examples

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants