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

Name changes and docstrings added #6

Merged
merged 17 commits into from
Aug 9, 2023
19 changes: 19 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,22 @@ jobs:
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
test-moonshot:
env:
JULIA_DEPOT_PATH: /scratch/sshin/github-actions/julia_depot_madnlp
runs-on: self-hosted
strategy:
matrix:
julia-version: ['1.9']
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
with:
file: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
9 changes: 7 additions & 2 deletions ExaModelsExamples/src/ExaModelsExamples.jl
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
module ExaModelsExamples

import ExaModels: ExaModels, NLPModels
import JuMP, NLPModelsJuMP
import PowerModels: PowerModels, silence
using JuMP, NLPModelsJuMP

include("adbenchmarkmodel.jl")
include("opf.jl")
include("luksanvlcek.jl")
include("distillation.jl")
Expand Down Expand Up @@ -63,4 +62,10 @@ function parse_log(file)
end
end

for name in filter(names(ExaModelsExamples; all=true)) do x
endswith(string(x), "model")
end
@eval export $name
end

end # module ExaModelsExamples
144 changes: 0 additions & 144 deletions ExaModelsExamples/src/adbenchmarkmodel.jl

This file was deleted.

25 changes: 7 additions & 18 deletions ExaModelsExamples/src/distillation.jl
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
function distillation_column_model(T, S = Array, device = nothing)
function distillation_column_model(T, backend = nothing)

NT = 30
FT = 17
Expand All @@ -12,13 +12,13 @@ function distillation_column_model(T, S = Array, device = nothing)
alpha= 1.6
dt = 10/T
xAf = 0.5
xA0s = S([(i,0.5) for i in 0:NT+1])
xA0s = ExaModels.convert_array([(i,0.5) for i in 0:NT+1], backend)

itr0 = S(collect(Iterators.product(1:T,1:FT-1)))
itr1 = S(collect(Iterators.product(1:T,FT+1:NT)))
itr2 = S(collect(Iterators.product(0:T,0:NT+1)))
itr0 = ExaModels.convert_array(collect(Iterators.product(1:T,1:FT-1)), backend)
itr1 = ExaModels.convert_array(collect(Iterators.product(1:T,FT+1:NT)), backend)
itr2 = ExaModels.convert_array(collect(Iterators.product(0:T,0:NT+1)), backend)

c = ExaModels.Core(S)
c = ExaModels.ExaCore(backend)

xA = ExaModels.variable(c, 0:T, 0:NT+1; start = .5)
yA = ExaModels.variable(c, 0:T, 0:NT+1; start = .5)
Expand Down Expand Up @@ -60,10 +60,7 @@ function distillation_column_model(T, S = Array, device = nothing)
ExaModels.constraint(c, L2[t]- u[t] * D - F for t in 0:T)
ExaModels.constraint(c, yA[t,i] * (1-xA[t,i]) - alpha * xA[t,i] * (1-yA[t,i]) for (t,i) in itr2)

# Iterators.product
return ExaModels.Model(
c; device = device
)
return ExaModels.ExaModel(c)
end

function jump_distillation_column_model(T)
Expand All @@ -86,14 +83,6 @@ function jump_distillation_column_model(T)
itr1 = collect(Iterators.product(1:T,FT+1:NT))
itr2 = collect(Iterators.product(0:T,0:NT+1))

# c = ExaModels.Core()

# xA = ExaModels.variable(c, 0:T, 0:NT+1; start = .5)
# yA = ExaModels.variable(c, 0:T, 0:NT+1; start = .5)
# u = ExaModels.variable(c, 0:T; start = 1.)
# V = ExaModels.variable(c, 0:T; start = 1.)
# L2 = ExaModels.variable(c, 0:T; start = 1.)

m = JuMP.Model()

JuMP.@variable(m, xA[0:T,0:NT+1], start = .5)
Expand Down
4 changes: 2 additions & 2 deletions ExaModelsExamples/src/luksanvlcek.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
function luksan_vlcek_model(N, backend = nothing)

c = ExaModels.Core(backend)
c = ExaModels.ExaCore(backend)
x = ExaModels.variable(
c, N;
start = (mod(i,2)==1 ? -1.2 : 1. for i=1:N)
Expand All @@ -10,7 +10,7 @@ function luksan_vlcek_model(N, backend = nothing)
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 in 1:N-2)
ExaModels.objective(c, 100*(x[i-1]^2-x[i])^2+(x[i-1]-1)^2 for i in 2:N)
return ExaModels.Model(c)
return ExaModels.ExaModel(c)
end

