From a6ed5a3694381b2a2ced8cac46ed3de50d0e3210 Mon Sep 17 00:00:00 2001 From: lxvm Date: Thu, 22 Feb 2024 19:34:48 -0500 Subject: [PATCH 1/3] update tests --- test/interface.jl | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/test/interface.jl b/test/interface.jl index 2ac89e7..2ef5f42 100644 --- a/test/interface.jl +++ b/test/interface.jl @@ -54,8 +54,8 @@ end end DEU.parameters) dists = (Uniform(1, 2), Uniform(3, 4), truncated(Normal(0, 1), -5, 5)) gd = GenericDistribution(dists...) + x = [mean(d) for d in dists] @testset "DiffEq" begin - x = [mean(d) for d in dists] h(x, u, p) = x, p prob = ODEProblem(eoms[1], u0s[1], tspan, ps[1]) sm = SystemMap(prob, Tsit5(); saveat = 1.0) @@ -66,21 +66,21 @@ end end for foo in getters @constinferred foo(ep) end - f = @constinferred build_integrand(ep, Koopman(), Val(false)) + f = @constinferred build_integrand(ep, Koopman(), x, DEU.parameters(ep), nothing) @constinferred f(x, DEU.parameters(ep)) - fbatch = @constinferred build_integrand(ep, Koopman(), Val(true)) + fbatch = #= @constinferred =# build_integrand(ep, Koopman(), x, DEU.parameters(ep), 10) y = reshape(repeat(x, outer = 5), :, 5) dy = similar(y[1, :]) @constinferred fbatch(dy, y, DEU.parameters(ep)) # nout > 1 g2(soln, p) = [soln[1, end], soln[2, end]] - ep = @constinferred ExpectationProblem(sm, g2, h, gd; nout = 2) - f = @constinferred build_integrand(ep, Koopman(), Val(false)) + ep = @constinferred ExpectationProblem(sm, g2, h, gd) + f = @constinferred build_integrand(ep, Koopman(), x, DEU.parameters(ep), nothing) @constinferred f(x, DEU.parameters(ep)) - fbatch = @constinferred build_integrand(ep, Koopman(), Val(true)) + fbatch = #= @constinferred =# build_integrand(ep, Koopman(), x, DEU.parameters(ep), 10) y = reshape(repeat(x, outer = 5), :, 5) dy = similar(y[1:2, :]) @constinferred fbatch(dy, y, DEU.parameters(ep)) @@ -91,7 +91,7 @@ end end for foo in getters @constinferred foo(ep) end - f = @constinferred build_integrand(ep, Koopman(), Val(false)) + f = @constinferred build_integrand(ep, Koopman(), x, DEU.parameters(ep), nothing) @constinferred f([0.0, 1.0, 2.0], DEU.parameters(ep)) end end From 17fbcdc4aeaa434ed27ae318430cb26bf6baf5b3 Mon Sep 17 00:00:00 2001 From: lxvm Date: Thu, 22 Feb 2024 20:05:16 -0500 Subject: [PATCH 2/3] avoid some boxing --- src/expectation.jl | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/expectation.jl b/src/expectation.jl index 4c8a2bf..f3a3864 100644 --- a/src/expectation.jl +++ b/src/expectation.jl @@ -63,14 +63,14 @@ function build_integrand(prob::ExpectationProblem{F}, ::Koopman, mid, p, batch::Integer) where {F <: SystemMap} @unpack S, g, h, d = prob - prob_func = function (prob, i, repeat, x) # TODO is it better to make prob/output funcs outside of integrand, then call w/ closure? - u0, p = h((_make_view(x, i)), prob.u0, prob.p) - remake(prob, u0 = u0, p = p) + function prob_func(prob, i, repeat, x) # TODO is it better to make prob/output funcs outside of integrand, then call w/ closure? + u0, _p = h((_make_view(x, i)), prob.u0, prob.p) + remake(prob, u0 = u0, p = _p) end output_func(sol, i, x) = (g(sol, sol.prob.p) * pdf(d, (_make_view(x, i))), false) - function integrand_koopman_systemmap_batch(x, p) + function integrand_koopman_systemmap_batch(x, _) trajectories = size(x)[end] # TODO How to inject ensemble method in solve? currently in SystemMap, but does that make sense? ensprob = EnsembleProblem(S.prob; output_func = (sol, i) -> output_func(sol, i, x), From 32026749fa62a2a7f2cefc38b5ed2c955de07d89 Mon Sep 17 00:00:00 2001 From: lxvm Date: Thu, 22 Feb 2024 20:05:30 -0500 Subject: [PATCH 3/3] remove deprecated nout --- test/processnoise.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/processnoise.jl b/test/processnoise.jl index 5ad57f2..d256708 100644 --- a/test/processnoise.jl +++ b/test/processnoise.jl @@ -15,7 +15,7 @@ prob = SDEProblem(f, g, u0, (0.0, 1.0), noise = W) sm = ProcessNoiseSystemMap(prob, 8, LambaEM(), abstol = 1e-3, reltol = 1e-3) cov(x, u, p) = x, p observed(sol, p) = sol[:, end] -exprob = ExpectationProblem(sm, observed, cov; nout = length(u0)) +exprob = ExpectationProblem(sm, observed, cov) sol1 = solve(exprob, Koopman(), ireltol = 1e-3, iabstol = 1e-3, batch = 64, quadalg = CubaDivonne()) sol2 = solve(exprob, MonteCarlo(1_000_000))