Skip to content

Switch Tests to use the new logger #585

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 25 additions & 22 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ using
Printf,
Statistics,
OffsetArrays,
FFTW
FFTW,
Logging

@hascuda begin
import CUDAdrv
Expand Down Expand Up @@ -81,25 +82,27 @@ closures = (
:VerstappenAnisotropicMinimumDissipation
)

@testset "Oceananigans" begin
include("test_grids.jl")
include("test_fields.jl")
include("test_halo_regions.jl")
include("test_operators.jl")
include("test_solvers.jl")
include("test_coriolis.jl")
include("test_surface_waves.jl")
include("test_buoyancy.jl")
include("test_models.jl")
include("test_time_stepping.jl")
include("test_boundary_conditions.jl")
include("test_forcings.jl")
include("test_turbulence_closures.jl")
include("test_dynamics.jl")
include("test_diagnostics.jl")
include("test_output_writers.jl")
include("test_regression.jl")
include("test_examples.jl")
include("test_abstract_operations.jl")
include("test_verification.jl")
with_logger(ModelLogger()) do
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is pretty clean! I guess it makes sense to use with_logger here but for log messages peppered around the rest of the package would global_logger(ModelLogger()) be better?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think so! Do you think the line could be added in Oceananigans.jl?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah we should do that, hopefully it doesn't also effect other packages. But we can leave it for another PR to avoid dragging this one out.

@testset "Oceananigans" begin
include("test_grids.jl")
include("test_fields.jl")
include("test_halo_regions.jl")
include("test_operators.jl")
include("test_solvers.jl")
include("test_coriolis.jl")
include("test_surface_waves.jl")
include("test_buoyancy.jl")
include("test_models.jl")
include("test_time_stepping.jl")
include("test_boundary_conditions.jl")
include("test_forcings.jl")
include("test_turbulence_closures.jl")
include("test_dynamics.jl")
include("test_diagnostics.jl")
include("test_output_writers.jl")
include("test_regression.jl")
include("test_examples.jl")
include("test_abstract_operations.jl")
include("test_verification.jl")
end
end
264 changes: 132 additions & 132 deletions test/test_abstract_operations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,173 +228,173 @@ function multiplication_and_derivative_ccc(model)
end

@testset "Abstract operations" begin
println("Testing abstract operations...")

for FT in float_types
arch = CPU()
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
u, v, w = Oceananigans.VelocityFields(arch, grid)
c = Field(Cell, Cell, Cell, arch, grid)

@testset "Unary operations and derivatives [$FT]" begin
for ψ in (u, v, w, c)
for op_symbol in Oceananigans.AbstractOperations.unary_operators
op = eval(op_symbol)
@test typeof(op(ψ)[2, 2, 2]) <: Number
end
@info "Testing abstract operations..."

for FT in float_types
arch = CPU()
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))
u, v, w = Oceananigans.VelocityFields(arch, grid)
c = Field(Cell, Cell, Cell, arch, grid)

for d_symbol in Oceananigans.AbstractOperations.derivative_operators
d = eval(d_symbol)
@test typeof(d(ψ)[2, 2, 2]) <: Number
@testset "Unary operations and derivatives [$FT]" begin
for ψ in (u, v, w, c)
for op_symbol in Oceananigans.AbstractOperations.unary_operators
op = eval(op_symbol)
@test typeof(op(ψ)[2, 2, 2]) <: Number
end

for d_symbol in Oceananigans.AbstractOperations.derivative_operators
d = eval(d_symbol)
@test typeof(d(ψ)[2, 2, 2]) <: Number
end
end
end
end

