Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test_negative_positive_uniform failure #462

Open
kathoum opened this issue Mar 10, 2024 · 6 comments
Open

test_negative_positive_uniform failure #462

kathoum opened this issue Mar 10, 2024 · 6 comments
Labels
C-util Component: utility classes and helpers. E-intermediate Effort: intermediate. T-bug Type: bug.

Comments

@kathoum
Copy link
Contributor

kathoum commented Mar 10, 2024

Test "test_negative_positive_uniform" occasionally fails on my machine (linux x86_64, rust 1.65.0):

---- summary::tests::test_negative_positive_uniform stdout ----
thread 'summary::tests::test_negative_positive_uniform' panicked at 'assert_relative_eq!(aval, sval, max_relative = distance)

    left  = -5.667140121494932
    right = -5.674032139894776

', metrics-util/src/summary.rs:307:13

To reproduce, run the test repeatedly until it fails (a few hundred repetitions may be required):

while cargo test --release --lib -- test_negative_positive_uniform ; do ; done
@kathoum
Copy link
Contributor Author

kathoum commented Mar 10, 2024

Can be reproduced with the following change: in

let mut rng = thread_rng();

Replace thread_rng() with rand::rngs::mock::StepRng::new(seed.0, seed.1) with seed = (12194833282344109743, 13893952441524021419)

@tobz
Copy link
Member

tobz commented Mar 11, 2024

Interesting.

Thanks for the reproduction. Hopefully I can dig into this at some point soon.

@tobz tobz added C-util Component: utility classes and helpers. E-intermediate Effort: intermediate. T-bug Type: bug. labels Mar 11, 2024
@tobz
Copy link
Member

tobz commented Mar 16, 2024

As a small update, I did follow your instructions and was also able to reproduce this locally.

Haven't started digging into why it breaks, but good to know the reproduction is solid. 👍🏻

@kathoum
Copy link
Contributor Author

kathoum commented Mar 24, 2024

I looked into the failure and I think the cause is the interpolation: it seems to me that the implementation of DDSketch rounds the 'rank' towards zero.

The line where truncation happens is https://github.com/mheffner/rust-sketches-ddsketch/blob/d6069cba291ed81924139b34c7ba92647b634a42/src/ddsketch.rs#L111

Truncating 'rank' is equivalent to 'Lower' interpolation mode in ndarray, so, to check this, I changed test_positive_uniform and test_negative_positive_uniform to call quantile_axis_mut with Lower instead of Linear: no test failures after >100k runs.

Additionally: with Lower interpolation mode, the assertions pass even with max_relative = alpha (no need to multiply by 2*aval, because assert_relative_eq already performs relative error calculation).

@tobz
Copy link
Member

tobz commented Mar 25, 2024

Interesting; nice find!

This makes sense to me from reading your comment, but I want to spend a little time trying to check the official DDSketch libraries to make sure that what rust-sketches-ddsketch is doing is actually the right behavior in the first place... since now you've got me thinking about this. :)

@tobz
Copy link
Member

tobz commented Apr 12, 2024

By the way, I haven't forgotten about this.

Work has been busy, and I've been working with one of the DDSketch authors (I work at Datadog) on another internal Rust project that also needs DDSketch... so I'm hoping to figure out both the answer to my above thoughts, and see if that inevitably means we should use the current crate, another crate, or write something entirely new.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-util Component: utility classes and helpers. E-intermediate Effort: intermediate. T-bug Type: bug.
Projects
None yet
Development

No branches or pull requests

2 participants