Skip to content

Commit c148b7d

Browse files
committed
test td
1 parent 36e29c1 commit c148b7d

File tree

3 files changed

+31
-5
lines changed

3 files changed

+31
-5
lines changed

.buildkite/Manifest-v1.11.toml

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# This file is machine-generated - editing it directly is not advised
22

3-
julia_version = "1.11.5"
3+
julia_version = "1.11.3"
44
manifest_format = "2.0"
5-
project_hash = "04945e2a7116cfacb2d57340f477dbe23e208227"
5+
project_hash = "a25db2ac38461b28c1b3a6176008dee03780354b"
66

77
[[deps.ADTypes]]
88
git-tree-sha1 = "be7ae030256b8ef14a441726c4c37766b90b93a3"
@@ -1818,7 +1818,7 @@ version = "2.5.4+0"
18181818
[[deps.OpenLibm_jll]]
18191819
deps = ["Artifacts", "Libdl"]
18201820
uuid = "05823500-19ac-5b8b-9628-191a04bc5112"
1821-
version = "0.8.5+0"
1821+
version = "0.8.1+2"
18221822

18231823
[[deps.OpenMPI_jll]]
18241824
deps = ["Artifacts", "CompilerSupportLibraries_jll", "Hwloc_jll", "JLLWrappers", "LazyArtifacts", "Libdl", "MPIPreferences", "TOML", "Zlib_jll"]
@@ -2539,8 +2539,10 @@ uuid = "b718987f-49a8-5099-9789-dcd902bef87d"
25392539
version = "1.0.2"
25402540

25412541
[[deps.Thermodynamics]]
2542-
deps = ["DocStringExtensions", "KernelAbstractions", "Random", "RootSolvers"]
2543-
git-tree-sha1 = "bff801ad0a9bbb5c1bf38ffe89a83907a1b145cd"
2542+
deps = ["DocStringExtensions", "ForwardDiff", "KernelAbstractions", "Random", "RootSolvers"]
2543+
git-tree-sha1 = "1c6b10882d535f28b5c79be9d8d782a12f5592f9"
2544+
repo-rev = "zs/test_autodiff"
2545+
repo-url = "https://github.com/CliMA/Thermodynamics.jl.git"
25442546
uuid = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
25452547
version = "0.12.15"
25462548
weakdeps = ["ClimaParams"]

.buildkite/Project.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ SnoopCompileCore = "e2b509da-e806-4183-be48-004708413034"
3838
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
3939
StatsBase = "2913bbd2-ae8a-5f71-8c99-4fb6c76f3a91"
4040
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
41+
Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
4142
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"
4243

4344
[compat]

src/prognostic_equations/implicit/autodiff_utils.jl

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,29 @@ end
143143
return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
144144
end
145145

146+
# Set the derivative of max(x, y) to handle cases where x == y. When x == y,
147+
# the derivative is set to the derivative of x (the first argument) to ensure
148+
# continuity and avoid numerical issues. This is a common approach in automatic
149+
# differentiation for max functions.
150+
151+
@inline function Base.max(d::ForwardDiff.Dual{Jacobian}, r::Integer)
152+
tag = Val(Jacobian)
153+
x = ForwardDiff.value(d)
154+
partials = ForwardDiff.partials(d)
155+
val = max(x, r)
156+
deriv = 1
157+
return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
158+
end
159+
160+
# @inline function Base.clamp(d::ForwardDiff.Dual{Jacobian}, r1::FT, r2::FT) where {FT}
161+
# tag = Val(Jacobian)
162+
# x = ForwardDiff.value(d)
163+
# partials = ForwardDiff.partials(d)
164+
# val = clamp(x, r1, r2)
165+
# deriv = 1
166+
# return ForwardDiff.dual_definition_retval(tag, val, deriv, partials)
167+
# end
168+
146169
# Ignore all derivative information when comparing Duals to other Numbers. This
147170
# ensures that conditional statements are always equivalent for Duals and Reals.
148171
for func in (:iszero,)

0 commit comments

Comments
 (0)