Skip to content

Introduce step-setup in samplers - #8351

Open
OttoVintola wants to merge 5 commits into
pymc-devs:mainfrom
OttoVintola:step-setup
Open

Introduce step-setup in samplers#8351
OttoVintola wants to merge 5 commits into
pymc-devs:mainfrom
OttoVintola:step-setup

Conversation

@OttoVintola

@OttoVintola OttoVintola commented Jul 9, 2026

Copy link
Copy Markdown

Description

I added a function to pm.sample(...) that passes the number of draws to the step methods if they have the setup attribute. With this setup method, we can pre-allocate a vector to store TreeBatch for each sampling draw in bartrs.

Related Issue

  • Closes #
  • Related to #

Checklist

Type of change

  • New feature / enhancement
  • Bug fix
  • Documentation
  • Maintenance
  • Other (please specify):

@read-the-docs-community

read-the-docs-community Bot commented Jul 9, 2026

Copy link
Copy Markdown

Documentation build overview

📚 pymc | 🛠️ Build #33532433 | 📁 Comparing 8138fa5 against latest (56384e5)

  🔍 Preview build  

65 files changed · + 10 added · ± 45 modified · - 10 deleted

+ Added

± Modified

- Deleted

@codecov

codecov Bot commented Jul 9, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 90.12%. Comparing base (56384e5) to head (8138fa5).
⚠️ Report is 28 commits behind head on main.

Files with missing lines Patch % Lines
pymc/sampling/parallel.py 0.00% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #8351      +/-   ##
==========================================
- Coverage   91.73%   90.12%   -1.61%     
==========================================
  Files         128      128              
  Lines       20672    20697      +25     
==========================================
- Hits        18963    18653     -310     
- Misses       1709     2044     +335     
Files with missing lines Coverage Δ
pymc/sampling/mcmc.py 81.06% <100.00%> (-10.85%) ⬇️
pymc/sampling/population.py 65.47% <100.00%> (ø)
pymc/step_methods/compound.py 98.70% <100.00%> (ø)
pymc/step_methods/hmc/base_hmc.py 92.25% <100.00%> (ø)
pymc/sampling/parallel.py 64.79% <0.00%> (ø)

... and 5 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Comment thread pymc/sampling/mcmc.py Outdated
tune = get_default_tune_steps(step, tune)

for method in flatten_steps(step):
if hasattr(method, "setup"):

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can't we add it to the baseclass so we don't need to hasattr check it?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need it, I just added the hasattr so that pm.sample() does not throw.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see there's a set_rng... could this be passed into setup? I haven't checked when/where is it called from

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think set_rng is called per chain. If we move set_rng to setup, then the rng would be shared across chains, and vice versa if we move setup to set_rng then it would be called for each chain repeatedly. That would not be an issue in the current implementation of BART because we can check if setup has already been called. Then the method should be renamed to something like setup_chain

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah setup_chain sounds good enough, and we combine both sources of info

@OttoVintola OttoVintola Jul 22, 2026

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

d19d46f has setup_chain now @ricardoV94

@OttoVintola
OttoVintola requested a review from ricardoV94 July 27, 2026 11:15
@ricardoV94 ricardoV94 added maintenance major Include in major changes release notes section samplers labels Jul 27, 2026
@ricardoV94 ricardoV94 changed the title add step-setup Introduce step-setup in samplers Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

maintenance major Include in major changes release notes section samplers

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants