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

Rename the package #2

Merged
merged 3 commits into from
Jul 31, 2023
Merged
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
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
name = "SIMDiffExamples"
name = "ExaModelsExamples"
uuid = "ff8351d9-12a3-4c2d-a61a-51dfbae68567"
authors = ["Sungho Shin <[email protected]>"]
version = "0.1.0"

[deps]
PowerModels = "c36e90e8-916a-50a6-bd94-075b64ef4655"
SIMDiff = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
ExaModels = "1037b233-b668-4ce9-9b63-f9f681f55dd2"
Printf = "de0858da-6303-5e67-8744-51eddeeeb8d7"
JuMP = "4076af6c-e467-56ae-b986-b466b2749572"
NLPModelsJuMP = "792afdf1-32c1-5681-94e0-d7bf7a5df49e"
1 change: 1 addition & 0 deletions ExaModelsExamples/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# ExaModelsExamples.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module SIMDiffExamples
module ExaModelsExamples

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

Expand Down Expand Up @@ -63,4 +63,4 @@ function parse_log(file)
end
end

end # module SIMDiffExamples
end # module ExaModelsExamples
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ function ADBenchmarkModel(m)
ADBenchmarkStats()
)
end
function ADBenchmarkModel(c::SIMDiff.Core; kwargs...)
m = SIMDiff.Model(c;kwargs...)
function ADBenchmarkModel(c::ExaModels.Core; kwargs...)
m = ExaModels.Model(c;kwargs...)
return ADBenchmarkModel(m)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,50 +18,50 @@ function distillation_column_model(T, S = Array, device = nothing)
itr1 = S(collect(Iterators.product(1:T,FT+1:NT)))
itr2 = S(collect(Iterators.product(0:T,0:NT+1)))

c = SIMDiff.Core(S)
c = ExaModels.Core(S)

xA = SIMDiff.variable(c, 0:T, 0:NT+1; start = .5)
yA = SIMDiff.variable(c, 0:T, 0:NT+1; start = .5)
u = SIMDiff.variable(c, 0:T; start = 1.)
V = SIMDiff.variable(c, 0:T; start = 1.)
L2 = SIMDiff.variable(c, 0:T; start = 1.)
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.)

SIMDiff.objective(c, (yA[t,1] - ybar)^2 for t=0:T)
SIMDiff.objective(c, ( u[t] - ubar)^2 for t=0:T)
ExaModels.objective(c, (yA[t,1] - ybar)^2 for t=0:T)
ExaModels.objective(c, ( u[t] - ubar)^2 for t=0:T)

