Skip to content
14 changes: 5 additions & 9 deletions src/graph.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,17 +113,13 @@ struct SecondFixed{F}
inner::F
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::ParSource, idx, start = 1) = (ParIndexed(n, idx), idx + 1)


@inline Base.getindex(n::VarSource, i) = Var(i)
@inline Base.getindex(::ParameterSource, i) = ParameterNode(i)
Par(iter::Type) = ParSource()
Par(iter, idx...) = ParIndexed(Par(iter, idx[2:end]...), idx[1])
Par(iter::Type{T}, idx...) where {T<:Tuple} =
Tuple(Par(p, i, idx...) for (i, p) in enumerate(T.parameters))

Par(iter::Type{T}, idx...) where {T<:NamedTuple} = NamedTuple{T.parameters[1]}(
Par(p, i, idx...) for (i, p) in enumerate(T.parameters[2].parameters)
)

@inline Node1(f::F, inner::I) where {F,I} = Node1{F,I}(inner)
@inline Node2(f::F, inner1::I1, inner2::I2) where {F,I1,I2} = Node2{F,I1,I2}(inner1, inner2)
Expand All @@ -144,7 +140,7 @@ 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 v.inner(i, x, θ)[n]
@inline (v::ParIndexed{I,n})(i, x, θ) where {I,n} = @inbounds 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 @@ -37,7 +37,7 @@ Returns a `SIMDFunction` using the `gen`.
"""
function SIMDFunction(gen::Base.Generator, o0 = 0, o1 = 0, o2 = 0)

f = gen.f(Par(eltype(gen.iter)))
f = gen.f(ParSource())

_simdfunction(f, o0, o1, o2)
end
Expand Down
5 changes: 4 additions & 1 deletion test/NLPTest/NLPTest.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const NLP_TEST_ARGUMENTS = [
("luksan_vlcek", 20),
("ac_power", "pglib_opf_case3_lmbd.m"),
("ac_power", "pglib_opf_case14_ieee.m"),
("struct_ac_power", "pglib_opf_case3_lmbd.m"),
("struct_ac_power", "pglib_opf_case14_ieee.m"),
]

const SOLVERS = [
Expand All @@ -20,7 +22,7 @@ const SOLVERS = [
("percival", nlp -> percival(nlp)),
]

const EXCLUDE1 = [("ac_power", "percival")]
const EXCLUDE1 = [("ac_power", "percival"), ("struct_ac_power", "percival")]
const EXCLUDE2 = []

for backend in BACKENDS
Expand All @@ -32,6 +34,7 @@ end
include("luksan.jl")
include("power.jl")
include("parameter_test.jl")
include("power_struct.jl")

function test_nlp(m1, m2; full = false)
@testset "NLP meta tests" begin
Expand Down
5 changes: 4 additions & 1 deletion test/NLPTest/power.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ function parse_ac_power_data(filename)
end

function _exa_ac_power_model(backend, filename)

data = parse_ac_power_data(filename, backend)
__exa_ac_power_model(backend, data)
end

function __exa_ac_power_model(backend, data)

w = ExaModels.ExaCore(backend = backend)

va = ExaModels.variable(w, length(data.bus);)
Expand Down
16 changes: 16 additions & 0 deletions test/NLPTest/power_struct.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
struct BusData{T}
i::Int
pd::T
gs::T
qd::T
bs::T
end

function parse_struct_ac_power_data(filename)
(;parse_ac_power_data(filename)...,
bus = [BusData(b.i, b.pd, b.gs, b.qd, b.bs) for b in parse_ac_power_data(filename).bus]
)
end

_exa_struct_ac_power_model(backend, filename) = __exa_ac_power_model(backend, parse_struct_ac_power_data(filename))
_jump_struct_ac_power_model(backend, filename) = _jump_ac_power_model(backend, filename)
Loading