Skip to content

Commit f720593

Browse files
Update IntervalArithmetic and ForwardDiff dependencies (#73)
- Update `IntervalArithmetic` and `ForwardDiff` dependencies to v1.0 - Change `NaN` behavior of `MC` objects to use intervals from `IntervalArithmetic`
1 parent e692640 commit f720593

34 files changed

Lines changed: 1723 additions & 1837 deletions

.github/workflows/ci.yml

Lines changed: 12 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -7,46 +7,30 @@ on:
77
branches:
88
- master
99
tags: '*'
10+
permissions:
11+
actions: write
12+
contents: read
1013
jobs:
1114
test:
1215
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
1316
runs-on: ${{ matrix.os }}
1417
strategy:
1518
fail-fast: false
1619
matrix:
17-
18-
include:
19-
- version: '1.6'
20-
os: ubuntu-latest
21-
arch: x64
22-
- version: '1.6'
23-
os: windows-latest
24-
arch: x64
25-
- version: '1.9'
26-
os: ubuntu-latest
27-
arch: x64
28-
- version: '1.9'
29-
os: windows-latest
30-
arch: x64
20+
version: ['1.10', '1']
21+
os: [ubuntu-latest, windows-latest]
22+
arch: [x64]
3123
steps:
32-
- uses: actions/checkout@v2
33-
- uses: julia-actions/setup-julia@v1
24+
- uses: actions/checkout@v4
25+
- uses: julia-actions/setup-julia@v2
3426
with:
3527
version: ${{ matrix.version }}
3628
arch: ${{ matrix.arch }}
37-
- uses: actions/cache@v4
38-
env:
39-
cache-name: cache-artifacts
40-
with:
41-
path: ~/.julia/artifacts
42-
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
43-
restore-keys: |
44-
${{ runner.os }}-test-${{ env.cache-name }}-
45-
${{ runner.os }}-test-
46-
${{ runner.os }}-
29+
- uses: julia-actions/cache@v1
4730
- uses: julia-actions/julia-buildpkg@v1
4831
- uses: julia-actions/julia-runtest@v1
4932
- uses: julia-actions/julia-processcoverage@v1
50-
- uses: codecov/codecov-action@v1
33+
- uses: codecov/codecov-action@v5
5134
with:
52-
file: lcov.info
35+
files: lcov.info
36+
token: ${{ secrets.CODECOV_TOKEN }}

Project.toml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
name = "McCormick"
22
uuid = "53c679d3-6890-5091-8386-c291e8c8aaa1"
33
authors = ["Matthew Wilhelm <matthew.wilhelm@uconn.edu>"]
4-
version = "0.13.11"
4+
version = "0.14.0"
55

66
[deps]
77
DiffRules = "b552c78f-8df3-52c6-915a-8e097449b14b"
@@ -20,16 +20,16 @@ UnPack = "3a884ed6-31ef-47d7-9d2a-63182c4928ed"
2020
[compat]
2121
DiffRules = "1.5"
2222
DocStringExtensions = "~0.8, ~0.9"
23-
ForwardDiff = "~0.10"
24-
IntervalArithmetic = "~0.20"
25-
IntervalRootFinding = "~0.5"
23+
ForwardDiff = "1"
24+
IntervalArithmetic = "1"
25+
IntervalRootFinding = "~0.6"
2626
NaNMath = "0.3.5, 1.0"
2727
NNlib = "~0.8, ~0.9"
2828
Reexport = "~0.2, ~1"
2929
StaticArrays = "~1"
3030
SpecialFunctions = "~1, ~2"
3131
UnPack = "~1"
32-
julia = "1.6"
32+
julia = "1.10"
3333

3434
[extras]
3535
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ using McCormick
6262
f(x) = x*(x - 5.0)*sin(x)
6363

6464
x = 2.0 # Value of independent variable x
65-
Intv = Interval(1.0, 4.0) # Define interval to relax over
65+
Intv = interval(1.0, 4.0) # Define interval to relax over
6666
# Note that McCormick.jl reexports IntervalArithmetic.jl
6767
# and StaticArrays. So no using statement for these is
6868
# necessary.
@@ -104,10 +104,10 @@ f(x, y) = (4.0 - 2.1*x^2 + (x^4)/6.0)*x^2 + x*y + (-4.0 + 4.0*y^2)*y^2
104104

105105
# Define intervals for independent variables
106106
n = 30
107-
X = Interval{Float64}(-2, 0)
108-
Y = Interval{Float64}(-0.5, 0.5)
109-
xrange = range(X.lo, stop=X.hi, length=n)
110-
yrange = range(Y.lo, stop=Y.hi, length=n)
107+
X = interval(-2, 0)
108+
Y = interval(-0.5, 0.5)
109+
xrange = range(X.bareinterval.lo, stop=X.bareinterval.hi, length=n)
110+
yrange = range(Y.bareinterval.lo, stop=Y.bareinterval.hi, length=n)
111111

112112
# Calculate differentiable McCormick relaxation
113113
for (i,x) in enumerate(xrange)

src/McCormick.jl

Lines changed: 35 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -32,24 +32,16 @@ import NNlib: relu, selu, leakyrelu, sigmoid, swish, gelu, elu, softsign, logcos
3232

3333
using IntervalArithmetic
3434
using IntervalArithmetic: @round
35-
if isdefined(IntervalArithmetic, :big53)
36-
big_val(x) = IntervalArithmetic.big53(x)
37-
else
38-
big_val(x) = IntervalArithmetic.bigequiv(x)
39-
end
4035

4136
using IntervalRootFinding
42-
import IntervalArithmetic: dist, mid, pow, +, -, *, /, convert, in, isempty,
37+
import IntervalArithmetic: dist, mid, pow, +, -, *, /, convert,
4338
one, zero, real, eps, max, min, abs, exp,
44-
expm1, log, log2, log10, log1p, sqrt, ^,
45-
sin, cos, tan, min, max, sec, csc, cot, step, sech,
46-
csch, coth, acsch, acoth, asech,
47-
sign, dist, mid, pow, Interval, interval, sinh, cosh,
48-
, IntervalBox, bisect, isdisjoint, length,
49-
atan, asin, acos, AbstractInterval, atomic,
50-
sind, cosd, tand, asind, acosd, atand,
51-
secd, cscd, cotd, asecd, acscd, acotd, half_pi,
52-
setrounding, diam, isthin, abs2
39+
expm1, log, log2, log10, log1p, sqrt, ^, sin,
40+
cos, tan, min, max, sec, csc, cot, step, sech,
41+
csch, coth, acsch, acoth, asech, sign, dist, mid,
42+
pow, interval, sinh, cosh, length, atan, asin, acos,
43+
atomic, sind, cosd, tand, asind, acosd, atand, secd, cscd,
44+
cotd, asecd, acscd, acotd, setrounding, diam, isthin, abs2
5345

5446
import SpecialFunctions: erf, erfc, erfinv, erfcinv
5547
export erf, erfinv, erfc, erfcinv, erf_kernel, erfinv_kernel, erfc_kernel, erfcinv_kernel
@@ -134,18 +126,6 @@ const MC_MV_TOL = 1E-8
134126
const MC_DEGEN_TOL = 1E-14
135127
const MC_DOMAIN_TOL = 1E-10
136128

137-
const IntervalConstr = interval
138-
const Half64 = Float64(0.5)
139-
const Two64 = Float64(2.0)
140-
const Three64 = Float64(3.0)
141-
const EqualityTolerance = Float64(1E-12)
142-
const DegToRadIntv = atomic(Interval{Float64}, pi)/Interval(180.0)
143-
const one_intv = one(Interval{Float64})
144-
const half_intv = Interval{Float64}(0.5)
145-
const two_intv = Interval{Float64}(2.0)
146-
const log2_intv = log(Interval{Float64}(2.0))
147-
const log10_intv = log(Interval{Float64}(10.0))
148-
149129
const NumberNotRelax = Union{Bool, Float16, Float32, Signed, Unsigned, BigFloat,
150130
Int8, Int64, Int32, Int16, Int128}
151131

@@ -289,14 +269,14 @@ function cut(xL::Float64, xU::Float64, cv::Float64, cc::Float64,
289269
return cvo, cco, cv_grado, cc_grado
290270
end
291271

292-
lo(x::Interval{Float64}) = x.lo
293-
hi(x::Interval{Float64}) = x.hi
272+
lo(x::Interval{Float64}) = x.bareinterval.lo
273+
hi(x::Interval{Float64}) = x.bareinterval.hi
294274

295275
function step(x::Interval{Float64})
296-
isempty(x) && return emptyinterval(x)
297-
xmin::Float64 = ((x.lo) < 0.0) ? 0.0 : 1.0
298-
xmax::Float64 = ((x.hi) >= 0.0) ? 1.0 : 0.0
299-
return Interval{Float64}(xmin,xmax)
276+
isempty_interval(x) && return x
277+
xmin::Float64 = ((x.bareinterval.lo) < 0.0) ? 0.0 : 1.0
278+
xmax::Float64 = ((x.bareinterval.hi) >= 0.0) ? 1.0 : 0.0
279+
return interval(xmin, xmax)
300280
end
301281

302282

@@ -333,11 +313,11 @@ end
333313
"""
334314
MC{N,T}(y::Interval{Float64})
335315
336-
Constructs a McCormick relaxation with the convex relaxation equal to `y.lo` and
337-
concave relaxation equal to `y.hi`.
316+
Constructs a McCormick relaxation with the convex relaxation equal to `y.bareinterval.lo` and
317+
concave relaxation equal to `y.bareinterval.hi`.
338318
"""
339319
function MC{N,T}(y::Interval{Float64}) where {N, T <: RelaxTag}
340-
MC{N,T}(y.lo, y.hi, y, zero(SVector{N,Float64}),
320+
MC{N,T}(y.bareinterval.lo, y.bareinterval.hi, y, zero(SVector{N,Float64}),
341321
zero(SVector{N,Float64}), true)
342322
end
343323

@@ -347,11 +327,11 @@ MC{N,T}(y::Float64)
347327
Constructs a McCormick relaxation with the convex relaxation equal to `y` and
348328
concave relaxation equal to `y`.
349329
"""
350-
MC{N,T}(y::Float64) where {N, T <: RelaxTag} = MC{N,T}(Interval{Float64}(y))
330+
MC{N,T}(y::Float64) where {N, T <: RelaxTag} = MC{N,T}(interval(y))
351331
function MC{N,T}(y::Y) where {N, T <: RelaxTag, Y <: AbstractIrrational}
352-
MC{N,T}(Interval{Float64}(y))
332+
MC{N,T}(interval(y))
353333
end
354-
MC{N,T}(y::Q) where {N, T <: RelaxTag, Q <: NumberNotRelax} = MC{N,T}(Interval{Float64}(y))
334+
MC{N,T}(y::Q) where {N, T <: RelaxTag, Q <: NumberNotRelax} = MC{N,T}(interval(y))
355335

356336
"""
357337
MC{N,T}(cv::Float64, cc::Float64)
@@ -360,7 +340,7 @@ Constructs a McCormick relaxation with the convex relaxation equal to `cv` and
360340
concave relaxation equal to `cc`.
361341
"""
362342
function MC{N,T}(cv::Float64, cc::Float64) where {N, T <: RelaxTag}
363-
MC{N,T}(cv, cc, Interval{Float64}(cv, cc), zero(SVector{N,Float64}),
343+
MC{N,T}(cv, cc, interval(cv, cc), zero(SVector{N,Float64}),
364344
zero(SVector{N,Float64}), true)
365345
end
366346
MC{N,T}(cv::Q, cc::R) where {N, T <: RelaxTag, Q <: NumberNotRelax, R <: NumberNotRelax} = MC{N,T}(Float64(cv), Float64(cc))
@@ -393,8 +373,8 @@ function MC{N,T}(x::MC{N,T}) where {N, T <: RelaxTag}
393373
end
394374

395375
Intv(x::MC) = x.Intv
396-
lo(x::MC) = x.Intv.lo
397-
hi(x::MC) = x.Intv.hi
376+
lo(x::MC) = x.Intv.bareinterval.lo
377+
hi(x::MC) = x.Intv.bareinterval.hi
398378
cc(x::MC) = x.cc
399379
cv(x::MC) = x.cv
400380
cc_grad(x::MC) = x.cc_grad
@@ -407,8 +387,8 @@ isthin(x::MC) = isthin(x.Intv)
407387

408388
function isone(x::MC)
409389
flag = true
410-
flag &= (x.Intv.lo == 1.0)
411-
flag &= (x.Intv.hi == 1.0)
390+
flag &= (x.Intv.bareinterval.lo == 1.0)
391+
flag &= (x.Intv.bareinterval.hi == 1.0)
412392
flag &= x.cnst
413393
return flag
414394
end
@@ -453,11 +433,11 @@ end
453433
"""
454434
MCNoGrad(y::Interval{Float64})
455435
456-
Constructs McCormick relaxation with convex relaxation equal to `y.lo` and
457-
concave relaxation equal to `y.hi`.
436+
Constructs McCormick relaxation with convex relaxation equal to `y.bareinterval.lo` and
437+
concave relaxation equal to `y.bareinterval.hi`.
458438
"""
459439
function MCNoGrad(y::Interval{Float64})
460-
MCNoGrad(y.lo, y.hi, y, true)
440+
MCNoGrad(y.bareinterval.lo, y.bareinterval.hi, y, true)
461441
end
462442

463443
"""
@@ -466,11 +446,11 @@ MCNoGrad(y::Float64)
466446
Constructs McCormick relaxation with convex relaxation equal to `y` and
467447
concave relaxation equal to `y`.
468448
"""
469-
MCNoGrad(y::Float64) = MCNoGrad(Interval{Float64}(y))
449+
MCNoGrad(y::Float64) = MCNoGrad(interval(y))
470450
function MCNoGrad(y::Y) where Y <: AbstractIrrational
471-
MCNoGrad(Interval{Float64}(y))
451+
MCNoGrad(interval(y))
472452
end
473-
MCNoGrad(y::Q) where Q <: NumberNotRelax = MCNoGrad(Interval{Float64}(y))
453+
MCNoGrad(y::Q) where Q <: NumberNotRelax = MCNoGrad(interval(y))
474454

475455
"""
476456
MCNoGrad(cv::Float64, cc::Float64)
@@ -479,12 +459,12 @@ Constructs McCormick relaxation with convex relaxation equal to `cv` and
479459
concave relaxation equal to `cc`.
480460
"""
481461
function MCNoGrad(cv::Float64, cc::Float64)
482-
MC{N,T}(cv, cc, Interval{Float64}(cv, cc), true)
462+
MC{N,T}(cv, cc, interval(cv, cc), true)
483463
end
484464

485465
Intv(x::MCNoGrad) = x.Intv
486-
lo(x::MCNoGrad) = x.Intv.lo
487-
hi(x::MCNoGrad) = x.Intv.hi
466+
lo(x::MCNoGrad) = x.Intv.bareinterval.lo
467+
hi(x::MCNoGrad) = x.Intv.bareinterval.hi
488468
cc(x::MCNoGrad) = x.cc
489469
cv(x::MCNoGrad) = x.cv
490470
cnst(x::MCNoGrad) = x.cnst
@@ -494,8 +474,8 @@ isthin(x::MCNoGrad) = isthin(x.Intv)
494474

495475
function isone(x::MCNoGrad)
496476
flag = true
497-
flag &= (x.Intv.lo == 1.0)
498-
flag &= (x.Intv.hi == 1.0)
477+
flag &= (x.Intv.bareinterval.lo == 1.0)
478+
flag &= (x.Intv.bareinterval.hi == 1.0)
499479
flag &= x.cnst
500480
return flag
501481
end

0 commit comments

Comments
 (0)