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

Expose random seed fixing to developer (mostly for testing) #248

Closed
quinn-dougherty opened this issue Apr 13, 2022 · 2 comments · Fixed by #2992
Closed

Expose random seed fixing to developer (mostly for testing) #248

quinn-dougherty opened this issue Apr 13, 2022 · 2 comments · Fixed by #2992
Labels
Language Regarding Squiggle language semantics, distributions and function registry

Comments

@quinn-dougherty
Copy link
Contributor

quinn-dougherty commented Apr 13, 2022

  • _ Is refactor
  • x Is new feature
  • _ Concerns documentation

Description of suggestion or shortcoming:

A whole bunch easier than #227, and 227 depends on it

@quinn-dougherty quinn-dougherty added the Language Regarding Squiggle language semantics, distributions and function registry label Apr 13, 2022
@quinn-dougherty quinn-dougherty added this to Todo in To the alpha! via automation Apr 13, 2022
@berekuk
Copy link
Collaborator

berekuk commented Oct 7, 2022

probably this https://www.npmjs.com/package/random

Another option to investigate: https://github.com/davidbau/seedrandom

the thing is our montecarlo often calls .sample method from Jstat, so it may not be incredibly obvious how to implement.

Jstat uses Math.random (https://github.com/jstat/jstat/blob/e56dd7386e62f6787260cdc382b78b6848d21b62/dist/jstat.js#L113), so it should be possible to monkey-patch it with seedrandom. Or there's that jStat.setRandom function that could be used to avoid global monkey-patching.

@berekuk
Copy link
Collaborator

berekuk commented Oct 7, 2022

One interesting longer-term issue we'll have to deal with is threads. If Squiggle will become smart enough to execute in multiple threads (for better CPU utilization), we'll have to handle it somehow.

Consider:

f = getRandom()
g = getRandom()

Then:

project->runAll(~seed=123)

If Squiggle decides to execute f and g in different threads, the result will become non-deterministic even with a fixed top-level seed. We could deal with this by assigning different unique seeds to each thread, derived from the original seed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Language Regarding Squiggle language semantics, distributions and function registry
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants