Skip to content

Commit

Permalink
alternative test environment for IA v0.22
Browse files Browse the repository at this point in the history
  • Loading branch information
schillic committed Nov 30, 2024
1 parent f1575ff commit 3c4a0ac
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 30 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/CompatHelper.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
- name: Run CompatHelper
run: |
julia -e 'import CompatHelper;
CompatHelper.main(; subdirs=["", "test", "docs"],
CompatHelper.main(; subdirs=["", "test", "docs", "test/IntervalArithmetic v0.22"],
bump_compat_containing_equality_specifier=false)'
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
17 changes: 17 additions & 0 deletions test/IntervalArithmetic v0.22/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[deps]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Documenter = "e30172f5-a6a5-5a46-863b-614d45cd2de4"
DynamicPolynomials = "7c1d4256-1411-5781-91ec-d7bc3513ac07"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
RangeEnclosures = "1b4d18b6-9e5d-11e9-236c-f792b01831f8"
SDPA = "b9a10b5b-afa4-512f-a053-bb3d8080febc"
SumOfSquares = "4b9e565b-77fc-50a5-a571-1244f986bda1"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[compat]
Aqua = "0.8.9"
Documenter = "0.27, 1"
DynamicPolynomials = "0.3 - 0.6"
IntervalArithmetic = "0.22"
SDPA = "0.2 - 0.6"
SumOfSquares = "0.3.6 - 0.7"
3 changes: 3 additions & 0 deletions test/IntervalArithmetic v0.22/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
global oldIA = false

include("../runtests.jl")
22 changes: 14 additions & 8 deletions test/paper.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,34 +10,40 @@ struct MyEnclosure end
end

f(x) = x
@test enclose(f, 0 .. 1, MyEnclosure()) == 1 .. 2
@test isequal_interval(enclose(f, 0 .. 1, MyEnclosure()), 1 .. 2)
end

@testset "How to use the package" begin
f(x) = -sum(k * x * sin(k * (x - 3) / 3) for k in 1:5)
D = -10 .. 10
@test enclose(f, D, NaturalEnclosure()) == interval(-150, 150)
@test isequal_interval(enclose(f, D, NaturalEnclosure()), interval(-150, 150))
res = enclose(f, D, BranchAndBoundEnclosure())
@test res isa Interval && inf(res) -56.42311 && sup(res) 34.99878
@test res isa Interval
if oldIA
@test inf(res) -56.42311 && sup(res) 34.99878
else
@test inf(res) -56.42400 && sup(res) 34.988386
end
end

@testset "Combining different solvers" begin
g(x) = x^2 - 2 * x + 1
Dg = 0 .. 4
@test enclose(g, Dg, NaturalEnclosure()) == interval(-7, 17)
@test enclose(g, Dg, MeanValueEnclosure()) == interval(-11, 13)
@test isequal_interval(enclose(g, Dg, NaturalEnclosure()), interval(-7, 17))
@test isequal_interval(enclose(g, Dg, MeanValueEnclosure()), interval(-11, 13))

@test enclose(g, Dg, [NaturalEnclosure(), MeanValueEnclosure()]) == interval(-7, 13)
# TODO combining solvers is currently not supported for IntervalArithmetic v0.22
@ts @test isequal_interval(enclose(g, Dg, [NaturalEnclosure(), MeanValueEnclosure()]), interval(-7, 13))
end

@testset "Using solvers based on external libraries" begin
@ts @testset "Using solvers based on external libraries" begin
g(x) = x^2 - 2 * x + 1
Dg = 0 .. 4
res = enclose(g, Dg, MooreSkelboeEnclosure())
@test res isa Interval && inf(res) -0.0019195181 && sup(res) 9.0010805
end

@testset "Multivariate functions" begin
@ts @testset "Multivariate functions" begin
h(x) = sin(x[1]) - cos(x[2]) - sin(x[1]) * cos(x[1])
Dh = IntervalBox(-5 .. 5, -5 .. 5)
res = enclose(h, Dh, BranchAndBoundEnclosure())
Expand Down
53 changes: 41 additions & 12 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -1,22 +1,51 @@
using Test, RangeEnclosures
using AffineArithmetic, IntervalOptimisation, TaylorModels, SDPA, SumOfSquares
using SDPA, SumOfSquares
using DynamicPolynomials: @polyvar

available_solvers = (NaturalEnclosure(),
MeanValueEnclosure(),
AffineArithmeticEnclosure(),
MooreSkelboeEnclosure(),
TaylorModelsEnclosure(),
BranchAndBoundEnclosure())
global oldIA
if !isdefined(Main, :oldIA)
@show oldIA = true
end

@static if oldIA
using AffineArithmetic, IntervalOptimisation, TaylorModels
available_solvers = (NaturalEnclosure(),
MeanValueEnclosure(),
AffineArithmeticEnclosure(),
MooreSkelboeEnclosure(),
TaylorModelsEnclosure(),
BranchAndBoundEnclosure())

# execute the argument code
macro ts(arg)
quote
$(esc(arg))
end
end

isequal_interval = (==)
else
available_solvers = (NaturalEnclosure(),
MeanValueEnclosure(),
BranchAndBoundEnclosure())

# skip the argument code
macro ts(arg) end

using RangeEnclosures: Interval # this is necessary for some reason
using RangeEnclosures.IntervalArithmetic: isequal_interval, inf, sup
end

include("univariate.jl")
include("multivariate.jl")
@ts include("multivariate.jl")
include("paper.jl")

using Documenter
include("../docs/init.jl")
@testset "doctests" begin
doctest(RangeEnclosures)
@ts begin
using Documenter
include("../docs/init.jl")
@testset "doctests" begin
doctest(RangeEnclosures)
end
end

include("Aqua.jl")
20 changes: 11 additions & 9 deletions test/univariate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@ end
rleft, rright = relative_precision(x, xref)
@test rleft 1e-5 && rright 1e-5

x = enclose(f, dom, TaylorModelsEnclosure(; order=4))
xref = interval(-4.2783, 12.7084)
rleft, rright = relative_precision(x, xref)
@test rleft 1e-5 && rright 1e-5
@ts begin
x = enclose(f, dom, TaylorModelsEnclosure(; order=4))
xref = interval(-4.2783, 12.7084)
rleft, rright = relative_precision(x, xref)
@test rleft 1e-5 && rright 1e-5

x = enclose(f, dom, MooreSkelboeEnclosure())
xref = interval(4.83299, 10.5448)
rleft, rright = relative_precision(x, xref)
@test rleft 1e-5 && rright 1e-5
x = enclose(f, dom, MooreSkelboeEnclosure())
xref = interval(4.83299, 10.5448)
rleft, rright = relative_precision(x, xref)
@test rleft 1e-5 && rright 1e-5
end
end

@testset "Test univariate polynomial input" begin
Expand All @@ -56,7 +58,7 @@ end
@test rleft 1e-5 && rright 1e-5
end

@testset "Taylor-model solver without normalization" begin
@ts @testset "Taylor-model solver without normalization" begin
f(x) = x^2 - 5x
dom = interval(-1, 1)
x = enclose(f, dom, TaylorModelsEnclosure(; normalize=false))
Expand Down

0 comments on commit 3c4a0ac

Please sign in to comment.