Skip to content

Commit

Permalink
bump some deps versions (#5)
Browse files Browse the repository at this point in the history
* bump some deps versions

* some fixes

* fix max_time

* improve CI config
  • Loading branch information
mohamed82008 authored May 11, 2022
1 parent b2cf2f2 commit 9bd69d2
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 13 deletions.
9 changes: 7 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
name: CI
on:
- push
- pull_request
pull_request:
branches:
- master
push:
branches:
- master
tags: '*'
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }} - ${{ github.event_name }}
Expand Down
6 changes: 3 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ Percival = "01435c0c-c90d-11e9-3788-63660f8fbccc"
Reexport = "189a3867-3050-52da-a836-e630ba90ab69"

[compat]
ADNLPModels = "0.1, 0.2, 0.3"
NLPModelsModifiers = "0.1, 0.2, 0.4"
ADNLPModels = "0.3"
NLPModelsModifiers = "0.5"
NonconvexCore = "1"
Parameters = "0.12"
Percival = "0.3.1"
Percival = "0.5"
Reexport = "1"
julia = "1"

Expand Down
40 changes: 37 additions & 3 deletions src/NonconvexPercival.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ end
function _percival(nlp;
T = eltype(nlp.meta.x0),
μ::Real = convert(T, 10),
max_iter::Int = 1000, max_time::Real = convert(T, Inf),
max_iter::Int = 1000, max_time::Real = Inf,
max_eval::Int = 100000, atol::Real = convert(T, 1e-6),
rtol::Real = convert(T, 1e-6), ctol::Real = convert(T, 1e-6),
first_order = true, memory = 5,
Expand All @@ -73,7 +73,7 @@ function _percival(nlp;
modifier = m -> begin
op = NLPModelsModifiers.LinearOperators.LBFGSOperator(T, m.meta.nvar; mem = memory)
return NLPModelsModifiers.LBFGSModel(m.meta, m, op)
end
end
_kwargs = (
max_iter = max_iter, max_time = max_time,
max_eval = max_eval, atol = atol, rtol = rtol,
Expand Down Expand Up @@ -162,7 +162,41 @@ function get_percival_problem(obj, ineq_constr, eq_constr, x0, xlb, xub)
end
lcon = [fill(convert(T, -Inf), ineq_nconstr); zeros(T, eq_nconstr)]
ucon = zeros(T, ineq_nconstr + eq_nconstr)
return ADNLPModels.ADNLPModel(obj, x0, xlb, xub, c, lcon, ucon, adbackend = ADNLPModels.ZygoteAD())
nlp = zygote_nlp_model(obj, x0, xlb, xub, c, lcon, ucon)
return nlp
end

function zygote_nlp_model(f, x0::S, lvar::S, uvar::S, c, lcon::S, ucon::S) where {S}
T = eltype(S)
y0 = fill!(similar(lcon), zero(T))
name::String = "Generic"
lin::AbstractVector{<:Integer} = Int[]
backend = ADNLPModels.ZygoteAD(0, 0)
AD = typeof(backend)
minimize::Bool = true
nvar = length(x0)
ncon = length(lcon)

nnzh = nvar * (nvar + 1) / 2
nnzj = nvar * ncon
meta = ADNLPModels.NLPModelMeta{T, S}(
nvar,
x0 = x0,
lvar = lvar,
uvar = uvar,
ncon = ncon,
y0 = y0,
lcon = lcon,
ucon = ucon,
nnzj = nnzj,
nnzh = nnzh,
lin = lin,
minimize = minimize,
islp = false,
name = name,
)
adbackend = AD(nvar, f, ncon; x0 = x0)
return ADNLPModels.ADNLPModel(meta, ADNLPModels.Counters(), adbackend, f, c)
end

end
10 changes: 5 additions & 5 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ alg = AugLag()

@testset "Simple constraints" begin
m = Model(f)
addvar!(m, [0.0, 0.0], [10.0, 10.0])
addvar!(m, [1e-4, 1e-4], [10.0, 10.0])
add_ineq_constraint!(m, x -> g(x, 2, 0))
add_ineq_constraint!(m, x -> g(x, -1, 1))
for first_order in (true, false)
Expand All @@ -20,7 +20,7 @@ end

@testset "Equality constraints" begin
m = Model(f)
addvar!(m, [0.0, 0.0], [10.0, 10.0])
addvar!(m, [1e-4, 1e-4], [10.0, 10.0])
add_ineq_constraint!(m, x -> g(x, 2, 0))
add_ineq_constraint!(m, x -> g(x, -1, 1))
add_eq_constraint!(m, x -> sum(x) - 1/3 - 8/27)
Expand All @@ -35,7 +35,7 @@ end
@testset "Equality constraints BigFloat" begin
T = BigFloat
m = Model(f)
addvar!(m, T.([0.0, 0.0]), T.([10.0, 10.0]))
addvar!(m, T.([1e-4, 1e-4]), T.([10.0, 10.0]))
add_ineq_constraint!(m, x -> g(x, T(2), T(0)))
add_ineq_constraint!(m, x -> g(x, T(-1), T(1)))
add_eq_constraint!(m, x -> sum(x) - T(1/3) - T(8/27))
Expand All @@ -51,7 +51,7 @@ end

@testset "Block constraints" begin
m = Model(f)
addvar!(m, [0.0, 0.0], [10.0, 10.0])
addvar!(m, [1e-4, 1e-4], [10.0, 10.0])
add_ineq_constraint!(m, FunctionWrapper(x -> [g(x, 2, 0), g(x, -1, 1)], 2))

for first_order in (true, false)
Expand All @@ -65,7 +65,7 @@ end
@testset "Infinite bounds" begin
@testset "Infinite upper bound" begin
m = Model(f)
addvar!(m, [0.0, 0.0], [Inf, Inf])
addvar!(m, [1e-4, 1e-4], [Inf, Inf])
add_ineq_constraint!(m, x -> g(x, 2, 0))
add_ineq_constraint!(m, x -> g(x, -1, 1))

Expand Down

0 comments on commit 9bd69d2

Please sign in to comment.