function jump_luksan_vlcek_model(N)
Expand Down
5 changes: 3 additions & 2 deletions ExaModelsExamples/src/opf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ function ac_power_model(

data = parse_ac_power_data(filename, backend)

w = ExaModels.Core(T, backend)
w = ExaModels.ExaCore(T, backend)

va = ExaModels.variable(
w, length(data.bus);
Expand Down Expand Up @@ -350,6 +350,7 @@ function ac_power_model(
g.bus =>-qg[g.i]
for g in data.gen)

return ExaModels.Model(w)
return ExaModels.ExaModel(w)

end

41 changes: 20 additions & 21 deletions ExaModelsExamples/src/quadrotor.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
function quadrotor_model(N,device=nothing)
S = Array
function quadrotor_model(N,backend=nothing)

n = 9
p = 4
Expand All @@ -10,12 +9,12 @@ function quadrotor_model(N,device=nothing)
Q = [1,0,1,0,1,0,1,1,1]
Qf= [1,0,1,0,1,0,1,1,1]/dt

c = ExaModels.Core(device)
c = ExaModels.ExaCore(backend)

x0s = ExaModels.data(c, (i,0.) for i=1:n)
itr0 = ExaModels.data(c, (i,j,R[j]) for (i,j) in Base.product(1:N,1:p))
itr1 = S([(i,j,Q[j],d(i,j,N)) for (i,j) in Base.product(1:N,1:n)])
itr2 = S([(j,Qf[j],d(N+1,j,N)) for j in 1:n])
x0s = ExaModels.convert_array([(i,0.) for i=1:n], backend)
itr0 = ExaModels.convert_array([(i,j,R[j]) for (i,j) in Base.product(1:N,1:p)], backend)
itr1 = ExaModels.convert_array([(i,j,Q[j],d(i,j,N)) for (i,j) in Base.product(1:N,1:n)], backend)
itr2 = ExaModels.convert_array([(j,Qf[j],d(N+1,j,N)) for j in 1:n], backend)

x= ExaModels.variable(c,1:N+1,1:n)
u= ExaModels.variable(c,1:N,1:p)
Expand All @@ -34,7 +33,7 @@ function quadrotor_model(N,device=nothing)
ExaModels.objective(c, .5*Q*(x[i,j]-d)^2 for (i,j,Q,d) in itr1)
ExaModels.objective(c, .5*Qf*(x[N+1,j]-d)^2 for (j,Qf,d) in itr2)

return ExaModels.Model(c)
return ExaModels.ExaModel(c)
end

function jump_quadrotor_model(N)
Expand All @@ -49,19 +48,19 @@ function jump_quadrotor_model(N)
R = ones(4)/10

m = JuMP.Model()
@variable(m,x[1:N+1,1:n],start = 0)
@variable(m,u[1:N,1:p],start = 0)
@constraint(m,[i=1:n],x[1,i]==x0[i])
@constraint(m,[i=1:N],x[i+1,1] == x[i,1] + (x[i,2])*dt)
@NLconstraint(m,[i=1:N], x[i+1,2] == x[i,2] + (u[i,1]*cos(x[i,7])*sin(x[i,8])*cos(x[i,9])+u[i,1]*sin(x[i,7])*sin(x[i,9]))*dt)
@constraint(m,[i=1:N], x[i+1,3] == x[i,3] + (x[i,4])*dt)
@NLconstraint(m,[i=1:N], x[i+1,4] == x[i,4] + (u[i,1]*cos(x[i,7])*sin(x[i,8])*sin(x[i,9])-u[i,1]*sin(x[i,7])*cos(x[i,9]))*dt)
@constraint(m,[i=1:N], x[i+1,5] == x[i,5] + (x[i,6])*dt)
@NLconstraint(m,[i=1:N], x[i+1,6] == x[i,6] + (u[i,1]*cos(x[i,7])*cos(x[i,8])-9.8)*dt)
@NLconstraint(m,[i=1:N], x[i+1,7] == x[i,7] + (u[i,2]*cos(x[i,7])/cos(x[i,8])+u[i,3]*sin(x[i,7])/cos(x[i,8]))*dt)
@NLconstraint(m,[i=1:N], x[i+1,8] == x[i,8] + (-u[i,2]*sin(x[i,7])+u[i,3]*cos(x[i,7]))*dt)
@NLconstraint(m,[i=1:N], x[i+1,9] == x[i,9] + (u[i,2]*cos(x[i,7])*tan(x[i,8])+u[i,3]*sin(x[i,7])*tan(x[i,8])+u[i,4])*dt)
@objective(m,Min, .5*sum(Q[j]*(x[i,j]-d(i,j,N))^2 for i=1:N for j=1:n) + .5*sum(R[j]*(u[i,j]^2) for i=1:N for j=1:p)
JuMP.@variable(m,x[1:N+1,1:n],start = 0)
JuMP.@variable(m,u[1:N,1:p],start = 0)
JuMP.@constraint(m,[i=1:n],x[1,i]==x0[i])
JuMP.@constraint(m,[i=1:N],x[i+1,1] == x[i,1] + (x[i,2])*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,2] == x[i,2] + (u[i,1]*cos(x[i,7])*sin(x[i,8])*cos(x[i,9])+u[i,1]*sin(x[i,7])*sin(x[i,9]))*dt)
JuMP.@constraint(m,[i=1:N], x[i+1,3] == x[i,3] + (x[i,4])*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,4] == x[i,4] + (u[i,1]*cos(x[i,7])*sin(x[i,8])*sin(x[i,9])-u[i,1]*sin(x[i,7])*cos(x[i,9]))*dt)
JuMP.@constraint(m,[i=1:N], x[i+1,5] == x[i,5] + (x[i,6])*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,6] == x[i,6] + (u[i,1]*cos(x[i,7])*cos(x[i,8])-9.8)*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,7] == x[i,7] + (u[i,2]*cos(x[i,7])/cos(x[i,8])+u[i,3]*sin(x[i,7])/cos(x[i,8]))*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,8] == x[i,8] + (-u[i,2]*sin(x[i,7])+u[i,3]*cos(x[i,7]))*dt)
JuMP.@NLconstraint(m,[i=1:N], x[i+1,9] == x[i,9] + (u[i,2]*cos(x[i,7])*tan(x[i,8])+u[i,3]*sin(x[i,7])*tan(x[i,8])+u[i,4])*dt)
JuMP.@objective(m,Min, .5*sum(Q[j]*(x[i,j]-d(i,j,N))^2 for i=1:N for j=1:n) + .5*sum(R[j]*(u[i,j]^2) for i=1:N for j=1:p)
+ .5*sum(Qf[j]*(x[N+1,j]-d(N+1,j,N))^2 for j=1:n))
return m
end
12 changes: 7 additions & 5 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ version = "0.1.0"

