Skip to content

Commit 7b2073a

Browse files
distributed tests pass
1 parent e019b2c commit 7b2073a

File tree

6 files changed

+24
-71
lines changed

6 files changed

+24
-71
lines changed

Project.toml

+2-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ StaticArrays = "90137ffa-7385-5640-81b9-e52037218182"
2020
julia = "1"
2121

2222
[extras]
23+
OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed"
2324
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
2425

2526
[targets]
26-
test = ["Test"]
27+
test = ["OrdinaryDiffEq", "Test"]

src/direct.jl

-9
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,3 @@ end
3232
function simplified_expr(eq::Equation)
3333
Expr(:(=), simplified_expr(eq.lhs), simplified_expr(eq.rhs))
3434
end
35-
36-
macro I(ex)
37-
name = :ICompile
38-
ret = return quote
39-
macro $(esc(name))()
40-
esc($ex)
41-
end
42-
end
43-
end

src/utils.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ function build_function(rhss, vs, ps = (), args = (), conv = simplified_expr, ex
5252
fargs = ps == () ? :(u,$(args...)) : :(u,p,$(args...))
5353

5454
oop_ex = :(
55-
($(fargs.args...)) -> begin
55+
($(fargs.args...),) -> begin
5656
X = $let_expr
5757
T = promote_type(map(typeof,X)...)
5858
convert.(T,X)
@@ -71,7 +71,7 @@ function build_function(rhss, vs, ps = (), args = (), conv = simplified_expr, ex
7171
if expression == Val{true}
7272
return oop_ex, iip_ex
7373
else
74-
return GeneralizedGenerated.mk_function(oop_ex), GeneralizedGenerated.mk_function(iip_ex)
74+
return GeneralizedGenerated.mk_function(@__MODULE__,oop_ex), GeneralizedGenerated.mk_function(@__MODULE__,iip_ex)
7575
end
7676
end
7777

test/direct.jl

+6-46
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,11 @@ end
3636
eqs =*(y-x),
3737
x*-z)-y,
3838
x*y - β*z]
39-
f = eval(ModelingToolkit.build_function(eqs,[x,y,z],[σ,ρ,β]))
39+
f1,f2 = ModelingToolkit.build_function(eqs,[x,y,z],[σ,ρ,β])
40+
f = eval(f1)
4041
out = [1.0,2,3]
4142
o1 = f([1.0,2,3],[1.0,2,3])
43+
f = eval(f2)
4244
f(out,[1.0,2,3],[1.0,2,3])
4345
@test all(o1 .== out)
4446

@@ -55,45 +57,16 @@ function test_worldage()
5557
end
5658
test_worldage()
5759

58-
mac = @I begin
59-
@parameters σ() ρ() β()
60-
@variables x() y() z()
61-
62-
eqs =*(y-x),
63-
x*-z)-y,
64-
x*y - β*z]
65-
ModelingToolkit.build_function(eqs,[x,y,z],[σ,ρ,β])
66-
end
67-
f = @ICompile
68-
out = [1.0,2,3]
69-
o1 = f([1.0,2,3],[1.0,2,3])
70-
f(out,[1.0,2,3],[1.0,2,3])
71-
@test all(o1 .== out)
72-
73-
mac = @I begin
74-
@parameters σ ρ β
75-
@variables x y z
76-
77-
eqs =*(y-x),
78-
x*-z)-y,
79-
x*y - β*z]
80-
= ModelingToolkit.jacobian(eqs,[x,y,z])
81-
ModelingToolkit.build_function(∂,[x,y,z],[σ,ρ,β])
82-
end
83-
f = @ICompile
84-
out = zeros(3,3)
85-
o1 = f([1.0,2,3],[1.0,2,3])
86-
f(out,[1.0,2,3],[1.0,2,3])
87-
@test all(out .== o1)
88-
8960
## No parameters
9061
@variables x y z
9162
eqs = [(y-x)^2,
9263
x*(x-z)-y,
9364
x*y - y*z]
94-
f = eval(ModelingToolkit.build_function(eqs,[x,y,z]))
65+
f1,f2 = ModelingToolkit.build_function(eqs,[x,y,z])
66+
f = eval(f1)
9567
out = zeros(3)
9668
o1 = f([1.0,2,3])
69+
f = eval(f2)
9770
f(out,[1.0,2,3])
9871
@test all(out .== o1)
9972

@@ -108,16 +81,3 @@ function test_worldage()
10881
f_iip(out,[1.0,2,3])
10982
end
11083
test_worldage()
111-
112-
mac = @I begin
113-
@variables x y z
114-
eqs = [(y-x)^2,
115-
x*(x-z)-y,
116-
x*y - y*z]
117-
ModelingToolkit.build_function(eqs,[x,y,z])
118-
end
119-
f = @ICompile
120-
out = zeros(3)
121-
o1 = f([1.0,2,3])
122-
f(out,[1.0,2,3])
123-
@test all(out .== o1)

test/distributed.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ using Distributed
22
# add processes to workspace
33
addprocs(2)
44

5-
using ModelingToolkit
6-
using OrdinaryDiffEq
5+
@everywhere using ModelingToolkit, OrdinaryDiffEq
6+
using
77

88
# create the Lorenz system
99
@parameters t σ ρ β
@@ -24,7 +24,7 @@ ode_prob = ODEProblem(ode_func, u0, (0., 10.),params)
2424

2525
@everywhere begin
2626

27-
using DifferentialEquations
27+
using OrdinaryDiffEq
2828
using ModelingToolkit
2929

3030
function solve_lorenz(ode_problem)

test/system_construction.jl

+11-10
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ test_diffeq_inference("standard", de, t, (x, y, z), (σ, ρ, β))
3838
generate_function(de, [x,y,z], [σ,ρ,β])
3939
jac_expr = generate_jacobian(de)
4040
jac = calculate_jacobian(de)
41-
jacfun = eval(jac_expr)
41+
jacfun = eval(jac_expr[2])
4242
# iip
4343
f = ODEFunction(de, [x,y,z], [σ,ρ,β])
4444
Wfact, Wfact_t = ModelingToolkit.calculate_factorized_W(de)
@@ -52,22 +52,22 @@ J = zeros(3, 3)
5252
jacfun(J, u, p, t)
5353
FW = zeros(3, 3)
5454
FWt = zeros(3, 3)
55-
fw(FW, u, p, 0.2, 0.1)
56-
fwt(FWt, u, p, 0.2, 0.1)
55+
eval(fw[2])(FW, u, p, 0.2, 0.1)
56+
eval(fwt[2])(FWt, u, p, 0.2, 0.1)
5757
# oop
5858
f = ODEFunction(de, [x,y,z], [σ,ρ,β])
5959
fw, fwt = map(eval, ModelingToolkit.generate_factorized_W(de))
6060
du = @SArray zeros(3)
6161
u = SVector(1:3...)
6262
p = SVector(4:6...)
6363
@test f(u, p, 0.1) === @SArray [4, 0, -16]
64-
Sfw = fw(u, p, 0.2, 0.1)
64+
Sfw = eval(fw[1])(u, p, 0.2, 0.1)
6565
@test Sfw.L UnitLowerTriangular(FW)
6666
@test Sfw.U UpperTriangular(FW)
6767
sol = Sfw \ @SArray ones(3)
6868
@test sol isa SArray
6969
@test sol -(I - 0.2*J)\ones(3)
70-
Sfw_t = fwt(u, p, 0.2, 0.1)
70+
Sfw_t = eval(fwt[1])(u, p, 0.2, 0.1)
7171
@test Sfw_t.L UnitLowerTriangular(FWt)
7272
@test Sfw_t.U UpperTriangular(FWt)
7373
sol = Sfw_t \ @SArray ones(3)
@@ -82,7 +82,7 @@ sol = Sfw_t \ @SArray ones(3)
8282
de = ODESystem(eqs)
8383
test_diffeq_inference("global iv-varying", de, t, (x, y, z), (σ′, ρ, β))
8484
@test begin
85-
f = eval(generate_function(de, [x,y,z], [σ′,ρ,β]))
85+
f = eval(generate_function(de, [x,y,z], [σ′,ρ,β])[2])
8686
du = [0.0,0.0,0.0]
8787
f(du, [1.0,2.0,3.0], [x->x+7,2,3], 5.0)
8888
du [11, -3, -7]
@@ -95,7 +95,7 @@ sol = Sfw_t \ @SArray ones(3)
9595
de = ODESystem(eqs)
9696
test_diffeq_inference("single internal iv-varying", de, t, (x, y, z), (σ, ρ, β))
9797
@test begin
98-
f = eval(generate_function(de, [x,y,z], [σ,ρ,β]))
98+
f = eval(generate_function(de, [x,y,z], [σ,ρ,β])[2])
9999
du = [0.0,0.0,0.0]
100100
f(du, [1.0,2.0,3.0], [x->x+7,2,3], 5.0)
101101
du [11, -3, -7]
@@ -105,7 +105,7 @@ sol = Sfw_t \ @SArray ones(3)
105105
de = ODESystem(eqs)
106106
test_diffeq_inference("many internal iv-varying", de, t, (x,), (σ,))
107107
@test begin
108-
f = eval(generate_function(de, [x], [σ]))
108+
f = eval(generate_function(de, [x], [σ])[2])
109109
du = [0.0]
110110
f(du, [1.0], [t -> t + 2], 5.0)
111111
du [27561]
@@ -148,7 +148,7 @@ eqs = [0 ~ σ*(y-x),
148148
ns = NonlinearSystem(eqs, [x,y,z])
149149
test_nlsys_inference("standard", ns, (x, y, z), (σ, ρ, β))
150150
@test begin
151-
f = eval(generate_function(ns, [x,y,z], [σ,ρ,β]))
151+
f = eval(generate_function(ns, [x,y,z], [σ,ρ,β])[2])
152152
du = [0.0, 0.0, 0.0]
153153
f(du, [1,2,3], [1,2,3])
154154
du [1, -3, -7]
@@ -161,10 +161,11 @@ eqs = [D(x) ~ -A*x,
161161
D(y) ~ A*x - B*_x]
162162
de = ODESystem(eqs)
163163
@test begin
164-
f = eval(generate_function(de, [x,y], [A,B,C]))
164+
f = eval(generate_function(de, [x,y], [A,B,C])[2])
165165
du = [0.0,0.0]
166166
f(du, [1.0,2.0], [1,2,3], 0.0)
167167
du [-1, -1/3]
168+
f = eval(generate_function(de, [x,y], [A,B,C])[1])
168169
du f([1.0,2.0], [1,2,3], 0.0)
169170
end
170171

0 commit comments

Comments
 (0)