@testset "Binary operations [$FT]" begin
generic_function(x, y, z) = x + y + z
for (ψ, ϕ) in ((u, v), (u, w), (v, w), (u, c), (generic_function, c), (u, generic_function))
for op_symbol in Oceananigans.AbstractOperations.binary_operators
op = eval(op_symbol)
@test typeof(op(ψ, ϕ)[2, 2, 2]) <: Number
@testset "Binary operations [$FT]" begin
generic_function(x, y, z) = x + y + z
for (ψ, ϕ) in ((u, v), (u, w), (v, w), (u, c), (generic_function, c), (u, generic_function))
for op_symbol in Oceananigans.AbstractOperations.binary_operators
op = eval(op_symbol)
@test typeof(op(ψ, ϕ)[2, 2, 2]) <: Number
end
end
end
end

@testset "Multiary operations [$FT]" begin
generic_function(x, y, z) = x + y + z
for (ψ, ϕ, σ) in ((u, v, w), (u, v, c), (u, v, generic_function))
for op_symbol in Oceananigans.AbstractOperations.multiary_operators
op = eval(op_symbol)
@test typeof(op((Cell, Cell, Cell), ψ, ϕ, σ)[2, 2, 2]) <: Number
@testset "Multiary operations [$FT]" begin
generic_function(x, y, z) = x + y + z
for (ψ, ϕ, σ) in ((u, v, w), (u, v, c), (u, v, generic_function))
for op_symbol in Oceananigans.AbstractOperations.multiary_operators
op = eval(op_symbol)
@test typeof(op((Cell, Cell, Cell), ψ, ϕ, σ)[2, 2, 2]) <: Number
end
end
end
end
end

@testset "Fidelity of simple binary operations" begin
arch = CPU()
println(" Testing simple binary operations...")
for FT in float_types
num1 = FT(π)
num2 = FT(42)
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))

u, v, w = Oceananigans.VelocityFields(arch, grid)
T, S = Oceananigans.TracerFields(arch, grid, (:T, :S))

for op in (+, *, -, /)
@test simple_binary_operation(op, u, v, num1, num2)
@test simple_binary_operation(op, u, w, num1, num2)
@test simple_binary_operation(op, u, T, num1, num2)
@test simple_binary_operation(op, T, S, num1, num2)
@testset "Fidelity of simple binary operations" begin
arch = CPU()
@info " Testing simple binary operations..."
for FT in float_types
num1 = FT(π)
num2 = FT(42)
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))

u, v, w = Oceananigans.VelocityFields(arch, grid)
T, S = Oceananigans.TracerFields(arch, grid, (:T, :S))

for op in (+, *, -, /)
@test simple_binary_operation(op, u, v, num1, num2)
@test simple_binary_operation(op, u, w, num1, num2)
@test simple_binary_operation(op, u, T, num1, num2)
@test simple_binary_operation(op, T, S, num1, num2)
end
@test three_field_addition(u, v, w, num1, num2)
end
@test three_field_addition(u, v, w, num1, num2)
end
end

@testset "Derivatives" begin
arch = CPU()
println(" Testing derivatives...")
for FT in float_types
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))

u, v, w = Oceananigans.VelocityFields(arch, grid)
T, S = Oceananigans.TracerFields(arch, grid, (:T, :S))
for a in (u, v, w, T)
@test x_derivative(a)
@test y_derivative(a)
@test z_derivative(a)
@testset "Derivatives" begin
arch = CPU()
@info " Testing derivatives..."
for FT in float_types
grid = RegularCartesianGrid(FT, size=(3, 3, 3), length=(3, 3, 3))

u, v, w = Oceananigans.VelocityFields(arch, grid)
T, S = Oceananigans.TracerFields(arch, grid, (:T, :S))
for a in (u, v, w, T)
@test x_derivative(a)
@test y_derivative(a)
@test z_derivative(a)
end
@test x_derivative_cell(FT, arch)
end
@test x_derivative_cell(FT, arch)
end
end

