Skip to content

Commit

Permalink
fixup! test: clean up NeuralAdapter tests and use res.u instead of re…
Browse files Browse the repository at this point in the history
…s.minimizer
  • Loading branch information
sathvikbhagavan committed Mar 4, 2024
1 parent 08bd81a commit abd8c87
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 10 deletions.
2 changes: 1 addition & 1 deletion lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ function test_2d_poisson_equation_adaptive_loss(adaptive_loss, run, outdir, hasl
res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.03); maxiters = maxiters,
callback = callback)

u_predict = reshape([first(phi([x, y], res.minimizer)) for x in xs for y in ys],
u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys],
(length(xs), length(ys)))
diff_u = abs.(u_predict .- u_real)
total_diff = sum(diff_u)
Expand Down
16 changes: 7 additions & 9 deletions test/neural_adapter_tests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -164,11 +164,9 @@ end
for i in 1:count_decomp
println("decomposition $i")
domains_ = domains_map[i]
phi_in(cord) = phis[i - 1](cord, reses[i - 1].minimizer)
# phi_bound(x,y) = if (x isa Matrix) phi_in(vcat(x, fill(y,size(x)))) else phi_in(vcat(fill(x,size(y)),y)) end
phi_in(cord) = phis[i - 1](cord, reses[i - 1].u)
phi_bound(x, y) = phi_in(vcat(x, y))
@register_symbolic phi_bound(x, y)
global phi_bound
Base.Broadcast.broadcasted(::typeof(phi_bound), x, y) = phi_bound(x, y)
bcs_ = create_bcs(domains_[1].domain, phi_bound)
@named pde_system_ = PDESystem(eq, bcs_, domains_, [x, y], [u(x, y)])
Expand All @@ -177,7 +175,7 @@ end
discretization = PhysicsInformedNN(chains[i], strategy; init_params = init_params[i])
prob = discretize(pde_system_, discretization)
@time res_ = Optimization.solve(prob, OptimizationOptimisers.Adam(5e-3), maxiters = 10000)
@show res_.minimum
@show res_.objective
phi = discretization.phi
push!(reses, res_)
push!(phis, phi)
Expand All @@ -198,7 +196,7 @@ end
end
for x_ in xs
i = index_of_interval(x_)
u_predict_sub = [first(phis[i]([x_, y], reses[i].minimizer)) for y in ys]
u_predict_sub = [first(phis[i]([x_, y], reses[i].u)) for y in ys]
u_real_sub = [analytic_sol_func(x_, y) for y in ys]
diff_u_sub = u_predict_sub .- u_real_sub
append!(u_predict_array, u_predict_sub)
Expand Down Expand Up @@ -235,15 +233,15 @@ end
prob_ = NeuralPDE.neural_adapter(losses, init_params2, pde_system_map,
GridTraining([0.1 / count_decomp, 0.1]))
@time res_ = solve(prob_, OptimizationOptimisers.Adam(5e-3); maxiters = 5000)
@show res_.minimum
prob_ = NeuralPDE.neural_adapter(losses, res_.minimizer, pde_system_map,
@show res_.objective
prob_ = NeuralPDE.neural_adapter(losses, res_.u, pde_system_map,
GridTraining(0.01))
@time res_ = solve(prob_, OptimizationOptimisers.Adam(5e-3); maxiters = 5000)
@show res_.minimum
@show res_.objective

phi_ = NeuralPDE.Phi(chain2)
xs, ys = [infimum(d.domain):dx:supremum(d.domain) for d in domains]
u_predict_ = reshape([first(phi_([x, y], res_.minimizer)) for x in xs for y in ys],
u_predict_ = reshape([first(phi_([x, y], res_.u)) for x in xs for y in ys],
(length(xs), length(ys)))
u_real = reshape([analytic_sol_func(x, y) for x in xs for y in ys],
(length(xs), length(ys)))
Expand Down

0 comments on commit abd8c87

Please sign in to comment.