[deps]
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
SolverCore = "ff4d7338-4cf1-434d-91df-b86cb86fb843"

[weakdeps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand All @@ -19,18 +20,19 @@ ExaModelsOneAPI = "oneAPI"
ExaModelsSpecialFunctions = "SpecialFunctions"

[compat]
julia = "1.9"
NLPModels = "0.20"
SpecialFunctions = "2"
KernelAbstractions = "0.9"
SolverCore = "0.3"
CUDA = "4"
KernelAbstractions = "0.9"
SpecialFunctions = "2"
oneAPI = "1"
julia = "1.9"

[extras]
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
ADNLPModels = "54578032-b7ea-4c30-94aa-7cbd1cce6c9a"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
ExaModelsExaples = "ff8351d9-12a3-4c2d-a61a-51dfbae68567"
NLPModels = "a4795742-8479-5a88-8948-cc11e1c8c1a6"
NLPModelsIpopt = "f4238b75-b362-5c4c-b852-0801c9a21d71"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
Expand Down
12 changes: 6 additions & 6 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@ for jl_filename in _JL_FILENAMES
end


# makedocs(
# sitename = "ExaModels.jl",
# authors = "Sungho Shin",
# format = Documenter.LaTeX(platform="docker"),
# pages = _PAGES
# )
makedocs(
sitename = "ExaModels.jl",
authors = "Sungho Shin",
format = Documenter.LaTeX(platform="docker"),
pages = _PAGES
)

makedocs(
sitename = "ExaModels.jl",
Expand Down
Loading
Loading