Skip to content

feat: expose callback#53

Open
williambdean wants to merge 4 commits intomainfrom
expose-callback
Open

feat: expose callback#53
williambdean wants to merge 4 commits intomainfrom
expose-callback

Conversation

@williambdean
Copy link
Copy Markdown
Contributor

@williambdean williambdean commented Mar 10, 2026

Getting ball rolling for pymc-devs/nutpie#166

This creates a new constructor new_with_sample_callback in order to keep backwards
compatibility.

@williambdean williambdean requested a review from aseyboldt March 10, 2026 05:24
@williambdean williambdean force-pushed the expose-callback branch 3 times, most recently from 46203f6 to ce92b91 Compare March 10, 2026 17:17
Extend ChainProgress with optional latest_sample field instead of
adding separate SampleCallback. Consolidates callback API while
maintaining access to per-sample data.
pub runtime: Duration,
pub divergent_draws: Vec<usize>,
/// The most recent sample from this chain (if available)
pub latest_sample: Option<SampleData>,
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 like the idea of having a separate struct for the draw specific entries, but we should then also move the existing ones into the struct. I don't think we have to worry about backward compatibility here too much, and nuts-rs is still pre-1.0. (But maybe we should change that soonish...)

And do we really need to store the position? I can't really think of anything useful to do with it, given that it's just the unconstrained flattened parameters without any labels. Do you have a specific use-case in mind?

Copy link
Copy Markdown
Contributor Author

@williambdean williambdean Mar 13, 2026

Choose a reason for hiding this comment

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

Removed the position and renamed to be closed to PyMC sampler names.

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.

Thanks. Can you also put the existing last sample stats (tuning, step_size, latest_num_steps) into the latest_sample struct?

chains.iter().map(|chain| chain.progress()).collect_vec();
responses_tx.send(SamplerResponse::Progress(progress.into())).map_err(|e| {
anyhow::anyhow!(
responses_tx
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.

Looks like some unrelated formatting changes slipped in?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I had a bit of a hard time getting the env setup locally. But did run cargo fmt

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 you just take those changes out of the PR?

@williambdean
Copy link
Copy Markdown
Contributor Author

williambdean commented Mar 13, 2026

Coverage is failing for some reason. .. Maybe I should have forked...

Logs: https://github.com/pymc-devs/nuts-rs/actions/runs/23067147874

progress
.lock()
.expect("Poisoned mutex")
.update(&info, now.elapsed());
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 think we can just put the extra stats you want to expose to the info struct? That way we don't have to call stats.get_all (which allocates a bunch) and also don't lock the progress twice.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Addressed in 74887dd

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.

2 participants