@testset "Combined binary operations and derivatives" begin
println(" Testing combined binary operations and derivatives...")
arch = CPU()
Nx = 3 # Δx=1, xC = 0.5, 1.5, 2.5
for FT in float_types
grid = RegularCartesianGrid(FT, size=(Nx, Nx, Nx), length=(Nx, Nx, Nx))
a, b = (Field(Cell, Cell, Cell, arch, grid) for i in 1:2)
@testset "Combined binary operations and derivatives" begin
@info " Testing combined binary operations and derivatives..."
arch = CPU()
Nx = 3 # Δx=1, xC = 0.5, 1.5, 2.5
for FT in float_types
grid = RegularCartesianGrid(FT, size=(Nx, Nx, Nx), length=(Nx, Nx, Nx))
a, b = (Field(Cell, Cell, Cell, arch, grid) for i in 1:2)

set!(b, 2)
set!(a, (x, y, z) -> x < 2 ? 3x : 6)
set!(b, 2)
set!(a, (x, y, z) -> x < 2 ? 3x : 6)

# 0 0.5 1 1.5 2 2.5 3
# x -▶ ∘ ~~~|--- * ---|--- * ---|--- * ---|~~~ ∘
# i Face: 0 1 2 3 4
# i Cell: 0 1 2 3 4
# 0 0.5 1 1.5 2 2.5 3
# x -▶ ∘ ~~~|--- * ---|--- * ---|--- * ---|~~~ ∘
# i Face: 0 1 2 3 4
# i Cell: 0 1 2 3 4

# a = [ 0, 1.5, 4.5, 6, 0 ]
# b = [ 0, 2, 2, 2, 0 ]
# ∂x(a) = [ 1.5, 3, 1.5, -6 ]
# a = [ 0, 1.5, 4.5, 6, 0 ]
# b = [ 0, 2, 2, 2, 0 ]
# ∂x(a) = [ 1.5, 3, 1.5, -6 ]

# x -▶ ∘ ~~~|--- * ---|--- * ---|--- * ---|~~~ ∘
# i Face: 0 1 2 3 4
# i Cell: 0 1 2 3 4
# x -▶ ∘ ~~~|--- * ---|--- * ---|--- * ---|~~~ ∘
# i Face: 0 1 2 3 4
# i Cell: 0 1 2 3 4

# ccc: b * ∂x(a) = [ 4.5, 4.5 -4.5, ]
# fcc: b * ∂x(a) = [ 3, 6, 3, -6 ]
# ccc: b * ∂x(a) = [ 4.5, 4.5 -4.5, ]
# fcc: b * ∂x(a) = [ 3, 6, 3, -6 ]


@test times_x_derivative(a, b, (C, C, C), 1, 2, 2, 4.5)
@test times_x_derivative(a, b, (F, C, C), 1, 2, 2, 3)
@test times_x_derivative(a, b, (C, C, C), 1, 2, 2, 4.5)
@test times_x_derivative(a, b, (F, C, C), 1, 2, 2, 3)

@test times_x_derivative(a, b, (C, C, C), 2, 2, 2, 4.5)
@test times_x_derivative(a, b, (F, C, C), 2, 2, 2, 6)
@test times_x_derivative(a, b, (C, C, C), 2, 2, 2, 4.5)
@test times_x_derivative(a, b, (F, C, C), 2, 2, 2, 6)

@test times_x_derivative(a, b, (C, C, C), 3, 2, 2, -4.5)
@test times_x_derivative(a, b, (F, C, C), 3, 2, 2, 3)
@test times_x_derivative(a, b, (C, C, C), 3, 2, 2, -4.5)
@test times_x_derivative(a, b, (F, C, C), 3, 2, 2, 3)
end
end
end

for arch in archs
@testset "Computations [$(typeof(arch))]" begin
println(" Testing combined binary operations and derivatives...")
for FT in float_types
println(" Testing computation of abstract operations [$FT, $(typeof(arch))]...")
model = Model(architecture=arch, float_type=FT,
grid=RegularCartesianGrid(FT, size=(16, 16, 16), length=(1, 1, 1)))

