Skip to content

feat: expose callback#53

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

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

Conversation

@williambdean
Copy link

@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
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
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.

src/sampler.rs Outdated
None
}
})
.unwrap_or(0);
Copy link
Member

Choose a reason for hiding this comment

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

I don't think adding zeros is good here. I'm currently working on other samplers for instance, and they might not have all of those. Maybe just make the stats optional? (ie Option instead of f64)

Copy link
Author

Choose a reason for hiding this comment

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

Turned into Option

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

@williambdean
Copy link
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

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