Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update to IntervalArithmetic v0.22, drop IntervalBox #205

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 3 additions & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ version = "0.2.6"
ForwardDiff = "f6369f11-7733-5829-9624-2563aa707210"
IntervalArithmetic = "d1acc4aa-44c8-5952-acd4-ba5d80a2a253"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
PkgVersion = "eebad327-c553-4316-9ea0-9fa01ccd7688"
ReachabilityBase = "379f33d0-9447-4353-bd03-d664070e549f"
Requires = "ae029012-a4dd-5104-9daa-d747884805df"

[compat]
ForwardDiff = "0.10"
IntervalArithmetic = "0.15 - 0.20, =0.21.0" # v0.21.1 removed IntervalBox
IntervalArithmetic = "0.15 - 0.22"
LinearAlgebra = "<0.0.1, 1.6"
PkgVersion = "0.3"
ReachabilityBase = "0.1.1 - 0.3"
Requires = "0.5, 1"
julia = "1.6"
25 changes: 22 additions & 3 deletions src/RangeEnclosures.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,30 @@ module RangeEnclosures
using Requires
import ForwardDiff
using LinearAlgebra: dot
using IntervalArithmetic: Interval, IntervalBox, interval, inf, sup, mid,
emptyinterval, hull, diam, bisect, (..)
const Interval_or_IntervalBox = Union{Interval,IntervalBox}
import IntervalArithmetic
using IntervalArithmetic: Interval, interval, inf, sup, mid,
emptyinterval, hull, diam, bisect
using ReachabilityBase.Require

# resolving IntervalArithmetic version problems
import PkgVersion
@static if VERSION >= v"1.9"
vIA = pkgversion(IntervalArithmetic)
else
vIA = PkgVersion.Version(IntervalArithmetic)
end
@static if vIA < v"0.22"
using IntervalArithmetic: (..)
else
.. = interval
end
@static if vIA < v"0.21.1"
using IntervalArithmetic: IntervalBox
else
IntervalBox = AbstractVector{<:Interval}
end
const Interval_or_IntervalBox = Union{Interval,IntervalBox}

include("algorithms.jl")
include("intervalarithmetic.jl")
include("branchandbound.jl")
Expand Down
4 changes: 2 additions & 2 deletions src/branchandbound.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ end

function _monotonicity_check(f::Function, X::Interval, dfX::Interval)
if inf(dfX) >= 0 || sup(dfX) <= 0 # monotone function, evaluate at extrema
lo = interval(X.lo)
hi = interval(X.hi)
lo = interval(inf(X))
hi = interval(sup(X))
return hull(f(lo), f(hi)), true
end

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
Loading