Skip to content
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
6 changes: 4 additions & 2 deletions docs/src/guide.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,17 @@ constraint(
c,
3x[i+1]^3 + 2 * x[i+2] - 5 + sin(x[i+1] - x[i+2])sin(x[i+1] + x[i+2]) + 4x[i+1] -
x[i]exp(x[i] - x[i+1]) - 3 for i = 1:(N-2);
lcon = -1.0, ucon = 1.0
lcon = -1.0,
ucon = 1.0,
)

# If you want to create a single-bounded constraint, you can set `lcon` to `-Inf` or `ucon` to `Inf`. For example, if we wanted to set the lower bound of the constraint to -1 and the upper bound to infinity, we could do it as follows:
constraint(
c,
3x[i+1]^3 + 2 * x[i+2] - 5 + sin(x[i+1] - x[i+2])sin(x[i+1] + x[i+2]) + 4x[i+1] -
x[i]exp(x[i] - x[i+1]) - 3 for i = 1:(N-2);
lcon = -1.0, ucon = Inf
lcon = -1.0,
ucon = Inf,
)

# ## ExaModel
Expand Down
14 changes: 7 additions & 7 deletions ext/ExaModelsMOI.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,9 +314,7 @@ function exafy_con(
func = MOI.get(moim, MOI.ConstraintFunction(), ci)
set = MOI.get(moim, MOI.ConstraintSet(), ci)
con_to_idx[ci] = offset + i
start = if MOI.supports(
moim, MOI.ConstraintPrimalStart(), typeof(ci)
)
start = if MOI.supports(moim, MOI.ConstraintPrimalStart(), typeof(ci))
MOI.get(moim, MOI.ConstraintPrimalStart(), ci)
else
nothing
Expand Down Expand Up @@ -457,10 +455,12 @@ function _exafy(i::R, var_to_idx, p) where {R<:Real}
end

function _exafy(e::MOI.ScalarNonlinearFunction, var_to_idx, p = ())
return op(e.head)((begin
c, p = _exafy(e, var_to_idx, p)
c
end for e in e.args)...), p
return op(e.head)((
begin
c, p = _exafy(e, var_to_idx, p)
c
end for e in e.args
)...), p
end

function _exafy(e::MOI.ScalarAffineFunction{T}, var_to_idx, p = ()) where {T}
Expand Down
13 changes: 8 additions & 5 deletions src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -115,11 +115,13 @@ end

@inline Base.getproperty(n::ParSource, s::Symbol) = ParIndexed(n, s)
@inline Base.getindex(n::ParSource, i) = ParIndexed(n, i)
@inline Base.indexed_iterate(n::P, idx, start = 1) where P <: Union{ParSource, ParIndexed} = (ParIndexed(n, idx), idx + 1)
@inline Base.indexed_iterate(n::P, idx, start = 1) where {P<:Union{ParSource,ParIndexed}} =
(ParIndexed(n, idx), idx + 1)

@inline Base.getproperty(v::ParIndexed{I, n}, s::Symbol) where {I, n} = ParIndexed(v, s)
@inline Base.getindex(v::ParIndexed{I, n}, i) where {I, n} = ParIndexed(v, i)
@inline Base.indexed_iterate(v::ParIndexed{I, n}, idx, start = 1) where {I, n} = (ParIndexed(v, idx), idx + 1)
@inline Base.getproperty(v::ParIndexed{I,n}, s::Symbol) where {I,n} = ParIndexed(v, s)
@inline Base.getindex(v::ParIndexed{I,n}, i) where {I,n} = ParIndexed(v, i)
@inline Base.indexed_iterate(v::ParIndexed{I,n}, idx, start = 1) where {I,n} =
(ParIndexed(v, idx), idx + 1)


@inline Base.getindex(n::VarSource, i) = Var(i)
Expand All @@ -144,7 +146,8 @@ struct Identity end
@inline (v::ParameterNode{I})(::Identity, x, ::Nothing) where {I<:AbstractNode} = NaN

@inline (v::ParSource)(i, x, θ) = i
@inline (v::ParIndexed{I,n})(i, x, θ) where {I,n} = @inbounds getfield(getfield(v, :inner)(i, x, θ), n)
@inline (v::ParIndexed{I,n})(i, x, θ) where {I,n} =
@inbounds getfield(getfield(v, :inner)(i, x, θ), n)

(v::ParIndexed)(i::Identity, x, θ) = NaN # despecialized
(v::ParSource)(i::Identity, x, θ) = NaN # despecialized
Expand Down
2 changes: 1 addition & 1 deletion src/simdfunction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ struct SIMDFunction{F,C1,C2}
end

@inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F,C1,C2} = sf.f(i, x, θ)
@inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F <: Real,C1,C2} = sf.f
@inline (sf::SIMDFunction{F,C1,C2})(i, x, θ) where {F<:Real,C1,C2} = sf.f

"""
SIMDFunction(gen::Base.Generator, o0 = 0, o1 = 0, o2 = 0)
Expand Down
13 changes: 9 additions & 4 deletions test/NLPTest/luksan_struct.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
struct I2
i::Tuple{Int, Int}
i::Tuple{Int,Int}
end

struct I1
Expand All @@ -9,10 +9,15 @@ end
function _exa_luksan_struct_model(backend, N; M = 1)

c = ExaCore(backend = backend)
data = [I1(I2((i,j))) for i = 1:N, j = 1:M]
data = [I1(I2((i, j))) for i = 1:N, j = 1:M]
x = variable(c, N, M; start = [luksan_vlcek_x0(i.i.i[1]) for i in data])
s = constraint(c, luksan_vlcek_con1(x, i.i.i[1], i.i.i[2]) for i in data[1:end-2,:])
constraint!(c, s, (i.i.i[1], i.i.i[2]) => luksan_vlcek_con2(x, i.i.i[1], i.i.i[2]) for i in data[1:end-2,:])
s = constraint(c, luksan_vlcek_con1(x, i.i.i[1], i.i.i[2]) for i in data[1:(end-2), :])
constraint!(
c,
s,
(i.i.i[1], i.i.i[2]) => luksan_vlcek_con2(x, i.i.i[1], i.i.i[2]) for
i in data[1:(end-2), :]
)
objective(c, luksan_vlcek_obj(x, i, j) for i = 2:N, j = 1:M)

return ExaModel(c; prod = true), (x,), (s,)
Expand Down