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

Change the core draw primitive to be selecting an integer from 0 to n #1986

Closed
Zalathar opened this issue May 19, 2019 · 5 comments
Closed
Labels
internals Stuff that only Hypothesis devs should ever see

Comments

@Zalathar
Copy link
Contributor

From #1961 (comment) by @DRMacIver:

Counter-proposal: How about instead of this, we change the fundamental design of Hypothesis in order to support this very specific use case. *very straight face*

I'm actually serious. A thing I've been wondering about recently is moving from draw_bits to a choice(n) function which just chooses a number between 0 and n. This would already move a bunch of our redundancy. If we then added an optional weights parameter to it, we could move sampler and weighted coin to just be thin shims over this method.

This would in particular mean that we would solve this problem by removing the redundancy of representation in this case.

@Zalathar
Copy link
Contributor Author

(I pulled this out because I think it's an interesting/good idea, and I want to be able to comment on it without junking up that other thread.)

@Zalathar
Copy link
Contributor Author

I did some experimental work on refitting ConjectureData to use _draw_bits internally, instead of _draw_bytes.

One thing I found is that some input functions naturally want to return raw bytes (e.g. sliced from an input buffer), some input functions want to return integers, and some input functions just want to generate random data in the usual way. (And some want to choose between these options depending on the circumstances.)

It might be useful to allow some flexibility in allowing the input function to return bytes, or an integer, or some sentinel that instructs the caller to supply random data. Then ConjectureData would be responsible for detecting the type of returned data, and performing any necessary conversions in a central place.

@Zac-HD
Copy link
Member

Zac-HD commented Sep 6, 2019

Note: #1961 has lots more information that prospective implementors should read, from visualisations of the current data distribution to discussion of alternative approaches and why they won't work!

@Zac-HD Zac-HD added internals Stuff that only Hypothesis devs should ever see and removed new-feature entirely novel capabilities or strategies labels Nov 24, 2019
@Zac-HD
Copy link
Member

Zac-HD commented Nov 18, 2020

This could also allow symbolic execution like Crosshair to exercise Hypothesis tests - an early attempt based on bytes wasn't impressive, but I think the concept could work well if applied at the level proposed by this issue. See pschanely/CrossHair#45 for details.

@Zac-HD
Copy link
Member

Zac-HD commented Oct 22, 2023

Closing this in favor of #3086 (comment); we now think that using a tree of (int, float, bytes, str) leaves will be a better underlying data structure than just integers.

@Zac-HD Zac-HD closed this as completed Oct 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internals Stuff that only Hypothesis devs should ever see
Projects
None yet
Development

No branches or pull requests

2 participants