-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Deterministic seeded random streams across runs (#194)
* Create failing test * simplify * feed all eval requests through a single channel * formatting * `var"` macros not necessary after all * typos * catch errors not seen locally to understand CI failures better * add env to make `Random` available * formatting * remove copypasted code that unnecessarily created a new notebook file away from the project
- Loading branch information
1 parent
84cb855
commit 4efa39a
Showing
5 changed files
with
69 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
[deps] | ||
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: Random seed | ||
--- | ||
|
||
```{julia} | ||
using Random | ||
Random.seed!(123) | ||
rand() | ||
``` | ||
|
||
```{julia} | ||
rand() | ||
``` | ||
|
||
```{julia} | ||
rand() | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
include("../utilities/prelude.jl") | ||
|
||
@testset "seeded random numbers are consistent across runs" begin | ||
notebook = joinpath(@__DIR__, "../examples/random_seed/random_seed.qmd") | ||
|
||
server = QuartoNotebookRunner.Server() | ||
|
||
jsons = map(1:2) do _ | ||
QuartoNotebookRunner.run!(server, notebook; showprogress = false) | ||
end | ||
|
||
_output(cell) = only(cell.outputs).data["text/plain"] | ||
|
||
@test tryparse(Float64, _output(jsons[1].cells[2])) !== nothing | ||
@test tryparse(Float64, _output(jsons[1].cells[4])) !== nothing | ||
@test tryparse(Float64, _output(jsons[1].cells[6])) !== nothing | ||
|
||
@test length(unique([_output(jsons[1].cells[i]) for i in [2, 4, 6]])) == 3 | ||
|
||
@test _output(jsons[1].cells[2]) == _output(jsons[2].cells[2]) | ||
@test _output(jsons[1].cells[4]) == _output(jsons[2].cells[4]) | ||
@test _output(jsons[1].cells[6]) == _output(jsons[2].cells[6]) | ||
|
||
close!(server) | ||
end |