@testset "Derivative computations [$FT, $(typeof(arch))]" begin
println(" Testing compute! derivatives...")
@test compute_derivative(model, ∂x)
@test compute_derivative(model, ∂y)
@test compute_derivative(model, ∂z)
end
for arch in archs
@testset "Computations [$(typeof(arch))]" begin
@info " Testing combined binary operations and derivatives..."
for FT in float_types
@info " Testing computation of abstract operations [$FT, $(typeof(arch))]..."
model = Model(architecture=arch, float_type=FT,
grid=RegularCartesianGrid(FT, size=(16, 16, 16), length=(1, 1, 1)))

@testset "Derivative computations [$FT, $(typeof(arch))]" begin
@info " Testing compute! derivatives..."
@test compute_derivative(model, ∂x)
@test compute_derivative(model, ∂y)
@test compute_derivative(model, ∂z)
end

@testset "Unary computations [$FT, $(typeof(arch))]" begin
println(" Testing compute! unary operations...")
for unary in Oceananigans.AbstractOperations.unary_operators
@test compute_unary(eval(unary), model)
@testset "Unary computations [$FT, $(typeof(arch))]" begin
@info " Testing compute! unary operations..."
for unary in Oceananigans.AbstractOperations.unary_operators
@test compute_unary(eval(unary), model)
end
end
end

@testset "Binary computations [$FT, $(typeof(arch))]" begin
println(" Testing compute! binary operations...")
@test compute_plus(model)
@test compute_minus(model)
@test compute_times(model)
end
@testset "Binary computations [$FT, $(typeof(arch))]" begin
@info " Testing compute! binary operations..."
@test compute_plus(model)
@test compute_minus(model)
@test compute_times(model)
end

@testset "Multiary computations [$FT, $(typeof(arch))]" begin
println(" Testing compute! multiary operations...")
@test compute_many_plus(model)
@testset "Multiary computations [$FT, $(typeof(arch))]" begin
@info " Testing compute! multiary operations..."
@test compute_many_plus(model)

println(" Testing compute! kinetic energy...")
@test compute_kinetic_energy(model)
end
@info " Testing compute! kinetic energy..."
@test compute_kinetic_energy(model)
end

@testset "Horizontal averages of operations [$FT, $(typeof(arch))]" begin
println(" Testing horizontal averges...")
@test horizontal_average_of_plus(model)
@test horizontal_average_of_minus(model)
@test horizontal_average_of_times(model)
@testset "Horizontal averages of operations [$FT, $(typeof(arch))]" begin
@info " Testing horizontal averges..."
@test horizontal_average_of_plus(model)
@test horizontal_average_of_minus(model)
@test horizontal_average_of_times(model)

@test multiplication_and_derivative_ccf(model)
@test multiplication_and_derivative_ccc(model)
@test multiplication_and_derivative_ccf(model)
@test multiplication_and_derivative_ccc(model)
end
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion test/test_boundary_conditions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function test_flux_budget(arch, FT, fldname)
end

@testset "Boundary conditions" begin
println("Testing boundary conditions...")
@info "Testing boundary conditions..."

@testset "Boundary functions" begin
simple_bc(ξ, η, t) = exp(ξ) * cos(η) * sin(t)
Expand Down
2 changes: 1 addition & 1 deletion test/test_buoyancy.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ end
EquationsOfState = (LinearEquationOfState, RoquetIdealizedNonlinearEquationOfState)

@testset "Buoyancy" begin
println("Testing buoyancy...")
@info "Testing buoyancy..."

@testset "Equations of State" begin
for FT in float_types
Expand Down
2 changes: 1 addition & 1 deletion test/test_coriolis.jl
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ function instantiate_betaplane_2(FT)
end

@testset "Coriolis" begin
println("Testing Coriolis...")
@info "Testing Coriolis..."

@testset "Coriolis" begin
for FT in float_types
Expand Down
Loading