From 0eb1e55e5b6cb4e303727aed387c7637b6372a6b Mon Sep 17 00:00:00 2001 From: Avik Pal Date: Wed, 16 Oct 2024 16:35:42 -0400 Subject: [PATCH] refactor: remove NeuralPDELogging in-favor of extension --- .buildkite/pipeline.yml | 6 +- .github/workflows/CompatHelper.yml | 2 +- .github/workflows/Downgrade.yml | 2 +- .github/workflows/Tests.yml | 2 +- Project.toml | 10 +- ext/NeuralPDETensorBoardLoggerExt.jl | 19 +++ lib/NeuralPDELogging/LICENSE | 9 -- lib/NeuralPDELogging/Project.toml | 27 ---- lib/NeuralPDELogging/src/NeuralPDELogging.jl | 24 ---- .../test/adaptive_loss_log_tests.jl | 130 ------------------ lib/NeuralPDELogging/test/runtests.jl | 45 ------ src/pinn_types.jl | 11 +- test/logging_tests.jl | 102 ++++++++++++++ test/runtests.jl | 21 +-- 14 files changed, 144 insertions(+), 266 deletions(-) create mode 100644 ext/NeuralPDETensorBoardLoggerExt.jl delete mode 100644 lib/NeuralPDELogging/LICENSE delete mode 100644 lib/NeuralPDELogging/Project.toml delete mode 100644 lib/NeuralPDELogging/src/NeuralPDELogging.jl delete mode 100644 lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl delete mode 100644 lib/NeuralPDELogging/test/runtests.jl create mode 100644 test/logging_tests.jl diff --git a/.buildkite/pipeline.yml b/.buildkite/pipeline.yml index a83997c38d..29a8d655a3 100644 --- a/.buildkite/pipeline.yml +++ b/.buildkite/pipeline.yml @@ -1,15 +1,15 @@ steps: - - label: "GPU" + - label: "CUDA" plugins: - JuliaCI/julia#v1: version: "1" - JuliaCI/julia-test#v1: - coverage: false # 1000x slowdown + coverage: true agents: queue: "juliagpu" cuda: "*" env: - GROUP: 'GPU' + GROUP: 'CUDA' JULIA_PKG_SERVER: "" # it often struggles with our large artifacts # SECRET_CODECOV_TOKEN: "..." timeout_in_minutes: 240 diff --git a/.github/workflows/CompatHelper.yml b/.github/workflows/CompatHelper.yml index 8e1252862c..73494545f2 100644 --- a/.github/workflows/CompatHelper.yml +++ b/.github/workflows/CompatHelper.yml @@ -23,4 +23,4 @@ jobs: - name: CompatHelper.main() env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - run: julia -e 'using CompatHelper; CompatHelper.main(;subdirs=["", "docs", "lib/NeuralPDELogging"])' + run: julia -e 'using CompatHelper; CompatHelper.main(;subdirs=["", "docs"])' diff --git a/.github/workflows/Downgrade.yml b/.github/workflows/Downgrade.yml index dad88f475b..bcfab6b5d0 100644 --- a/.github/workflows/Downgrade.yml +++ b/.github/workflows/Downgrade.yml @@ -55,7 +55,7 @@ jobs: GROUP: ${{ matrix.group }} - uses: julia-actions/julia-processcoverage@v1 with: - directories: src,lib/NeuralPDELogging/src + directories: src,ext - uses: codecov/codecov-action@v4 with: files: lcov.info diff --git a/.github/workflows/Tests.yml b/.github/workflows/Tests.yml index c66a8912c0..b1b5ecd8f4 100644 --- a/.github/workflows/Tests.yml +++ b/.github/workflows/Tests.yml @@ -41,6 +41,6 @@ jobs: uses: "SciML/.github/.github/workflows/tests.yml@v1" with: group: "${{ matrix.group }}" - coverage-directories: "src,lib/NeuralPDELogging/src" + coverage-directories: "src,ext" julia-version: "${{ matrix.version }}" secrets: "inherit" diff --git a/Project.toml b/Project.toml index f8542433f6..21b49693df 100644 --- a/Project.toml +++ b/Project.toml @@ -44,6 +44,12 @@ Symbolics = "0c5d862f-8b57-4792-8d23-62f2024744c7" WeightInitializers = "d49dbf32-c5c2-4618-8acc-27bb2598ef2d" Zygote = "e88e6eb3-aa80-5325-afca-941959d7151f" +[weakdeps] +TensorBoardLogger = "899adc3e-224a-11e9-021f-63837185c80f" + +[extensions] +NeuralPDETensorBoardLoggerExt = "TensorBoardLogger" + [compat] ADTypes = "1.9.0" Adapt = "4" @@ -96,6 +102,7 @@ StochasticDiffEq = "6.69.1" SymbolicIndexingInterface = "0.3.31" SymbolicUtils = "3.7.2" Symbolics = "6.14" +TensorBoardLogger = "0.1.24" Test = "1.10" WeightInitializers = "1.0.3" Zygote = "0.6.71" @@ -117,7 +124,8 @@ OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" StochasticDiffEq = "789caeaf-c7a9-5a7d-9973-96adeb23e2a0" +TensorBoardLogger = "899adc3e-224a-11e9-021f-63837185c80f" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [targets] -test = ["Aqua", "CUDA", "DiffEqNoiseProcess", "ExplicitImports", "Flux", "LineSearches", "LuxCUDA", "LuxCore", "LuxLib", "MethodOfLines", "OptimizationOptimJL", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "StochasticDiffEq", "Test"] +test = ["Aqua", "CUDA", "DiffEqNoiseProcess", "ExplicitImports", "Flux", "LineSearches", "LuxCUDA", "LuxCore", "LuxLib", "MethodOfLines", "OptimizationOptimJL", "OrdinaryDiffEq", "Pkg", "SafeTestsets", "StochasticDiffEq", "TensorBoardLogger", "Test"] diff --git a/ext/NeuralPDETensorBoardLoggerExt.jl b/ext/NeuralPDETensorBoardLoggerExt.jl new file mode 100644 index 0000000000..4115a427f3 --- /dev/null +++ b/ext/NeuralPDETensorBoardLoggerExt.jl @@ -0,0 +1,19 @@ +module NeuralPDETensorBoardLoggerExt + +using NeuralPDE: NeuralPDE +using TensorBoardLogger: TBLogger, log_value + +function NeuralPDE.logvector(logger::TBLogger, vector::AbstractVector{<:Real}, + name::AbstractString, step::Integer) + foreach(enumerate(vector)) do (j, v) + log_value(logger, "$(name)/$(j)", v; step) + end +end + +function NeuralPDE.logscalar(logger::TBLogger, scalar::Real, name::AbstractString, + step::Integer) + log_value(logger, "$(name)", scalar; step) + return nothing +end + +end diff --git a/lib/NeuralPDELogging/LICENSE b/lib/NeuralPDELogging/LICENSE deleted file mode 100644 index cc31a9f503..0000000000 --- a/lib/NeuralPDELogging/LICENSE +++ /dev/null @@ -1,9 +0,0 @@ -The NeuralPDE.jl package is licensed under the MIT "Expat" License: - -Copyright (c) 2017: ChrisRackauckas. - -Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/lib/NeuralPDELogging/Project.toml b/lib/NeuralPDELogging/Project.toml deleted file mode 100644 index b2fd8d70bc..0000000000 --- a/lib/NeuralPDELogging/Project.toml +++ /dev/null @@ -1,27 +0,0 @@ -name = "NeuralPDELogging" -uuid = "7c138fc3-9327-4ab8-b9a3-c864f3475625" -authors = ["Zoe McCarthy "] -version = "0.1.0" - -[deps] -Logging = "56ddb016-857b-54e1-b83d-db4d58db5568" -NeuralPDE = "315f7962-48a3-4962-8226-d0f33b1235f0" -TensorBoardLogger = "899adc3e-224a-11e9-021f-63837185c80f" - -[compat] -NeuralPDE = "5" -TensorBoardLogger = "0.1" -julia = "1.6" - -[extras] -Lux = "b2108857-7c20-44ae-9111-449ecde12c47" -Optimization = "7f7a1694-90dd-40f0-9382-eb1efda571ba" -OptimizationOptimisers = "42dfb2eb-d2b4-4451-abcd-913932933ac1" -ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" -Pkg = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" -Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" -SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" -Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" - -[targets] -test = ["Test", "SafeTestsets", "Pkg", "Lux", "Optimization", "OptimizationOptimisers", "ModelingToolkit", "Random"] diff --git a/lib/NeuralPDELogging/src/NeuralPDELogging.jl b/lib/NeuralPDELogging/src/NeuralPDELogging.jl deleted file mode 100644 index 940dbe51a4..0000000000 --- a/lib/NeuralPDELogging/src/NeuralPDELogging.jl +++ /dev/null @@ -1,24 +0,0 @@ -module NeuralPDELogging - -using NeuralPDE -using TensorBoardLogger - -"""This function overrides the empty function in NeuralPDE in order to use TensorBoardLogger in that package -This is light type piracy but it should be alright since this is a subpackage of NeuralPDE""" -function NeuralPDE.logvector(logger::TBLogger, vector::AbstractVector{R}, - name::AbstractString, step::Integer) where {R <: Real} - for j in 1:length(vector) - log_value(logger, "$(name)/$(j)", vector[j], step = step) - end - nothing -end - -"""This function overrides the empty function in NeuralPDE in order to use TensorBoardLogger in that package. -This is light type piracy but it should be alright since this is a subpackage of NeuralPDE""" -function NeuralPDE.logscalar(logger::TBLogger, scalar::R, name::AbstractString, - step::Integer) where {R <: Real} - log_value(logger, "$(name)", scalar, step = step) - nothing -end - -end diff --git a/lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl b/lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl deleted file mode 100644 index 1f0430a991..0000000000 --- a/lib/NeuralPDELogging/test/adaptive_loss_log_tests.jl +++ /dev/null @@ -1,130 +0,0 @@ -@info "adaptive_loss_logging_tests" -using Test, NeuralPDE -using Optimization, OptimizationOptimisers -import ModelingToolkit: Interval, infimum, supremum -using Random, Lux -@info "Starting Soon!" - -nonadaptive_loss = NeuralPDE.NonAdaptiveLoss(pde_loss_weights = 1, bc_loss_weights = 1) -gradnormadaptive_loss = NeuralPDE.GradientScaleAdaptiveLoss(100, pde_loss_weights = 1e3, - bc_loss_weights = 1) -adaptive_loss = NeuralPDE.MiniMaxAdaptiveLoss(100; pde_loss_weights = 1, - bc_loss_weights = 1) -adaptive_losses = [nonadaptive_loss, gradnormadaptive_loss, adaptive_loss] -maxiters = 800 -seed = 60 - -## 2D Poisson equation -function test_2d_poisson_equation_adaptive_loss(adaptive_loss, run, outdir, haslogger; - seed = 60, maxiters = 800) - logdir = joinpath(outdir, string(run)) - if haslogger - logger = TBLogger(logdir) - else - logger = nothing - end - Random.seed!(seed) - hid = 40 - chain_ = Lux.Chain(Dense(2, hid, Lux.σ), Dense(hid, hid, Lux.σ), - Dense(hid, 1)) - strategy_ = NeuralPDE.StochasticTraining(256) - @info "adaptive reweighting test logdir: $(logdir), maxiters: $(maxiters), 2D Poisson equation, adaptive_loss: $(nameof(typeof(adaptive_loss))) " - @parameters x y - @variables u(..) - Dxx = Differential(x)^2 - Dyy = Differential(y)^2 - - # 2D PDE - eq = Dxx(u(x, y)) + Dyy(u(x, y)) ~ -sin(pi * x) * sin(pi * y) - - # Initial and boundary conditions - bcs = [u(0, y) ~ 0.0, u(1, y) ~ -sin(pi * 1) * sin(pi * y), - u(x, 0) ~ 0.0, u(x, 1) ~ -sin(pi * x) * sin(pi * 1)] - # Space and time domains - domains = [x ∈ Interval(0.0, 1.0), - y ∈ Interval(0.0, 1.0)] - - iteration = [0] - discretization = NeuralPDE.PhysicsInformedNN(chain_, - strategy_; - adaptive_loss = adaptive_loss, - logger = logger, - iteration = iteration) - - @named pde_system = PDESystem(eq, bcs, domains, [x, y], [u(x, y)]) - prob = NeuralPDE.discretize(pde_system, discretization) - phi = discretization.phi - sym_prob = NeuralPDE.symbolic_discretize(pde_system, discretization) - - xs, ys = [infimum(d.domain):0.01:supremum(d.domain) for d in domains] - analytic_sol_func(x, y) = (sin(pi * x) * sin(pi * y)) / (2pi^2) - u_real = reshape([analytic_sol_func(x, y) for x in xs for y in ys], - (length(xs), length(ys))) - - callback = function (p, l) - iteration[1] += 1 - if iteration[1] % 100 == 0 - @info "Current loss is: $l, iteration is $(iteration[])" - end - if haslogger - log_value(logger, "outer_error/loss", l, step = iteration[]) - if iteration[1] % 30 == 0 - u_predict = reshape([first(phi([x, y], p.u)) for x in xs for y in ys], - (length(xs), length(ys))) - total_diff = sum(abs, u_predict .- u_real) - log_value(logger, "outer_error/total_diff", total_diff, step = iteration[1]) - log_value(logger, "outer_error/total_diff_rel", - total_diff / sum(abs2, u_real), step = iteration[1]) - log_value(logger, "outer_error/total_diff_sq", - sum(abs2, u_predict .- u_real), step = iteration[1]) - end - end - return false - end - res = Optimization.solve(prob, OptimizationOptimisers.Adam(0.03); maxiters, callback) - - 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) - total_u = sum(abs.(u_real)) - total_diff_rel = total_diff / total_u - - #p1 = plot(xs, ys, u_real, linetype=:contourf,title = "analytic"); - #p2 = plot(xs, ys, u_predict, linetype=:contourf,title = "predict"); - #p3 = plot(xs, ys, diff_u,linetype=:contourf,title = "error"); - #(plot=plot(p1,p2,p3), error=total_diff, total_diff_rel=total_diff_rel) - (error = total_diff, total_diff_rel = total_diff_rel) -end - -possible_logger_dir = mktempdir() -if ENV["LOG_SETTING"] == "NoImport" - haslogger = false - expected_log_folders = 0 -elseif ENV["LOG_SETTING"] == "ImportNoUse" - using NeuralPDELogging - haslogger = false - expected_log_folders = 0 -elseif ENV["LOG_SETTING"] == "ImportUse" - using NeuralPDELogging - using TensorBoardLogger - haslogger = true - expected_log_folders = 3 -end - -@info "has logger: $(haslogger), expected log folders: $(expected_log_folders)" - -function test_2d_poisson_equation_adaptive_loss_run_seediters(adaptive_loss, run) - test_2d_poisson_equation_adaptive_loss(adaptive_loss, run, possible_logger_dir, - haslogger; seed = seed, maxiters = maxiters) -end -error_results = map(test_2d_poisson_equation_adaptive_loss_run_seediters, adaptive_losses, - 1:length(adaptive_losses)) - -@test length(readdir(possible_logger_dir)) == expected_log_folders -if expected_log_folders > 0 - @info "dirs at $(possible_logger_dir): $(string(readdir(possible_logger_dir)))" - for logdir in readdir(possible_logger_dir) - @test length(readdir(joinpath(possible_logger_dir, logdir))) > 0 - end -end diff --git a/lib/NeuralPDELogging/test/runtests.jl b/lib/NeuralPDELogging/test/runtests.jl deleted file mode 100644 index 2f4d45864e..0000000000 --- a/lib/NeuralPDELogging/test/runtests.jl +++ /dev/null @@ -1,45 +0,0 @@ -using Pkg -using SafeTestsets - -const GROUP = get(ENV, "GROUP", "All") - -const is_APPVEYOR = Sys.iswindows() && haskey(ENV, "APPVEYOR") - -const is_TRAVIS = haskey(ENV, "TRAVIS") - -is_CI = haskey(ENV, "CI") - -@time begin - if GROUP == "All" || GROUP == "Logging" - @time @safetestset "AdaptiveLossLogNoImport" begin - using Pkg - neuralpde_dir = dirname(abspath(joinpath(@__DIR__, "..", "..", ".."))) - @info "loading neuralpde package at : $(neuralpde_dir)" - neuralpde = Pkg.PackageSpec(path = neuralpde_dir) - Pkg.develop(neuralpde) - @info "making sure that there are no logs without having imported NeuralPDELogging" - ENV["LOG_SETTING"] = "NoImport" - include("adaptive_loss_log_tests.jl") - end - @time @safetestset "AdaptiveLossLogImportNoUse" begin - using Pkg - neuralpde_dir = dirname(abspath(joinpath(@__DIR__, "..", "..", ".."))) - @info "loading neuralpde package at : $(neuralpde_dir)" - neuralpde = Pkg.PackageSpec(path = neuralpde_dir) - Pkg.develop(neuralpde) - @info "making sure that there are still no logs now that we have imported NeuralPDELogging" - ENV["LOG_SETTING"] = "ImportNoUse" - include("adaptive_loss_log_tests.jl") - end - @time @safetestset "AdaptiveLossLogImportUse" begin - using Pkg - neuralpde_dir = dirname(abspath(joinpath(@__DIR__, "..", "..", ".."))) - @info "loading neuralpde package at : $(neuralpde_dir)" - neuralpde = Pkg.PackageSpec(path = neuralpde_dir) - Pkg.develop(neuralpde) - ENV["LOG_SETTING"] = "ImportUse" - @info "making sure that logs are generated now if we use a logger" - include("adaptive_loss_log_tests.jl") - end - end -end diff --git a/src/pinn_types.jl b/src/pinn_types.jl index 1fdd4cb436..15b426f0f1 100644 --- a/src/pinn_types.jl +++ b/src/pinn_types.jl @@ -10,15 +10,8 @@ end LogOptions(; log_frequency = 50) = LogOptions(log_frequency) -"""This function is defined here as stubs to be overridden by the subpackage NeuralPDELogging if imported""" -function logvector(logger, v::AbstractVector{<:Real}, name::AbstractString, step::Integer) - nothing -end - -"""This function is defined here as stubs to be overridden by the subpackage NeuralPDELogging if imported""" -function logscalar(logger, s::Real, name::AbstractString, step::Integer) - nothing -end +logvector(logger, v::AbstractVector{<:Real}, name::AbstractString, step::Integer) = nothing +logscalar(logger, s::Real, name::AbstractString, step::Integer) = nothing """ An encoding of the test function phi that is used for calculating the PDE diff --git a/test/logging_tests.jl b/test/logging_tests.jl new file mode 100644 index 0000000000..36add38a37 --- /dev/null +++ b/test/logging_tests.jl @@ -0,0 +1,102 @@ +using Test, NeuralPDE, Optimization, OptimizationOptimisers, Random, Lux +import ModelingToolkit: Interval, infimum, supremum + +nonadaptive_loss = NonAdaptiveLoss(pde_loss_weights = 1, bc_loss_weights = 1) +gradnormadaptive_loss = GradientScaleAdaptiveLoss(100, pde_loss_weights = 1e3, + bc_loss_weights = 1) +adaptive_loss = MiniMaxAdaptiveLoss(100; pde_loss_weights = 1, bc_loss_weights = 1) +adaptive_losses = [nonadaptive_loss, gradnormadaptive_loss, adaptive_loss] + +possible_logger_dir = mktempdir() +if ENV["LOG_SETTING"] == "NoImport" + haslogger = false + expected_log_folders = 0 +elseif ENV["LOG_SETTING"] == "ImportNoUse" + using TensorBoardLogger + haslogger = false + expected_log_folders = 0 +elseif ENV["LOG_SETTING"] == "ImportUse" + using TensorBoardLogger + haslogger = true + expected_log_folders = 3 +end + +@info "has logger: $(haslogger), expected log folders: $(expected_log_folders)" + +function test_2d_poisson_equation_adaptive_loss(adaptive_loss, run, outdir, haslogger; + seed = 60, maxiters = 800) + logdir = joinpath(outdir, string(run)) + logger = haslogger ? TBLogger(logdir) : nothing + + Random.seed!(seed) + hid = 40 + chain_ = Chain(Dense(2, hid, σ), Dense(hid, hid, σ), Dense(hid, 1)) + strategy_ = StochasticTraining(256) + + @parameters x y + @variables u(..) + Dxx = Differential(x)^2 + Dyy = Differential(y)^2 + + # 2D PDE + eq = Dxx(u(x, y)) + Dyy(u(x, y)) ~ -sinpi(x) * sinpi(y) + + # Initial and boundary conditions + bcs = [u(0, y) ~ 0.0, u(1, y) ~ -sinpi(1) * sinpi(y), + u(x, 0) ~ 0.0, u(x, 1) ~ -sinpi(x) * sinpi(1)] + # Space and time domains + domains = [x ∈ Interval(0.0, 1.0), y ∈ Interval(0.0, 1.0)] + + discretization = PhysicsInformedNN(chain_, strategy_; adaptive_loss, logger) + + @named pde_system = PDESystem(eq, bcs, domains, [x, y], [u(x, y)]) + prob = NeuralPDE.discretize(pde_system, discretization) + phi = discretization.phi + + xs, ys = [infimum(d.domain):0.01:supremum(d.domain) for d in domains] + sz = (length(xs), length(ys)) + analytic_sol_func(x, y) = (sinpi(x) * sinpi(y)) / (2pi^2) + u_real = reshape([analytic_sol_func(x, y) for x in xs for y in ys], sz) + + callback = function (p, l) + if p.iter % 100 == 0 + @info "Current loss is: $l, iteration is $(p.iter)" + end + if haslogger + log_value(logger, "outer_error/loss", l, step = p.iter) + if p.iter % 30 == 0 + u_predict = reshape([first(phi([x, y], p.u)) for x in xs for y in ys], + (length(xs), length(ys))) + total_diff = sum(abs, u_predict .- u_real) + log_value(logger, "outer_error/total_diff", total_diff, step = p.iter) + log_value(logger, "outer_error/total_diff_rel", + total_diff / sum(abs2, u_real), step = p.iter) + log_value(logger, "outer_error/total_diff_sq", + sum(abs2, u_predict .- u_real), step = p.iter) + end + end + return false + end + res = solve(prob, OptimizationOptimisers.Adam(0.03); maxiters, callback) + + u_predict = reshape([first(phi([x, y], res.u)) for x in xs for y in ys], sz) + diff_u = abs.(u_predict .- u_real) + total_diff = sum(diff_u) + total_u = sum(abs.(u_real)) + total_diff_rel = total_diff / total_u + + return (error = total_diff, total_diff_rel = total_diff_rel) +end + +@testset "$(nameof(typeof(adaptive_loss)))" for (i, adaptive_loss) in enumerate(adaptive_losses) + test_2d_poisson_equation_adaptive_loss(adaptive_loss, i, possible_logger_dir, + haslogger; seed = 60, maxiters = 800) +end + +@test length(readdir(possible_logger_dir)) == expected_log_folders +if expected_log_folders > 0 + @info "dirs at $(possible_logger_dir): $(string(readdir(possible_logger_dir)))" + for logdir in readdir(possible_logger_dir) + @test length(readdir(joinpath(possible_logger_dir, logdir))) > 0 + end +end diff --git a/test/runtests.jl b/test/runtests.jl index 3be1416f9a..16ebea0e05 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,15 +1,7 @@ -using Pkg -using SafeTestsets +using Pkg, SafeTestsets, Test const GROUP = get(ENV, "GROUP", "All") -const is_APPVEYOR = Sys.iswindows() && haskey(ENV, "APPVEYOR") - -function dev_subpkg(subpkg) - subpkg_path = joinpath(dirname(@__DIR__), "lib", subpkg) - Pkg.develop(PackageSpec(path = subpkg_path)) -end - @time begin if GROUP == "All" || GROUP == "QA" @time @safetestset "Quality Assurance" include("qa.jl") @@ -56,14 +48,13 @@ end end if GROUP == "All" || GROUP == "Logging" - dev_subpkg("NeuralPDELogging") - subpkg_path = joinpath(dirname(@__DIR__), "lib", "NeuralPDELogging") - # XXX: problem in TensorBoardLogger that causes error if run with --depwarn=error - Pkg.test(PackageSpec(; name = "NeuralPDELogging", path = subpkg_path); - julia_args = ["--depwarn=yes"]) + @testset for log_setting in ["NoImport", "ImportNoUse", "ImportUse"] + ENV["LOG_SETTING"] = log_setting + @time @safetestset "Logging" include("logging_tests.jl") + end end - if !is_APPVEYOR && GROUP == "GPU" + if GROUP == "CUDA" @safetestset "NNPDE_gpu_Lux" include("NNPDE_tests_gpu_Lux.jl") end