Skip to content

Commit c380453

Browse files
Merge branch 'master' into master
2 parents 6189427 + 60bced2 commit c380453

12 files changed

+52
-64
lines changed

lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ function test_2d_poisson_equation_adaptive_loss(adaptive_loss, run, outdir, hasl
8888
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.03); maxiters = maxiters,
8989
callback = callback)
9090

91-
u_predict = reshape([first(phi([x, y], res.minimizer)) for x in xs for y in ys],
91+
u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
9292
(length(xs), length(ys)))
9393
diff_u = abs.(u_predict .- u_real)
9494
total_diff = sum(diff_u)

src/advancedHMC_MCMC.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ function getlogpdf(strategy::QuadratureTraining, Tar::LogTargetDensity, f,
176176
function integrand(t::Number, θ)
177177
innerdiff(Tar, f, autodiff, [t], θ, ode_params)
178178
end
179-
intprob = IntegralProblem(integrand, tspan[1], tspan[2], θ; nout = length(Tar.prob.u0))
179+
intprob = IntegralProblem(integrand, (tspan[1], tspan[2]), θ; nout = length(Tar.prob.u0))
180180
sol = solve(intprob, QuadGKJL(); abstol = strategy.abstol, reltol = strategy.reltol)
181181
sum(sol.u)
182182
end

src/discretize.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ function get_numeric_integral(pinnrep::PINNRepresentation)
317317
ChainRulesCore.@ignore_derivatives @views(cord_[integrating_var_id]) .= x
318318
return integrand_func(cord_, p, phi, derivative, nothing, u, nothing)
319319
end
320-
prob_ = IntegralProblem(integrand_, lb, ub, θ)
320+
prob_ = IntegralProblem(integrand_, (lb, ub), θ)
321321
sol = solve(prob_, CubatureJLh(), reltol = 1e-3, abstol = 1e-3)[1]
322322

323323
return sol

src/ode_solve.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ function generate_loss(strategy::QuadratureTraining, phi, f, autodiff::Bool, tsp
232232
@assert batch == 0 # not implemented
233233

234234
function loss(θ, _)
235-
intprob = IntegralProblem(integrand, tspan[1], tspan[2], θ)
235+
intprob = IntegralProblem(integrand, (tspan[1], tspan[2]), θ)
236236
sol = solve(intprob, QuadGKJL(); abstol = strategy.abstol, reltol = strategy.reltol)
237237
sol.u
238238
end

src/training_strategies.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,7 @@ function get_loss_function(loss_function, lb, ub, eltypeθ, strategy::Quadrature
315315
sum(abs2, view(loss_(x, θ), 1, :), dims = 2) #./ size_x
316316
end
317317
integral_function = BatchIntegralFunction(integrand, max_batch = strategy.batch)
318-
prob = IntegralProblem(integral_function, lb, ub, θ)
318+
prob = IntegralProblem(integral_function, (lb, ub), θ)
319319
solve(prob,
320320
strategy.quadrature_alg,
321321
reltol = strategy.reltol,

test/IDE_tests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ end
3030
phi = discretization.phi
3131
analytic_sol_func(t) = 1 / 2 * (exp(-t)) * (sin(2 * t))
3232
u_real = [analytic_sol_func(t) for t in ts]
33-
u_predict = [first(phi([t], res.minimizer)) for t in ts]
33+
u_predict = [first(phi([t], res.u)) for t in ts]
3434
@test Flux.mse(u_real, u_predict) < 0.01
3535
end
3636

@@ -54,7 +54,7 @@ eq = Ix(u(x) * cos(x)) ~ (x^3) / 3
5454
maxiters = 200)
5555
xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
5656
phi = discretization.phi
57-
u_predict = [first(phi([x], res.minimizer)) for x in xs]
57+
u_predict = [first(phi([x], res.u)) for x in xs]
5858
u_real = [x^2 / cos(x) for x in xs]
5959
@test Flux.mse(u_real, u_predict) < 0.001
6060
end
@@ -78,7 +78,7 @@ end
7878
ys = 0.00:0.01:1.00
7979
phi = discretization.phi
8080
u_real = collect(1 - x^2 - y^2 for y in ys, x in xs);
81-
u_predict = collect(Array(phi([x, y], res.minimizer))[1] for y in ys, x in xs);
81+
u_predict = collect(Array(phi([x, y], res.u))[1] for y in ys, x in xs);
8282
@test Flux.mse(u_real, u_predict) < 0.001
8383
end
8484

@@ -101,7 +101,7 @@ end
101101
ys = 0.00:0.01:1.00
102102
phi = discretization.phi
103103
u_real = collect(x + y^2 for y in ys, x in xs);
104-
u_predict = collect(Array(phi([x, y], res.minimizer))[1] for y in ys, x in xs);
104+
u_predict = collect(Array(phi([x, y], res.u))[1] for y in ys, x in xs);
105105
@test Flux.mse(u_real, u_predict) < 0.01
106106
end
107107

@@ -144,7 +144,7 @@ end
144144
res = solve(prob, OptimizationOptimJL.BFGS(); callback = callback, maxiters = 200)
145145
xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
146146
phi = discretization.phi
147-
u_predict = [first(phi([x], res.minimizer)) for x in xs]
147+
u_predict = [first(phi([x], res.u)) for x in xs]
148148
u_real = [1 / x^2 for x in xs]
149149
@test u_realu_predict rtol=10^-2
150150
end
@@ -163,7 +163,7 @@ end
163163
res = solve(prob, OptimizationOptimJL.BFGS(); callback = callback, maxiters = 300)
164164
xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
165165
phi = discretization.phi
166-
u_predict = [first(phi([x], res.minimizer)) for x in xs]
166+
u_predict = [first(phi([x], res.u)) for x in xs]
167167
u_real = [1 / x^2 for x in xs]
168168
@test u_realu_predict rtol=10^-2
169169
end

test/NNPDE_tests.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ function test_ode(strategy_)
4040
prob = discretize(pde_system, discretization)
4141

4242
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.1); maxiters = 1000)
43-
prob = remake(prob, u0 = res.minimizer)
43+
prob = remake(prob, u0 = res.u)
4444
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 500)
45-
prob = remake(prob, u0 = res.minimizer)
45+
prob = remake(prob, u0 = res.u)
4646
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.001); maxiters = 500)
4747
phi = discretization.phi
4848
analytic_sol_func(t) = exp(-(t^2) / 2) / (1 + t + t^3) + t^2
4949
ts = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
5050
u_real = [analytic_sol_func(t) for t in ts]
51-
u_predict = [first(phi(t, res.minimizer)) for t in ts]
51+
u_predict = [first(phi(t, res.u)) for t in ts]
5252
@test u_predictu_real atol=0.1
5353
end
5454

