Skip to content

Commit 1cdaedf

Browse files
mikeingoldgithub-actions[bot]JoshuaLampert
authored
Unit testing code cleanup (#193)
* Add a test * Add tests * Reorganization * Update changelog, formatting tweak * Format suggestion Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Temp for debugging: add Enzyme version check * More debugging * Remove debugging * Remove new tests and add clarifying note * Formatting and closures * Remove new line from changelog * Apply suggestion Co-authored-by: Joshua Lampert <[email protected]> * Fix formatting error --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Joshua Lampert <[email protected]>
1 parent 1d62e61 commit 1cdaedf

File tree

2 files changed

+39
-24
lines changed

2 files changed

+39
-24
lines changed

ext/MeshIntegralsEnzymeExt.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Geometry}) = true
2121
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Domain}) = true
2222
# except for those that throw errors (see GitHub Issue #154)
2323
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.BezierCurve}) = false
24-
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.CylinderSurface}) = false
2524
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.Cylinder}) = false
25+
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.CylinderSurface}) = false
2626
MeshIntegrals.supports_autoenzyme(::Type{<:Meshes.ParametrizedCurve}) = false
2727

2828
end

test/utils.jl

Lines changed: 38 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ end
1717

1818
@testitem "Utilities" setup=[Utils] begin
1919
# _KVector
20-
v = Meshes.Vec(3, 4)
21-
@test norm(MeshIntegrals._KVector(v)) 5.0u"m"
20+
let v = Meshes.Vec(3, 4)
21+
@test norm(MeshIntegrals._KVector(v)) 5.0u"m"
22+
end
2223

2324
# _units
24-
p = Point(1.0u"cm", 2.0u"mm", 3.0u"m")
25-
@test _units(p) == u"m"
25+
let p = Point(1.0u"cm", 2.0u"mm", 3.0u"m")
26+
@test _units(p) == u"m"
27+
end
2628

2729
# _zeros
2830
@test _zeros(2) == (0.0, 0.0)
@@ -33,37 +35,50 @@ end
3335
@test _ones(Float32, 2) == (1.0f0, 1.0f0)
3436
end
3537

36-
@testitem "Differentiation (EnzymeExt loaded)" setup=[Utils] begin
37-
# supports_autoenzyme(::Type{<:Any})
38-
@test MeshIntegrals.supports_autoenzyme(Nothing) == false
39-
40-
# _default_diff_method -- using type or instance, Enzyme-supported combination
38+
@testitem "Differentiation (MeshIntegralsEnzymeExt loaded)" setup=[Utils] begin
39+
# supports_autoenzyme & _default_diff_method
40+
# Nominal usage: Enzyme-supported geometry and FP type
4141
let sphere = Sphere(Point(0, 0, 0), 1.0)
4242
@test _default_diff_method(Meshes.Sphere, Float64) isa AutoEnzyme
4343
@test _default_diff_method(sphere, Float64) isa AutoEnzyme
4444
end
45-
46-
# _default_diff_method -- Enzyme-unsupported FP types
45+
# supports_autoenzyme(::Type{<:Any}) for CI completeness
46+
@test MeshIntegrals.supports_autoenzyme(Nothing) == false
47+
# BezierCurve: blocked by upstream Meshes-Enzyme incompatibility
48+
let curve = BezierCurve([Point(t, 0) for t in range(-π, π, length = 361)])
49+
@test_throws "proven readonly" jacobian(curve, (0.5,), AutoEnzyme())
50+
@test _default_diff_method(Meshes.BezierCurve, Float64) isa FiniteDifference
51+
end
52+
# Cylinder: blocked by version-dependent upstream Meshes-Enzyme incompatibility
53+
let cyl = Cylinder(Point(0, 0, 0), Point(0, 0, 1), 2.0)
54+
@test _default_diff_method(Meshes.Cylinder, Float64) isa FiniteDifference
55+
end
56+
# CylinderSurface: blocked by version-dependent upstream Meshes-Enzyme incompatibility
57+
let cylsurf = CylinderSurface(Point(0, 0, 0), Point(0, 0, 1), 2.0)
58+
@test _default_diff_method(Meshes.CylinderSurface, Float64) isa FiniteDifference
59+
end
60+
# ParametrizedCurve: parametric functions are user-defined, can't guarantee behavior
61+
@test _default_diff_method(Meshes.ParametrizedCurve, Float64) isa FiniteDifference
62+
# Non-Float64: other FP types not supported by Enzyme
4763
@test _default_diff_method(Meshes.Sphere, Float16) isa FiniteDifference
4864
@test _default_diff_method(Meshes.Sphere, BigFloat) isa FiniteDifference
4965

50-
# _default_diff_method -- geometries that currently error with AutoEnzyme
51-
@test _default_diff_method(Meshes.BezierCurve, Float64) isa FiniteDifference
52-
@test _default_diff_method(Meshes.CylinderSurface, Float64) isa FiniteDifference
53-
@test _default_diff_method(Meshes.Cylinder, Float64) isa FiniteDifference
54-
@test _default_diff_method(Meshes.ParametrizedCurve, Float64) isa FiniteDifference
55-
5666
# FiniteDifference
57-
@test FiniteDifference().ε 1e-6
67+
let diff = FiniteDifference()
68+
@test typeof(diff.ε) == Float64
69+
@test diff.ε 1e-6
70+
end
5871

5972
# Two-argument jacobian
60-
segment = Segment(Point(0), Point(1))
61-
@test MeshIntegrals.jacobian(segment, (0.5,)) == (Vec(1),)
73+
let segment = Segment(Point(0), Point(1))
74+
@test MeshIntegrals.jacobian(segment, (0.5,)) == (Vec(1),)
75+
end
6276

6377
# Test jacobian with wrong number of parametric coordinates
64-
box = Box(Point(0, 0), Point(1, 1))
65-
@test_throws ArgumentError jacobian(box, zeros(3), FiniteDifference())
66-
@test_throws ArgumentError jacobian(box, zeros(3), AutoEnzyme())
78+
let box = Box(Point(0, 0), Point(1, 1))
79+
@test_throws ArgumentError jacobian(box, zeros(3), FiniteDifference())
80+
@test_throws ArgumentError jacobian(box, zeros(3), AutoEnzyme())
81+
end
6782
end
6883

6984
@testitem "_ParametricGeometry" setup=[Utils] begin

0 commit comments

Comments
 (0)