SIMDiff.constraint(
ExaModels.constraint(
c,
xA[0,i] - xA0 for (i,xA0) in xA0s
)
SIMDiff.constraint(
ExaModels.constraint(
c,
(xA[t,0] - xA[t-1,0]) / dt - (1/Ac) * (yA[t,1] - xA[t,0]) for t=1:T)
SIMDiff.constraint(
ExaModels.constraint(
c, (xA[t,i] - xA[t-1,i]) / dt - (1/At) * (u[t] * D * (yA[t,i-1] - xA[t,i]) - V[t] * (yA[t,i] - yA[t,i+1]))
for (t,i) in itr0)
SIMDiff.constraint(
ExaModels.constraint(
c, (xA[t,FT] - xA[t-1,FT]) / dt - (1/At) * (
F * xAf + u[t] * D * xA[t,FT-1] - L2[t] * xA[t,FT]
- V[t] * (yA[t,FT] - yA[t,FT+1])
)
for t=1:T)
SIMDiff.constraint(
ExaModels.constraint(
c, (xA[t,i] - xA[t-1,i]) / dt - (1/At) * (
L2[t] * (yA[t,i-1] - xA[t,i]) - V[t] * (yA[t,i] - yA[t,i+1])
)
for (t,i) in itr1)
SIMDiff.constraint(
ExaModels.constraint(
c, (xA[t,NT+1] - xA[t-1,NT+1]) / dt - (1/Ar) * (
L2[t] * xA[t,NT] - (F - D) * xA[t,NT+1] - V[t] * yA[t,NT+1]
)
for t=1:T
)
SIMDiff.constraint(c, V[t] - u[t] * D - D for t in 0:T)
SIMDiff.constraint(c, L2[t]- u[t] * D - F for t in 0:T)
SIMDiff.constraint(c, yA[t,i] * (1-xA[t,i]) - alpha * xA[t,i] * (1-yA[t,i]) for (t,i) in itr2)
ExaModels.constraint(c, V[t] - u[t] * D - D for t in 0:T)
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 SIMDiff.Model(
return ExaModels.Model(
c; device = device
)
end
Expand All @@ -86,13 +86,13 @@ 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 = SIMDiff.Core()
# c = ExaModels.Core()

# xA = SIMDiff.variable(c, 0:T, 0:NT+1; start = .5)
# yA = SIMDiff.variable(c, 0:T, 0:NT+1; start = .5)
# u = SIMDiff.variable(c, 0:T; start = 1.)
# V = SIMDiff.variable(c, 0:T; start = 1.)
# L2 = SIMDiff.variable(c, 0:T; start = 1.)
# 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()

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
function luksan_vlcek_model(N, backend = nothing)

c = SIMDiff.Core(backend)
x = SIMDiff.variable(
c = ExaModels.Core(backend)
x = ExaModels.variable(
c, N;
start = (mod(i,2)==1 ? -1.2 : 1. for i=1:N)
)
SIMDiff.constraint(
ExaModels.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 in 1:N-2)
SIMDiff.objective(c, 100*(x[i-1]^2-x[i])^2+(x[i-1]-1)^2 for i in 2:N)
return SIMDiff.Model(c)
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)
end

function jump_luksan_vlcek_model(N)
Expand Down
48 changes: 24 additions & 24 deletions SIMDiffExamples/src/opf.jl → ExaModelsExamples/src/opf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ function jump_ac_power_model(file_name)
return model
end

convert_data(data::N, backend) where {names, N <: NamedTuple{names}} = NamedTuple{names}(SIMDiff.convert_array(d,backend) for d in data)
convert_data(data::N, backend) where {names, N <: NamedTuple{names}} = NamedTuple{names}(ExaModels.convert_array(d,backend) for d in data)
parse_ac_power_data(filename, backend) = convert_data(parse_ac_power_data(filename), backend)

function parse_ac_power_data(filename)
Expand Down Expand Up @@ -217,139 +217,139 @@ function ac_power_model(

data = parse_ac_power_data(filename, backend)

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

va = SIMDiff.variable(
va = ExaModels.variable(
w, length(data.bus);
)

vm = SIMDiff.variable(
vm = ExaModels.variable(
w,
length(data.bus);
start = fill!(similar(data.bus,Float64),1.),
lvar = data.vmin,
uvar = data.vmax
)
pg = SIMDiff.variable(
pg = ExaModels.variable(
w,
length(data.gen);
lvar = data.pmin,
uvar = data.pmax
)

qg = SIMDiff.variable(
qg = ExaModels.variable(
w,
length(data.gen);
lvar = data.qmin,
uvar = data.qmax
)

p = SIMDiff.variable(
p = ExaModels.variable(
w,
length(data.arc);
lvar = -data.rate_a,
uvar = data.rate_a
)

q = SIMDiff.variable(
q = ExaModels.variable(
w,
length(data.arc);
lvar = -data.rate_a,
uvar = data.rate_a
)

o = SIMDiff.objective(
o = ExaModels.objective(
w,
g.cost1 * pg[g.i]^2 + g.cost2 * pg[g.i] + g.cost3
for g in data.gen)

c1 = SIMDiff.constraint(
c1 = ExaModels.constraint(
w,
va[i] for i in data.ref_buses)

c2 = SIMDiff.constraint(
c2 = ExaModels.constraint(
w,
p[b.f_idx]
- b.c5*vm[b.f_bus]^2
- b.c3*(vm[b.f_bus]*vm[b.t_bus]*cos(va[b.f_bus]-va[b.t_bus]))
- b.c4*(vm[b.f_bus]*vm[b.t_bus]*sin(va[b.f_bus]-va[b.t_bus]))
for b in data.branch)

c3 = SIMDiff.constraint(
c3 = ExaModels.constraint(
w,
q[b.f_idx]
+ b.c6*vm[b.f_bus]^2
+ b.c4*(vm[b.f_bus]*vm[b.t_bus]*cos(va[b.f_bus]-va[b.t_bus]))
- b.c3*(vm[b.f_bus]*vm[b.t_bus]*sin(va[b.f_bus]-va[b.t_bus]))
for b in data.branch)

c4 = SIMDiff.constraint(
c4 = ExaModels.constraint(
w,
p[b.t_idx]
- b.c7*vm[b.t_bus]^2
- b.c1*(vm[b.t_bus]*vm[b.f_bus]*cos(va[b.t_bus]-va[b.f_bus]))
- b.c2*(vm[b.t_bus]*vm[b.f_bus]*sin(va[b.t_bus]-va[b.f_bus]))
for b in data.branch)

c5 = SIMDiff.constraint(
c5 = ExaModels.constraint(
w,
q[b.t_idx]
+ b.c8*vm[b.t_bus]^2
+ b.c2*(vm[b.t_bus]*vm[b.f_bus]*cos(va[b.t_bus]-va[b.f_bus]))
- b.c1*(vm[b.t_bus]*vm[b.f_bus]*sin(va[b.t_bus]-va[b.f_bus]))
for b in data.branch)

c6 = SIMDiff.constraint(
c6 = ExaModels.constraint(
w,
va[b.f_bus] - va[b.t_bus] for b in data.branch;
lcon = data.angmin,
ucon = data.angmax
)
c7 = SIMDiff.constraint(
c7 = ExaModels.constraint(
w,
p[b.f_idx]^2 + q[b.f_idx]^2 - b.rate_a_sq for b in data.branch;
lcon = fill!(similar(data.branch,Float64,length(data.branch)),-Inf)
)
c8 = SIMDiff.constraint(
c8 = ExaModels.constraint(
w,
p[b.t_idx]^2 + q[b.t_idx]^2 - b.rate_a_sq for b in data.branch;
lcon = fill!(similar(data.branch,Float64,length(data.branch)),-Inf)
)

c9 = SIMDiff.constraint(
c9 = ExaModels.constraint(
w,
+ b.pd
+ b.gs * vm[b.i]^2
for b in data.bus)

c10 = SIMDiff.constraint(
c10 = ExaModels.constraint(
w,
+ b.qd
- b.bs * vm[b.i]^2
for b in data.bus)

c11 = SIMDiff.constraint!(
c11 = ExaModels.constraint!(
w,
c9,
a.bus => p[a.i]
for a in data.arc)
c12 = SIMDiff.constraint!(
c12 = ExaModels.constraint!(
w,
c10,
a.bus => q[a.i]
for a in data.arc)

c13 = SIMDiff.constraint!(
c13 = ExaModels.constraint!(
w,
c9,
g.bus =>-pg[g.i]
for g in data.gen)
c14 = SIMDiff.constraint!(
c14 = ExaModels.constraint!(
w,
c10,
g.bus =>-qg[g.i]
for g in data.gen)

return SIMDiff.Model(w)
return ExaModels.Model(w)

end
Original file line number Diff line number Diff line change
Expand Up @@ -10,31 +10,31 @@ 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 = SIMDiff.Core(device)
c = ExaModels.Core(device)

x0s = SIMDiff.data(c, (i,0.) for i=1:n)
itr0 = SIMDiff.data(c, (i,j,R[j]) for (i,j) in Base.product(1:N,1:p))
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])

x= SIMDiff.variable(c,1:N+1,1:n)
u= SIMDiff.variable(c,1:N,1:p)
x= ExaModels.variable(c,1:N+1,1:n)
u= ExaModels.variable(c,1:N,1:p)

SIMDiff.constraint(c, x[1,i]-x0 for (i,x0) in x0s)
SIMDiff.constraint(c, -x[i+1,1] + x[i,1] + (x[i,2])*dt for i=1:N)
SIMDiff.constraint(c, -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 for i=1:N)
SIMDiff.constraint(c, -x[i+1,3] + x[i,3] + (x[i,4])*dt for i=1:N)
SIMDiff.constraint(c, -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 for i=1:N)
SIMDiff.constraint(c, -x[i+1,5] + x[i,5] + (x[i,6])*dt for i=1:N)
SIMDiff.constraint(c, -x[i+1,6] + x[i,6] + (u[i,1]*cos(x[i,7])*cos(x[i,8])-9.8)*dt for i=1:N)
SIMDiff.constraint(c, -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 for i=1:N)
SIMDiff.constraint(c, -x[i+1,8] + x[i,8] + (-u[i,2]*sin(x[i,7])+u[i,3]*cos(x[i,7]))*dt for i=1:N)
SIMDiff.constraint(c, -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 for i=1:N)
SIMDiff.objective(c, .5*R*(u[i,j]^2) for (i,j,R) in itr0)
SIMDiff.objective(c, .5*Q*(x[i,j]-d)^2 for (i,j,Q,d) in itr1)
SIMDiff.objective(c, .5*Qf*(x[N+1,j]-d)^2 for (j,Qf,d) in itr2)
ExaModels.constraint(c, x[1,i]-x0 for (i,x0) in x0s)
ExaModels.constraint(c, -x[i+1,1] + x[i,1] + (x[i,2])*dt for i=1:N)
ExaModels.constraint(c, -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 for i=1:N)
ExaModels.constraint(c, -x[i+1,3] + x[i,3] + (x[i,4])*dt for i=1:N)
ExaModels.constraint(c, -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 for i=1:N)
ExaModels.constraint(c, -x[i+1,5] + x[i,5] + (x[i,6])*dt for i=1:N)
ExaModels.constraint(c, -x[i+1,6] + x[i,6] + (u[i,1]*cos(x[i,7])*cos(x[i,8])-9.8)*dt for i=1:N)
ExaModels.constraint(c, -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 for i=1:N)
ExaModels.constraint(c, -x[i+1,8] + x[i,8] + (-u[i,2]*sin(x[i,7])+u[i,3]*cos(x[i,7]))*dt for i=1:N)
ExaModels.constraint(c, -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 for i=1:N)
ExaModels.objective(c, .5*R*(u[i,j]^2) for (i,j,R) in itr0)
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 SIMDiff.Model(c)
return ExaModels.Model(c)
end

function jump_quadrotor_model(N)
Expand Down
Loading
Loading