Skip to content

Commit 10a8154

Browse files
committed
Switch to using StableRNGs instead of Base.Random
1 parent 74e9230 commit 10a8154

10 files changed

+37
-35
lines changed

test/OptTests/basic_exp.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
using Test, LinearAlgebra, SparseArrays, Random
1+
using Test, LinearAlgebra, SparseArrays
22

33
#if not run in full test setup, just do it for one float type
44
@isdefined(UnitTestFloats) || (UnitTestFloats = [Float64])
55

66
function basic_exp_data(Type::Type{T}) where {T <: AbstractFloat}
7-
7+
88
#x is of dimension 7
99
n = 7
1010
A1 = hcat(ones(T,1,3), zeros(T,1,4)) #ZeroCone

test/OptTests/basic_socp.jl

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
using Test, LinearAlgebra, SparseArrays, Random
1+
using Test, LinearAlgebra, SparseArrays, StableRNGs
22

33
#if not run in full test setup, just do it for one float type
44
@isdefined(UnitTestFloats) || (UnitTestFloats = [Float64])
55

66
function basic_SOCP_data(Type::Type{T}) where {T <: AbstractFloat}
77

8-
rng = Random.MersenneTwister(242713)
8+
rng = StableRNGs.StableRNG(242713)
99
n = 3
1010
P = randn(rng,n,n)*1
1111
P = SparseMatrixCSC{T}(convert(Matrix{T},(P'*P)))
@@ -43,18 +43,19 @@ end
4343

4444
@test solver.solution.status == Clarabel.SOLVED
4545
@test isapprox(
46-
norm(solver.solution.x -
47-
FloatT[ -0.5 ; 0.435603 ; -0.245459]),
48-
zero(FloatT), atol=tol)
49-
@test isapprox(solver.solution.obj_val, FloatT(-8.4590e-01), atol=tol)
50-
@test isapprox(solver.solution.obj_val_dual, FloatT(-8.4590e-01), atol=tol)
46+
norm(solver.solution.x - FloatT[-0.127715, 0.108242, -0.067784]),
47+
zero(FloatT);
48+
atol=tol,
49+
)
50+
@test isapprox(solver.solution.obj_val, FloatT(-0.148520), atol=tol)
51+
@test isapprox(solver.solution.obj_val_dual, FloatT(-0.148520), atol=tol)
5152

5253

5354
end
5455

5556
@testset "feasible_sparse" begin
5657

57-
# same data, but with one SOC cone so that we get the
58+
# same data, but with one SOC cone so that we get the
5859
# sparse representation for code coverage
5960
P,c,A,b,cones = basic_SOCP_data(FloatT)
6061
cones = Clarabel.SupportedCone[Clarabel.NonnegativeConeT(3), Clarabel.NonnegativeConeT(6)]

test/OptTests/socp-lasso.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Test, LinearAlgebra, Random, SparseArrays
1+
using Test, LinearAlgebra, SparseArrays, StableRNGs
22

33
#only test this once
44
FloatT = Float64
@@ -10,7 +10,7 @@ function SOCP_lasso_data(Type::Type{T}) where {T <: AbstractFloat}
1010
#instances will have different optimal values
1111

1212
# generate problem data
13-
rng = Random.MersenneTwister(12345)
13+
rng = StableRNGs.StableRNG(12345)
1414
n = 8
1515
m = 50 * n
1616
F = rand(rng, T, m, n)
@@ -61,7 +61,7 @@ tol = FloatT(1e-3)
6161
Clarabel.solve!(solver)
6262

6363
@test solver.solution.status == Clarabel.SOLVED
64-
@test isapprox(solver.solution.obj_val, -5.0233e+00, atol=tol)
64+
@test isapprox(solver.solution.obj_val, -4.7081728e+02, atol=tol)
6565

6666
end
6767

test/Project.toml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,11 @@ Convex = "f65535da-76fb-5f13-bab9-19810c17039a"
33
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
44
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
55
MathOptInterface = "b8f27783-ece8-5eb3-8dc8-9495eed66fee"
6-
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
76
SparseArrays = "2f01184e-e22b-5df5-ae63-d93ebab69eaf"
7+
StableRNGs = "860ef19b-820b-49d6-a774-d7a799459cd3"
88
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
99

1010
[compat]
1111
Convex = "0.15"
12-
JuMP = "0.2, 1"
12+
JuMP = "1"
13+
StableRNGs = "1"

test/UnitTests/test_coneops_psdtrianglecone.jl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Test, LinearAlgebra, SparseArrays, Clarabel, Random
1+
using Test, LinearAlgebra, SparseArrays, Clarabel, StableRNGs
22

3-
rng = Random.MersenneTwister(242713)
3+
rng = StableRNGs.StableRNG(242713)
44

55
FloatT = Float64
66

@@ -11,8 +11,8 @@ FloatT = Float64
1111
K = Clarabel.PSDTriangleCone(5)
1212
@test Clarabel.numel(K)== 15
1313
@test Clarabel.degree(K) == 5
14-
@test_throws DomainError Clarabel.PSDTriangleCone(-1)
15-
14+
@test_throws DomainError Clarabel.PSDTriangleCone(-1)
15+
1616

1717
end
1818

@@ -169,7 +169,7 @@ FloatT = Float64
169169
eS = eigvals(S + αs.*dS)
170170
@test minimum([eZ;eS]) 0. atol = sqrt(eps(FloatT))
171171

172-
#should reach maximum step
172+
#should reach maximum step
173173
dS .= randpsd(rng,n); dZ .= randpsd(rng,n)
174174
map((v,M)->Clarabel.mat_to_svec!(v,M),(ds,dz),(dS,dZ))
175175
(αz,αs) = Clarabel.step_length(K,dz,ds,z,s,settings,1.0)

test/UnitTests/test_coneops_secondordercone.jl

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
using Test, LinearAlgebra, SparseArrays, Clarabel, Random
1+
using Test, LinearAlgebra, SparseArrays, Clarabel, StableRNGs
22

3-
rng = Random.MersenneTwister(242713)
3+
rng = StableRNGs.StableRNG(242713)
44

55
FloatT = Float64
66

@@ -17,8 +17,8 @@ FloatT = Float64
1717

1818
@testset "test_coneops_scaled_unit_shift" begin
1919

20-
n = 5
21-
s = randn(n)
20+
n = 5
21+
s = randn(rng, n)
2222
s[1] = -1.
2323
K = Clarabel.SecondOrderCone(5)
2424
(m,_) = Clarabel.margins(K,s,Clarabel.PrimalCone)
@@ -32,8 +32,8 @@ FloatT = Float64
3232

3333
n = 5 #must be > 4 to avoid dense representation
3434
K = Clarabel.SecondOrderCone(n)
35-
s = randn(n)
36-
z = randn(n)
35+
s = randn(rng, n)
36+
z = randn(rng, n)
3737
(mz,_) = Clarabel.margins(K,z,Clarabel.DualCone)
3838
corz = mz > 0. ? 0. : 1. -mz
3939
(ms,_) = Clarabel.margins(K,s,Clarabel.PrimalCone)
@@ -59,7 +59,7 @@ FloatT = Float64
5959
#this should be W^TW
6060
W2_A = η^2 .* (D + u*u' - v*v')
6161

62-
#W^TW should agree with Hinv
62+
#W^TW should agree with Hinv
6363
J = -I(n).*1.; J[1,1] = 1.
6464
Hinv = η^2 .* (2*w*w' - J)
6565

@@ -80,14 +80,14 @@ FloatT = Float64
8080
# W_B should be symmetric
8181
@test norm(W_B-W_B') 0 atol = 1e-14
8282

83-
#matrix and its inverse should agree
83+
#matrix and its inverse should agree
8484
@test norm(W_B*W_Binv - I(n)) 0 atol = 1e-14
8585

8686
# square should agree with the directly constructed one
8787
W2_B = W_B*W_B
8888
@test norm(W2_B-W2_A) 0 atol = 1e-12
8989

90-
90+
9191
end
9292

9393

test/run_component_tests.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using Random, Test
1+
using Test
22

33
@testset "Clarabel Unit Tests" begin
44

55
#tests on cones
66
include("./UnitTests/test_coneops_psdtrianglecone.jl")
77
include("./UnitTests/test_coneops_secondordercone.jl")
88

9-
#tests on constructors
9+
#tests on constructors
1010
include("./UnitTests/test_constructors.jl")
1111

1212
#tests on equilibration
@@ -15,7 +15,7 @@ using Random, Test
1515
#tests on json IO
1616
include("./UnitTests/test_json.jl")
1717

18-
#tests on cone simplification and merging
18+
#tests on cone simplification and merging
1919
include("./UnitTests/test_cones_new_collapsed.jl")
2020

2121
end

test/run_interface_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Random, Test
1+
using Test
22
using Clarabel
33

44
@testset "Clarabel Interfaces Testset" begin

test/run_solver_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Random, Test
1+
using Test
22
using Clarabel
33

44
UnitTestFloats = [Float64,BigFloat]

test/runtests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using Random, Test, Clarabel
1+
using Test, Clarabel
22
include("./testing_utils.jl")
33

44
@testset "Clarabel Tests" begin

0 commit comments

Comments
 (0)