@@ -183,7 +183,7 @@ function test_2d_poisson_equation(chain_, strategy_)
183183
xs, ys = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
184184
analytic_sol_func(x, y) = (sin(pi * x) * sin(pi * y)) / (2pi^2)
185185

186-
u_predict = reshape([first(phi([x, y], res.minimizer)) for x in xs for y in ys],
186+
u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
187187
(length(xs), length(ys)))
188188
u_real = reshape([analytic_sol_func(x, y) for x in xs for y in ys],
189189
(length(xs), length(ys)))
@@ -431,14 +431,14 @@ end
431431
@named pde_system = PDESystem(eq, bcs, domains, [θ], [u])
432432
prob = discretize(pde_system, discretization)
433433
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.1); maxiters = 1000)
434-
prob = remake(prob, u0 = res.minimizer)
434+
prob = remake(prob, u0 = res.u)
435435
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 500)
436-
prob = remake(prob, u0 = res.minimizer)
436+
prob = remake(prob, u0 = res.u)
437437
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.001); maxiters = 500)
438438
phi = discretization.phi
439439
analytic_sol_func(t) = exp(-(t^2) / 2) / (1 + t + t^3) + t^2
440440
ts = [infimum(d.domain):0.01:supremum(d.domain) for d in domains][1]
441441
u_real = [analytic_sol_func(t) for t in ts]
442-
u_predict = [first(phi(t, res.minimizer)) for t in ts]
442+
u_predict = [first(phi(t, res.u)) for t in ts]
443443
@test u_predictu_real atol=0.1
444444
end

