Skip to content

Commit 479a258

Browse files
committed
Fix test depwarns
1 parent 1064187 commit 479a258

File tree

3 files changed

+35
-20
lines changed

3 files changed

+35
-20
lines changed

src/semialgebraic_sets.jl

Lines changed: 27 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@ function ModelKit.System(V::SemialgebraicSets.AbstractAlgebraicSet; kwargs...)
55
end
66

77
"""
8-
SemialgebraicSetsHCSolver(; excess_residual_tol = nothing, real_tol = 1e-6, compile = false, options...)
8+
SemialgebraicSetsHCSolver(; excess_residual_tol = nothing, real_atol = 1e-6, real_rtol = 0.0, compile = false, options...)
99
1010
Construct a `SemialgebraicSets.AbstractAlgebraicSolver` to be used in `SemialgebraicSets`.
1111
`options` are all valid options for [`solve`](@ref).
1212
13-
Solutions with imaginary part of absolute value larger than `real_tol` are
14-
filtered out.
13+
Solutions with imaginary part larger than the specified tolerances are
14+
filtered out (see [`is_real`](@ref) for details).
1515
1616
For overdetermined systems, `excess_residual_tol` can be set to a `Float64`
1717
value. Excess solutions that have a residual smaller than `excess_residual_tol`
@@ -43,19 +43,32 @@ julia> collect(V)
4343
"""
4444
struct SemialgebraicSetsHCSolver <: SemialgebraicSets.AbstractAlgebraicSolver
4545
excess_residual_tol::Union{Nothing,Float64}
46-
real_tol::Float64
46+
real_atol::Float64
47+
real_rtol::Float64
4748
options::Any
4849
end
49-
SemialgebraicSetsHCSolver(;
50+
function SemialgebraicSetsHCSolver(;
5051
excess_residual_tol = nothing,
51-
real_tol = 1e-6,
52+
real_atol = 1e-6,
53+
real_rtol = 0.0,
54+
real_tol = nothing,
5255
compile = :none,
5356
options...,
54-
) = SemialgebraicSetsHCSolver(
55-
excess_residual_tol,
56-
real_tol,
57-
(compile = compile, options...),
5857
)
58+
if real_tol !== nothing
59+
Base.depwarn(
60+
"The `real_tol` keyword argument is deprecated and will be removed in a future version. Use `real_atol` instead.",
61+
:SemialgebraicSetsHCSolver,
62+
)
63+
real_atol = real_tol
64+
end
65+
SemialgebraicSetsHCSolver(
66+
excess_residual_tol,
67+
real_atol,
68+
real_rtol,
69+
(compile = compile, options...),
70+
)
71+
end
5972

6073
function SemialgebraicSets.default_gröbner_basis_algorithm(
6174
::Any,
@@ -77,7 +90,9 @@ function Base.show(io::IO, solver::SemialgebraicSetsHCSolver)
7790
print(io, "excess_residual_tol = ", solver.excess_residual_tol)
7891
print(io, ", ")
7992
end
80-
print(io, "real_tol = ", solver.real_tol)
93+
print(io, "real_atol = ", solver.real_atol)
94+
print(io, ", ")
95+
print(io, "real_rtol = ", solver.real_rtol)
8196
print(io, ", ")
8297
join(
8398
io,
@@ -117,5 +132,5 @@ function SemialgebraicSets.solve(
117132
hcsolver.excess_residual_tol,
118133
)
119134
# Only return real, non-singular solutions
120-
return real_solutions(results; real_tol = hcsolver.real_tol, only_nonsingular = true)
135+
return real_solutions(results; real_atol = hcsolver.real_atol, real_rtol = hcsolver.real_rtol, only_nonsingular = true)
121136
end

test/endgame_tracker_test.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@
4040
@test all(is_real, res)
4141
@test !any(pr -> isreal(pr; atol = 0.0), res) # there's a tiny imaginary part
4242
@test all(pr -> isreal(pr; atol = 1e-16), res)
43-
@test all(pr -> isreal(pr; tol = 0.0, rtol = 1e-16), res)
43+
@test all(pr -> isreal(pr; atol = 0.0, rtol = 1e-16), res)
4444
@test all(isreal, res)
4545
@test all(is_singular, res)
4646
end

test/semialgebraic_sets_test.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@
88

99
# Inspired from https://jump.dev/SumOfSquares.jl/v0.4.6/generated/Polynomial%20Optimization/
1010
f =
11-
(ε, tol) -> begin
12-
@testset "ε= tol=$tol" begin
11+
(ε, atol) -> begin
12+
@testset "ε= atol=$atol" begin
1313
solver = SemialgebraicSetsHCSolver(;
14-
excess_residual_tol = tol,
15-
real_tol = tol,
14+
excess_residual_tol = atol,
15+
real_atol = atol,
1616
compile = false,
1717
)
1818
@test sprint(show, solver) ==
19-
"SemialgebraicSetsHCSolver(; excess_residual_tol = $tol, real_tol = $tol, compile = false)"
19+
"SemialgebraicSetsHCSolver(; excess_residual_tol = $atol, real_atol = $atol, real_rtol = 0.0, compile = false)"
2020
o = 1 + ε
2121
V = SemialgebraicSets.algebraicset(
2222
[-x - y + o, -o * x * y + o * y^2 - y, -o * x^2 + y^2 - 2y + o],
@@ -25,8 +25,8 @@
2525
S = collect(V)
2626
S = sort!(map(s -> round.(s, digits = 2), S))
2727
@test length(S) == 2
28-
@test S[1] [0.0, 1.0] atol = tol
29-
@test S[2] [1.0, 0.0] atol = tol
28+
@test S[1] [0.0, 1.0] atol = atol
29+
@test S[2] [1.0, 0.0] atol = atol
3030
end
3131
end
3232
f(1e-5, 1e-4)

0 commit comments

Comments
 (0)