From 6c80a0f1aeecfc8e9c9e7d457ae5ce2766fb1806 Mon Sep 17 00:00:00 2001 From: Michael Goerz Date: Thu, 2 Oct 2025 12:35:39 -0400 Subject: [PATCH 1/2] Fix use of `rng` in `random_hermitian_real_matrix` The `rng` argument was not being taken into account, making it impossible to pass in an `rng` for reproducability --- src/random.jl | 2 +- test/test_random.jl | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/random.jl b/src/random.jl index 1f7f589..9b52896 100644 --- a/src/random.jl +++ b/src/random.jl @@ -290,7 +290,7 @@ function random_hermitian_real_matrix( exact_spectral_radius=false ) Δ = √(12 / N) - X = Δ * (rand(N, N) .- 0.5) + X = Δ * (rand(rng, N, N) .- 0.5) H = ρ * (X + X') / (2 * √2) if exact_spectral_radius λ = eigvals(H) diff --git a/test/test_random.jl b/test/test_random.jl index 1f6b8e3..529384e 100644 --- a/test/test_random.jl +++ b/test/test_random.jl @@ -449,7 +449,7 @@ end @test λ isa Vector{ComplexF64} @test abs(maximum(abs.(λ)) - 2.0) < 1e-5 # exact! λ = reduce(vcat, [eigvals(Array(evaluate(H, tlist, n))) for n = 1:50:1000]) - @test 1.9 < maximum(abs.(λ)) ≤ 2.0 + @test 1.8 < maximum(abs.(λ)) ≤ 2.0 end From 26fdf1d96e4514e4c60034a216214045062f157c Mon Sep 17 00:00:00 2001 From: Michael Goerz Date: Thu, 2 Oct 2025 12:45:04 -0400 Subject: [PATCH 2/2] Fix use of `rng` when generating random pulses --- src/dummy_problem.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/dummy_problem.jl b/src/dummy_problem.jl index 5207fee..71494bf 100644 --- a/src/dummy_problem.jl +++ b/src/dummy_problem.jl @@ -66,7 +66,7 @@ function dummy_control_problem(; ) tlist = collect(range(0; length=(n_steps + 1), step=dt)) - pulses = [rand(length(tlist) - 1) for l = 1:n_controls] + pulses = [rand(rng, length(tlist) - 1) for l = 1:n_controls] for l = 1:n_controls # we normalize on the *intervals*, not on the time grid points pulses[l] ./= norm(pulses[l])