test/NNPDE_tests_gpu_Lux.jl

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ const gpud = gpu_device()
5252
analytic_sol_func(t) = exp(-(t^2) / 2) / (1 + t + t^3) + t^2
5353
ts = [infimum(d.domain):(dt / 10):supremum(d.domain) for d in domains][1]
5454
u_real = [analytic_sol_func(t) for t in ts]
55-
u_predict = [first(Array(phi([t], res.minimizer))) for t in ts]
55+
u_predict = [first(Array(phi([t], res.u))) for t in ts]
5656
@test u_predictu_real atol=0.2
5757
end
5858

@@ -86,12 +86,12 @@ end
8686
discretization = PhysicsInformedNN(chain, strategy; init_params = ps)
8787
prob = discretize(pdesys, discretization)
8888
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 1000)
89-
prob = remake(prob, u0 = res.minimizer)
89+
prob = remake(prob, u0 = res.u)
9090
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.001); maxiters = 1000)
9191
phi = discretization.phi
9292
u_exact = (t, x) -> exp.(-t) * cos.(x)
9393
ts, xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
94-
u_predict = reshape([first(Array(phi([t, x], res.minimizer))) for t in ts for x in xs],
94+
u_predict = reshape([first(Array(phi([t, x], res.u))) for t in ts for x in xs],
9595
(length(ts), length(xs)))
9696
u_real = reshape([u_exact(t, x) for t in ts for x in xs], (length(ts), length(xs)))
9797
diff_u = abs.(u_predict .- u_real)
@@ -130,12 +130,12 @@ end
130130
discretization = PhysicsInformedNN(chain, strategy; init_params = ps)
131131
prob = discretize(pdesys, discretization)
132132
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.1); maxiters = 2000)
133-
prob = remake(prob, u0 = res.minimizer)
133+
prob = remake(prob, u0 = res.u)
134134
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 2000)
135135
phi = discretization.phi
136136
u_exact = (t, x) -> exp(-t) * cos(x)
137137
ts, xs = [infimum(d.domain):0.01:supremum(d.domain) for d in domains]
138-
u_predict = reshape([first(Array(phi([t, x], res.minimizer))) for t in ts for x in xs],
138+
u_predict = reshape([first(Array(phi([t, x], res.u))) for t in ts for x in xs],
139139
(length(ts), length(xs)))
140140
u_real = reshape([u_exact(t, x) for t in ts for x in xs], (length(ts), length(xs)))
141141
diff_u = abs.(u_predict .- u_real)
@@ -184,12 +184,12 @@ end
184184
@named pde_system = PDESystem(eq, bcs, domains, [t, x, y], [u(t, x, y)])
185185
prob = discretize(pde_system, discretization)
186186
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.01); maxiters = 2500)
187-
prob = remake(prob, u0 = res.minimizer)
187+
prob = remake(prob, u0 = res.u)
188188
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.001); maxiters = 2500)
189189
phi = discretization.phi
190190
ts, xs, ys = [infimum(d.domain):0.1:supremum(d.domain) for d in domains]
191191
u_real = [analytic_sol_func(t, x, y) for t in ts for x in xs for y in ys]
192-
u_predict = [first(Array(phi([t, x, y], res.minimizer))) for t in ts for x in xs
192+
u_predict = [first(Array(phi([t, x, y], res.u))) for t in ts for x in xs
193193
for y in ys]
194194

195195
@test u_predictu_real rtol=0.2

test/adaptive_loss_tests.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ function test_2d_poisson_equation_adaptive_loss(adaptive_loss; seed = 60, maxite
6060
return false
6161
end
6262
res = solve(prob, OptimizationOptimisers.Adam(0.03); maxiters = maxiters, callback = callback)
63-
u_predict = reshape([first(phi([x, y], res.minimizer)) for x in xs for y in ys],
63+
u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
6464
(length(xs), length(ys)))
6565
diff_u = abs.(u_predict .- u_real)
6666
total_diff = sum(diff_u)

test/additional_loss_tests.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ using ComponentArrays
4343
function inner_f(x, θ)
4444
dx * phi(x, θ) .- 1
4545
end
46-
prob1 = IntegralProblem(inner_f, lb, ub, θ)
46+
prob1 = IntegralProblem(inner_f, (lb, ub), θ)
4747
norm2 = solve(prob1, HCubatureJL(), reltol = 1e-8, abstol = 1e-8, maxiters = 10)
4848
abs(norm2[1])
4949
end
@@ -63,7 +63,7 @@ using ComponentArrays
6363
return false
6464
end
6565
res = solve(prob, OptimizationOptimJL.LBFGS(), maxiters = 400, callback = cb_)
66-
prob = remake(prob, u0 = res.minimizer)
66+
prob = remake(prob, u0 = res.u)
6767
res = solve(prob, OptimizationOptimJL.BFGS(), maxiters = 2000, callback = cb_)
6868
C = 142.88418699042
6969
analytic_sol_func(x) = C * exp((1 / (2 *^2)) * (2 * α * x^2 - β * x^4))
@@ -88,7 +88,7 @@ using ComponentArrays
8888
return false
8989
end
9090
res = solve(prob, OptimizationOptimJL.LBFGS(), maxiters = 400, callback = cb_)
91-
prob = remake(prob, u0 = res.minimizer)
91+
prob = remake(prob, u0 = res.u)
9292
res = solve(prob, OptimizationOptimJL.BFGS(), maxiters = 2000, callback = cb_)
9393
C = 142.88418699042
9494
analytic_sol_func(x) = C * exp((1 / (2 *^2)) * (2 * α * x^2 - β * x^4))
@@ -170,7 +170,7 @@ end
170170
Float64[])
171171

172172
res = solve(prob, OptimizationOptimJL.BFGS(); maxiters = 6000)
173-
p_ = res.minimizer[(end - 2):end]
173+
p_ = res.u[(end - 2):end]
174174
@test sum(abs2, p_[1] - 10.00) < 0.1
175175
@test sum(abs2, p_[2] - 28.00) < 0.1
176176
@test sum(abs2, p_[3] - (8 / 3)) < 0.1
@@ -189,7 +189,7 @@ end
189189
sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization)
190190
sym_prob.loss_functions.full_loss_function(sym_prob.flat_init_params, nothing)
191191
res = solve(prob, OptimizationOptimJL.BFGS(); maxiters = 6000)
192-
p_ = res.minimizer[(end - 2):end]
192+
p_ = res.u[(end - 2):end]
193193
@test sum(abs2, p_[1] - 10.00) < 0.1
194194
@test sum(abs2, p_[2] - 28.00) < 0.1
195195
@test sum(abs2, p_[3] - (8 / 3)) < 0.1
@@ -225,7 +225,7 @@ end
225225
phi(xs, flat_init_params)
226226
additional_loss_(phi, flat_init_params, nothing)
227227
res = solve(prob, OptimizationOptimisers.Adam(0.01), maxiters = 500)
228-
prob = remake(prob, u0 = res.minimizer)
228+
prob = remake(prob, u0 = res.u)
229229
res = solve(prob, OptimizationOptimJL.BFGS(), maxiters = 500)
230230
@test phi(xs, res.u)aproxf_(xs) rtol=0.01
231231
end

0 commit comments

Comments
 (0)